[vlc-commits] qt: expose interface scale factor

Pierre Lamot git at videolan.org
Fri Jun 19 09:54:11 CEST 2020


vlc | branch: master | Pierre Lamot <pierre at videolabs.io> | Mon May 11 11:49:19 2020 +0200| [540a21bd17775cb4e3ad0410d383fbf29bc4e493] | committer: Pierre Lamot

qt: expose interface scale factor

  This allows better handling of fractional scaling and allows user to
  define their own scale factor.

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

 modules/gui/qt/maininterface/main_interface.cpp | 25 +++++++++++++++++++++++++
 modules/gui/qt/maininterface/main_interface.hpp |  7 +++++++
 modules/gui/qt/qt.cpp                           |  5 +++++
 3 files changed, 37 insertions(+)

diff --git a/modules/gui/qt/maininterface/main_interface.cpp b/modules/gui/qt/maininterface/main_interface.cpp
index 320c22e0d8..072c574d08 100644
--- a/modules/gui/qt/maininterface/main_interface.cpp
+++ b/modules/gui/qt/maininterface/main_interface.cpp
@@ -78,6 +78,8 @@
 #include <vlc_actions.h>                    /* Wheel event */
 #include <vlc_vout_window.h>                /* VOUT_ events */
 
+#define VLC_REFERENCE_SCALE_FACTOR 96.
+
 using  namespace vlc::playlist;
 
 // #define DEBUG_INTF
@@ -129,6 +131,13 @@ MainInterface::MainInterface( intf_thread_t *_p_intf )
     /* */
     b_pauseOnMinimize = var_InheritBool( p_intf, "qt-pause-minimized" );
 
+    m_intfUserScaleFactor = var_InheritFloat(p_intf, "qt-interface-scale");
+    winId(); //force window creation
+    QWindow* window = windowHandle();
+    if (window)
+        connect(window, &QWindow::screenChanged, this, &MainInterface::updateIntfScaleFactor);
+    updateIntfScaleFactor();
+
     /* Get the available interfaces */
     m_extraInterfaces = new VLCVarChoiceModel(p_intf, "intf-add", this);
 
@@ -302,6 +311,22 @@ void MainInterface::sendHotkey(Qt::Key key , Qt::KeyboardModifiers modifiers)
     var_SetInteger(vlc_object_instance(p_intf), "key-pressed", vlckey);
 }
 
+void MainInterface::updateIntfScaleFactor()
+{
+    QWindow* window = windowHandle();
+    m_intfScaleFactor = m_intfUserScaleFactor;
+    if (window)
+    {
+        QScreen* screen = window->screen();
+        if (screen)
+        {
+            qreal dpi = screen->logicalDotsPerInch();
+            m_intfScaleFactor = m_intfUserScaleFactor * dpi / VLC_REFERENCE_SCALE_FACTOR;
+        }
+    }
+    emit intfScaleFactorChanged();
+}
+
 inline void MainInterface::initSystray()
 {
     bool b_systrayAvailable = QSystemTrayIcon::isSystemTrayAvailable();
diff --git a/modules/gui/qt/maininterface/main_interface.hpp b/modules/gui/qt/maininterface/main_interface.hpp
index 8566a471c8..cd05b8353b 100644
--- a/modules/gui/qt/maininterface/main_interface.hpp
+++ b/modules/gui/qt/maininterface/main_interface.hpp
@@ -69,6 +69,7 @@ class MainInterface : public QVLCMW
     Q_PROPERTY(bool hasEmbededVideo READ hasEmbededVideo NOTIFY hasEmbededVideoChanged)
     Q_PROPERTY(bool showRemainingTime READ isShowRemainingTime WRITE setShowRemainingTime NOTIFY showRemainingTimeChanged)
     Q_PROPERTY(VLCVarChoiceModel* extraInterfaces READ getExtraInterfaces CONSTANT)
+    Q_PROPERTY(float intfScaleFactor READ getIntfScaleFactor NOTIFY intfScaleFactorChanged)
 
 public:
     /* tors */
@@ -105,6 +106,7 @@ public:
     bool isPlaylistVisible() { return playlistVisible; }
     bool isInterfaceAlwaysOnTop() { return b_interfaceOnTop; }
     inline bool isShowRemainingTime() const  { return m_showRemainingTime; }
+    inline float getIntfScaleFactor() const { return m_intfScaleFactor; }
 
     bool hasEmbededVideo() const;
     VideoSurfaceProvider* getVideoSurfaceProvider() const;
@@ -157,6 +159,8 @@ protected:
     QMap<QWidget *, QSize> stackWidgetsSizes;
 
     /* Flags */
+    float                m_intfUserScaleFactor;
+    float                m_intfScaleFactor;
     unsigned             i_notificationSetting; /// Systray Notifications
     bool                 b_autoresize;          ///< persistent resizable window
     bool                 b_videoFullScreen;     ///< --fullscreen
@@ -215,6 +219,7 @@ protected slots:
     void setRaise();
     void setFullScreen( bool );
     void onInputChanged( bool );
+    void updateIntfScaleFactor();
 
     void sendHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers );
 
@@ -238,6 +243,8 @@ signals:
     void hasEmbededVideoChanged(bool);
     void toolBarConfUpdated();
     void showRemainingTimeChanged(bool);
+
+    void intfScaleFactorChanged();
 };
 
 #endif
diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index 9bab39e933..804a8a9408 100644
--- a/modules/gui/qt/qt.cpp
+++ b/modules/gui/qt/qt.cpp
@@ -153,6 +153,8 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
                              " This option only works with Windows and " \
                              "X11 with composite extensions." )
 
+#define INTERFACE_SCALE_TEXT N_( "User scale factor for the interface, betwwen 0.1 and 10.0" )
+
 #define ERROR_TEXT N_( "Show unimportant error and warnings dialogs" )
 
 #define UPDATER_TEXT N_( "Activate the updates availability notification" )
@@ -281,6 +283,9 @@ vlc_module_begin ()
     add_float_with_range( "qt-fs-opacity", 0.8, 0.1, 1., OPACITY_FS_TEXT,
                           OPACITY_FS_LONGTEXT, false )
 
+    add_float_with_range( "qt-interface-scale", 1.0, 0.1, 10., INTERFACE_SCALE_TEXT,
+                          INTERFACE_SCALE_TEXT, false )
+
     add_bool( "qt-video-autoresize", true, KEEPSIZE_TEXT,
               KEEPSIZE_LONGTEXT, false )
     add_bool( "qt-name-in-title", true, TITLE_TEXT,



More information about the vlc-commits mailing list