2929
3030#include < libaudqt/libaudqt.h>
3131
32- class AlbumArtQt : public GeneralPlugin {
32+ class AlbumArtQt : public GeneralPlugin
33+ {
3334public:
3435 static constexpr PluginInfo info = {
3536 N_ (" Album Art" ),
@@ -43,10 +44,11 @@ class AlbumArtQt : public GeneralPlugin {
4344 void * get_qt_widget () override ;
4445};
4546
46- class ArtLabel : public QLabel {
47+ class ArtLabel : public QLabel
48+ {
4749public:
4850#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
49- ArtLabel (QWidget * parent = nullptr , Qt::WindowFlags f = Qt::WindowFlags()) : QLabel (parent, f)
51+ ArtLabel (QWidget * parent = nullptr , Qt::WindowFlags f = Qt::WindowFlags ()) : QLabel (parent, f)
5052#else
5153 ArtLabel (QWidget * parent = nullptr , Qt::WindowFlags f = 0 ) : QLabel (parent, f)
5254#endif
@@ -55,7 +57,7 @@ class ArtLabel : public QLabel {
5557 }
5658
5759#if QT_VERSION >= QT_VERSION_CHECK(5, 6, 0)
58- ArtLabel (const QString & text, QWidget * parent = nullptr , Qt::WindowFlags f = Qt::WindowFlags()) : QLabel (text, parent, f)
60+ ArtLabel (const QString & text, QWidget * parent = nullptr , Qt::WindowFlags f = Qt::WindowFlags ()) : QLabel (text, parent, f)
5961#else
6062 ArtLabel (const QString & text, QWidget * parent = nullptr , Qt::WindowFlags f = 0 ) : QLabel (text, parent, f)
6163#endif
@@ -105,8 +107,8 @@ class ArtLabel : public QLabel {
105107 static constexpr int MARGIN = 4 ;
106108
107109 const HookReceiver<ArtLabel>
108- update_hook{" playback ready" , this , &ArtLabel::update_art},
109- clear_hook{" playback stop" , this , &ArtLabel::clear};
110+ update_hook{" playback ready" , this , & ArtLabel::update_art},
111+ clear_hook{" playback stop" , this , & ArtLabel::clear};
110112
111113 QPixmap origPixmap;
112114 QSize origSize;
@@ -117,33 +119,38 @@ class ArtLabel : public QLabel {
117119 setMinimumSize (MARGIN + 1 , MARGIN + 1 );
118120 setAlignment (Qt::AlignCenter);
119121
120- if (aud_drct_get_ready ())
121- update_art ();
122+ if (aud_drct_get_ready ())
123+ update_art ();
122124 }
123125
124126 void drawArt ()
125127 {
126- qreal r = qApp->devicePixelRatio ();
127- if (aud::abs (r - 1.0 ) <= 0.01 &&
128- origSize.width () <= size ().width () - MARGIN &&
129- origSize.height () <= size ().height () - MARGIN) {
128+ qreal r = qApp->devicePixelRatio ();
129+ QSize currentSize = size ();
130+
131+ if (aud::abs (r - 1.0 ) <= 0.01 &&
132+ origSize.width () <= currentSize.width () - MARGIN &&
133+ origSize.height () <= currentSize.height () - MARGIN)
134+ {
130135 // If device pixel ratio is close to 1:1 (within 1%) and art is
131136 // smaller than widget, set pixels directly w/o scaling
132137 setPixmap (origPixmap);
133- } else {
138+ }
139+ else
140+ {
134141 // Otherwise scale image with device pixel ratio, but limit size to
135142 // widget dimensions.
136- auto width = std::min (r * (size () .width () - MARGIN),
137- r * origSize.width ());
138- auto height = std::min (r * (size () .height () - MARGIN),
139- r * origSize.height ());
143+ auto width = std::min (r * (currentSize .width () - MARGIN),
144+ r * origSize.width ());
145+ auto height = std::min (r * (currentSize .height () - MARGIN),
146+ r * origSize.height ());
140147
141148 setPixmap (origPixmap.scaled (width, height, Qt::KeepAspectRatio,
142149 Qt::SmoothTransformation));
143150 }
144151
145152#ifdef Q_OS_MAC
146- repaint ();
153+ repaint ();
147154#endif
148155 }
149156};
0 commit comments