From 6486d97ee3052e3765721f8adf25b0cd75b59680 Mon Sep 17 00:00:00 2001 From: beville Date: Mon, 4 Feb 2013 17:24:48 +0000 Subject: [PATCH] Added modal image quick popup git-svn-id: http://comictagger.googlecode.com/svn/trunk@405 6c5673fe-1810-88d6-992b-cd32ca31540c --- coverimagewidget.py | 26 +++++++++++++ imagepopup.py | 90 +++++++++++++++++++++++++++++++++++++++++++++ imagepopup.ui | 38 +++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 imagepopup.py create mode 100644 imagepopup.ui diff --git a/coverimagewidget.py b/coverimagewidget.py index 0109a3f..5c72a86 100644 --- a/coverimagewidget.py +++ b/coverimagewidget.py @@ -30,6 +30,28 @@ from options import MetaDataStyle from comicvinetalker import ComicVineTalker, ComicVineTalkerException from imagefetcher import ImageFetcher from pageloader import PageLoader +from imagepopup import ImagePopup + +# helper func to allow a label to be clickable +def clickable(widget): + + class Filter(QObject): + + dblclicked = pyqtSignal() + + def eventFilter(self, obj, event): + + if obj == widget: + if event.type() == QEvent.MouseButtonDblClick: + self.dblclicked.emit() + return True + + return False + + filter = Filter(widget) + widget.installEventFilter(filter) + return filter.dblclicked + class CoverImageWidget(QWidget): @@ -53,6 +75,7 @@ class CoverImageWidget(QWidget): self.btnLeft.clicked.connect( self.decrementImage ) self.btnRight.clicked.connect( self.incrementImage ) self.resetWidget() + clickable(self.lblImage).connect(self.showPopup) self.updateContent() @@ -220,3 +243,6 @@ class CoverImageWidget(QWidget): img_h = scaled_pixmap.height() self.lblImage.resize( img_w, img_h ) self.lblImage.move( (frame_w - img_w)/2, (frame_h - img_h)/2 ) + + def showPopup( self ): + self.popup = ImagePopup(self, self.current_pixmap) diff --git a/imagepopup.py b/imagepopup.py new file mode 100644 index 0000000..82c58a3 --- /dev/null +++ b/imagepopup.py @@ -0,0 +1,90 @@ +""" +A PyQT4 widget to display a popup image +""" + +""" +Copyright 2012 Anthony Beville + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +""" + +import sys +from PyQt4 import QtCore, QtGui, uic +import os +from settings import ComicTaggerSettings + + +class ImagePopup(QtGui.QDialog): + + def __init__(self, parent, image_pixmap): + super(ImagePopup, self).__init__(parent) + + uic.loadUi(os.path.join(ComicTaggerSettings.baseDir(), 'imagepopup.ui' ), self) + + QtGui.QApplication.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor)) + + self.setWindowModality(QtCore.Qt.WindowModal) + self.setWindowFlags(QtCore.Qt.Popup) + self.setWindowState(QtCore.Qt.WindowFullScreen) + + self.imagePixmap = image_pixmap + + screen_size = QtGui.QDesktopWidget().screenGeometry() + self.resize(screen_size.width(), screen_size.height()) + self.move( 0, 0) + + # This is a total hack. Uses a snapshot of the desktop, and overlays a + # translucent screen over it. + self.desktopBg = QtGui.QPixmap.grabWindow(QtGui.QApplication.desktop ().winId(), + 0,0, screen_size.width(), screen_size.height()) + bg = QtGui.QPixmap(os.path.join(ComicTaggerSettings.baseDir(), 'graphics/popup_bg.png' )) + self.clientBgPixmap = bg.scaled(screen_size.width(), screen_size.height()) + self.setMask(self.clientBgPixmap.mask()) + + self.applyImagePixmap() + self.showFullScreen() + self.raise_( ) + QtGui.QApplication.restoreOverrideCursor() + + + def closeme( self ): + self.close() + + def paintEvent (self, event): + self.painter = QtGui.QPainter(self) + self.painter.setRenderHint(QtGui.QPainter.Antialiasing) + self.painter.drawPixmap(0, 0, self.desktopBg) + self.painter.drawPixmap(0, 0, self.clientBgPixmap) + + self.painter.end() + + def applyImagePixmap( self ): + win_h = self.height() + win_w = self.width() + + if self.imagePixmap.width() > win_w or self.imagePixmap.height() > win_h: + # scale the pixmap to fit in the frame + display_pixmap = self.imagePixmap.scaled(win_w, win_h, QtCore.Qt.KeepAspectRatio) + self.lblImage.setPixmap( display_pixmap ) + else: + display_pixmap = self.imagePixmap + self.lblImage.setPixmap( display_pixmap ) + + # move and resize the label to be centered in the fame + img_w = display_pixmap.width() + img_h = display_pixmap.height() + self.lblImage.resize( img_w, img_h ) + self.lblImage.move( (win_w - img_w)/2, (win_h - img_h)/2 ) + + def mousePressEvent( self , event): + self.close() diff --git a/imagepopup.ui b/imagepopup.ui new file mode 100644 index 0000000..23efd89 --- /dev/null +++ b/imagepopup.ui @@ -0,0 +1,38 @@ + + + Form + + + Qt::ApplicationModal + + + + 0 + 0 + 817 + 455 + + + + Form + + + 1.000000000000000 + + + + + 300 + 120 + 66 + 17 + + + + + + + + + +