Skip to content

Commit bc12722

Browse files
committed
Set default accent color
1 parent 519d1b5 commit bc12722

File tree

5 files changed

+43
-23
lines changed

5 files changed

+43
-23
lines changed

src/app/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ qt_add_executable(${APP_TARGET}
1010
libraryinfo.h
1111
)
1212

13+
set_source_files_properties(qml/Colors.qml PROPERTIES QT_QML_SINGLETON_TYPE TRUE)
14+
1315
qt_add_qml_module(${APP_TARGET}
1416
URI ScratchCPP
1517
VERSION 1.0
1618
QML_FILES
1719
qml/main.qml
20+
qml/Colors.qml
1821
qml/dialogs/AboutDialog.qml
1922
qml/dialogs/ProjectSettingsDialog.qml
2023
qml/dialogs/PreferencesDialog.qml

src/app/qml/Colors.qml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: GPL-3.0-or-later
2+
3+
pragma Singleton
4+
import QtQuick
5+
import ScratchCPP.Ui
6+
7+
QtObject {
8+
readonly property list<color> darkAccentColors: [
9+
Qt.rgba(0.85, 0.31, 0.33, 1),
10+
Qt.rgba(0.85, 0.62, 0.31, 1),
11+
Qt.rgba(0.85, 0.84, 0.31, 1),
12+
Qt.rgba(0.39, 0.85, 0.31, 1),
13+
Qt.rgba(0.31, 0.75, 0.85, 1),
14+
Qt.rgba(0.32, 0.32, 0.85, 1),
15+
Qt.rgba(0.68, 0.31, 0.85, 1),
16+
]
17+
18+
readonly property list<color> lightAccentColors: [
19+
Qt.rgba(0.75, 0.08, 0.09, 1),
20+
Qt.rgba(0.75, 0.47, 0.08, 1),
21+
Qt.rgba(0.75, 0.74, 0.08, 1),
22+
Qt.rgba(0.17, 0.75, 0.08, 1),
23+
Qt.rgba(0.08, 0.63, 0.75, 1),
24+
Qt.rgba(0.08, 0.08, 0.75, 1),
25+
Qt.rgba(0.54, 0.08, 0.75, 1),
26+
]
27+
28+
readonly property color defaultAccentColor: ThemeEngine.theme == ThemeEngine.DarkTheme ? darkAccentColors[1] : lightAccentColors[1]
29+
}

src/app/qml/dialogs/PreferencesDialog.qml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import ScratchCPP.Global
77
import ScratchCPP.Ui
88
import ScratchCPP.UiComponents
99

10+
import ".."
11+
1012
CustomDialog {
1113
title: qsTr("Preferences")
1214
standardButtons: Dialog.Cancel | Dialog.Ok
@@ -20,26 +22,6 @@ CustomDialog {
2022
QtObject {
2123
id: priv
2224
property int accentColorIndex: -1
23-
24-
readonly property list<color> darkAccentColors: [
25-
Qt.rgba(0.85, 0.31, 0.33, 1),
26-
Qt.rgba(0.85, 0.62, 0.31, 1),
27-
Qt.rgba(0.85, 0.84, 0.31, 1),
28-
Qt.rgba(0.39, 0.85, 0.31, 1),
29-
Qt.rgba(0.31, 0.75, 0.85, 1),
30-
Qt.rgba(0.32, 0.32, 0.85, 1),
31-
Qt.rgba(0.68, 0.31, 0.85, 1),
32-
]
33-
34-
readonly property list<color> lightAccentColors: [
35-
Qt.rgba(0.75, 0.08, 0.09, 1),
36-
Qt.rgba(0.75, 0.47, 0.08, 1),
37-
Qt.rgba(0.75, 0.74, 0.08, 1),
38-
Qt.rgba(0.17, 0.75, 0.08, 1),
39-
Qt.rgba(0.08, 0.63, 0.75, 1),
40-
Qt.rgba(0.08, 0.08, 0.75, 1),
41-
Qt.rgba(0.54, 0.08, 0.75, 1),
42-
]
4325
}
4426

4527
contentItem: ColumnLayout {
@@ -71,7 +53,7 @@ CustomDialog {
7153

7254
Repeater {
7355
id: accentColors
74-
model: ThemeEngine.theme == ThemeEngine.DarkTheme ? priv.darkAccentColors : priv.lightAccentColors
56+
model: ThemeEngine.theme == ThemeEngine.DarkTheme ? Colors.darkAccentColors : Colors.lightAccentColors
7557

7658
ColorButton {
7759
required property color modelData
@@ -99,9 +81,9 @@ CustomDialog {
9981
console.log(priv.accentColorIndex, ThemeEngine.theme);
10082

10183
if(ThemeEngine.theme == ThemeEngine.DarkTheme) {
102-
ThemeEngine.accentColor = priv.darkAccentColors[priv.accentColorIndex];
84+
ThemeEngine.accentColor = Colors.darkAccentColors[priv.accentColorIndex];
10385
} else {
104-
ThemeEngine.accentColor = priv.lightAccentColors[priv.accentColorIndex];
86+
ThemeEngine.accentColor = Colors.lightAccentColors[priv.accentColorIndex];
10587
}
10688
}
10789
}

src/app/qml/main.qml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,9 @@ ApplicationWindow {
172172
}
173173
}
174174
}
175+
176+
Component.onCompleted: {
177+
if(ThemeEngine.accentColor === Qt.rgba(0, 0, 0, 0))
178+
ThemeEngine.accentColor = Colors.defaultAccentColor;
179+
}
175180
}

src/ui/uimodule.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ void scratchcpp::ui::UiModule::registerExports()
3232
void UiModule::initSettings()
3333
{
3434
INIT_SETTINGS_KEY("theme", static_cast<int>(IThemeEngine::Theme::DarkTheme));
35+
INIT_SETTINGS_KEY("accentColor", QColor(0, 0, 0, 0)); // default accent color should be set by the application
3536
}

0 commit comments

Comments
 (0)