[vlc-devel] [PATCH 2/2] qt: improve rendering of central cone for HiDpi

Pierre Lamot pierre at videolabs.io
Wed Nov 15 10:34:29 CET 2017


---
 modules/gui/qt/components/interface_widgets.cpp | 32 +++++++++++--------------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/modules/gui/qt/components/interface_widgets.cpp b/modules/gui/qt/components/interface_widgets.cpp
index 7c34d13614..e4d32ab72c 100644
--- a/modules/gui/qt/components/interface_widgets.cpp
+++ b/modules/gui/qt/components/interface_widgets.cpp
@@ -434,8 +434,9 @@ void BackgroundWidget::paintEvent( QPaintEvent *e )
     int i_maxwidth, i_maxheight;
     QPixmap pixmap = QPixmap( pixmapUrl );
     QPainter painter(this);
-    QBitmap pMask;
-    float f_alpha = 1.0;
+
+    qreal dpr = devicePixelRatioF();
+    pixmap.setDevicePixelRatio( dpr );
 
     i_maxwidth  = __MIN( maximumWidth(), width() ) - MARGIN * 2;
     i_maxheight = __MIN( maximumHeight(), height() ) - MARGIN * 2;
@@ -447,32 +448,27 @@ void BackgroundWidget::paintEvent( QPaintEvent *e )
         /* Scale down the pixmap if the widget is too small */
         if( pixmap.width() > i_maxwidth || pixmap.height() > i_maxheight )
         {
-            pixmap = pixmap.scaled( i_maxwidth, i_maxheight,
+            pixmap = pixmap.scaled( i_maxwidth * dpr, i_maxheight * dpr ,
                             Qt::KeepAspectRatio, Qt::SmoothTransformation );
         }
         else
         if ( b_expandPixmap &&
              pixmap.width() < width() && pixmap.height() < height() )
         {
-            /* Scale up the pixmap to fill widget's size */
-            f_alpha = ( (float) pixmap.height() / (float) height() );
             pixmap = pixmap.scaled(
-                    width() - MARGIN * 2,
-                    height() - MARGIN * 2,
-                    Qt::KeepAspectRatio,
-                    ( f_alpha < .2 )? /* Don't waste cpu when not visible */
-                        Qt::SmoothTransformation:
-                        Qt::FastTransformation
-                    );
-            /* Non agressive alpha compositing when sizing up */
-            pMask = QBitmap( pixmap.width(), pixmap.height() );
-            pMask.fill( QColor::fromRgbF( 1.0, 1.0, 1.0, f_alpha ) );
-            pixmap.setMask( pMask );
+                    (width() - MARGIN * 2) * dpr,
+                    (height() - MARGIN * 2) * dpr ,
+                    Qt::KeepAspectRatio, Qt::SmoothTransformation);
+        }
+        else if (dpr != 1.0)
+        {
+            pixmap = pixmap.scaled( pixmap.width() * dpr, pixmap.height() * dpr,
+                                    Qt::KeepAspectRatio, Qt::SmoothTransformation );
         }
 
         painter.drawPixmap(
-                MARGIN + ( i_maxwidth - pixmap.width() ) /2,
-                MARGIN + ( i_maxheight - pixmap.height() ) /2,
+                MARGIN + ( i_maxwidth * dpr - pixmap.width() ) / (2 * dpr),
+                MARGIN + ( i_maxheight * dpr - pixmap.height() ) / (2 * dpr),
                 pixmap);
     }
     QWidget::paintEvent( e );
-- 
2.14.1



More information about the vlc-devel mailing list