Skip to content

Commit

Permalink
Control the current theme in the preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
eplatonoff committed Sep 16, 2024
1 parent d0c47d9 commit cf00541
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 54 deletions.
61 changes: 30 additions & 31 deletions src/Components/Preferences.qml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import QtQuick
import QtQuick.Controls

import "Preferences"

Expand Down Expand Up @@ -160,25 +161,27 @@ Item {
}

Item {
id: followSystemTheme
visible: Qt.platform.os === "osx"

id: showInDock
height: preferences.cellHeight
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0

Checkbox {
id: followSystemThemeCheck
checked: appSettings.followSystemTheme
id: showInDockCheck
checked: appSettings.showInDock
}

Text {
id: followSystemThemeLabel
id: showInDockLabel
height: 19
text: qsTr("Follow system color theme")
text: qsTr("Show app in Dock")
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: followSystemThemeCheck.right
anchors.left: showInDockCheck.right
anchors.leftMargin: 0
color: colors.getColor("dark")
anchors.verticalCenter: parent.verticalCenter
Expand All @@ -187,61 +190,57 @@ Item {
font.pixelSize: fontSize

renderType: Text.NativeRendering

}

MouseArea {
id: followSystemThemeTrigger
id: showInDockCheckTrigger
anchors.fill: parent
cursorShape: Qt.PointingHandCursor

onReleased: {
appSettings.followSystemTheme = !appSettings.followSystemTheme
appSettings.showInDock = !appSettings.showInDock
}
}
}

Item {
visible: Qt.platform.os === "osx"

id: showInDock
id: colorTheme
height: preferences.cellHeight
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: parent.left
anchors.leftMargin: 0

Checkbox {
id: showInDockCheck
checked: appSettings.showInDock
}

Text {
id: showInDockLabel
id: colorThemeLabel
height: 19
text: qsTr("Show app in Dock")
anchors.right: parent.right
anchors.rightMargin: 0
anchors.left: showInDockCheck.right
text: qsTr("Color theme")
anchors.left: parent.left
anchors.leftMargin: 0
color: colors.getColor("dark")
anchors.verticalCenter: parent.verticalCenter
color: colors.getColor("dark")

font.family: localFont.name
font.pixelSize: fontSize

renderType: Text.NativeRendering
}

MouseArea {
id: showInDockCheckTrigger
anchors.fill: parent
cursorShape: Qt.PointingHandCursor

onReleased: {
appSettings.showInDock = !appSettings.showInDock
ComboBox {
id: colorThemeCombo
model: ["Light", "Dark", "System"]
currentIndex: {
var index = colorThemeCombo.model.indexOf(appSettings.colorTheme);
return index !== -1 ? index : 0;
}
anchors.left: colorThemeLabel.right
anchors.leftMargin: 10
anchors.verticalCenter: parent.verticalCenter
onActivated: {
appSettings.colorTheme = colorThemeCombo.currentText
}
}

}
}

Expand Down
36 changes: 13 additions & 23 deletions src/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,23 @@ ApplicationWindow {
SystemPalette{
id: systemPalette

property color lightColor: '#ffffff'
property bool sysemDarkMode: Application.styleHints.colorScheme === Qt.ColorScheme.Dark
property alias follow: appSettings.followSystemTheme
property alias colorTheme: appSettings.colorTheme

onSysemDarkModeChanged: setSystemColors()
onFollowChanged: setSystemColors()
Component.onCompleted: setSystemColors()
onColorThemeChanged: updateTheme()
onSysemDarkModeChanged: updateTheme()
Component.onCompleted: updateTheme()


function setSystemColors(){
if(appSettings.followSystemTheme){
function updateTheme(){
if(systemPalette.colorTheme === "System"){
appSettings.darkMode = sysemDarkMode
}
else if (systemPalette.colorTheme === "Dark") {
appSettings.darkMode = true
}
else {
appSettings.darkMode = false
}
}
}

Expand Down Expand Up @@ -114,7 +118,7 @@ ApplicationWindow {
id: appSettings

property bool darkMode: false
property bool followSystemTheme: true
property string colorTheme: "System"
property bool showInDock: false

property alias soundMuted: notifications.soundMuted
Expand Down Expand Up @@ -256,20 +260,6 @@ ApplicationWindow {
id: digitalClock
}

Icon {
id: darkModeButton
glyph: appSettings.darkMode ? "\uea05" : "\uea0a"
anchors.top: parent.top
anchors.topMargin: 0
anchors.right: parent.right
anchors.rightMargin: 0

onReleased: {
appSettings.darkMode = !appSettings.darkMode
}
}


Icon {
id: soundButton
glyph: notifications.soundMuted ? "\uea09" : "\uea06"
Expand Down

0 comments on commit cf00541

Please sign in to comment.