[vlc-commits] qt: scale icons to match user Dpi

Pierre Lamot git at videolan.org
Sat Oct 14 22:26:18 CEST 2017


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Fri Sep 29 10:25:07 2017 +0200| [ba090008fa8de1b6768c6737ea1ac117d878eeb3] | committer: Jean-Baptiste Kempf

qt: scale icons to match user Dpi

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ba090008fa8de1b6768c6737ea1ac117d878eeb3
---

 modules/gui/qt/components/controller.cpp            |  5 ++++-
 modules/gui/qt/components/extended_panels.cpp       |  5 ++++-
 modules/gui/qt/components/playlist/views.cpp        | 17 +++++++++--------
 modules/gui/qt/components/sout/profile_selector.cpp |  9 +++++++--
 modules/gui/qt/dialogs/toolbar.cpp                  |  8 ++++----
 5 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/modules/gui/qt/components/controller.cpp b/modules/gui/qt/components/controller.cpp
index e6769bc755..3d33263fe0 100644
--- a/modules/gui/qt/components/controller.cpp
+++ b/modules/gui/qt/components/controller.cpp
@@ -49,6 +49,8 @@
 #include <QRegion>
 #include <QSignalMapper>
 #include <QTimer>
+#include <QApplication>
+#include <QScreen>
 
 //#define DEBUG_LAYOUT 1
 
@@ -641,7 +643,8 @@ QFrame *AbstractController::telexFrame()
     QSignalMapper *contextButtonMapper = new QSignalMapper( this );
     QToolButton *contextButton = NULL;
     int i_iconminsize = __MAX( 16, telexOn->minimumHeight() );
-    QPixmap iconPixmap( i_iconminsize, i_iconminsize );
+    qreal f_ratio = QApplication::primaryScreen()->devicePixelRatio();
+    QPixmap iconPixmap( i_iconminsize * f_ratio, i_iconminsize * f_ratio );
     iconPixmap.fill( Qt::transparent );
     QPainter iconPixmapPainter( &iconPixmap );
     QLinearGradient iconPixmapPainterGradient( iconPixmap.rect().center() / 2,
diff --git a/modules/gui/qt/components/extended_panels.cpp b/modules/gui/qt/components/extended_panels.cpp
index 82dfe9c3a9..a7160b124b 100644
--- a/modules/gui/qt/components/extended_panels.cpp
+++ b/modules/gui/qt/components/extended_panels.cpp
@@ -42,6 +42,8 @@
 #include <QGraphicsScene>
 #include <QPainter>
 #include <QRegExp>
+#include <QApplication>
+#include <QScreen>
 
 #include "components/extended_panels.hpp"
 #include "dialogs/preferences.hpp"
@@ -1155,7 +1157,8 @@ void Equalizer::build()
     for( i = 0 ; i < NB_PRESETS ; i ++ )
     {
         QGraphicsScene scene;
-        QPixmap icon( 40, 40 );
+        qreal f_ratio = QApplication::primaryScreen()->devicePixelRatio();
+        QPixmap icon( 40 * f_ratio, 40 * f_ratio );
         icon.fill( Qt::transparent );
         QPainter painter( &icon );
         for ( int j = 0; j < eqz_preset_10b[i].i_band; j++ )
diff --git a/modules/gui/qt/components/playlist/views.cpp b/modules/gui/qt/components/playlist/views.cpp
index c99e170827..e01bbaeeb6 100644
--- a/modules/gui/qt/components/playlist/views.cpp
+++ b/modules/gui/qt/components/playlist/views.cpp
@@ -34,6 +34,7 @@
 #include <QDragMoveEvent>
 #include <QMetaType>
 #include <QHeaderView>
+#include <QSvgRenderer>
 
 #include <assert.h>
 
@@ -132,10 +133,8 @@ void PlIconViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
             painter->fillPath( nodeRectPath, option.palette.color( QPalette::Highlight ) );
             painter->setOpacity( 1.0 );
         }
-        QPixmap dirPix( ":/type/node" );
-        QRect r2( dirPix.rect() );
-        r2.moveCenter( r.center() );
-        painter->drawPixmap( r2, dirPix );
+        QSvgRenderer renderer( QString(":/type/node") );
+        renderer.render(painter, r);
     }
 
     // Draw title
@@ -233,10 +232,12 @@ void PlListViewItemDelegate::paint( QPainter * painter, const QStyleOptionViewIt
     //Draw children indicator
     if( !index.data( VLCModel::LEAF_NODE_ROLE ).toBool() )
     {
-        QPixmap dirPix = QPixmap( ":/type/node" );
-        painter->drawPixmap( QPoint( textRect.x(), textRect.center().y() - dirPix.height() / 2 ),
-                             dirPix );
-        textRect.setLeft( textRect.x() + dirPix.width() + 5 );
+        qreal pixsize = fm.height();
+        QSvgRenderer renderer( QString( ":/type/node" ) );
+        renderer.render(painter, QRect(
+                            textRect.x(), textRect.center().y() - pixsize / 2,
+                            pixsize, pixsize ) );
+        textRect.setLeft( textRect.x() + pixsize + 5 );
     }
 
     painter->drawText( textRect,
diff --git a/modules/gui/qt/components/sout/profile_selector.cpp b/modules/gui/qt/components/sout/profile_selector.cpp
index 49213b11ea..11582c9961 100644
--- a/modules/gui/qt/components/sout/profile_selector.cpp
+++ b/modules/gui/qt/components/sout/profile_selector.cpp
@@ -37,6 +37,7 @@
 #include <QSpinBox>
 #include <QUrl>
 #include <QListWidgetItem>
+#include <QFontMetrics>
 
 #include <assert.h>
 #include <vlc_modules.h>
@@ -618,16 +619,20 @@ void VLCProfileEditor::muxSelected()
     SETYESNOSTATE( capsubs, "capsubs" );
     SETYESNOSTATE( capstream, "capstream" );
     SETYESNOSTATE( capchaps, "capchaps" );
+
+    int textsize = QFontMetrics(ui.muxerwarning->font()).ascent();
     if( current->property("module").toString() == "avformat" )
         ui.muxerwarning->setText(
-                    QString( "<img src=\":/menu/info\"/> %1" )
+                    QString( "<img src=\":/menu/info\" width=%2 height=%2/> %1" )
                     .arg( qtr( "This muxer is not provided directly by VLC: It could be missing." ) )
+                    .arg(textsize)
                     );
     else if ( !caps["muxers"].contains( current->property("module").toString() ) &&
               !caps["muxers"].contains( "mux_" + current->property("module").toString() ) )
         ui.muxerwarning->setText(
-                    QString( "<img src=\":/pixmaps/clear\"/> %1" )
+                    QString( "<img src=\":/toobar/clear\" width=%2 height=%2/> %1" )
                     .arg( qtr( "This muxer is missing. Using this profile will fail" ) )
+                    .arg(textsize)
                     );
     else
         ui.muxerwarning->setText("");
diff --git a/modules/gui/qt/dialogs/toolbar.cpp b/modules/gui/qt/dialogs/toolbar.cpp
index 755eaf30d9..904902a307 100644
--- a/modules/gui/qt/dialogs/toolbar.cpp
+++ b/modules/gui/qt/dialogs/toolbar.cpp
@@ -397,16 +397,16 @@ WidgetListing::WidgetListing( intf_thread_t *p_intf, QWidget *_parent )
     setViewMode( QListView::ListMode );
     setTextElideMode( Qt::ElideNone );
     setDragEnabled( true );
-    setIconSize( QSize( 64, 32 ) );
-
+    int icon_size = fontMetrics().height();
+    setIconSize( QSize( icon_size * 2, icon_size ) );
     /* All the buttons do not need a special rendering */
     for( int i = 0; i < BUTTON_MAX; i++ )
     {
         QListWidgetItem *widgetItem = new QListWidgetItem( this );
         widgetItem->setText( qtr( nameL[i] ) );
         widgetItem->setSizeHint( QSize( widgetItem->sizeHint().width(), 32 ) );
-        QPixmap pix( iconL[i] );
-        widgetItem->setIcon( pix.scaled( 16, 16, Qt::KeepAspectRatio, Qt::SmoothTransformation ) );
+
+        widgetItem->setIcon( QIcon( iconL[i] ) );
         widgetItem->setData( Qt::UserRole, QVariant( i ) );
         widgetItem->setToolTip( widgetItem->text() );
         addItem( widgetItem );



More information about the vlc-commits mailing list