Skip to content

Commit

Permalink
Add dark mode switch for Linux and Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mrnom authored and uglide committed May 28, 2021
1 parent 87aaea7 commit 80fdf9c
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/app/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <QSslSocket>
#include <QtConcurrent>

#if defined(Q_OS_WINDOWS)
#include "win_darkmode.h"
#if defined(Q_OS_WINDOWS) || defined(Q_OS_LINUX)
#include "darkmode.h"
#include <QStyleFactory>
#endif

Expand Down Expand Up @@ -51,8 +51,8 @@ Application::Application(int& argc, char** argv)
processCmdArgs();
initAppFonts();

#if defined(Q_OS_WINDOWS)
if (isWindowsDarkThemeEnabled()) {
#if defined(Q_OS_WINDOWS) || defined(Q_OS_LINUX)
if (isDarkThemeEnabled()) {
setStyle(QStyleFactory::create("Fusion"));
setPalette(createDarkModePalette());
}
Expand Down
15 changes: 12 additions & 3 deletions src/app/win_darkmode.h → src/app/darkmode.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@
#include <QPalette>
#include <QSettings>

bool isWindowsDarkThemeEnabled() {
QSettings settings(
bool isDarkThemeEnabled() {
#if defined(Q_OS_WINDOWS)
QSettings settings;
QSettings systemSettings(
"HKEY_CURRENT_"
"USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
QSettings::NativeFormat);

return settings.value("AppsUseLightTheme") == 0;
return settings.value("app/darkModeOn", systemSettings.value("AppsUseLightTheme") == 0).toBool();
#elif defined(Q_OS_LINUX)
QSettings settings;

return settings.value("app/darkModeOn", false).toBool();
#else
return false;
#endif
}

QPalette createDarkModePalette() {
Expand Down
31 changes: 26 additions & 5 deletions src/qml/GlobalSettings.qml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ Dialog {
}

GridLayout {
columns: 3
columns: 2
rows: 3
flow: GridLayout.TopToBottom
Layout.fillWidth: true
rowSpacing: 10
columnSpacing: 15
Expand Down Expand Up @@ -97,6 +99,20 @@ Dialog {
onValueChanged: root.restartRequired = true
}

BoolOption {
id: darkMode

Layout.fillWidth: true
Layout.preferredHeight: 30

value: false
label: qsTranslate("RDM","Dark Mode")

visible: !PlatformUtils.isOSX()

onValueChanged: root.restartRequired = true
}

BoolOption {
id: systemProxy

Expand All @@ -114,11 +130,10 @@ Dialog {

Layout.fillWidth: true
Layout.preferredHeight: 30
Layout.columnSpan: 2

value: false
label: qsTranslate("RDM","Use system proxy only for HTTP(S) requests")
}
}
}

SettingsGroupTitle {
Expand All @@ -128,9 +143,12 @@ Dialog {

GridLayout {
columns: 2
rows: 2
flow: GridLayout.TopToBottom
rowSpacing: 10
columnSpacing: 15


ComboboxOption {
id: valueEditorFont

Expand Down Expand Up @@ -179,7 +197,9 @@ Dialog {

GridLayout {
columns: 2
rowSpacing: 30
rows: 3
flow: GridLayout.TopToBottom
rowSpacing: 10
columnSpacing: 20

BoolOption {
Expand All @@ -188,7 +208,7 @@ Dialog {
Layout.fillWidth: true
Layout.preferredHeight: 30

value: Qt.platform.os == "windiws"? true : false
value: Qt.platform.os == "windows"? true : false
label: qsTranslate("RDM","Show namespaced keys on top")
}

Expand Down Expand Up @@ -337,6 +357,7 @@ Dialog {
property alias valueEditorFontSize: valueEditorFontSize.value
property alias valueSizeLimit: valueSizeLimit.value
property alias locale: appLang.value
property alias darkModeOn: darkMode.value
property alias useSystemProxy: systemProxy.value
property alias disableProxyForRedisConnections: disableProxyForRedisConnections.value
}
Expand Down
2 changes: 1 addition & 1 deletion src/rdm.pro
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ HEADERS += \
$$PWD/app/apputils.h \
$$PWD/app/qmlutils.h \
$$PWD/app/qcompress.h \
$$PWD/app/win_darkmode.h \
$$PWD/app/darkmode.h \
$$files($$PWD/app/models/*.h) \
$$files($$PWD/app/models/key-models/*.h) \
$$files($$PWD/modules/connections-tree/*.h) \
Expand Down

0 comments on commit 80fdf9c

Please sign in to comment.