1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2017 Werner Schweer and others
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 "inspectorTextLineBase.h"
15 #include "libmscore/textlinebase.h"
16 #include "libmscore/score.h"
17
18 namespace Ms {
19
20 //---------------------------------------------------------
21 // populateHookType
22 //---------------------------------------------------------
23
populateHookType(QComboBox * b)24 void populateHookType(QComboBox* b)
25 {
26 b->clear();
27 b->addItem(b->QObject::tr("None", "no hook type"), int(HookType::NONE));
28 b->addItem(b->QObject::tr("90\u00b0"), int(HookType::HOOK_90)); // °
29 b->addItem(b->QObject::tr("45\u00b0"), int(HookType::HOOK_45)); // °
30 b->addItem(b->QObject::tr("90\u00b0 centered"), int(HookType::HOOK_90T)); // °
31 }
32
33 //---------------------------------------------------------
34 // populateTextPlace
35 //---------------------------------------------------------
36
populateTextPlace(QComboBox * b)37 void populateTextPlace(QComboBox* b)
38 {
39 b->clear();
40 b->addItem(b->QObject::tr("Auto"), int(PlaceText::AUTO));
41 b->addItem(b->QObject::tr("Above"), int(PlaceText::ABOVE));
42 b->addItem(b->QObject::tr("Below"), int(PlaceText::BELOW));
43 b->addItem(b->QObject::tr("Left"), int(PlaceText::LEFT));
44 }
45
46 //---------------------------------------------------------
47 // InspectorTextLineBase
48 //---------------------------------------------------------
49
InspectorTextLineBase(QWidget * parent)50 InspectorTextLineBase::InspectorTextLineBase(QWidget* parent)
51 : InspectorElementBase(parent)
52 {
53 l.setupUi(addWidget());
54 setupLineStyle(l.lineStyle);
55 tl.setupUi(addWidget());
56
57 const std::vector<InspectorItem> iiList = {
58 { Pid::DIAGONAL, 0, l.diagonal, l.resetDiagonal },
59 { Pid::LINE_VISIBLE, 0, l.lineVisible, l.resetLineVisible },
60 { Pid::COLOR, 0, l.lineColor, l.resetLineColor },
61 { Pid::LINE_WIDTH, 0, l.lineWidth, l.resetLineWidth },
62 { Pid::LINE_STYLE, 0, l.lineStyle, l.resetLineStyle },
63 { Pid::DASH_LINE_LEN, 0, l.dashLineLength, l.resetDashLineLength },
64 { Pid::DASH_GAP_LEN, 0, l.dashGapLength, l.resetDashGapLength },
65
66 { Pid::BEGIN_TEXT, 0, tl.beginText, tl.resetBeginText },
67 { Pid::BEGIN_TEXT_PLACE, 0, tl.beginTextPlacement, tl.resetBeginTextPlacement },
68 { Pid::BEGIN_TEXT_ALIGN, 0, tl.beginTextAlign, tl.resetBeginTextAlign },
69 { Pid::BEGIN_FONT_FACE, 0, tl.beginFontFace, tl.resetBeginFontFace },
70 { Pid::BEGIN_FONT_SIZE, 0, tl.beginFontSize, tl.resetBeginFontSize },
71 { Pid::BEGIN_FONT_STYLE, 0, tl.beginFontStyle, tl.resetBeginFontStyle },
72 { Pid::BEGIN_TEXT_OFFSET, 0, tl.beginTextOffset, tl.resetBeginTextOffset },
73 { Pid::BEGIN_HOOK_TYPE, 0, tl.beginHookType, tl.resetBeginHookType },
74 { Pid::BEGIN_HOOK_HEIGHT, 0, tl.beginHookHeight, tl.resetBeginHookHeight },
75
76 { Pid::CONTINUE_TEXT, 0, tl.continueText, tl.resetContinueText },
77 { Pid::CONTINUE_TEXT_PLACE, 0, tl.continueTextPlacement, tl.resetContinueTextPlacement },
78 { Pid::CONTINUE_TEXT_ALIGN, 0, tl.continueTextAlign, tl.resetContinueTextAlign },
79 { Pid::CONTINUE_FONT_FACE, 0, tl.continueFontFace, tl.resetContinueFontFace },
80 { Pid::CONTINUE_FONT_SIZE, 0, tl.continueFontSize, tl.resetContinueFontSize },
81 { Pid::CONTINUE_FONT_STYLE, 0, tl.continueFontStyle, tl.resetContinueFontStyle },
82 { Pid::CONTINUE_TEXT_OFFSET, 0, tl.continueTextOffset, tl.resetContinueTextOffset },
83
84 { Pid::END_TEXT, 0, tl.endText, tl.resetEndText },
85 { Pid::END_TEXT_PLACE, 0, tl.endTextPlacement, tl.resetEndTextPlacement },
86 { Pid::END_TEXT_ALIGN, 0, tl.endTextAlign, tl.resetEndTextAlign },
87 { Pid::END_FONT_FACE, 0, tl.endFontFace, tl.resetEndFontFace },
88 { Pid::END_FONT_SIZE, 0, tl.endFontSize, tl.resetEndFontSize },
89 { Pid::END_FONT_STYLE, 0, tl.endFontStyle, tl.resetEndFontStyle },
90 { Pid::END_TEXT_OFFSET, 0, tl.endTextOffset, tl.resetEndTextOffset },
91 { Pid::END_HOOK_TYPE, 0, tl.endHookType, tl.resetEndHookType },
92 { Pid::END_HOOK_HEIGHT, 0, tl.endHookHeight, tl.resetEndHookHeight },
93 };
94
95 for (auto& i : iiList)
96 iList.push_back(i);
97 const std::vector<InspectorPanel> ppList = {
98 { l.title, l.panel },
99 { tl.title, tl.panel },
100 };
101 for (auto& i : ppList)
102 pList.push_back(i);
103
104 populateHookType(tl.beginHookType);
105 populateHookType(tl.endHookType);
106 populateTextPlace(tl.beginTextPlacement);
107 populateTextPlace(tl.continueTextPlacement);
108 populateTextPlace(tl.endTextPlacement);
109
110 connect(tl.hasBeginText, &QCheckBox::clicked, this, &InspectorTextLineBase::hasBeginTextClicked);
111 connect(tl.hasContinueText, &QCheckBox::clicked, this, &InspectorTextLineBase::hasContinueTextClicked);
112 connect(tl.hasEndText, &QCheckBox::clicked, this, &InspectorTextLineBase::hasEndTextClicked);
113 }
114
115 //---------------------------------------------------------
116 // setElement
117 //---------------------------------------------------------
118
setElement()119 void InspectorTextLineBase::setElement()
120 {
121 InspectorElementBase::setElement();
122 TextLineBaseSegment* ts = static_cast<TextLineBaseSegment*>(inspector->element());
123 TextLineBase* t = ts->textLineBase();
124
125 bool bt = !t->beginText().isEmpty();
126 bool ct = !t->continueText().isEmpty();
127 bool et = !t->endText().isEmpty();
128
129 tl.hasBeginText->setChecked(bt);
130 tl.hasContinueText->setChecked(ct);
131 tl.hasEndText->setChecked(et);
132
133 tl.beginWidget->setVisible(bt);
134 tl.continueWidget->setVisible(ct);
135 tl.endWidget->setVisible(et);
136
137 updateLineType();
138 updateBeginHookType();
139 updateEndHookType();
140 }
141
142 //---------------------------------------------------------
143 // updateLineType
144 //---------------------------------------------------------
145
updateLineType()146 void InspectorTextLineBase::updateLineType()
147 {
148 TextLineBaseSegment* ts = static_cast<TextLineBaseSegment*>(inspector->element());
149 TextLineBase* t = ts->textLineBase();
150 bool userDash = t->lineStyle() == Qt::CustomDashLine;
151
152 l.dashLineLength->setVisible(userDash);
153 l.dashGapLength->setVisible(userDash);
154 l.resetDashLineLength->setVisible(userDash);
155 l.resetDashGapLength->setVisible(userDash);
156 l.dashLineLengthLabel->setVisible(userDash);
157 l.dashGapLengthLabel->setVisible(userDash);
158 }
159
160 //---------------------------------------------------------
161 // updateBeginHookType
162 //---------------------------------------------------------
163
updateBeginHookType()164 void InspectorTextLineBase::updateBeginHookType()
165 {
166 TextLineBaseSegment* ts = static_cast<TextLineBaseSegment*>(inspector->element());
167 TextLineBase* t = ts->textLineBase();
168 bool hook = t->beginHookType() != HookType::NONE;
169
170 tl.beginHookHeightWidget->setVisible(hook);
171 tl.resetBeginHookHeight->setVisible(hook);
172 }
173
174 //---------------------------------------------------------
175 // updateEndHookType
176 //---------------------------------------------------------
177
updateEndHookType()178 void InspectorTextLineBase::updateEndHookType()
179 {
180 TextLineBaseSegment* ts = static_cast<TextLineBaseSegment*>(inspector->element());
181 TextLineBase* t = ts->textLineBase();
182 bool hook = t->endHookType() != HookType::NONE;
183
184 tl.endHookHeightWidget->setVisible(hook);
185 tl.resetEndHookHeight->setVisible(hook);
186 }
187
188 //---------------------------------------------------------
189 // valueChanged
190 //---------------------------------------------------------
191
valueChanged(int idx)192 void InspectorTextLineBase::valueChanged(int idx)
193 {
194 InspectorBase::valueChanged(idx);
195 if (iList[idx].t == Pid::LINE_STYLE)
196 updateLineType();
197 else if (iList[idx].t == Pid::BEGIN_HOOK_TYPE)
198 updateBeginHookType();
199 else if (iList[idx].t == Pid::END_HOOK_TYPE)
200 updateEndHookType();
201 else if (iList[idx].t == Pid::COLOR)
202 inspector->update();
203 }
204
205 //---------------------------------------------------------
206 // hasBeginTextClicked
207 //---------------------------------------------------------
208
hasBeginTextClicked(bool checked)209 void InspectorTextLineBase::hasBeginTextClicked(bool checked)
210 {
211 if (!checked) {
212 TextLineBaseSegment* ts = static_cast<TextLineBaseSegment*>(inspector->element());
213 TextLineBase* t = ts->textLineBase();
214
215 t->score()->startCmd();
216 PropertyFlags ps = t->propertyFlags(Pid::BEGIN_TEXT);
217 if (ps == PropertyFlags::STYLED)
218 ps = PropertyFlags::UNSTYLED;
219 t->undoChangeProperty(Pid::BEGIN_TEXT, QString(), ps);
220 t->undoResetProperty(Pid::BEGIN_TEXT_PLACE);
221 t->undoResetProperty(Pid::BEGIN_TEXT_ALIGN);
222 t->undoResetProperty(Pid::BEGIN_FONT_FACE);
223 t->undoResetProperty(Pid::BEGIN_FONT_SIZE);
224 t->undoResetProperty(Pid::BEGIN_FONT_STYLE);
225 t->undoResetProperty(Pid::BEGIN_TEXT_OFFSET);
226 t->triggerLayout();
227 t->score()->endCmd();
228 }
229 }
230
231 //---------------------------------------------------------
232 // hasContinueTextClicked
233 //---------------------------------------------------------
234
hasContinueTextClicked(bool checked)235 void InspectorTextLineBase::hasContinueTextClicked(bool checked)
236 {
237 if (!checked) {
238 TextLineBaseSegment* ts = static_cast<TextLineBaseSegment*>(inspector->element());
239 TextLineBase* t = ts->textLineBase();
240
241 t->score()->startCmd();
242 PropertyFlags ps = t->propertyFlags(Pid::CONTINUE_TEXT);
243 if (ps == PropertyFlags::STYLED)
244 ps = PropertyFlags::UNSTYLED;
245 t->undoChangeProperty(Pid::CONTINUE_TEXT, QString(), ps);
246 t->undoResetProperty(Pid::CONTINUE_TEXT_PLACE);
247 t->undoResetProperty(Pid::CONTINUE_TEXT_ALIGN);
248 t->undoResetProperty(Pid::CONTINUE_FONT_FACE);
249 t->undoResetProperty(Pid::CONTINUE_FONT_SIZE);
250 t->undoResetProperty(Pid::CONTINUE_FONT_STYLE);
251 t->undoResetProperty(Pid::CONTINUE_TEXT_OFFSET);
252 t->triggerLayout();
253 t->score()->endCmd();
254 }
255 }
256
257 //---------------------------------------------------------
258 // hasEndTextClicked
259 //---------------------------------------------------------
260
hasEndTextClicked(bool checked)261 void InspectorTextLineBase::hasEndTextClicked(bool checked)
262 {
263 if (!checked) {
264 TextLineBaseSegment* ts = static_cast<TextLineBaseSegment*>(inspector->element());
265 TextLineBase* t = ts->textLineBase();
266
267 t->score()->startCmd();
268 PropertyFlags ps = t->propertyFlags(Pid::END_TEXT);
269 if (ps == PropertyFlags::STYLED)
270 ps = PropertyFlags::UNSTYLED;
271 t->undoChangeProperty(Pid::END_TEXT, QString(), ps);
272 t->undoResetProperty(Pid::END_TEXT_PLACE);
273 t->undoResetProperty(Pid::END_TEXT_ALIGN);
274 t->undoResetProperty(Pid::END_FONT_FACE);
275 t->undoResetProperty(Pid::END_FONT_SIZE);
276 t->undoResetProperty(Pid::END_FONT_STYLE);
277 t->undoResetProperty(Pid::END_TEXT_OFFSET);
278 t->triggerLayout();
279 t->score()->endCmd();
280 }
281 }
282
283 } // namespace Ms
284