Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions qml/Shortcuts.qml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Popup {
<tr><th colspan='2'>Tools</th></tr>
<tr><td>%1+W</td><td>show wavelength calculator</td></tr>
<tr><td>%1+D</td><td>toggle dark mode</td></tr>
<tr><td>%1+Shift+D</td><td>toggle system brightness</td></tr>
<tr><td>F1</td><td>show keys combinations</td></tr>
<tr><td>F2</td><td>show info</td></tr>
<tr><td>F3</td><td>check for update</td></tr>
Expand Down
13 changes: 12 additions & 1 deletion qml/menu/Top.qml
Original file line number Diff line number Diff line change
Expand Up @@ -210,13 +210,24 @@ MenuBar {
MenuItem {
id: darkModeSelect
text: qsTr("&Dark Mode")
shortcut: "Ctrl+D"
shortcut: applicationAppearance.useSystemBrightness ? null : "Ctrl+D"
checkable: true
visible: applicationAppearance.useSystemBrightness ? false : true
checked: applicationAppearance.darkMode
onCheckedChanged: {
applicationAppearance.darkMode = darkModeSelect.checked;
}
}
MenuItem {
id: systemBrightness
text: qsTr("&Use system brightness")
shortcut: "Ctrl+Shift+D"
checkable: true
checked: applicationAppearance.useSystemBrightness
onCheckedChanged: {
applicationAppearance.useSystemBrightness = systemBrightness.checked;
}
}
MenuItem {
id: calculator
text: qsTr("&Calculator")
Expand Down
41 changes: 35 additions & 6 deletions src/common/appearance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ bool Appearance::darkMode() const

void Appearance::setDarkMode(const bool &setDark)
{
if (setDark == darkMode()) {
if (setDark == darkMode())
{
return;
}
auto store = settings();
Expand All @@ -53,6 +54,29 @@ void Appearance::setDarkMode(const bool &setDark)
emit darkModeChanged(setDark);
}

bool Appearance::useSystemBrightness() const
{
auto store = settings();
Q_ASSERT(store);

auto value = store->value("useSystemBrightness");
return value.isValid() ? value.toBool() : true;
}

void Appearance::setUseSystemBrightness(const bool &setSystemBrightness)
{
if (setSystemBrightness == useSystemBrightness())
{
return;
}
auto store = settings();
Q_ASSERT(store);

store->setValue("useSystemBrightness", setSystemBrightness);
emit useSystemBrightnessChanged(setSystemBrightness);
setDarkModeFromSystem();
}

bool Appearance::experimentFunctions() const
{
auto store = settings();
Expand All @@ -64,7 +88,8 @@ bool Appearance::experimentFunctions() const

void Appearance::setExperimentFunctions(bool value)
{
if (value == experimentFunctions()) {
if (value == experimentFunctions())
{
return;
}
auto store = settings();
Expand Down Expand Up @@ -108,10 +133,13 @@ int Appearance::cursorOffset() const

bool Appearance::setDarkModeFromSystem()
{
bool darkMode = darkModeFromSystem();
if (useSystemBrightness())
{
bool darkMode = darkModeFromSystem();

setDarkMode(darkMode);
return darkMode;
setDarkMode(darkMode);
}
return darkMode();
}

Settings *Appearance::settings() const
Expand All @@ -123,5 +151,6 @@ bool Appearance::darkModeFromSystem() const
{
QColor middleGrey(127, 127, 127);
auto app = qobject_cast<QGuiApplication *>(QGuiApplication::instance());
return middleGrey.lightnessF() > app->palette().color(QPalette::Window).lightnessF();
return middleGrey.lightnessF()
> app->palette().color(QPalette::Window).lightnessF();
}
5 changes: 5 additions & 0 deletions src/common/appearance.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Appearance : public QObject
{
Q_OBJECT
Q_PROPERTY(bool darkMode READ darkMode WRITE setDarkMode NOTIFY darkModeChanged)
Q_PROPERTY(bool useSystemBrightness READ useSystemBrightness WRITE setUseSystemBrightness NOTIFY useSystemBrightnessChanged)
Q_PROPERTY(bool showAboutOnStartup READ showAboutOnStartup CONSTANT)
Q_PROPERTY(bool experimentFunctions READ experimentFunctions WRITE setExperimentFunctions NOTIFY
experimentFunctionsChanged)
Expand All @@ -44,6 +45,9 @@ class Appearance : public QObject
bool darkMode() const;
void setDarkMode(const bool &setDark);

bool useSystemBrightness() const;
void setUseSystemBrightness(const bool &setSystemBrightness);

bool experimentFunctions() const;
void setExperimentFunctions(bool value);

Expand All @@ -58,6 +62,7 @@ public slots:

signals:
void darkModeChanged(bool);
void useSystemBrightnessChanged(bool);
void experimentFunctionsChanged(bool);
void visibilityChanged();

Expand Down