mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get rid of other uses of QLabels to draw icons
This commit is contained in:
parent
d3599a92fe
commit
c89a61234e
@ -4,11 +4,12 @@ __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
|||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
from PyQt5.Qt import (
|
from PyQt5.Qt import (
|
||||||
QDialog, Qt, QPixmap, QIcon, QSize, QVBoxLayout, QHBoxLayout, QLabel,
|
QDialog, Qt, QIcon, QVBoxLayout, QHBoxLayout, QLabel, QCheckBox, QDialogButtonBox
|
||||||
QCheckBox, QDialogButtonBox)
|
)
|
||||||
|
|
||||||
from calibre import confirm_config_name
|
from calibre import confirm_config_name
|
||||||
from calibre.gui2 import dynamic
|
from calibre.gui2 import dynamic
|
||||||
|
from calibre.gui2.dialogs.message_box import Icon
|
||||||
|
|
||||||
|
|
||||||
class Dialog(QDialog):
|
class Dialog(QDialog):
|
||||||
@ -22,16 +23,14 @@ class Dialog(QDialog):
|
|||||||
self.h = h = QHBoxLayout()
|
self.h = h = QHBoxLayout()
|
||||||
l.addLayout(h)
|
l.addLayout(h)
|
||||||
|
|
||||||
self.label = la = QLabel(self)
|
self.icon_widget = Icon(self)
|
||||||
la.setScaledContents(True), la.setMaximumSize(QSize(96, 96)), la.setMinimumSize(QSize(96, 96))
|
self.icon_widget.set_icon(QIcon(I(icon)))
|
||||||
la.setPixmap(QPixmap(I(icon)))
|
|
||||||
la.setObjectName("label")
|
|
||||||
|
|
||||||
self.msg = m = QLabel(self)
|
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)
|
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)
|
self.again = a = QCheckBox((confirm_msg or _("&Show this warning again")), self)
|
||||||
a.setChecked(True), a.setObjectName("again")
|
a.setChecked(True), a.setObjectName("again")
|
||||||
|
@ -19,23 +19,25 @@ from calibre.gui2 import gprefs
|
|||||||
|
|
||||||
class Icon(QWidget):
|
class Icon(QWidget):
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None, size=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
self.pixmap = None
|
self.pixmap = None
|
||||||
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
self.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||||
|
self.size = size or 64
|
||||||
|
|
||||||
def set_icon(self, qicon):
|
def set_icon(self, qicon):
|
||||||
self.pixmap = qicon.pixmap(64, 64)
|
self.pixmap = qicon.pixmap(self.size, self.size)
|
||||||
|
self.update()
|
||||||
|
|
||||||
def sizeHint(self):
|
def sizeHint(self):
|
||||||
return QSize(64, 64)
|
return QSize(self.size, self.size)
|
||||||
|
|
||||||
def paintEvent(self, ev):
|
def paintEvent(self, ev):
|
||||||
if self.pixmap is not None:
|
if self.pixmap is not None:
|
||||||
x = (self.width() - 64) // 2
|
x = (self.width() - self.size) // 2
|
||||||
y = (self.height() - 64) // 2
|
y = (self.height() - self.size) // 2
|
||||||
p = QPainter(self)
|
p = QPainter(self)
|
||||||
p.drawPixmap(x, y, 64, 64, self.pixmap)
|
p.drawPixmap(x, y, self.size, self.size, self.pixmap)
|
||||||
|
|
||||||
|
|
||||||
class MessageBox(QDialog): # {{{
|
class MessageBox(QDialog): # {{{
|
||||||
|
@ -18,6 +18,7 @@ from PyQt5.Qt import (
|
|||||||
from calibre.constants import __appname__, __version__, islinux
|
from calibre.constants import __appname__, __version__, islinux
|
||||||
from calibre.gui2 import (gprefs, min_available_height, available_width,
|
from calibre.gui2 import (gprefs, min_available_height, available_width,
|
||||||
show_restart_warning)
|
show_restart_warning)
|
||||||
|
from calibre.gui2.dialogs.message_box import Icon
|
||||||
from calibre.gui2.preferences import init_gui, AbortCommit, get_plugin
|
from calibre.gui2.preferences import init_gui, AbortCommit, get_plugin
|
||||||
from calibre.customize.ui import preferences_plugins
|
from calibre.customize.ui import preferences_plugins
|
||||||
|
|
||||||
@ -76,9 +77,8 @@ class TitleBar(QWidget):
|
|||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
self.l = l = QHBoxLayout(self)
|
self.l = l = QHBoxLayout(self)
|
||||||
self.icon = i = QLabel('')
|
self.icon = Icon(self, size=ICON_SIZE)
|
||||||
i.setScaledContents(True)
|
l.addWidget(self.icon)
|
||||||
l.addWidget(i), i.setFixedSize(QSize(ICON_SIZE, ICON_SIZE))
|
|
||||||
self.title = QLabel('')
|
self.title = QLabel('')
|
||||||
self.title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
self.title.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
|
||||||
l.addWidget(self.title)
|
l.addWidget(self.title)
|
||||||
@ -91,8 +91,7 @@ class TitleBar(QWidget):
|
|||||||
self.show_msg()
|
self.show_msg()
|
||||||
|
|
||||||
def show_plugin(self, plugin=None):
|
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.set_icon(QIcon(I('lt.png') if plugin is None else plugin.icon))
|
||||||
self.icon.setPixmap(self.pmap)
|
|
||||||
self.title.setText('<h1>' + (_('Preferences') if plugin is None else plugin.gui_name))
|
self.title.setText('<h1>' + (_('Preferences') if plugin is None else plugin.gui_name))
|
||||||
|
|
||||||
def show_msg(self, msg=None):
|
def show_msg(self, msg=None):
|
||||||
@ -421,4 +420,3 @@ if __name__ == '__main__':
|
|||||||
p = Preferences(gui)
|
p = Preferences(gui)
|
||||||
p.exec_()
|
p.exec_()
|
||||||
gui.shutdown()
|
gui.shutdown()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user