From 5140a2e774545dc7cecf247048a3d66bc71a5710 Mon Sep 17 00:00:00 2001
From: Pratik Patel
Date: Wed, 16 Oct 2024 19:54:22 +0530
Subject: [PATCH] qt: add option to use dark palette
Gbp-Pq: Name 0081-qt-add-option-to-use-dark-palette.patch
---
.../gui/qt/components/simple_preferences.cpp | 19 ++++++
modules/gui/qt/dialogs/firstrun.cpp | 2 +-
modules/gui/qt/dialogs/firstrun.hpp | 6 +-
modules/gui/qt/dialogs/help.cpp | 37 +++++++----
modules/gui/qt/qt.cpp | 62 ++++++++++++++++++-
modules/gui/qt/qt.hpp | 3 +
modules/gui/qt/ui/about.ui | 7 ---
modules/gui/qt/ui/sprefs_interface.ui | 7 +++
modules/gui/qt/util/qvlcframe.hpp | 60 +++++++++++++++++-
9 files changed, 176 insertions(+), 27 deletions(-)
diff --git a/modules/gui/qt/components/simple_preferences.cpp b/modules/gui/qt/components/simple_preferences.cpp
index 6192dbb7..22049585 100644
--- a/modules/gui/qt/components/simple_preferences.cpp
+++ b/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,6 +772,10 @@ 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;
@@ -797,6 +802,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 );
diff --git a/modules/gui/qt/dialogs/firstrun.cpp b/modules/gui/qt/dialogs/firstrun.cpp
index 43f7108b..3b1a95a1 100644
--- a/modules/gui/qt/dialogs/firstrun.cpp
+++ b/modules/gui/qt/dialogs/firstrun.cpp
@@ -30,7 +30,7 @@
#include
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();
diff --git a/modules/gui/qt/dialogs/firstrun.hpp b/modules/gui/qt/dialogs/firstrun.hpp
index 6d3a0d06..3854399b 100644
--- a/modules/gui/qt/dialogs/firstrun.hpp
+++ b/modules/gui/qt/dialogs/firstrun.hpp
@@ -22,12 +22,10 @@
*****************************************************************************/
#include "qt.hpp"
-
-#include
-#include
+#include "util/qvlcframe.hpp"
class QCheckBox;
-class FirstRun : public QWidget
+class FirstRun : public QVLCDialog
{
Q_OBJECT
public:
diff --git a/modules/gui/qt/dialogs/help.cpp b/modules/gui/qt/dialogs/help.cpp
index 4e3b2d8b..8f630427 100644
--- a/modules/gui/qt/dialogs/help.cpp
+++ b/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(" " + qtr( "VLC media player" ) + "
");
+ 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("" +
- qtr( "VLC media player is a free and open source media player, encoder, and streamer made by the volunteers of the VideoLAN community.
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!
Help and join us!" ) +
- "
");
+ ui.version->setText(qfu( " " VERSION_MESSAGE ) );
+ ui.title->setText(" " + qtr( "VLC media player" ) + "
");
+ QString translatedString = qtr( "VLC media player is a free and open source media player, encoder, and streamer made by the volunteers of the VideoLAN community.
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!
Help and join us!" );
+ if ( var_InheritBool( p_intf, "qt-dark-palette" ) )
+ translatedString.remove(QLatin1String("#0057ae"));
+ ui.MainBlabla->setText("
" + translatedString + " ");
#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( ""+qtr( "License" )+"
");
- ui.licenseButton->installEventFilter( this );
-
- ui.authorsButton->setText( ""+qtr( "Authors" )+"
");
- ui.authorsButton->installEventFilter( this );
+ ui.licenseButton->setText(QString("%2
")
+ .arg(linkColor, qtr("License")));
+ ui.licenseButton->installEventFilter(this);
- ui.creditsButton->setText( ""+qtr( "Credits" )+"
");
- ui.creditsButton->installEventFilter( this );
+ ui.authorsButton->setText(QString("%2
")
+ .arg(linkColor, qtr("Authors")));
+ ui.authorsButton->installEventFilter(this);
+ ui.creditsButton->setText(QString("%2
")
+ .arg(linkColor, qtr("Credits")));
+ ui.creditsButton->installEventFilter(this);
ui.version->installEventFilter( this );
}
diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index cefc7583..0286a7c2 100644
--- a/modules/gui/qt/qt.cpp
+++ b/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();
diff --git a/modules/gui/qt/qt.hpp b/modules/gui/qt/qt.hpp
index e59583ab..489ef75a 100644
--- a/modules/gui/qt/qt.hpp
+++ b/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;
diff --git a/modules/gui/qt/ui/about.ui b/modules/gui/qt/ui/about.ui
index ff05004f..619227b4 100644
--- a/modules/gui/qt/ui/about.ui
+++ b/modules/gui/qt/ui/about.ui
@@ -65,10 +65,6 @@
0
-
- background-color: rgb(245, 245, 245);
-color:rgb(0,0,0);
-
-
@@ -288,9 +284,6 @@ margin-bottom: 6px;
60
-
- background-color: rgb(230, 230, 230);color:rgb(0,0,0);
-
0
diff --git a/modules/gui/qt/ui/sprefs_interface.ui b/modules/gui/qt/ui/sprefs_interface.ui
index da2faf54..d8425b38 100644
--- a/modules/gui/qt/ui/sprefs_interface.ui
+++ b/modules/gui/qt/ui/sprefs_interface.ui
@@ -284,6 +284,13 @@
-
+ -
+
+
+ Use a dark palette
+
+
+
diff --git a/modules/gui/qt/util/qvlcframe.hpp b/modules/gui/qt/util/qvlcframe.hpp
index fc422c2e..ab32bc3b 100644
--- a/modules/gui/qt/util/qvlcframe.hpp
+++ b/modules/gui/qt/util/qvlcframe.hpp
@@ -36,6 +36,47 @@
#include "qt.hpp"
+#ifdef _WIN32
+ #include
+ #include
+ #include
+
+ 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(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();
--
2.30.2