Skip to content

Commit 4183a95

Browse files
committed
Add option for "invert score" to follow app theme
1 parent 1ebb637 commit 4183a95

File tree

10 files changed

+67
-29
lines changed

10 files changed

+67
-29
lines changed

src/appshell/qml/Preferences/AppearancePreferencesPage.qml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ PreferencesPage {
214214
SeparatorLine {}
215215

216216
ThemeAdditionalOptionsSection {
217-
scoreInversionEnabled: appearanceModel.scoreInversionEnabled
217+
scoreInversionMode: appearanceModel.scoreInversionMode
218218

219219
navigation.section: root.navigationSection
220220
navigation.order: root.navigationOrderStart + 7
@@ -229,8 +229,8 @@ PreferencesPage {
229229
}
230230
}
231231

232-
onScoreInversionEnableChangeRequested: function(enable) {
233-
appearanceModel.scoreInversionEnabled = enable
232+
onScoreInversionModeChangeRequested: function(mode) {
233+
appearanceModel.scoreInversionMode = mode
234234
}
235235
}
236236
}

src/appshell/qml/Preferences/internal/ThemeAdditionalOptionsSection.qml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,31 @@ import Muse.UiComponents 1.0
2626
BaseSection {
2727
id: root
2828

29-
property alias scoreInversionEnabled: scoreInversionEnable.checked
29+
property int scoreInversionMode: 0
3030

3131
signal resetThemeToDefaultRequested()
32-
signal scoreInversionEnableChangeRequested(bool enable)
32+
signal scoreInversionModeChangeRequested(int mode)
3333

34-
CheckBox {
35-
id: scoreInversionEnable
34+
ComboBoxWithTitle {
35+
id: scoreInversionModeDropdown
3636
width: parent.width
3737

38-
text: qsTrc("appshell/preferences", "Invert score")
38+
title: qsTrc("appshell/preferences", "Invert score:")
3939

40-
navigation.name: "ScoreInversionBox"
40+
navigation.name: "ScoreInversionModeDropdown"
4141
navigation.panel: root.navigation
4242
navigation.row: 0
4343

44-
onClicked: {
45-
root.scoreInversionEnableChangeRequested(!checked)
44+
model: [
45+
{ text: qsTrc("appshell/preferences", "Disabled"), value: 0 },
46+
{ text: qsTrc("appshell/preferences", "Follow app theme"), value: 1 },
47+
{ text: qsTrc("appshell/preferences", "Always"), value: 2 },
48+
]
49+
50+
currentIndex: scoreInversionModeDropdown.indexOfValue(root.scoreInversionMode)
51+
52+
onValueEdited: function(newIndex, newValue) {
53+
root.scoreInversionModeChangeRequested(newValue)
4654
}
4755
}
4856

src/appshell/view/preferences/appearancepreferencesmodel.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void AppearancePreferencesModel::init()
5757
});
5858

5959
engravingConfiguration()->scoreInversionChanged().onNotify(this, [this]() {
60-
emit invertScoreColorChanged();
60+
emit scoreInversionModeChanged();
6161
emit foregroundColorChanged();
6262
});
6363

@@ -252,9 +252,9 @@ QString AppearancePreferencesModel::foregroundWallpaperPath() const
252252
return notationConfiguration()->foregroundWallpaperPath().toQString();
253253
}
254254

255-
bool AppearancePreferencesModel::scoreInversionEnabled() const
255+
int AppearancePreferencesModel::scoreInversionMode() const
256256
{
257-
return engravingConfiguration()->scoreInversionEnabled();
257+
return static_cast<int>(engravingConfiguration()->scoreInversionMode());
258258
}
259259

260260
void AppearancePreferencesModel::setCurrentThemeCode(const QString& themeCode)
@@ -362,12 +362,12 @@ void AppearancePreferencesModel::setForegroundWallpaperPath(const QString& path)
362362
emit foregroundWallpaperPathChanged();
363363
}
364364

365-
void AppearancePreferencesModel::setScoreInversionEnabled(bool value)
365+
void AppearancePreferencesModel::setScoreInversionMode(int mode)
366366
{
367-
if (value == scoreInversionEnabled()) {
367+
if (mode == scoreInversionMode()) {
368368
return;
369369
}
370370

371-
engravingConfiguration()->setScoreInversionEnabled(value);
372-
emit invertScoreColorChanged();
371+
engravingConfiguration()->setScoreInversionMode(static_cast<mu::engraving::ScoreInversionMode>(mode));
372+
emit scoreInversionModeChanged();
373373
}

src/appshell/view/preferences/appearancepreferencesmodel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AppearancePreferencesModel : public QObject, public muse::Injectable, publ
5858
Q_PROPERTY(
5959
QString foregroundWallpaperPath READ foregroundWallpaperPath WRITE setForegroundWallpaperPath NOTIFY foregroundWallpaperPathChanged)
6060

61-
Q_PROPERTY(bool scoreInversionEnabled READ scoreInversionEnabled WRITE setScoreInversionEnabled NOTIFY invertScoreColorChanged)
61+
Q_PROPERTY(int scoreInversionMode READ scoreInversionMode WRITE setScoreInversionMode NOTIFY scoreInversionModeChanged)
6262

6363
muse::Inject<muse::ui::IUiConfiguration> uiConfiguration = { this };
6464
muse::Inject<notation::INotationConfiguration> notationConfiguration = { this };
@@ -100,7 +100,7 @@ class AppearancePreferencesModel : public QObject, public muse::Injectable, publ
100100
QColor foregroundColor() const;
101101
QString foregroundWallpaperPath() const;
102102

103-
bool scoreInversionEnabled() const;
103+
int scoreInversionMode() const;
104104

105105
Q_INVOKABLE void resetAppearancePreferencesToDefault();
106106
Q_INVOKABLE void setNewColor(const QColor& newColor, ColorType colorType);
@@ -121,7 +121,7 @@ public slots:
121121
void setForegroundUseColor(bool value);
122122
void setForegroundColor(const QColor& color);
123123
void setForegroundWallpaperPath(const QString& path);
124-
void setScoreInversionEnabled(bool value);
124+
void setScoreInversionMode(int mode);
125125

126126
signals:
127127
void isFollowSystemThemeChanged();
@@ -134,7 +134,7 @@ public slots:
134134
void foregroundUseColorChanged();
135135
void foregroundColorChanged();
136136
void foregroundWallpaperPathChanged();
137-
void invertScoreColorChanged();
137+
void scoreInversionModeChanged();
138138

139139
private:
140140
muse::ui::ThemeInfo currentTheme() const;

src/engraving/iengravingconfiguration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ class IEngravingConfiguration : MODULE_EXPORT_INTERFACE
7373
virtual muse::async::Channel<voice_idx_t, Color> selectionColorChanged() const = 0;
7474

7575
virtual bool scoreInversionEnabled() const = 0;
76-
virtual void setScoreInversionEnabled(bool value) = 0;
76+
virtual ScoreInversionMode scoreInversionMode() const = 0;
77+
virtual void setScoreInversionMode(ScoreInversionMode mode) = 0;
7778
virtual muse::async::Notification scoreInversionChanged() const = 0;
7879

7980
virtual bool dynamicsApplyToAllVoices() const = 0;

src/engraving/internal/engravingconfiguration.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ static const Settings::Key DEFAULT_STYLE_FILE_PATH("engraving", "engraving/style
4444
static const Settings::Key PART_STYLE_FILE_PATH("engraving", "engraving/style/partStyleFile");
4545

4646
static const Settings::Key INVERT_SCORE_COLOR("engraving", "engraving/scoreColorInversion");
47+
static const Settings::Key SCORE_COLOR_INVERSION_MODE("engraving", "engraving/scoreColorInversionMode");
4748

4849
static const Settings::Key ALL_VOICES_COLOR("engraving", "engraving/colors/allVoicesColor");
4950
static const Settings::Key FORMATTING_COLOR("engraving", "engraving/colors/formattingColor");
@@ -85,11 +86,17 @@ void EngravingConfiguration::init()
8586
m_partStyleFilePathChanged.send(val.toPath());
8687
});
8788

89+
// TODO: How to upgrade old setting to new one?
8890
settings()->setDefaultValue(INVERT_SCORE_COLOR, Val(false));
8991
settings()->valueChanged(INVERT_SCORE_COLOR).onReceive(nullptr, [this](const Val&) {
9092
m_scoreInversionChanged.notify();
9193
});
9294

95+
settings()->setDefaultValue(SCORE_COLOR_INVERSION_MODE, Val(ScoreInversionMode::Disabled));
96+
settings()->valueChanged(SCORE_COLOR_INVERSION_MODE).onReceive(nullptr, [this](const Val&) {
97+
m_scoreInversionChanged.notify();
98+
});
99+
93100
for (voice_idx_t voice = 0; voice < VOICES; ++voice) {
94101
Settings::Key key("engraving", "engraving/colors/voice" + std::to_string(voice + 1));
95102

@@ -333,12 +340,22 @@ Color EngravingConfiguration::highlightSelectionColor(voice_idx_t voice) const
333340

334341
bool EngravingConfiguration::scoreInversionEnabled() const
335342
{
336-
return settings()->value(INVERT_SCORE_COLOR).toBool();
343+
switch (scoreInversionMode()) {
344+
case ScoreInversionMode::Disabled: return false;
345+
case ScoreInversionMode::FollowAppTheme: return uiConfiguration()->isDarkMode();
346+
case ScoreInversionMode::Always: return true;
347+
default: return false;
348+
}
349+
}
350+
351+
ScoreInversionMode EngravingConfiguration::scoreInversionMode() const
352+
{
353+
return settings()->value(SCORE_COLOR_INVERSION_MODE).toEnum<ScoreInversionMode>();
337354
}
338355

339-
void EngravingConfiguration::setScoreInversionEnabled(bool value)
356+
void EngravingConfiguration::setScoreInversionMode(ScoreInversionMode mode)
340357
{
341-
settings()->setSharedValue(INVERT_SCORE_COLOR, Val(value));
358+
settings()->setSharedValue(SCORE_COLOR_INVERSION_MODE, Val(mode));
342359
}
343360

344361
bool EngravingConfiguration::dynamicsApplyToAllVoices() const

src/engraving/internal/engravingconfiguration.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ class EngravingConfiguration : public IEngravingConfiguration, public muse::Inje
8181
Color highlightSelectionColor(voice_idx_t voice = 0) const override;
8282

8383
bool scoreInversionEnabled() const override;
84-
void setScoreInversionEnabled(bool value) override;
84+
ScoreInversionMode scoreInversionMode() const override;
85+
void setScoreInversionMode(ScoreInversionMode mode) override;
8586

8687
bool dynamicsApplyToAllVoices() const override;
8788
void setDynamicsApplyToAllVoices(bool v) override;

src/engraving/tests/mocks/engravingconfigurationmock.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class EngravingConfigurationMock : public IEngravingConfiguration
6767
MOCK_METHOD((muse::async::Channel<bool>), dynamicsApplyToAllVoicesChanged, (), (const, override));
6868

6969
MOCK_METHOD(bool, scoreInversionEnabled, (), (const, override));
70-
MOCK_METHOD(void, setScoreInversionEnabled, (bool), (override));
70+
MOCK_METHOD(ScoreInversionMode, scoreInversionMode, (), (const, override));
71+
MOCK_METHOD(void, setScoreInversionMode, (ScoreInversionMode), (override));
7172
MOCK_METHOD(muse::async::Notification, scoreInversionChanged, (), (const, override));
7273

7374
MOCK_METHOD(Color, formattingColor, (), (const, override));

src/engraving/types/types.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,16 @@ enum class LayoutFlag : unsigned char {
11841184
};
11851185

11861186
typedef muse::Flags<LayoutFlag> LayoutFlags;
1187+
1188+
//---------------------------------------------------------
1189+
// ScoreInversionMode
1190+
//---------------------------------------------------------
1191+
1192+
enum class ScoreInversionMode : unsigned char {
1193+
Disabled,
1194+
FollowAppTheme,
1195+
Always
1196+
};
11871197
} // mu::engraving
11881198

11891199
template<>

src/notation/internal/notationconfiguration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ void NotationConfiguration::resetForeground()
530530
settings()->setSharedValue(FOREGROUND_USE_COLOR, settings()->defaultValue(FOREGROUND_USE_COLOR));
531531
settings()->setSharedValue(FOREGROUND_WALLPAPER_PATH, settings()->defaultValue(FOREGROUND_WALLPAPER_PATH));
532532

533-
engravingConfiguration()->setScoreInversionEnabled(false);
533+
engravingConfiguration()->setScoreInversionMode(mu::engraving::ScoreInversionMode::Disabled);
534534
}
535535

536536
muse::async::Notification NotationConfiguration::foregroundChanged() const

0 commit comments

Comments
 (0)