From c89a61234e1e107db853db92dc0af97e2796a77a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 2 Nov 2016 18:06:00 +0530 Subject: [PATCH] Get rid of other uses of QLabels to draw icons --- src/calibre/gui2/dialogs/confirm_delete.py | 15 +++++++-------- src/calibre/gui2/dialogs/message_box.py | 14 ++++++++------ src/calibre/gui2/preferences/main.py | 10 ++++------ 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/calibre/gui2/dialogs/confirm_delete.py b/src/calibre/gui2/dialogs/confirm_delete.py index 9681064398..4a4ab2d008 100644 --- a/src/calibre/gui2/dialogs/confirm_delete.py +++ b/src/calibre/gui2/dialogs/confirm_delete.py @@ -4,11 +4,12 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' from PyQt5.Qt import ( - QDialog, Qt, QPixmap, QIcon, QSize, QVBoxLayout, QHBoxLayout, QLabel, - QCheckBox, QDialogButtonBox) + QDialog, Qt, QIcon, QVBoxLayout, QHBoxLayout, QLabel, QCheckBox, QDialogButtonBox +) from calibre import confirm_config_name from calibre.gui2 import dynamic +from calibre.gui2.dialogs.message_box import Icon class Dialog(QDialog): @@ -22,16 +23,14 @@ class Dialog(QDialog): self.h = h = QHBoxLayout() l.addLayout(h) - self.label = la = QLabel(self) - la.setScaledContents(True), la.setMaximumSize(QSize(96, 96)), la.setMinimumSize(QSize(96, 96)) - la.setPixmap(QPixmap(I(icon))) - la.setObjectName("label") + self.icon_widget = Icon(self) + self.icon_widget.set_icon(QIcon(I(icon))) self.msg = m = QLabel(self) - m.setMinimumWidth(300), m.setWordWrap(True), m.setObjectName("msg") + m.setMinimumWidth(350), m.setWordWrap(True), m.setObjectName("msg") m.setText(msg) - h.addWidget(la), h.addSpacing(10), h.addWidget(m) + h.addWidget(self.icon_widget), h.addSpacing(10), h.addWidget(m) self.again = a = QCheckBox((confirm_msg or _("&Show this warning again")), self) a.setChecked(True), a.setObjectName("again") diff --git a/src/calibre/gui2/dialogs/message_box.py b/src/calibre/gui2/dialogs/message_box.py index dd764f7d2b..e613ffd9ce 100644 --- a/src/calibre/gui2/dialogs/message_box.py +++ b/src/calibre/gui2/dialogs/message_box.py @@ -19,23 +19,25 @@ from calibre.gui2 import gprefs class Icon(QWidget): - def __init__(self, parent=None): + def __init__(self, parent=None, size=None): QWidget.__init__(self, parent) self.pixmap = None self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) + self.size = size or 64 def set_icon(self, qicon): - self.pixmap = qicon.pixmap(64, 64) + self.pixmap = qicon.pixmap(self.size, self.size) + self.update() def sizeHint(self): - return QSize(64, 64) + return QSize(self.size, self.size) def paintEvent(self, ev): if self.pixmap is not None: - x = (self.width() - 64) // 2 - y = (self.height() - 64) // 2 + x = (self.width() - self.size) // 2 + y = (self.height() - self.size) // 2 p = QPainter(self) - p.drawPixmap(x, y, 64, 64, self.pixmap) + p.drawPixmap(x, y, self.size, self.size, self.pixmap) class MessageBox(QDialog): # {{{ diff --git a/src/calibre/gui2/preferences/main.py b/src/calibre/gui2/preferences/main.py index b5ece35531..fc7bab7cb0 100644 --- a/src/calibre/gui2/preferences/main.py +++ b/src/calibre/gui2/preferences/main.py @@ -18,6 +18,7 @@ from PyQt5.Qt import ( from calibre.constants import __appname__, __version__, islinux from calibre.gui2 import (gprefs, min_available_height, available_width, show_restart_warning) +from calibre.gui2.dialogs.message_box import Icon from calibre.gui2.preferences import init_gui, AbortCommit, get_plugin from calibre.customize.ui import preferences_plugins @@ -76,9 +77,8 @@ class TitleBar(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.l = l = QHBoxLayout(self) - self.icon = i = QLabel('') - i.setScaledContents(True) - l.addWidget(i), i.setFixedSize(QSize(ICON_SIZE, ICON_SIZE)) + self.icon = Icon(self, size=ICON_SIZE) + l.addWidget(self.icon) self.title = QLabel('') self.title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) l.addWidget(self.title) @@ -91,8 +91,7 @@ class TitleBar(QWidget): self.show_msg() def show_plugin(self, plugin=None): - self.pmap = (QIcon(I('lt.png') if plugin is None else plugin.icon)).pixmap(ICON_SIZE, ICON_SIZE) - self.icon.setPixmap(self.pmap) + self.icon.set_icon(QIcon(I('lt.png') if plugin is None else plugin.icon)) self.title.setText('

' + (_('Preferences') if plugin is None else plugin.gui_name)) def show_msg(self, msg=None): @@ -421,4 +420,3 @@ if __name__ == '__main__': p = Preferences(gui) p.exec_() gui.shutdown() -