Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-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 "iuiconfiguration.h"
26 :
27 : #include "iglobalconfiguration.h"
28 : #include "global/types/config.h"
29 : #include "modularity/ioc.h"
30 : #include "internal/iplatformtheme.h"
31 : #include "io/filesystemwatcher.h"
32 :
33 : #include "types/val.h"
34 : #include "async/asyncable.h"
35 :
36 : namespace muse::ui {
37 : class UiConfiguration : public IUiConfiguration, public async::Asyncable
38 : {
39 : GlobalInject<IPlatformTheme> platformTheme;
40 : GlobalInject<IGlobalConfiguration> globalConfiguration;
41 :
42 : public:
43 :
44 0 : UiConfiguration() = default;
45 :
46 : void init();
47 : void deinit();
48 :
49 : ThemeList themes() const override;
50 : QStringList possibleAccentColors() const override;
51 : QStringList possibleFontFamilies() const override;
52 : QStringList nonTextFonts() const override;
53 : void setNonTextFonts(const QStringList& fontFamilies) override;
54 :
55 : bool isDarkMode() const override;
56 : void setIsDarkMode(bool dark) override;
57 :
58 : bool isHighContrast() const override;
59 : void setIsHighContrast(bool highContrast) override;
60 :
61 : const ThemeInfo& currentTheme() const override;
62 : async::Notification currentThemeChanged() const override;
63 : void setCurrentTheme(const ThemeCode& codeKey) override;
64 : void setCurrentThemeStyleValue(ThemeStyleKey key, const Val& val) override;
65 : void resetThemes() override;
66 :
67 : bool isFollowSystemThemeAvailable() const override;
68 : ValNt<bool> isFollowSystemTheme() const override;
69 : void setFollowSystemTheme(bool follow) override;
70 :
71 : std::string fontFamily() const override;
72 : void setFontFamily(const std::string& family) override;
73 : int fontSize(FontSizeType type = FontSizeType::BODY) const override;
74 : void setBodyFontSize(int size) override;
75 : async::Notification fontChanged() const override;
76 :
77 : std::string iconsFontFamily() const override;
78 : int iconsFontSize(IconSizeType type) const override;
79 : async::Notification iconsFontChanged() const override;
80 :
81 : io::path_t appIconPath() const override;
82 :
83 : std::string musicalFontFamily() const override;
84 : int musicalFontSize() const override;
85 : async::Notification musicalFontChanged() const override;
86 :
87 : std::string musicalTextFontFamily() const override;
88 : int musicalTextFontSize() const override;
89 : async::Notification musicalTextFontChanged() const override;
90 :
91 : std::string defaultFontFamily() const override;
92 : int defaultFontSize() const override;
93 :
94 : void resetFonts() override;
95 :
96 : void setCustomPhysicalDotsPerInch(std::optional<double> dpi) override;
97 : std::optional<double> customPhysicalDotsPerInch() const override;
98 :
99 : bool isGlobalMenuAvailable() const override;
100 : bool isSystemDragSupported() const override;
101 :
102 : void applyPlatformStyle(QWindow* window) override;
103 :
104 : int flickableMaxVelocity() const override;
105 :
106 : int tooltipDelay() const override;
107 :
108 : std::vector<QColor> colorDialogCustomColors() const override;
109 : void setColorDialogCustomColors(const std::vector<QColor>&) override;
110 :
111 : private:
112 : void initThemes();
113 : void correctUserFontIfNeeded();
114 :
115 : void notifyAboutCurrentThemeChanged();
116 :
117 : void updateCurrentTheme();
118 : void updateThemes();
119 :
120 : void updateSystemThemeListeningStatus();
121 : void synchThemeWithSystemIfNecessary();
122 :
123 : void doSetIsDarkMode(bool dark);
124 : void doSetCurrentTheme(const ThemeCode& themeCode);
125 :
126 : ThemeCode currentThemeCodeKey() const;
127 : ThemeInfo makeStandardTheme(const ThemeCode& codeKey) const;
128 :
129 : ThemeList readThemes() const;
130 : void writeThemes(const ThemeList& themes);
131 :
132 : async::Notification m_currentThemeChanged;
133 : async::Notification m_fontChanged;
134 : async::Notification m_musicalFontChanged;
135 : async::Notification m_musicalTextFontChanged;
136 : async::Notification m_iconsFontChanged;
137 :
138 : ValNt<bool> m_isFollowSystemTheme;
139 :
140 : ThemeList m_themes;
141 : size_t m_currentThemeIndex = 0;
142 : std::optional<double> m_customDPI;
143 :
144 : QStringList m_nonTextFonts;
145 :
146 : Config m_config;
147 :
148 : mutable io::FileSystemWatcher m_themeWatcher;
149 : };
150 : }
|