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