Skip to content

Commit e18f41f

Browse files
Ghabryjetrotal
andcommitted
Theming: Load the color theme proposed by jetrotal (with some adjustments because of low contrast)
When KIRIGAMI_FORCE_STYLE=0 it will load the native operation system theme instead Currently unsupported when Kirigami is a dynamic library (Linux). In this case Kirigami looks in a different location we do not control. Not gonna fix this, bet this will be imprved upstream someday. Co-Authored-By: Mauro Junior <45118493+jetrotal@users.noreply.github.com>
1 parent 6a78807 commit e18f41f

9 files changed

Lines changed: 208 additions & 13 deletions

File tree

resources/Resources.qrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
<file>app/easyrpg.png</file>
55
<file>app/editor.ico</file>
66
<file>app/logo.svg</file>
7+
<file>icons/ezbright/index.theme</file>
8+
<file>icons/ezbright/icons/arrow-down.svg</file>
9+
<file>icons/ezbright/icons/arrow-up.svg</file>
10+
<file>icons/ezdark/index.theme</file>
11+
<file>icons/ezdark/icons/arrow-down.svg</file>
12+
<file>icons/ezdark/icons/arrow-up.svg</file>
713
</qresource>
814
<qresource prefix="/bright">
915
<file alias="audio">icons/bright/audio.svg</file>
@@ -94,4 +100,7 @@
94100
<file alias="rank3">icons/ranks/rank3.svg</file>
95101
<file alias="rank4">icons/ranks/rank4.svg</file>
96102
</qresource>
103+
<qresource prefix="/qt/qml/org/kde/kirigami">
104+
<file>Theme.qml</file>
105+
</qresource>
97106
</RCC>

resources/Theme.qml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2015 Marco Martin <mart@kde.org>
3+
*
4+
* SPDX-License-Identifier: LGPL-2.0-or-later
5+
*/
6+
7+
import QtQuick
8+
import org.kde.kirigami as Kirigami
9+
10+
Kirigami.BasicThemeDefinition {
11+
readonly property color ezAccent: "#4DE600"
12+
readonly property color ezDanger: "#FF4E4E"
13+
readonly property color ezNeutral: "#D1C64E"
14+
readonly property color ezBaseBg: "#26272B"
15+
readonly property color ezElevatedBg: "#444450"
16+
readonly property color ezInputBg: "#222428"
17+
readonly property color ezHoverBg: "#3A3D41"
18+
readonly property color ezAltBg: "#2C2E33"
19+
readonly property color ezText: "#E0E0E0"
20+
21+
textColor: ezText
22+
disabledTextColor: Qt.darker(ezText, 1.8)
23+
24+
highlightColor: ezAccent
25+
highlightedTextColor: Qt.lighter(ezText, 1.5)
26+
backgroundColor: ezBaseBg
27+
alternateBackgroundColor: ezAltBg
28+
activeTextColor: "#000000"
29+
activeBackgroundColor: ezAccent
30+
linkColor: ezAccent
31+
linkBackgroundColor: "transparent"
32+
visitedLinkColor: Qt.darker(ezAccent, 1.3)
33+
visitedLinkBackgroundColor: Qt.darker(ezAccent, 1.3)
34+
hoverColor: ezHoverBg
35+
focusColor: ezAccent
36+
negativeTextColor: ezDanger
37+
negativeBackgroundColor: ezDanger
38+
neutralTextColor: ezNeutral
39+
neutralBackgroundColor: ezNeutral
40+
positiveTextColor: ezAccent
41+
positiveBackgroundColor: ezAccent
42+
43+
buttonTextColor: ezText
44+
buttonBackgroundColor: ezElevatedBg
45+
buttonAlternateBackgroundColor: Qt.darker(ezElevatedBg, 1.3)
46+
buttonHoverColor: ezHoverBg
47+
buttonFocusColor: ezAccent
48+
49+
viewTextColor: ezText
50+
viewBackgroundColor: ezBaseBg
51+
viewAlternateBackgroundColor: ezAltBg
52+
viewHoverColor: ezHoverBg
53+
viewFocusColor: ezAccent
54+
55+
selectionTextColor: "#000000"
56+
selectionBackgroundColor: ezAccent
57+
selectionAlternateBackgroundColor: "#1B5200"
58+
selectionHoverColor: ezAccent
59+
selectionFocusColor: ezAccent
60+
61+
tooltipTextColor: "#FFFFFF"
62+
tooltipBackgroundColor: ezInputBg
63+
tooltipAlternateBackgroundColor: ezElevatedBg
64+
tooltipHoverColor: ezHoverBg
65+
tooltipFocusColor: ezAccent
66+
67+
complementaryTextColor: "#FFFFFF"
68+
complementaryBackgroundColor: ezInputBg
69+
complementaryAlternateBackgroundColor: ezElevatedBg
70+
complementaryHoverColor: ezHoverBg
71+
complementaryFocusColor: ezAccent
72+
73+
headerTextColor: "#FFFFFF"
74+
headerBackgroundColor: ezElevatedBg
75+
headerAlternateBackgroundColor: ezAltBg
76+
headerHoverColor: ezHoverBg
77+
headerFocusColor: ezAccent
78+
79+
defaultFont: fontMetrics.font
80+
81+
property list<QtObject> children: [
82+
TextMetrics {
83+
id: fontMetrics
84+
},
85+
SystemPalette {
86+
id: palette
87+
colorGroup: SystemPalette.Active
88+
},
89+
SystemPalette {
90+
id: disabledPalette
91+
colorGroup: SystemPalette.Disabled
92+
}
93+
]
94+
95+
function __propagateColorSet(object, context) {}
96+
97+
function __propagateTextColor(object, color) {}
98+
function __propagateBackgroundColor(object, color) {}
99+
function __propagatePrimaryColor(object, color) {}
100+
function __propagateAccentColor(object, color) {}
101+
}
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Icon Theme]
2+
Name=ezbright
3+
Comment=EasyRPG Icon Theme (Bright Mode)
4+
Directories=icons
5+
6+
[icons]
7+
Size=32
8+
Type=Scalable
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Loading

resources/icons/ezdark/index.theme

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[Icon Theme]
2+
Name=ezdark
3+
Comment=EasyRPG Icon Theme (Dark Mode)
4+
Directories=icons
5+
6+
[icons]
7+
Size=32
8+
Type=Scalable

src/main.cpp

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,58 @@
2222
#include <QTimer>
2323
#include <QDebug>
2424
#include <QQmlApplicationEngine>
25+
#include <QQuickStyle>
26+
#include <QStyleHints>
2527

2628
int main(int argc, char *argv[]) {
27-
QApplication a(argc, argv);
29+
QApplication app(argc, argv);
30+
31+
app.setApplicationName("EasyRPG Editor");
32+
app.setOrganizationName("EasyRPG");
33+
app.setOrganizationDomain("easyrpg.org");
2834

2935
// show splash
3036
QPixmap logo(":/app/splash.png");
3137
QSplashScreen s(logo, Qt::WindowStaysOnTopHint);
38+
39+
// Style setup
40+
bool force_dark = false;
41+
42+
// Kirigami only loads a custom style when using a static build
43+
// Lets wait for upstream to improve this
44+
#if defined(_WIN32) || defined(__APPLE__)
45+
// Default to org.kde.breeze style (from qqc2-breeze style)
46+
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
47+
const char* fstyle = "KIRIGAMI_FORCE_STYLE";
48+
if (qEnvironmentVariableIsEmpty(fstyle) || qEnvironmentVariableIntValue(fstyle) > 0) {
49+
// Built in EasyRPG Style (Theme.qml)
50+
qputenv("KIRIGAMI_FORCE_STYLE", "1");
51+
force_dark = true;
52+
}
53+
QQuickStyle::setStyle(QStringLiteral("org.kde.breeze"));
54+
}
55+
#endif
56+
57+
auto hints = app.styleHints();
58+
auto scheme_changed = [=]() {
59+
if (!force_dark && hints->colorScheme() == Qt::ColorScheme::Light) {
60+
QIcon::setThemeName("ezbright");
61+
} else {
62+
QIcon::setThemeName("ezdark");
63+
}
64+
};
65+
scheme_changed();
66+
QObject::connect(hints, &QStyleHints::colorSchemeChanged, scheme_changed);
67+
3268
s.showMessage("EasyRPG Editor");
3369
//s.show();
3470
#ifdef NDEBUG
3571
// close splash after 3 seconds for release
3672
QTimer::singleShot(3000, &s, &QWidget::close);
3773
#endif
3874

39-
a.setApplicationName("EasyRPG Editor");
40-
a.setOrganizationName("EasyRPG");
41-
a.setOrganizationDomain("easyrpg.org");
42-
4375
// setup qml engine
4476
QQmlApplicationEngine engine;
45-
#ifdef QML_EXTRA_IMPORT_PATHS
46-
engine.addImportPath(QML_EXTRA_IMPORT_PATHS);
47-
#endif
4877
engine.loadFromModule("org.easyrpg.editor", "MainWindow");
4978

5079
if (engine.rootObjects().isEmpty()) {
@@ -53,7 +82,7 @@ int main(int argc, char *argv[]) {
5382

5483
// load translations
5584
s.showMessage("Loading translations...");
56-
a.processEvents();
85+
app.processEvents();
5786
QTranslator t;
5887
bool found = false;
5988
#ifndef NDEBUG
@@ -65,16 +94,16 @@ int main(int argc, char *argv[]) {
6594
if (!found)
6695
found = t.load(QLocale(), QLatin1String("easyrpg-editor"), QLatin1String("_"), QLatin1String(":/i18n"));
6796
if (found)
68-
a.installTranslator(&t);
97+
app.installTranslator(&t);
6998
else
7099
qDebug() << "No translation(s) available.";
71100

72101
// main window and project
73102
s.showMessage("Loading main window...");
74-
a.processEvents();
103+
app.processEvents();
75104
MainWindow w;
76105
s.showMessage("Loading last project...");
77-
a.processEvents();
106+
app.processEvents();
78107
w.LoadLastProject();
79108
s.clearMessage();
80109
w.show();
@@ -84,5 +113,5 @@ int main(int argc, char *argv[]) {
84113
#endif
85114

86115
// into event loop
87-
return a.exec();
116+
return app.exec();
88117
}

0 commit comments

Comments
 (0)