1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
|
From: Pratik Patel <pratikpatel8982@gmail.com>
Date: Wed, 16 Oct 2024 19:54:22 +0530
Subject: qt: add option to use dark palette
---
modules/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 6192dbb..2204958 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 43f7108..3b1a95a 100644
--- a/modules/gui/qt/dialogs/firstrun.cpp
+++ b/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();
diff --git a/modules/gui/qt/dialogs/firstrun.hpp b/modules/gui/qt/dialogs/firstrun.hpp
index 6d3a0d0..3854399 100644
--- a/modules/gui/qt/dialogs/firstrun.hpp
+++ b/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:
diff --git a/modules/gui/qt/dialogs/help.cpp b/modules/gui/qt/dialogs/help.cpp
index 4e3b2d8..8f63042 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("<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 );
}
diff --git a/modules/gui/qt/qt.cpp b/modules/gui/qt/qt.cpp
index cefc758..0286a7c 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 e59583a..489ef75 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 ff05004..619227b 100644
--- a/modules/gui/qt/ui/about.ui
+++ b/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>
diff --git a/modules/gui/qt/ui/sprefs_interface.ui b/modules/gui/qt/ui/sprefs_interface.ui
index da2faf5..d8425b3 100644
--- a/modules/gui/qt/ui/sprefs_interface.ui
+++ b/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>
diff --git a/modules/gui/qt/util/qvlcframe.hpp b/modules/gui/qt/util/qvlcframe.hpp
index fc422c2..ab32bc3 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 <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();
|