1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2016 Werner Schweer
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2
9 // as published by the Free Software Foundation and appearing in
10 // the file LICENSE.GPL
11 //=============================================================================
12
13 #include "inspector.h"
14 #include "inspectorBarline.h"
15 #include "libmscore/score.h"
16 #include "libmscore/barline.h"
17 #include "libmscore/staff.h"
18
19 namespace Ms {
20 //---------------------------------------------------------
21 // InspectorBarLine
22 //---------------------------------------------------------
23
InspectorBarLine(QWidget * parent)24 InspectorBarLine::InspectorBarLine(QWidget* parent)
25 : InspectorElementBase(parent)
26 {
27 s.setupUi(addWidget());
28 b.setupUi(addWidget());
29
30 for (auto i : BarLine::barLineTable)
31 b.type->addItem(qApp->translate("symUserNames", i.userName), int(i.type));
32
33 const std::vector<InspectorItem> il = {
34 { Pid::LEADING_SPACE, 1, s.leadingSpace, s.resetLeadingSpace },
35 { Pid::BARLINE_TYPE, 0, b.type, b.resetType },
36 { Pid::BARLINE_SPAN, 0, b.span, b.resetSpan },
37 { Pid::BARLINE_SPAN_FROM, 0, b.spanFrom, b.resetSpanFrom },
38 { Pid::BARLINE_SPAN_TO, 0, b.spanTo, b.resetSpanTo },
39 };
40 const std::vector<InspectorPanel> ppList = {
41 { s.title, s.panel },
42 { b.title, b.panel }
43 };
44
45 mapSignals(il, ppList);
46
47 #if 0
48 // when any of the span parameters is changed, span data need to be managed
49 connect(b.span, SIGNAL(valueChanged(int)), SLOT(manageSpanData()));
50 connect(b.spanFrom, SIGNAL(valueChanged(int)), SLOT(manageSpanData()));
51 connect(b.spanTo, SIGNAL(valueChanged(int)), SLOT(manageSpanData()));
52 #endif
53 connect(b.presetDefault, SIGNAL(clicked()), SLOT(presetDefaultClicked()));
54 connect(b.presetTick1, SIGNAL(clicked()), SLOT(presetTick1Clicked()));
55 connect(b.presetTick2, SIGNAL(clicked()), SLOT(presetTick2Clicked()));
56 connect(b.presetShort1, SIGNAL(clicked()), SLOT(presetShort1Clicked()));
57 connect(b.presetShort2, SIGNAL(clicked()), SLOT(presetShort2Clicked()));
58
59 connect(b.setAsStaffDefault, SIGNAL(clicked()), SLOT(setAsStaffDefault()));
60 }
61
62 //---------------------------------------------------------
63 // setAsStaffDefault
64 //---------------------------------------------------------
65
setAsStaffDefault()66 void InspectorBarLine::setAsStaffDefault()
67 {
68 BarLine* ebl = toBarLine(inspector->element());
69 QVariant span = ebl->getProperty(Pid::BARLINE_SPAN);
70 QVariant spanFrom = ebl->getProperty(Pid::BARLINE_SPAN_FROM);
71 QVariant spanTo = ebl->getProperty(Pid::BARLINE_SPAN_TO);
72
73 std::set<Staff*> staffList;
74
75 Score* score = ebl->score();
76 score->startCmd();
77 for (Element* el : *inspector->el()) {
78 if (!el || !el->isBarLine())
79 continue;
80 BarLine* bl = toBarLine(el);
81 Staff* staff = bl->staff();
82 if (std::find(staffList.begin(), staffList.end(), staff) == staffList.end()) {
83 staff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN, span);
84 staff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN_FROM, spanFrom);
85 staff->undoChangeProperty(Pid::STAFF_BARLINE_SPAN_TO, spanTo);
86 staffList.insert(staff);
87 }
88 if (bl->barLineType() == BarLineType::NORMAL)
89 bl->setGenerated(true);
90 }
91 score->endCmd();
92 }
93
94 //---------------------------------------------------------
95 // setElement
96 //---------------------------------------------------------
97
98 #include <QStandardItem>
99
setElement()100 void InspectorBarLine::setElement()
101 {
102 InspectorElementBase::setElement();
103 BarLine* bl = toBarLine(inspector->element());
104
105 // enable / disable individual type combo items according to score and selected bar line status
106 bool bMultiStaff = bl->score()->nstaves() > 1;
107 BarLineType blt = bl->barLineType();
108 bool isRepeat = blt & (BarLineType::START_REPEAT | BarLineType::END_REPEAT | BarLineType::END_START_REPEAT);
109 // bool isRepeat = blt & (BarLineType::START_REPEAT | BarLineType::END_REPEAT);
110
111 const QStandardItemModel* model = qobject_cast<const QStandardItemModel*>(b.type->model());
112 int i = 0;
113 for (auto& k : BarLine::barLineTable) {
114 QStandardItem* item = model->item(i);
115 // if combo item is repeat type, should be disabled for multi-staff scores
116 if (k.type & (BarLineType::START_REPEAT | BarLineType::END_REPEAT | BarLineType::END_START_REPEAT)) {
117 // if (k.type & (BarLineType::START_REPEAT | BarLineType::END_REPEAT)) {
118 // disable / enable
119 item->setFlags(bMultiStaff ?
120 item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) :
121 item->flags() | (Qt::ItemFlags)(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
122 }
123 // if combo item is NOT repeat type, should be disabled if selected bar line is a repeat
124 else {
125 item->setFlags(isRepeat ?
126 item->flags() & ~(Qt::ItemIsSelectable|Qt::ItemIsEnabled) :
127 item->flags() | (Qt::ItemFlags)(Qt::ItemIsSelectable|Qt::ItemIsEnabled) );
128 }
129 ++i;
130 }
131 #if 0
132 blockSpanDataSignals(true);
133 manageSpanData();
134 blockSpanDataSignals(false);
135 #endif
136 }
137
138 //---------------------------------------------------------
139 // presetDefaultClicked
140 //---------------------------------------------------------
141
presetDefaultClicked()142 void InspectorBarLine::presetDefaultClicked()
143 {
144 Score* score = inspector->element()->score();
145 score->startCmd();
146
147 BarLine* bl;
148 for (Element* el : *inspector->el()) {
149 if (el->isBarLine()) {
150 bl = toBarLine(el);
151 bl->undoResetProperty(Pid::BARLINE_SPAN);
152 bl->undoResetProperty(Pid::BARLINE_SPAN_FROM);
153 bl->undoResetProperty(Pid::BARLINE_SPAN_TO);
154 }
155 }
156
157 score->endCmd();
158 }
159
160 //---------------------------------------------------------
161 // presetTick1Clicked
162 //---------------------------------------------------------
163
presetTick1Clicked()164 void InspectorBarLine::presetTick1Clicked()
165 {
166 Score* score = inspector->element()->score();
167 score->startCmd();
168
169 BarLine* bl;
170 for (Element* el : *inspector->el()) {
171 if (el->isBarLine()) {
172 bl = toBarLine(el);
173 bl->undoChangeProperty(Pid::BARLINE_SPAN, false);
174 bl->undoChangeProperty(Pid::BARLINE_SPAN_FROM, BARLINE_SPAN_TICK1_FROM);
175 bl->undoChangeProperty(Pid::BARLINE_SPAN_TO, BARLINE_SPAN_TICK1_TO);
176 }
177 }
178
179 score->endCmd();
180 }
181
182 //---------------------------------------------------------
183 // presetTick2Clicked
184 //---------------------------------------------------------
185
presetTick2Clicked()186 void InspectorBarLine::presetTick2Clicked()
187 {
188 Score* score = inspector->element()->score();
189 score->startCmd();
190
191 BarLine* bl;
192 for (Element* el : *inspector->el()) {
193 if (el->isBarLine()) {
194 bl = toBarLine(el);
195 bl->undoChangeProperty(Pid::BARLINE_SPAN, false);
196 bl->undoChangeProperty(Pid::BARLINE_SPAN_FROM, BARLINE_SPAN_TICK2_FROM);
197 bl->undoChangeProperty(Pid::BARLINE_SPAN_TO, BARLINE_SPAN_TICK2_TO);
198 }
199 }
200
201 score->endCmd();
202 }
203
204 //---------------------------------------------------------
205 // presetShort1Clicked
206 //---------------------------------------------------------
207
presetShort1Clicked()208 void InspectorBarLine::presetShort1Clicked()
209 {
210 Score* score = inspector->element()->score();
211 score->startCmd();
212
213 BarLine* bl;
214 for (Element* el : *inspector->el()) {
215 if (el->isBarLine()) {
216 bl = toBarLine(el);
217 bl->undoChangeProperty(Pid::BARLINE_SPAN, false);
218 bl->undoChangeProperty(Pid::BARLINE_SPAN_FROM, BARLINE_SPAN_SHORT1_FROM);
219 int shortDelta = bl->staff() ? (bl->staff()->lines(bl->tick()) - 5) * 2 : 0;
220 bl->undoChangeProperty(Pid::BARLINE_SPAN_TO, BARLINE_SPAN_SHORT1_TO + shortDelta);
221 }
222 }
223 score->endCmd();
224 }
225
226 //---------------------------------------------------------
227 // presetShort2Clicked
228 //---------------------------------------------------------
229
presetShort2Clicked()230 void InspectorBarLine::presetShort2Clicked()
231 {
232 Score* score = inspector->element()->score();
233 score->startCmd();
234
235 BarLine* bl;
236 for (Element* el : *inspector->el()) {
237 if (el->isBarLine()) {
238 bl = toBarLine(el);
239 bl->undoChangeProperty(Pid::BARLINE_SPAN, false);
240 bl->undoChangeProperty(Pid::BARLINE_SPAN_FROM, BARLINE_SPAN_SHORT2_FROM);
241 int shortDelta = bl->staff() ? (bl->staff()->lines(bl->tick()) - 5) * 2 : 0;
242 bl->undoChangeProperty(Pid::BARLINE_SPAN_TO, BARLINE_SPAN_SHORT2_TO + shortDelta);
243 }
244 }
245 score->endCmd();
246 }
247
248 //---------------------------------------------------------
249 // manageSpanData
250 //
251 // Makes sure span data are legal and consistent
252 //---------------------------------------------------------
253
manageSpanData()254 void InspectorBarLine::manageSpanData()
255 {
256 #if 0
257 BarLine* bl = toBarLine(inspector->element());
258
259 // determine MIN and MAX for SPANFROM and SPANTO
260 Staff* staffFrom = bl->staff();
261 Staff* staffTo = bl->score()->staff(bl->staffIdx() + bl->span() - 1);
262 int staffFromLines= (staffFrom ? staffFrom->lines(bl->tick()) : 5);
263 int staffToLines = (staffTo ? staffTo->lines(bl->tick()) : 5);
264
265 // From: min = minimum possible according to number of staff lines
266 // max = if same as To, at least 1sp (2 units) above To; if not, max possible according to num.of lines
267
268 int min = staffFromLines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : MIN_BARLINE_SPAN_FROMTO;
269 int max = bl->span() < 2 ? bl->spanTo() - MIN_BARLINE_FROMTO_DIST
270 : (staffFromLines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (staffFromLines-1) * 2 + 2);
271 b.spanFrom->setMinimum(min);
272 b.spanFrom->setMaximum(max);
273
274 // To: min = if same as From, at least 1sp (2 units) below From; if not, min possible according to num.of lines
275 // max = max possible according to number of staff lines
276 min = bl->span() < 2 ? bl->spanFrom() + MIN_BARLINE_FROMTO_DIST
277 : (staffToLines == 1 ? BARLINE_SPAN_1LINESTAFF_FROM : MIN_BARLINE_SPAN_FROMTO);
278 max = staffToLines == 1 ? BARLINE_SPAN_1LINESTAFF_TO : (staffToLines-1) * 2 + 2;
279
280 b.spanTo->setMinimum(min);
281 b.spanTo->setMaximum(max);
282
283 // determine MAX for SPAN
284 max = bl->score()->nstaves() - bl->staffIdx();
285 b.span->setMaximum(max);
286 #endif
287 }
288
289 //---------------------------------------------------------
290 // blockSpanDataSignals
291 //
292 // block/unblok signals for span value controls
293 //---------------------------------------------------------
294
blockSpanDataSignals(bool val)295 void InspectorBarLine::blockSpanDataSignals(bool val)
296 {
297 b.span->blockSignals(val);
298 b.spanFrom->blockSignals(val);
299 b.spanTo->blockSignals(val);
300 }
301
302 }
303
304
305