[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: qt: Enabled Styles ComboBox on Windows

François Cartegnie (@fcartegnie) gitlab at videolan.org
Mon Oct 21 03:50:37 UTC 2024



François Cartegnie pushed to branch 3.0.x at VideoLAN / VLC


Commits:
93054081 by Pratik Patel at 2024-10-20T20:11:08+00:00
qt: Enabled Styles ComboBox on Windows

- - - - -
dd191b6f by Pratik Patel at 2024-10-20T20:11:08+00:00
qt: add option to use dark palette

- - - - -


9 changed files:

- modules/gui/qt/components/simple_preferences.cpp
- modules/gui/qt/dialogs/firstrun.cpp
- modules/gui/qt/dialogs/firstrun.hpp
- modules/gui/qt/dialogs/help.cpp
- modules/gui/qt/qt.cpp
- modules/gui/qt/qt.hpp
- modules/gui/qt/ui/about.ui
- modules/gui/qt/ui/sprefs_interface.ui
- modules/gui/qt/util/qvlcframe.hpp


Changes:

=====================================
modules/gui/qt/components/simple_preferences.cpp
=====================================
@@ -27,6 +27,7 @@
 # include "config.h"
 #endif
 
+#include "qt.hpp"
 #include "components/simple_preferences.hpp"
 #include "components/preferences_widgets.hpp"
 
@@ -771,11 +772,15 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
                 /* defaults to qt */
                 ui.qt->setChecked( true );
             }
+            
+            if ( var_InheritBool( p_intf, "qt-dark-palette" ) )
+                ui.qtdark->setChecked( true ); /*dark palette*/
+            
             free( psz_intf );
 
             optionWidgets["skinRB"] = ui.skins;
             optionWidgets["qtRB"] = ui.qt;
-#if !defined( _WIN32)
+
             ui.stylesCombo->addItem( qtr("System's default") );
             ui.stylesCombo->addItems( QStyleFactory::keys() );
             ui.stylesCombo->setCurrentIndex( ui.stylesCombo->findText(
@@ -786,10 +791,7 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
 
             CONNECT( ui.stylesCombo, currentIndexChanged( QString ), this, changeStyle( QString ) );
             optionWidgets["styleCB"] = ui.stylesCombo;
-#else
-            ui.stylesCombo->hide();
-            ui.stylesLabel->hide();
-#endif
+
             radioGroup = new QButtonGroup(this);
             radioGroup->addButton( ui.qt, 0 );
             radioGroup->addButton( ui.skins, 1 );
@@ -797,6 +799,20 @@ SPrefsPanel::SPrefsPanel( intf_thread_t *_p_intf, QWidget *_parent,
                      ui.styleStackedWidget, setCurrentIndex( int ) );
             ui.styleStackedWidget->setCurrentIndex( radioGroup->checkedId() );
 
+			CONFIG_BOOL( "qt-dark-palette", qtdark );
+			// Connecting the stateChanged signal of the checkbox
+			connect(ui.qtdark, &QCheckBox::stateChanged, ui.stylesCombo, [combobox = ui.stylesCombo](const int state) {
+				if (state == Qt::CheckState::Checked) {
+					// Set the current style to "Fusion"
+					combobox->setCurrentText(QStringLiteral("Fusion"));
+					// Apply the dark palette
+					applyDarkPalette();
+				} else {
+					// Remove the custom palette and revert to the default
+					QApplication::setPalette(QApplication::style()->standardPalette());
+				}
+			});
+
             CONNECT( ui.minimalviewBox, toggled( bool ),
                      ui.mainPreview, setNormalPreview( bool ) );
             CONFIG_BOOL( "qt-minimal-view", minimalviewBox );


=====================================
modules/gui/qt/dialogs/firstrun.cpp
=====================================
@@ -30,7 +30,7 @@
 #include <QDialogButtonBox>
 
 FirstRun::FirstRun( QWidget *_p, intf_thread_t *_p_intf  )
-         : QWidget( _p ), p_intf( _p_intf )
+         : QVLCDialog( _p, _p_intf), p_intf( _p_intf )
 {
     msg_Dbg( p_intf, "Boring first Run Wizard" );
     buildPrivDialog();


=====================================
modules/gui/qt/dialogs/firstrun.hpp
=====================================
@@ -22,12 +22,10 @@
  *****************************************************************************/
 
 #include "qt.hpp"
-
-#include <QWidget>
-#include <QSettings>
+#include "util/qvlcframe.hpp"
 
 class QCheckBox;
-class FirstRun : public QWidget
+class FirstRun : public QVLCDialog
 {
     Q_OBJECT
     public:


=====================================
modules/gui/qt/dialogs/help.cpp
=====================================
@@ -87,12 +87,23 @@ AboutDialog::AboutDialog( intf_thread_t *_p_intf)
     setWindowRole( "vlc-about" );
     setWindowModality( Qt::WindowModal );
 
-    ui.version->setText(qfu( " " VERSION_MESSAGE ) );
-    ui.title->setText("<html><head/><body><p><span style=\" font-size:26pt; color:#353535;\"> " + qtr( "VLC media player" ) + " </span></p></body></html>");
+    QString linkColor;
+    if ( var_InheritBool( p_intf, "qt-dark-palette" ) ) {
+        ui.horizontalFrame->setStyleSheet("background-color: rgb(10, 10, 10);");
+        ui.footer->setStyleSheet("background-color: rgb(25, 25, 25);");
+        linkColor = "#ffa851";
+    } else {
+        ui.horizontalFrame->setStyleSheet("background-color: rgb(230, 230, 230);");
+        ui.footer->setStyleSheet("background-color: rgb(245, 245, 245);");
+        linkColor = "#0057ae";
+    }
 
-    ui.MainBlabla->setText("<html><head/><body>" +
-    qtr( "<p>VLC media player is a free and open source media player, encoder, and streamer made by the volunteers of the <a href=\"http://www.videolan.org/\"><span style=\" text-decoration: underline; color:#0057ae;\">VideoLAN</span></a> community.</p><p>VLC uses its internal codecs, works on essentially every popular platform, and can read almost all files, CDs, DVDs, network streams, capture cards and other media formats!</p><p><a href=\"http://www.videolan.org/contribute/\"><span style=\" text-decoration: underline; color:#0057ae;\">Help and join us!</span></a>" ) +
-    "</p></body> </html>");
+    ui.version->setText(qfu( " " VERSION_MESSAGE ) );
+    ui.title->setText("<html><head/><body><p><span style=\" font-size:26pt;\"> " + qtr( "VLC media player" ) + " </span></p></body></html>");
+    QString translatedString = qtr( "<p>VLC media player is a free and open source media player, encoder, and streamer made by the volunteers of the <a href=\"http://www.videolan.org/\"><span style=\" text-decoration: underline; color:#0057ae;\">VideoLAN</span></a> community.</p><p>VLC uses its internal codecs, works on essentially every popular platform, and can read almost all files, CDs, DVDs, network streams, capture cards and other media formats!</p><p><a href=\"http://www.videolan.org/contribute/\"><span style=\" text-decoration: underline; color:#0057ae;\">Help and join us!</span></a>" );
+    if ( var_InheritBool( p_intf, "qt-dark-palette" ) )
+        translatedString.remove(QLatin1String("#0057ae"));
+    ui.MainBlabla->setText("<html><head/><body>" + translatedString + "</p></body> </html>");
 
 #if 0
     if( QDate::currentDate().dayOfYear() >= QT_XMAS_JOKE_DAY && var_InheritBool( p_intf, "qt-icon-change" ) )
@@ -116,15 +127,17 @@ AboutDialog::AboutDialog( intf_thread_t *_p_intf)
     /* People who wrote the software */
     ui.authorsPage->setText( qfu( psz_authors ) );
 
-    ui.licenseButton->setText( "<html><head/><body><p><span style=\" text-decoration: underline; color:#0057ae;\">"+qtr( "License" )+"</span></p></body></html>");
-    ui.licenseButton->installEventFilter( this );
-
-    ui.authorsButton->setText( "<html><head/><body><p><span style=\" text-decoration: underline; color:#0057ae;\">"+qtr( "Authors" )+"</span></p></body></html>");
-    ui.authorsButton->installEventFilter( this );
+    ui.licenseButton->setText(QString("<html><head/><body><p><span style=\" text-decoration: underline; color:%1;\">%2</span></p></body></html>")
+                           .arg(linkColor, qtr("License")));
+	ui.licenseButton->installEventFilter(this);
 
-    ui.creditsButton->setText( "<html><head/><body><p><span style=\" text-decoration: underline; color:#0057ae;\">"+qtr( "Credits" )+"</span></p></body></html>");
-    ui.creditsButton->installEventFilter( this );
+	ui.authorsButton->setText(QString("<html><head/><body><p><span style=\" text-decoration: underline; color:%1;\">%2</span></p></body></html>")
+							   .arg(linkColor, qtr("Authors")));
+	ui.authorsButton->installEventFilter(this);
 
+	ui.creditsButton->setText(QString("<html><head/><body><p><span style=\" text-decoration: underline; color:%1;\">%2</span></p></body></html>")
+							   .arg(linkColor, qtr("Credits")));
+	ui.creditsButton->installEventFilter(this);
     ui.version->installEventFilter( this );
 }
 


=====================================
modules/gui/qt/qt.cpp
=====================================
@@ -121,6 +121,9 @@ static void ShowDialog   ( intf_thread_t *, int, int, intf_dialog_args_t * );
 
 #define ERROR_TEXT N_( "Show unimportant error and warnings dialogs" )
 
+#define QT_DARK_TEXT N_( "Applies a dark palette to the style." )
+#define QT_DARK_LONGTEXT N_( "Applies a dark palette to the style. Works best with Fusion style." )
+
 #define UPDATER_TEXT N_( "Activate the updates availability notification" )
 #define UPDATER_LONGTEXT N_( "Activate the automatic notification of new " \
                             "versions of the software. It runs once every " \
@@ -256,6 +259,8 @@ vlc_module_begin ()
                 RECENTPLAY_FILTER_TEXT, RECENTPLAY_FILTER_LONGTEXT, false )
     add_integer( "qt-continue", 1, CONTINUE_PLAYBACK_TEXT, CONTINUE_PLAYBACK_TEXT, false )
             change_integer_list(i_continue_list, psz_continue_list_text )
+    add_bool( "qt-dark-palette", false, QT_DARK_TEXT,
+                  QT_DARK_LONGTEXT, false )	
 
 #ifdef UPDATE_CHECK
     add_bool( "qt-updates-notif", true, UPDATER_TEXT,
@@ -403,6 +408,57 @@ static bool HasWayland( void )
 }
 #endif
 
+bool isDarkPaletteEnabled(intf_thread_t *p_intf) {
+    static const bool darkPalette = var_InheritBool( p_intf, "qt-dark-palette" );
+    return darkPalette;
+}
+
+void applyDarkPalette() {
+    QPalette darkPalette;
+    QColor darkColor("#2d2d2d");
+    QColor gray("#808080");
+    QColor lightGray("#aaaaaa");
+    QColor baseColor("#191919");
+
+    // Active group (the currently focused window)
+    darkPalette.setColor(QPalette::Active, QPalette::Window, darkColor);
+    darkPalette.setColor(QPalette::Active, QPalette::WindowText, Qt::white);
+    darkPalette.setColor(QPalette::Active, QPalette::Base, baseColor);
+    darkPalette.setColor(QPalette::Active, QPalette::AlternateBase, darkColor);
+    darkPalette.setColor(QPalette::Active, QPalette::Button, darkColor);
+    darkPalette.setColor(QPalette::Active, QPalette::ButtonText, Qt::white);
+    darkPalette.setColor(QPalette::Active, QPalette::Text, Qt::white);
+    darkPalette.setColor(QPalette::Active, QPalette::Highlight, QColor("#2A82DA"));
+    darkPalette.setColor(QPalette::Active, QPalette::HighlightedText, Qt::white);
+    darkPalette.setColor(QPalette::Active, QPalette::Link, QColor("#FFA851"));
+
+    // Inactive group (unfocused window)
+    darkPalette.setColor(QPalette::Inactive, QPalette::Window, darkColor);
+    darkPalette.setColor(QPalette::Inactive, QPalette::WindowText, lightGray);
+    darkPalette.setColor(QPalette::Inactive, QPalette::Base, baseColor);
+    darkPalette.setColor(QPalette::Inactive, QPalette::AlternateBase, darkColor);
+    darkPalette.setColor(QPalette::Inactive, QPalette::Button, darkColor);
+    darkPalette.setColor(QPalette::Inactive, QPalette::ButtonText, lightGray);
+    darkPalette.setColor(QPalette::Inactive, QPalette::Text, lightGray);
+    darkPalette.setColor(QPalette::Inactive, QPalette::Highlight, QColor("#2A82DA"));
+    darkPalette.setColor(QPalette::Inactive, QPalette::HighlightedText, lightGray);
+
+    // Disabled group (grayed-out widgets)
+    darkPalette.setColor(QPalette::Disabled, QPalette::Window, darkColor);
+    darkPalette.setColor(QPalette::Disabled, QPalette::WindowText, lightGray);
+    darkPalette.setColor(QPalette::Disabled, QPalette::Base, baseColor);
+    darkPalette.setColor(QPalette::Disabled, QPalette::AlternateBase, darkColor);
+    darkPalette.setColor(QPalette::Disabled, QPalette::Button, lightGray.darker());
+    darkPalette.setColor(QPalette::Disabled, QPalette::ButtonText, gray);
+    darkPalette.setColor(QPalette::Disabled, QPalette::Text, gray);
+    darkPalette.setColor(QPalette::Disabled, QPalette::Highlight, gray);
+    darkPalette.setColor(QPalette::Disabled, QPalette::HighlightedText, gray);
+    darkPalette.setColor(QPalette::Disabled, QPalette::Light, darkColor);
+
+    // Apply the dark palette globally
+    QApplication::setPalette(darkPalette);
+}
+
 /* Open Interface */
 static int Open( vlc_object_t *p_this, bool isDialogProvider )
 {
@@ -637,9 +693,13 @@ static void *ThreadPlatform( void *obj, char *platform_name )
 
     /* Loads and tries to apply the preferred QStyle */
     QString s_style = getSettings()->value( "MainWindow/QtStyle", "" ).toString();
-    if( s_style.compare("") != 0 )
+    if (!s_style.isEmpty())
         QApplication::setStyle( s_style );
 
+    // Apply dark palette only if dark palette is enabled
+    if (isDarkPaletteEnabled(p_intf))
+        applyDarkPalette();
+    
     /* Launch */
     app.exec();
 


=====================================
modules/gui/qt/qt.hpp
=====================================
@@ -63,6 +63,9 @@ enum{
     NOTIFICATION_ALWAYS = 2,
 };
 
+bool isDarkPaletteEnabled(intf_thread_t *);
+void applyDarkPalette();
+
 struct intf_sys_t
 {
     vlc_thread_t thread;


=====================================
modules/gui/qt/ui/about.ui
=====================================
@@ -65,10 +65,6 @@
        <verstretch>0</verstretch>
       </sizepolicy>
      </property>
-     <property name="styleSheet">
-      <string notr="true">background-color: rgb(245, 245, 245);
-color:rgb(0,0,0);</string>
-     </property>
      <layout class="QGridLayout" name="gridLayout">
       <item row="2" column="2" rowspan="4">
        <widget class="QStackedWidget" name="stackedWidget">
@@ -288,9 +284,6 @@ margin-bottom: 6px;</string>
        <height>60</height>
       </size>
      </property>
-     <property name="styleSheet">
-      <string notr="true">background-color: rgb(230, 230, 230);color:rgb(0,0,0);</string>
-     </property>
      <layout class="QHBoxLayout" name="horizontalLayout_2">
       <property name="margin">
        <number>0</number>


=====================================
modules/gui/qt/ui/sprefs_interface.ui
=====================================
@@ -284,6 +284,13 @@
              <item row="11" column="2" colspan="2">
               <widget class="QComboBox" name="autoRaiseComboBox"/>
              </item>
+             <item row="4" column="2">
+              <widget class="QCheckBox" name="qtdark">
+               <property name="text">
+                <string>Use a dark palette</string>
+               </property>
+              </widget>
+             </item>
             </layout>
            </widget>
           </item>


=====================================
modules/gui/qt/util/qvlcframe.hpp
=====================================
@@ -36,6 +36,47 @@
 
 #include "qt.hpp"
 
+#ifdef _WIN32
+    #include <QLibrary>
+    #include <QSysInfo>
+    #include <dwmapi.h>
+
+    inline bool setImmersiveDarkModeAttribute(HWND hwnd, bool enable) {
+        typedef HRESULT(WINAPI *DwmSetWindowAttributeFunc)(HWND, DWORD, LPCVOID, DWORD);
+        static const auto dwmSetWindowAttributeFunc = []() -> DwmSetWindowAttributeFunc {
+            if (QSysInfo::windowsVersion() < QSysInfo::WinVersion::WV_WINDOWS10)
+                return nullptr;
+
+            QLibrary dwmapidll("dwmapi");
+            return reinterpret_cast<DwmSetWindowAttributeFunc>(dwmapidll.resolve("DwmSetWindowAttribute"));
+        }();
+
+        if (!dwmSetWindowAttributeFunc || !hwnd)
+            return false;
+
+        const BOOL pvAttribute = enable ? TRUE : FALSE;
+
+        enum Attribute : DWORD {
+            DWMWA_USE_IMMERSIVE_DARK_MODE = 20,
+            DWMWA_USE_DARK_MODE_UNDOCUMENTED = 19
+        };
+
+        return SUCCEEDED(dwmSetWindowAttributeFunc(hwnd, Attribute::DWMWA_USE_IMMERSIVE_DARK_MODE, &pvAttribute, sizeof(pvAttribute)))
+            || SUCCEEDED(dwmSetWindowAttributeFunc(hwnd, Attribute::DWMWA_USE_DARK_MODE_UNDOCUMENTED, &pvAttribute, sizeof(pvAttribute)));
+    }
+
+    // Overloaded function to apply dark mode to QWidget*
+    inline bool setImmersiveDarkModeAttribute(QWidget *widget) {
+        if (widget->isWindow()) {
+            widget->ensurePolished();
+            HWND hwnd = (HWND)widget->winId();  // Get native window handle
+            return setImmersiveDarkModeAttribute(hwnd,true);  // Call the HWND version
+        }
+        return false;
+    }
+
+#endif
+
 class QVLCTools
 {
    public:
@@ -102,7 +143,12 @@ class QVLCFrame : public QWidget
 {
 public:
     QVLCFrame( intf_thread_t *_p_intf ) : QWidget( NULL ), p_intf( _p_intf )
-    {};
+    {
+#ifdef Q_OS_WIN
+        if (isDarkPaletteEnabled(p_intf))
+            setImmersiveDarkModeAttribute(this);
+#endif
+	};
     virtual ~QVLCFrame()   {};
 
     void toggleVisible()
@@ -155,6 +201,10 @@ public:
     {
         setWindowFlags( Qt::Dialog|Qt::WindowMinMaxButtonsHint|
                         Qt::WindowSystemMenuHint|Qt::WindowCloseButtonHint );
+#ifdef Q_OS_WIN
+        if (isDarkPaletteEnabled(p_intf))
+            setImmersiveDarkModeAttribute(this);
+#endif
     }
     virtual ~QVLCDialog() {};
     void toggleVisible()
@@ -191,7 +241,13 @@ protected:
 class QVLCMW : public QMainWindow
 {
 public:
-    QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf ){}
+    QVLCMW( intf_thread_t *_p_intf ) : QMainWindow( NULL ), p_intf( _p_intf )
+	{
+#ifdef Q_OS_WIN
+        if (isDarkPaletteEnabled(p_intf))
+            setImmersiveDarkModeAttribute(this);
+#endif
+	}
     void toggleVisible()
     {
         if( isVisible() ) hide();



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ae1fe0e3f754cc4bf5bdd278a609f2c43a309dae...dd191b6f27a364a04c2a838b6a97aa8c9411a72e

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/ae1fe0e3f754cc4bf5bdd278a609f2c43a309dae...dd191b6f27a364a04c2a838b6a97aa8c9411a72e
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list