mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Draw a border for the image preview widget even when empty
This commit is contained in:
parent
e26df3b529
commit
0be966db4a
@ -80,6 +80,7 @@ class AskImage(Dialog):
|
|||||||
|
|
||||||
self.image_preview = ip = ImageView(self, 'insert-image-for-notes-preview', True)
|
self.image_preview = ip = ImageView(self, 'insert-image-for-notes-preview', True)
|
||||||
ip.cover_changed.connect(self.image_pasted_or_dropped)
|
ip.cover_changed.connect(self.image_pasted_or_dropped)
|
||||||
|
ip.draw_empty_border = True
|
||||||
h.addWidget(ip)
|
h.addWidget(ip)
|
||||||
|
|
||||||
self.vr = vr = QVBoxLayout()
|
self.vr = vr = QVBoxLayout()
|
||||||
|
@ -325,6 +325,7 @@ class ImageView(QWidget, ImageDropMixin):
|
|||||||
|
|
||||||
BORDER_WIDTH = 1
|
BORDER_WIDTH = 1
|
||||||
cover_changed = pyqtSignal(object)
|
cover_changed = pyqtSignal(object)
|
||||||
|
draw_empty_border = False
|
||||||
|
|
||||||
def __init__(self, parent=None, show_size_pref_name=None, default_show_size=False):
|
def __init__(self, parent=None, show_size_pref_name=None, default_show_size=False):
|
||||||
QWidget.__init__(self, parent)
|
QWidget.__init__(self, parent)
|
||||||
@ -368,7 +369,16 @@ class ImageView(QWidget, ImageDropMixin):
|
|||||||
def paintEvent(self, event):
|
def paintEvent(self, event):
|
||||||
QWidget.paintEvent(self, event)
|
QWidget.paintEvent(self, event)
|
||||||
pmap = self._pixmap
|
pmap = self._pixmap
|
||||||
|
p = QPainter(self)
|
||||||
|
p.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform)
|
||||||
|
try:
|
||||||
if pmap.isNull():
|
if pmap.isNull():
|
||||||
|
if self.draw_empty_border:
|
||||||
|
pen = QPen()
|
||||||
|
pen.setWidth(self.BORDER_WIDTH)
|
||||||
|
p.setPen(pen)
|
||||||
|
p.drawRect(self.rect())
|
||||||
|
p.end()
|
||||||
return
|
return
|
||||||
w, h = pmap.width(), pmap.height()
|
w, h = pmap.width(), pmap.height()
|
||||||
ow, oh = w, h
|
ow, oh = w, h
|
||||||
@ -381,8 +391,6 @@ class ImageView(QWidget, ImageDropMixin):
|
|||||||
x = int(abs(cw - w)/2)
|
x = int(abs(cw - w)/2)
|
||||||
y = int(abs(ch - h)/2)
|
y = int(abs(ch - h)/2)
|
||||||
target = QRect(x, y, w, h)
|
target = QRect(x, y, w, h)
|
||||||
p = QPainter(self)
|
|
||||||
p.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform)
|
|
||||||
p.drawPixmap(target, pmap)
|
p.drawPixmap(target, pmap)
|
||||||
if self.draw_border:
|
if self.draw_border:
|
||||||
pen = QPen()
|
pen = QPen()
|
||||||
@ -391,6 +399,7 @@ class ImageView(QWidget, ImageDropMixin):
|
|||||||
p.drawRect(target)
|
p.drawRect(target)
|
||||||
if self.show_size:
|
if self.show_size:
|
||||||
draw_size(p, target, ow, oh)
|
draw_size(p, target, ow, oh)
|
||||||
|
finally:
|
||||||
p.end()
|
p.end()
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user