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 : #include "paletteconfiguration.h"
23 :
24 : #include "log.h"
25 : #include "settings.h"
26 : #include "translation.h"
27 :
28 : using namespace mu;
29 : using namespace mu::palette;
30 : using namespace muse;
31 : using namespace muse::ui;
32 :
33 : static const std::string MODULE_NAME("palette");
34 : static const Settings::Key PALETTE_SCALE(MODULE_NAME, "application/paletteScale");
35 : static const Settings::Key PALETTE_USE_SINGLE(MODULE_NAME, "application/useSinglePalette");
36 : static const Settings::Key IS_SINGLE_CLICK_TO_OPEN_PALETTE(MODULE_NAME, "application/singleClickToOpenPalette");
37 : static const Settings::Key IS_PALETTE_DRAG_ENABLED(MODULE_NAME, "application/paletteDragEnabled");
38 :
39 0 : void PaletteConfiguration::init()
40 : {
41 0 : settings()->setDefaultValue(PALETTE_SCALE, Val(1.0));
42 0 : settings()->setDescription(PALETTE_SCALE, muse::qtrc("palette", "Palette scale").toStdString());
43 0 : settings()->setCanBeManuallyEdited(PALETTE_SCALE, true, Val(0.5), Val(5.0));
44 :
45 0 : settings()->setDefaultValue(PALETTE_USE_SINGLE, Val(false));
46 :
47 0 : m_isSinglePalette.val = settings()->value(PALETTE_USE_SINGLE).toBool();
48 0 : settings()->valueChanged(PALETTE_USE_SINGLE).onReceive(this, [this](const Val& newValue) {
49 0 : m_isSinglePalette.set(newValue.toBool());
50 0 : });
51 :
52 0 : settings()->setDefaultValue(IS_SINGLE_CLICK_TO_OPEN_PALETTE, Val(true));
53 :
54 0 : m_isSingleClickToOpenPalette.val = settings()->value(IS_SINGLE_CLICK_TO_OPEN_PALETTE).toBool();
55 0 : settings()->valueChanged(IS_SINGLE_CLICK_TO_OPEN_PALETTE).onReceive(this, [this](const Val& newValue) {
56 0 : m_isSingleClickToOpenPalette.set(newValue.toBool());
57 0 : });
58 :
59 0 : settings()->setDefaultValue(IS_PALETTE_DRAG_ENABLED, Val(true));
60 :
61 0 : m_isPaletteDragEnabled.val = settings()->value(IS_PALETTE_DRAG_ENABLED).toBool();
62 0 : settings()->valueChanged(IS_PALETTE_DRAG_ENABLED).onReceive(this, [this](const Val& newValue) {
63 0 : m_isPaletteDragEnabled.set(newValue.toBool());
64 0 : });
65 0 : }
66 :
67 0 : double PaletteConfiguration::paletteScaling() const
68 : {
69 0 : return settings()->value(PALETTE_SCALE).toDouble();
70 : }
71 :
72 0 : void PaletteConfiguration::setPaletteScaling(double scale)
73 : {
74 0 : settings()->setSharedValue(PALETTE_SCALE, Val(scale));
75 0 : }
76 :
77 0 : double PaletteConfiguration::paletteSpatium() const
78 : {
79 : static constexpr const double DPI_DISPLAY = 96.0; // 96 DPI nominal resolution
80 : static constexpr const double DPMM_DISPLAY = DPI_DISPLAY / 25.4;
81 : static constexpr const double PALETTE_SPATIUM = 1.764 * DPMM_DISPLAY;
82 :
83 0 : return PALETTE_SPATIUM;
84 : }
85 :
86 0 : ValCh<bool> PaletteConfiguration::isSinglePalette() const
87 : {
88 0 : return m_isSinglePalette;
89 : }
90 :
91 0 : void PaletteConfiguration::setIsSinglePalette(bool isSingle)
92 : {
93 0 : settings()->setSharedValue(PALETTE_USE_SINGLE, Val(isSingle));
94 0 : }
95 :
96 0 : ValCh<bool> PaletteConfiguration::isSingleClickToOpenPalette() const
97 : {
98 0 : return m_isSingleClickToOpenPalette;
99 : }
100 :
101 0 : void PaletteConfiguration::setIsSingleClickToOpenPalette(bool isSingleClick)
102 : {
103 0 : settings()->setSharedValue(IS_SINGLE_CLICK_TO_OPEN_PALETTE, Val(isSingleClick));
104 0 : }
105 :
106 0 : ValCh<bool> PaletteConfiguration::isPaletteDragEnabled() const
107 : {
108 0 : return m_isPaletteDragEnabled;
109 : }
110 :
111 0 : void PaletteConfiguration::setIsPaletteDragEnabled(bool enabled)
112 : {
113 0 : settings()->setSharedValue(IS_PALETTE_DRAG_ENABLED, Val(enabled));
114 0 : }
115 :
116 0 : QColor PaletteConfiguration::elementsBackgroundColor() const
117 : {
118 0 : return themeColor(BACKGROUND_PRIMARY_COLOR);
119 : }
120 :
121 0 : QColor PaletteConfiguration::elementsColor() const
122 : {
123 0 : return themeColor(FONT_PRIMARY_COLOR);
124 : }
125 :
126 0 : QColor PaletteConfiguration::gridColor() const
127 : {
128 0 : return themeColor(STROKE_COLOR);
129 : }
130 :
131 0 : QColor PaletteConfiguration::accentColor() const
132 : {
133 0 : return themeColor(ACCENT_COLOR);
134 : }
135 :
136 0 : QColor PaletteConfiguration::themeColor(ThemeStyleKey key) const
137 : {
138 0 : return uiConfiguration()->currentTheme().values[key].toString();
139 : }
140 :
141 0 : muse::async::Notification PaletteConfiguration::colorsChanged() const
142 : {
143 0 : return uiConfiguration()->currentThemeChanged();
144 : }
145 :
146 0 : muse::io::path_t PaletteConfiguration::keySignaturesDirPath() const
147 : {
148 0 : return globalConfiguration()->userAppDataPath() + "/keysigs";
149 : }
150 :
151 0 : muse::io::path_t PaletteConfiguration::timeSignaturesDirPath() const
152 : {
153 0 : return globalConfiguration()->userAppDataPath() + "/timesigs";
154 : }
155 :
156 0 : bool PaletteConfiguration::useFactorySettings() const
157 : {
158 0 : return globalConfiguration()->useFactorySettings();
159 : }
160 :
161 0 : bool PaletteConfiguration::enableExperimental() const
162 : {
163 0 : return globalConfiguration()->enableExperimental();
164 : }
165 :
166 0 : ValCh<PaletteConfiguration::PaletteConfig> PaletteConfiguration::paletteConfig(const QString& paletteId) const
167 : {
168 0 : if (!m_paletteConfigs.contains(paletteId)) {
169 0 : m_paletteConfigs[paletteId] = ValCh<PaletteConfig>();
170 : }
171 :
172 0 : return m_paletteConfigs[paletteId];
173 : }
174 :
175 0 : void PaletteConfiguration::setPaletteConfig(const QString& paletteId, const PaletteConfig& config)
176 : {
177 0 : m_paletteConfigs[paletteId].set(config);
178 0 : }
179 :
180 0 : ValCh<PaletteConfiguration::PaletteCellConfig> PaletteConfiguration::paletteCellConfig(const QString& cellId) const
181 : {
182 0 : if (!m_paletteCellsConfigs.contains(cellId)) {
183 0 : m_paletteCellsConfigs[cellId] = ValCh<PaletteCellConfig>();
184 : }
185 :
186 0 : return m_paletteCellsConfigs[cellId];
187 : }
188 :
189 0 : void PaletteConfiguration::setPaletteCellConfig(const QString& cellId, const PaletteCellConfig& config)
190 : {
191 0 : m_paletteCellsConfigs[cellId].set(config);
192 0 : }
|