Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #pragma once
24 :
25 : #include <qqmlintegration.h>
26 :
27 : #include <QObject>
28 :
29 : #include "modularity/ioc.h"
30 : #include "ui/iuiconfiguration.h"
31 : #include "notation/inotationconfiguration.h"
32 : #include "async/asyncable.h"
33 :
34 : namespace mu::preferences {
35 : class AppearancePreferencesModel : public QObject, public muse::Contextable, public muse::async::Asyncable
36 : {
37 : Q_OBJECT
38 : QML_ELEMENT;
39 :
40 : Q_PROPERTY(bool isFollowSystemThemeAvailable READ isFollowSystemThemeAvailable CONSTANT)
41 : Q_PROPERTY(bool isFollowSystemTheme READ isFollowSystemTheme WRITE setFollowSystemTheme NOTIFY isFollowSystemThemeChanged)
42 :
43 : Q_PROPERTY(QStringList generalThemeCodes READ generalThemeCodes CONSTANT)
44 : Q_PROPERTY(QStringList highContrastThemeCodes READ highContrastThemeCodes CONSTANT)
45 :
46 : Q_PROPERTY(bool highContrastEnabled READ highContrastEnabled WRITE setHighContrastEnabled NOTIFY highContrastEnabledChanged)
47 :
48 : Q_PROPERTY(QVariantList generalThemes READ generalThemes NOTIFY themesChanged)
49 : Q_PROPERTY(QVariantList highContrastThemes READ highContrastThemes NOTIFY themesChanged)
50 : Q_PROPERTY(QStringList accentColors READ accentColors NOTIFY themesChanged)
51 :
52 : Q_PROPERTY(QString currentThemeCode READ currentThemeCode WRITE setCurrentThemeCode NOTIFY themesChanged)
53 : Q_PROPERTY(int currentAccentColorIndex READ currentAccentColorIndex WRITE setCurrentAccentColorIndex NOTIFY themesChanged)
54 :
55 : Q_PROPERTY(int currentFontIndex READ currentFontIndex WRITE setCurrentFontIndex NOTIFY currentFontIndexChanged)
56 : Q_PROPERTY(int bodyTextSize READ bodyTextSize WRITE setBodyTextSize NOTIFY bodyTextSizeChanged)
57 :
58 : Q_PROPERTY(bool backgroundUseColor READ backgroundUseColor WRITE setBackgroundUseColor NOTIFY backgroundUseColorChanged)
59 : Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
60 : Q_PROPERTY(
61 : QString backgroundWallpaperPath READ backgroundWallpaperPath WRITE setBackgroundWallpaperPath NOTIFY backgroundWallpaperPathChanged)
62 :
63 : Q_PROPERTY(bool foregroundUseColor READ foregroundUseColor WRITE setForegroundUseColor NOTIFY foregroundUseColorChanged)
64 : Q_PROPERTY(QColor foregroundColor READ foregroundColor WRITE setForegroundColor NOTIFY foregroundColorChanged)
65 : Q_PROPERTY(
66 : QString foregroundWallpaperPath READ foregroundWallpaperPath WRITE setForegroundWallpaperPath NOTIFY foregroundWallpaperPathChanged)
67 :
68 : Q_PROPERTY(bool scoreInversionEnabled READ scoreInversionEnabled WRITE setScoreInversionEnabled NOTIFY invertScoreColorChanged)
69 : Q_PROPERTY(
70 : bool isOnlyInvertInDarkTheme READ isOnlyInvertInDarkTheme WRITE setOnlyInvertInDarkTheme NOTIFY isOnlyInvertInDarkThemeChanged)
71 :
72 : Q_PROPERTY(QColor engravingColor READ engravingColor WRITE setEngravingColor NOTIFY engravingColorChanged)
73 :
74 : muse::GlobalInject<muse::ui::IUiConfiguration> uiConfiguration;
75 : muse::GlobalInject<notation::INotationConfiguration> notationConfiguration;
76 :
77 : public:
78 : explicit AppearancePreferencesModel(QObject* parent = nullptr);
79 :
80 : Q_INVOKABLE void init();
81 :
82 : enum ColorType {
83 : AccentColor,
84 : TextAndIconsColor,
85 : DisabledColor,
86 : BorderColor
87 : };
88 0 : Q_ENUM(ColorType)
89 :
90 : bool isFollowSystemThemeAvailable() const;
91 : bool isFollowSystemTheme() const;
92 :
93 : bool highContrastEnabled() const;
94 : QStringList generalThemeCodes() const;
95 : QStringList highContrastThemeCodes() const;
96 : QVariantList generalThemes() const;
97 : QVariantList highContrastThemes() const;
98 :
99 : QStringList accentColors() const;
100 :
101 : QString currentThemeCode() const;
102 : int currentAccentColorIndex() const;
103 :
104 : int currentFontIndex() const;
105 : int bodyTextSize() const;
106 :
107 : bool backgroundUseColor() const;
108 : QColor backgroundColor() const;
109 : QString backgroundWallpaperPath() const;
110 :
111 : bool foregroundUseColor() const;
112 : QColor foregroundColor() const;
113 : QString foregroundWallpaperPath() const;
114 :
115 : bool scoreInversionEnabled() const;
116 : bool isOnlyInvertInDarkTheme() const;
117 :
118 : QColor engravingColor() const;
119 :
120 : Q_INVOKABLE void resetAppearancePreferencesToDefault();
121 : Q_INVOKABLE void setNewColor(const QColor& newColor, ColorType colorType);
122 : Q_INVOKABLE QStringList allFonts() const;
123 : Q_INVOKABLE QStringList wallpaperPathFilter() const;
124 : Q_INVOKABLE QString wallpapersDir() const;
125 :
126 : public slots:
127 : void setFollowSystemTheme(bool enabled);
128 : void setHighContrastEnabled(bool enabled);
129 : void setCurrentThemeCode(const QString& themeCode);
130 : void setCurrentAccentColorIndex(int index);
131 : void setCurrentFontIndex(int index);
132 : void setBodyTextSize(int size);
133 : void setBackgroundUseColor(bool value);
134 : void setBackgroundColor(const QColor& color);
135 : void setBackgroundWallpaperPath(const QString& path);
136 : void setForegroundUseColor(bool value);
137 : void setForegroundColor(const QColor& color);
138 : void setForegroundWallpaperPath(const QString& path);
139 : void setScoreInversionEnabled(bool value);
140 : void setOnlyInvertInDarkTheme(bool value);
141 : void setEngravingColor(const QColor& color);
142 :
143 : signals:
144 : void isFollowSystemThemeChanged();
145 : void highContrastEnabledChanged();
146 : void themesChanged();
147 : void currentFontIndexChanged();
148 : void bodyTextSizeChanged();
149 : void backgroundUseColorChanged();
150 : void backgroundColorChanged();
151 : void backgroundWallpaperPathChanged();
152 : void foregroundUseColorChanged();
153 : void foregroundColorChanged();
154 : void foregroundWallpaperPathChanged();
155 : void invertScoreColorChanged();
156 : void isOnlyInvertInDarkThemeChanged();
157 : void engravingColorChanged();
158 :
159 : private:
160 : muse::ui::ThemeInfo currentTheme() const;
161 : muse::ui::ThemeList allThemes() const;
162 :
163 : bool m_lastHighContrast = false;
164 : };
165 : }
|