Skip to content

Commit 8a7a375

Browse files
committed
Refine empty staves visibility section in the Properties panel
* Add icons on the buttons * Enable the buttons only when they do something * Tweak the copy
1 parent 88d81c9 commit 8a7a375

File tree

4 files changed

+183
-8
lines changed

4 files changed

+183
-8
lines changed

src/framework/ui/view/iconcodes.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,11 +215,10 @@ class IconCode
215215
NOTE_HEAD_HALF = 0xF342,
216216
NOTE_HEAD_WHOLE = 0xF343,
217217
NOTE_HEAD_BREVIS = 0xF344,
218-
DOUBLE_BAR_LINE = 0xF347,
219-
NOTE_HEAD = 0xF42F,
220-
NOTE_HEAD_PARENTHESES = 0xF430,
221218

222219
PLAY_REPEATS = 0xF345,
220+
221+
DOUBLE_BAR_LINE = 0xF347,
223222
BARLINE_WINGED = 0xF34C,
224223
BARLINE_UNWINGED = 0xF34D,
225224
ORIENTATION_PORTRAIT = 0xF350,
@@ -375,9 +374,10 @@ class IconCode
375374
GRACE8_AFTER = 0xF42C,
376375
GRACE16_AFTER = 0xF42D,
377376
GRACE32_AFTER = 0xF42E,
377+
NOTE_HEAD = 0xF42F,
378+
NOTE_HEAD_PARENTHESES = 0xF430,
378379

379380
MEASURE_REPEAT = 0xF431,
380-
381381
INSERT_ONE_MEASURE = 0xF432,
382382
STAFF_TYPE_CHANGE = 0xF433,
383383

@@ -494,6 +494,9 @@ class IconCode
494494
DURATION_CURSOR = 0xF492,
495495
WARNING_SMALL = 0xF493,
496496

497+
HIDE_EMPTY_STAVES = 0xF497,
498+
SHOW_EMPTY_STAVES = 0xF498,
499+
497500
NOTE_ALIGN_LEFT = 0xF4A3,
498501
NOTE_ALIGN_CENTER = 0xF4A4,
499502
NOTE_ALIGN_RIGHT = 0xF4A5,

src/inspector/models/emptystaves/emptystavesvisiblitysettingsmodel.cpp

Lines changed: 140 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
#include "engraving/dom/score.h"
2626
#include "engraving/dom/system.h"
2727
#include "engraving/dom/undo.h"
28+
#include "engraving/rendering/score/systemlayout.h"
2829

2930
using namespace mu::inspector;
3031
using namespace mu::notation;
3132
using namespace mu::engraving;
33+
using mu::engraving::rendering::score::SystemLayout;
3234

3335
EmptyStavesVisibilitySettingsModel::EmptyStavesVisibilitySettingsModel(QObject* parent, IElementRepositoryService* repository)
3436
: AbstractInspectorModel(parent, repository)
@@ -43,6 +45,37 @@ bool EmptyStavesVisibilitySettingsModel::isEmpty() const
4345
return !selection || !selection->isRange();
4446
}
4547

48+
void EmptyStavesVisibilitySettingsModel::loadProperties()
49+
{
50+
updateCanHideEmptyStavesInSelection();
51+
updateCanShowAllEmptyStaves();
52+
updateCanResetEmptyStavesVisibility();
53+
}
54+
55+
void EmptyStavesVisibilitySettingsModel::onCurrentNotationChanged()
56+
{
57+
INotationPtr notation = currentNotation();
58+
if (!notation) {
59+
return;
60+
}
61+
62+
notation->undoStack()->changesChannel().onReceive(this, [this](const ScoreChanges& changes) {
63+
if (changes.isTextEditing) {
64+
return;
65+
}
66+
67+
if (changes.changedPropertyIdSet.empty() && changes.changedStyleIdSet.empty()) {
68+
// In this specific case, it's not done by InspectorListModel::listenScoreChanges()
69+
onNotationChanged({}, {});
70+
}
71+
});
72+
}
73+
74+
void EmptyStavesVisibilitySettingsModel::onNotationChanged(const mu::engraving::PropertyIdSet&, const mu::engraving::StyleIdSet&)
75+
{
76+
loadProperties();
77+
}
78+
4679
void EmptyStavesVisibilitySettingsModel::hideEmptyStavesInSelection()
4780
{
4881
if (isEmpty()) {
@@ -58,7 +91,7 @@ void EmptyStavesVisibilitySettingsModel::hideEmptyStavesInSelection()
5891
const staff_idx_t staffStart = range->startStaffIndex();
5992
const staff_idx_t staffEnd = range->endStaffIndex();
6093

61-
beginCommand(muse::TranslatableString("undoableAction", "Hide empty staves in selection"));
94+
beginCommand(muse::TranslatableString("undoableAction", "Hide empty staves"));
6295

6396
for (System* system : systems) {
6497
for (staff_idx_t staffIdx = staffStart; staffIdx < staffEnd; ++staffIdx) {
@@ -80,7 +113,7 @@ void EmptyStavesVisibilitySettingsModel::showAllEmptyStaves()
80113
const INotationSelectionPtr sel = selection();
81114
const std::vector<System*> systems = sel->selectedSystems();
82115

83-
beginCommand(muse::TranslatableString("undoableAction", "Show all empty staves"));
116+
beginCommand(muse::TranslatableString("undoableAction", "Show empty staves"));
84117

85118
for (System* system : systems) {
86119
for (staff_idx_t staffIdx = 0; staffIdx < score->nstaves(); ++staffIdx) {
@@ -113,3 +146,108 @@ void EmptyStavesVisibilitySettingsModel::resetEmptyStavesVisibility()
113146

114147
endCommand();
115148
}
149+
150+
void EmptyStavesVisibilitySettingsModel::updateCanHideEmptyStavesInSelection()
151+
{
152+
auto set = [this] (bool can) {
153+
if (m_canHideEmptyStavesInSelection == can) {
154+
return;
155+
}
156+
m_canHideEmptyStavesInSelection = can;
157+
emit canHideEmptyStavesInSelectionChanged();
158+
};
159+
160+
if (isEmpty()) {
161+
set(false);
162+
return;
163+
}
164+
165+
const INotationSelectionPtr sel = selection();
166+
const std::vector<System*> systems = sel->selectedSystems();
167+
168+
const INotationSelectionRangePtr range = sel->range();
169+
const staff_idx_t staffStart = range->startStaffIndex();
170+
const staff_idx_t staffEnd = range->endStaffIndex();
171+
172+
for (const System* system : systems) {
173+
for (staff_idx_t staffIdx = staffStart; staffIdx < staffEnd; ++staffIdx) {
174+
if (system->staff(staffIdx)->show()
175+
&& SystemLayout::canChangeSysStaffVisibility(system, staffIdx)) {
176+
set(true);
177+
return;
178+
}
179+
}
180+
}
181+
182+
set(false);
183+
}
184+
185+
void EmptyStavesVisibilitySettingsModel::updateCanShowAllEmptyStaves()
186+
{
187+
auto set = [this] (bool can) {
188+
if (m_canShowAllEmptyStaves == can) {
189+
return;
190+
}
191+
m_canShowAllEmptyStaves = can;
192+
emit canShowAllEmptyStavesChanged();
193+
};
194+
195+
if (isEmpty()) {
196+
set(false);
197+
return;
198+
}
199+
200+
Score* score = currentNotation()->elements()->msScore();
201+
202+
const INotationSelectionPtr sel = selection();
203+
const std::vector<System*> systems = sel->selectedSystems();
204+
205+
for (const System* system : systems) {
206+
for (staff_idx_t staffIdx = 0; staffIdx < score->nstaves(); ++staffIdx) {
207+
if (!system->staff(staffIdx)->show()
208+
&& SystemLayout::canChangeSysStaffVisibility(system, staffIdx)) {
209+
set(true);
210+
return;
211+
}
212+
}
213+
}
214+
215+
set(false);
216+
}
217+
218+
void EmptyStavesVisibilitySettingsModel::updateCanResetEmptyStavesVisibility()
219+
{
220+
auto set = [this] (bool can) {
221+
if (m_canResetEmptyStavesVisibility == can) {
222+
return;
223+
}
224+
m_canResetEmptyStavesVisibility = can;
225+
emit canResetEmptyStavesVisibilityChanged();
226+
};
227+
228+
if (isEmpty()) {
229+
set(false);
230+
return;
231+
}
232+
233+
Score* score = currentNotation()->elements()->msScore();
234+
235+
const INotationSelectionPtr sel = selection();
236+
const std::vector<System*> systems = sel->selectedSystems();
237+
238+
for (const System* system : systems) {
239+
for (const MeasureBase* mb : system->measures()) {
240+
if (!mb->isMeasure()) {
241+
continue;
242+
}
243+
for (staff_idx_t staffIdx = 0; staffIdx < score->nstaves(); ++staffIdx) {
244+
if (toMeasure(mb)->hideStaffIfEmpty(staffIdx) != engraving::AutoOnOff::AUTO) {
245+
set(true);
246+
return;
247+
}
248+
}
249+
}
250+
}
251+
252+
set(false);
253+
}

src/inspector/models/emptystaves/emptystavesvisiblitysettingsmodel.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,43 @@ class EmptyStavesVisibilitySettingsModel : public AbstractInspectorModel
2828
{
2929
Q_OBJECT
3030

31+
Q_PROPERTY(bool canHideEmptyStavesInSelection READ canHideEmptyStavesInSelection NOTIFY canHideEmptyStavesInSelectionChanged)
32+
Q_PROPERTY(bool canShowAllEmptyStaves READ canShowAllEmptyStaves NOTIFY canShowAllEmptyStavesChanged)
33+
Q_PROPERTY(bool canResetEmptyStavesVisibility READ canResetEmptyStavesVisibility NOTIFY canResetEmptyStavesVisibilityChanged)
34+
3135
public:
3236
explicit EmptyStavesVisibilitySettingsModel(QObject* parent, IElementRepositoryService* repository);
3337

3438
void createProperties() override {}
35-
void loadProperties() override {}
39+
void loadProperties() override;
3640
void resetProperties() override {}
3741
void requestElements() override {}
3842

3943
bool isEmpty() const override;
4044

45+
bool canHideEmptyStavesInSelection() const { return m_canHideEmptyStavesInSelection; }
46+
bool canShowAllEmptyStaves() const { return m_canShowAllEmptyStaves; }
47+
bool canResetEmptyStavesVisibility() const { return m_canResetEmptyStavesVisibility; }
48+
4149
Q_INVOKABLE void hideEmptyStavesInSelection();
4250
Q_INVOKABLE void showAllEmptyStaves();
4351
Q_INVOKABLE void resetEmptyStavesVisibility();
52+
53+
signals:
54+
void canHideEmptyStavesInSelectionChanged();
55+
void canShowAllEmptyStavesChanged();
56+
void canResetEmptyStavesVisibilityChanged();
57+
58+
private:
59+
void onCurrentNotationChanged() override;
60+
void onNotationChanged(const mu::engraving::PropertyIdSet&, const mu::engraving::StyleIdSet&) override;
61+
62+
void updateCanHideEmptyStavesInSelection();
63+
void updateCanShowAllEmptyStaves();
64+
void updateCanResetEmptyStavesVisibility();
65+
66+
bool m_canHideEmptyStavesInSelection = false;
67+
bool m_canShowAllEmptyStaves = false;
68+
bool m_canResetEmptyStavesVisibility = false;
4469
};
4570
}

src/inspector/view/qml/MuseScore/Inspector/emptystaves/EmptyStavesVisibilityInspectorView.qml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@ InspectorSectionView {
4545
navigation.panel: root.navigationPanel
4646
navigation.row: root.navigationRowStart + 1
4747

48+
icon: IconCode.HIDE_EMPTY_STAVES
4849
text: qsTrc("inspector", "Hide empty staves")
50+
orientation: Qt.Horizontal
51+
enabled: root.model && root.model.canHideEmptyStavesInSelection
4952

5053
onClicked: {
5154
if (root.model) {
@@ -61,7 +64,10 @@ InspectorSectionView {
6164
navigation.panel: root.navigationPanel
6265
navigation.row: root.navigationRowStart + 2
6366

64-
text: qsTrc("inspector", "Show all empty staves")
67+
icon: IconCode.SHOW_EMPTY_STAVES
68+
text: qsTrc("inspector", "Show empty staves")
69+
orientation: Qt.Horizontal
70+
enabled: root.model && root.model.canShowAllEmptyStaves
6571

6672
onClicked: {
6773
if (root.model) {
@@ -77,7 +83,10 @@ InspectorSectionView {
7783
navigation.panel: root.navigationPanel
7884
navigation.row: root.navigationRowStart + 3
7985

86+
icon: IconCode.UNDO
8087
text: qsTrc("inspector", "Reset empty staves visibility")
88+
orientation: Qt.Horizontal
89+
enabled: root.model && root.model.canResetEmptyStavesVisibility
8190

8291
onClicked: {
8392
if (root.model) {

0 commit comments

Comments
 (0)