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)
|
||||
ip.cover_changed.connect(self.image_pasted_or_dropped)
|
||||
ip.draw_empty_border = True
|
||||
h.addWidget(ip)
|
||||
|
||||
self.vr = vr = QVBoxLayout()
|
||||
|
@ -325,6 +325,7 @@ class ImageView(QWidget, ImageDropMixin):
|
||||
|
||||
BORDER_WIDTH = 1
|
||||
cover_changed = pyqtSignal(object)
|
||||
draw_empty_border = False
|
||||
|
||||
def __init__(self, parent=None, show_size_pref_name=None, default_show_size=False):
|
||||
QWidget.__init__(self, parent)
|
||||
@ -368,7 +369,16 @@ class ImageView(QWidget, ImageDropMixin):
|
||||
def paintEvent(self, event):
|
||||
QWidget.paintEvent(self, event)
|
||||
pmap = self._pixmap
|
||||
p = QPainter(self)
|
||||
p.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform)
|
||||
try:
|
||||
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
|
||||
w, h = pmap.width(), pmap.height()
|
||||
ow, oh = w, h
|
||||
@ -381,8 +391,6 @@ class ImageView(QWidget, ImageDropMixin):
|
||||
x = int(abs(cw - w)/2)
|
||||
y = int(abs(ch - h)/2)
|
||||
target = QRect(x, y, w, h)
|
||||
p = QPainter(self)
|
||||
p.setRenderHints(QPainter.RenderHint.Antialiasing | QPainter.RenderHint.SmoothPixmapTransform)
|
||||
p.drawPixmap(target, pmap)
|
||||
if self.draw_border:
|
||||
pen = QPen()
|
||||
@ -391,6 +399,7 @@ class ImageView(QWidget, ImageDropMixin):
|
||||
p.drawRect(target)
|
||||
if self.show_size:
|
||||
draw_size(p, target, ow, oh)
|
||||
finally:
|
||||
p.end()
|
||||
# }}}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user