From d8410f1c4a308ebd146387a1d8ef0cb3dbad5314 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 2 May 2021 09:10:32 +0530 Subject: [PATCH] Fix #1926851 [[Enhancement - Viewer] Double-click on image to fit/unfit image](https://bugs.launchpad.net/calibre/+bug/1926851) --- src/calibre/gui2/image_popup.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/image_popup.py b/src/calibre/gui2/image_popup.py index 5876bf962a..298ae11469 100644 --- a/src/calibre/gui2/image_popup.py +++ b/src/calibre/gui2/image_popup.py @@ -9,7 +9,7 @@ __docformat__ = 'restructuredtext en' from qt.core import ( QApplication, QCheckBox, QDialog, QDialogButtonBox, QHBoxLayout, QIcon, QImage, QLabel, QPainter, QPalette, QPixmap, QScrollArea, QSize, QSizePolicy, - QSvgRenderer, Qt, QTransform, QUrl, QVBoxLayout + QSvgRenderer, Qt, QTransform, QUrl, QVBoxLayout, pyqtSignal ) from calibre import fit_image @@ -39,6 +39,8 @@ def render_svg(widget, path): class Label(QLabel): + toggle_fit = pyqtSignal() + def __init__(self, scrollarea): super().__init__(scrollarea) self.setBackgroundRole(QPalette.ColorRole.Text if QApplication.instance().is_dark_theme else QPalette.ColorRole.Base) @@ -82,6 +84,10 @@ class Label(QLabel): if v.isVisible(): v.setValue(v.value() - dy) + def mouseDoubleClickEvent(self, ev): + if ev.button() == Qt.MouseButton.LeftButton: + self.toggle_fit.emit() + class ImageView(QDialog): @@ -101,6 +107,7 @@ class ImageView(QDialog): sa.setAlignment(Qt.AlignmentFlag.AlignHCenter | Qt.AlignmentFlag.AlignVCenter) sa.setBackgroundRole(QPalette.ColorRole.Dark) self.label = l = Label(sa) + l.toggle_fit.connect(self.toggle_fit) sa.setWidget(l) self.bb = bb = QDialogButtonBox(QDialogButtonBox.StandardButton.Close) @@ -189,6 +196,9 @@ class ImageView(QDialog): self.factor = 1 self.adjust_image(1) + def toggle_fit(self): + self.fit_image.toggle() + def adjust_image(self, factor): if self.fit_image.isChecked(): self.set_to_viewport_size() @@ -272,6 +282,7 @@ class ImagePopup(object): if __name__ == '__main__': import sys + from calibre.gui2 import Application app = Application([]) p = QPixmap()