[vlc-devel] [PATCH 2/3] Qt: Remove manual DPI calculations.

Anatoliy Anischovich lin.aaa.lin at gmail.com
Sat Jul 30 15:38:34 CEST 2016


Since 5.6, Qt use an abstract coordinate system, no need to mess with calculating DPI by ourself.
---
 modules/gui/qt/components/controller.cpp        | 20 ++++--------
 modules/gui/qt/components/controller_widget.cpp |  2 +-
 modules/gui/qt/qt.hpp                           |  2 --
 modules/gui/qt/util/input_slider.cpp            | 42 +++++++------------------
 modules/gui/qt/util/input_slider.hpp            |  2 --
 5 files changed, 19 insertions(+), 49 deletions(-)

diff --git a/modules/gui/qt/components/controller.cpp b/modules/gui/qt/components/controller.cpp
index 98b594e..cffad74 100644
--- a/modules/gui/qt/components/controller.cpp
+++ b/modules/gui/qt/components/controller.cpp
@@ -100,12 +100,9 @@ void AbstractController::setupButton( QAbstractButton *aButton )
     sizePolicy.setHorizontalStretch( 0 );
     sizePolicy.setVerticalStretch( 0 );
 
-    qreal scalingFactorX = static_cast<qreal>(aButton->logicalDpiX()) / DPI_REF_VALUE;
-    qreal scalingFactorY = static_cast<qreal>(aButton->logicalDpiY()) / DPI_REF_VALUE;
-
     aButton->setSizePolicy( sizePolicy );
-    aButton->setFixedSize( QSize( 26.0*scalingFactorX, 26.0*scalingFactorY ) );
-    aButton->setIconSize( QSize( 20.0*scalingFactorX, 20.0*scalingFactorY ) );
+    aButton->setFixedSize( QSize( 26, 26 ) );
+    aButton->setIconSize( QSize( 20, 20 ) );
     aButton->setFocusPolicy( Qt::NoFocus );
 }
 
@@ -167,15 +164,14 @@ void AbstractController::createAndAddWidget( QBoxLayout *controlLayout_,
         buttonGroupLayout = NULL;
     }
 
-    qreal scalingFactorX = static_cast<qreal>(logicalDpiX())/DPI_REF_VALUE;
     /* Special case for SPACERS, who aren't QWidgets */
     if( i_type == WIDGET_SPACER )
     {
-        controlLayout_->addSpacing( static_cast<int>(12*scalingFactorX) );
+        controlLayout_->addSpacing( 12 );
     }
     else if(  i_type == WIDGET_SPACER_EXTEND )
     {
-        controlLayout_->addStretch( static_cast<int>(12*scalingFactorX) );
+        controlLayout_->addStretch( 12 );
     }
     else
     {
@@ -525,12 +521,8 @@ void AbstractController::applyAttributes( QToolButton *tmpButton, bool b_flat, b
             tmpButton->setAutoRaise( b_flat );
         if( b_big )
         {
-
-            qreal scalingFactorX = static_cast<qreal>(tmpButton->logicalDpiX()) / DPI_REF_VALUE;
-            qreal scalingFactorY = static_cast<qreal>(tmpButton->logicalDpiY()) / DPI_REF_VALUE;
-
-            tmpButton->setFixedSize( QSize( 32.0*scalingFactorX, 32.0*scalingFactorY ) );
-            tmpButton->setIconSize( QSize( 26.0*scalingFactorX, 26.0*scalingFactorY ) );
+            tmpButton->setFixedSize( QSize( 32, 32 ) );
+            tmpButton->setIconSize( QSize( 26, 26 ) );
         }
     }
 }
diff --git a/modules/gui/qt/components/controller_widget.cpp b/modules/gui/qt/components/controller_widget.cpp
index a37ad56..edf0660 100644
--- a/modules/gui/qt/components/controller_widget.cpp
+++ b/modules/gui/qt/components/controller_widget.cpp
@@ -50,7 +50,7 @@ SoundWidget::SoundWidget( QWidget *_parent, intf_thread_t * _p_intf,
 
     /* We need a Label for the pix */
     volMuteLabel = new QLabel;
-    volMuteLabelSize = QSize(16.0*logicalDpiX()/DPI_REF_VALUE, 16.0*logicalDpiY()/DPI_REF_VALUE);
+    volMuteLabelSize = QSize( 16, 16 );
     volMuteLabel->setPixmap( QPixmap( ":/toolbar/volume-medium" ).scaled(volMuteLabelSize) );
 
     /* We might need a subLayout too */
diff --git a/modules/gui/qt/qt.hpp b/modules/gui/qt/qt.hpp
index 7276bdc..99ce132 100644
--- a/modules/gui/qt/qt.hpp
+++ b/modules/gui/qt/qt.hpp
@@ -67,8 +67,6 @@ enum{
     NOTIFICATION_ALWAYS = 2,
 };
 
-#define DPI_REF_VALUE 96.0
-
 class QVLCApp;
 class MainInterface;
 class QSettings;
diff --git a/modules/gui/qt/util/input_slider.cpp b/modules/gui/qt/util/input_slider.cpp
index c4ded6c..6fa7f46 100644
--- a/modules/gui/qt/util/input_slider.cpp
+++ b/modules/gui/qt/util/input_slider.cpp
@@ -121,8 +121,7 @@ SeekSlider::SeekSlider( Qt::Orientation q, QWidget *_parent, bool _static )
     setFocusPolicy( Qt::NoFocus );
 
     /* Use the new/classic style */
-    qreal scalingFactorY = static_cast<qreal>(logicalDpiY()) / DPI_REF_VALUE;
-    setMinimumHeight( 18.0 * scalingFactorY );
+    setMinimumHeight( 18 );
     if( !b_classic )
     {
         alternativeStyle = new SeekStyle;
@@ -567,20 +566,14 @@ void SeekSlider::startAnimLoading()
     - Mark Kretschmann
     - Gábor Lehel
    */
-#define WLENGTH_BASE   80 // px
-#define WHEIGHT_BASE   22  // px
+#define WLENGTH   80 // px
+#define WHEIGHT   22  // px
 #define SOUNDMIN  0   // %
 
 SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
                           char *psz_colors, int max )
                         : QAbstractSlider( _parent )
 {
-    qreal scalingFactorX = static_cast<qreal>(logicalDpiX()) / DPI_REF_VALUE;
-    qreal scalingFactorY = static_cast<qreal>(logicalDpiY()) / DPI_REF_VALUE;
-
-    wlength = WLENGTH_BASE * scalingFactorX;
-    wheight = WHEIGHT_BASE * scalingFactorY;
-
     f_step = (float)(_i_step * 10000)
            / (float)((max - SOUNDMIN) * AOUT_VOLUME_DEFAULT);
     setRange( SOUNDMIN, max);
@@ -589,20 +582,9 @@ SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
     b_mouseOutside = true;
     b_isMuted = false;
 
-    const QPixmap pixOutsideRaw( ":/toolbar/volslide-outside" );
-    const QSize pixOutsideSize(
-                static_cast<qreal>(pixOutsideRaw.width()) * scalingFactorX,
-                static_cast<qreal>(pixOutsideRaw.height()) * scalingFactorY
-            );
-    pixOutside = pixOutsideRaw.scaled(pixOutsideSize);
-
-    const QPixmap tempRaw( ":/toolbar/volslide-inside" );
-    const QSize tempSize(
-                    static_cast<qreal>(tempRaw.width()) * scalingFactorX,
-                    static_cast<qreal>(tempRaw.height()) * scalingFactorY
-            );
-    const QPixmap temp = tempRaw.scaled(tempSize);
+    pixOutside = QPixmap( ":/toolbar/volslide-outside" );
 
+    const QPixmap temp( ":/toolbar/volslide-inside" );
     const QBitmap mask( temp.createHeuristicMask() );
 
     setFixedSize( pixOutside.size() );
@@ -611,8 +593,8 @@ SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
     pixGradient2 = QPixmap( mask.size() );
 
     /* Gradient building from the preferences */
-    QLinearGradient gradient( paddingL, 2, wlength + paddingL , 2 );
-    QLinearGradient gradient2( paddingL, 2, wlength + paddingL , 2 );
+    QLinearGradient gradient( paddingL, 2, WLENGTH + paddingL , 2 );
+    QLinearGradient gradient2( paddingL, 2, WLENGTH + paddingL , 2 );
 
     QStringList colorList = qfu( psz_colors ).split( ";" );
     free( psz_colors );
@@ -629,7 +611,7 @@ SoundSlider::SoundSlider( QWidget *_parent, float _i_step,
                     ( background.value() + foreground.value() ) / 2 );
 
     textfont.setPointSize( 7 );
-    textrect.setRect( 0, 0, 34.0*scalingFactorX, 15.0*scalingFactorY );
+    textrect.setRect( 0, 0, 34, 15 );
 
     /* Regular colors */
 #define c(i) colorList.at(i).toInt()
@@ -720,7 +702,7 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
     if( isSliding )
     {
         QRect rect( paddingL - 15,    -1,
-                    wlength + 15 * 2 , wheight + 5 );
+                    WLENGTH + 15 * 2 , WHEIGHT + 5 );
         if( !rect.contains( event->pos() ) )
         { /* We are outside */
             if ( !b_mouseOutside )
@@ -736,7 +718,7 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
     }
     else
     {
-        int i = ( ( event->x() - paddingL ) * maximum() + 40 ) / wlength;
+        int i = ( ( event->x() - paddingL ) * maximum() + 40 ) / WLENGTH;
         i = __MIN( __MAX( 0, i ), maximum() );
         setToolTip( QString("%1  %" ).arg( i ) );
     }
@@ -744,7 +726,7 @@ void SoundSlider::mouseMoveEvent( QMouseEvent *event )
 
 void SoundSlider::changeValue( int x )
 {
-    setValue( (x * maximum() + 40 ) / wlength );
+    setValue( (x * maximum() + 40 ) / WLENGTH );
 }
 
 void SoundSlider::setMuted( bool m )
@@ -763,7 +745,7 @@ void SoundSlider::paintEvent( QPaintEvent *e )
 
     painter.begin( this );
 
-    const int offset = int( ( wlength * value() + 100 ) / maximum() ) + paddingL;
+    const int offset = int( ( WLENGTH * value() + 100 ) / maximum() ) + paddingL;
 
     const QRectF boundsG( 0, 0, offset , paintGradient->height() );
     painter.drawPixmap( boundsG, *paintGradient, boundsG );
diff --git a/modules/gui/qt/util/input_slider.hpp b/modules/gui/qt/util/input_slider.hpp
index ca57b3b..a9559c9 100644
--- a/modules/gui/qt/util/input_slider.hpp
+++ b/modules/gui/qt/util/input_slider.hpp
@@ -162,8 +162,6 @@ private:
     int i_oldvalue; /* Store the old Value before changing */
     float f_step; /* How much do we increase each time we wheel */
     bool b_isMuted;
-    int wlength;
-    int wheight;
 
     QPixmap pixGradient; /* Gradient pix storage */
     QPixmap pixGradient2; /* Muted Gradient pix storage */
-- 
2.7.3



More information about the vlc-devel mailing list