CoverArtBox: preserve cover art aspect ratio on drawing

Cover is now placed correctly over the cover shadow, aspect ratio
is preserved.
This commit is contained in:
Laurent Monin
2013-01-11 18:10:55 +01:00
parent d3fcd06e32
commit 23c8271fbc

View File

@@ -101,10 +101,15 @@ class CoverArtBox(QtGui.QGroupBox):
pixmap = QtGui.QPixmap()
pixmap.loadFromData(self.data["data"])
if not pixmap.isNull():
offx, offy, w, h = (1, 1, 121, 121)
cover = QtGui.QPixmap(self.shadow)
pixmap = pixmap.scaled(121, 121, QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.SmoothTransformation)
pixmap = pixmap.scaled(w, h, QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
painter = QtGui.QPainter(cover)
painter.drawPixmap(1, 1, pixmap)
bgcolor = QtGui.QColor.fromRgb(0, 0, 0, 128)
painter.fillRect(QtCore.QRectF(offx, offy, w, h), bgcolor)
x = offx + (w - pixmap.width()) / 2
y = offy + (h - pixmap.height()) / 2
painter.drawPixmap(x, y, pixmap)
painter.end()
self.coverArt.setPixmap(cover)