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) 2023 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 :
23 : #include "singledraw.h"
24 :
25 : #include "draw/painter.h"
26 : #include "draw/svgrenderer.h"
27 : #include "draw/types/drawtypes.h"
28 :
29 : #include "iengravingconfiguration.h" // IWYU pragma: keep
30 :
31 : #include "style/style.h"
32 : #include "style/defaultstyle.h"
33 :
34 : #include "dom/accidental.h"
35 : #include "dom/actionicon.h"
36 : #include "dom/ambitus.h"
37 : #include "dom/arpeggio.h"
38 : #include "dom/articulation.h"
39 :
40 : #include "dom/bagpembell.h"
41 : #include "dom/barline.h"
42 : #include "dom/beam.h"
43 : #include "dom/bend.h"
44 : #include "dom/bracket.h"
45 : #include "dom/breath.h"
46 :
47 : #include "dom/chordbracket.h"
48 : #include "dom/chordline.h"
49 : #include "dom/clef.h"
50 : #include "dom/capo.h"
51 :
52 : #include "dom/deadslapped.h"
53 : #include "dom/dynamic.h"
54 :
55 : #include "dom/expression.h"
56 :
57 : #include "dom/fermata.h"
58 : #include "dom/figuredbass.h"
59 : #include "dom/fingering.h"
60 : #include "dom/fret.h"
61 :
62 : #include "dom/glissando.h"
63 : #include "dom/gradualtempochange.h"
64 : #include "dom/guitarbend.h"
65 :
66 : #include "dom/hairpin.h"
67 : #include "dom/hammeronpulloff.h"
68 : #include "dom/harppedaldiagram.h"
69 : #include "dom/harmonicmark.h"
70 : #include "dom/harmony.h"
71 : #include "dom/hook.h"
72 :
73 : #include "dom/image.h"
74 : #include "dom/instrchange.h"
75 : #include "dom/instrumentname.h"
76 :
77 : #include "dom/jump.h"
78 :
79 : #include "dom/keysig.h"
80 :
81 : #include "dom/layoutbreak.h"
82 : #include "dom/ledgerline.h"
83 : #include "dom/letring.h"
84 : #include "dom/lyrics.h"
85 :
86 : #include "dom/marker.h"
87 : #include "dom/measure.h"
88 : #include "dom/measurenumber.h"
89 : #include "dom/measurerepeat.h"
90 :
91 : #include "dom/note.h"
92 : #include "dom/noteline.h"
93 :
94 : #include "dom/ornament.h"
95 : #include "dom/ottava.h"
96 :
97 : #include "dom/palmmute.h"
98 : #include "dom/part.h"
99 : #include "dom/pedal.h"
100 : #include "dom/pickscrape.h"
101 : #include "dom/playcounttext.h"
102 : #include "dom/playtechannotation.h"
103 :
104 : #include "dom/rasgueado.h"
105 : #include "dom/rehearsalmark.h"
106 : #include "dom/rest.h"
107 :
108 : #include "dom/score.h"
109 : #include "dom/shadownote.h"
110 : #include "dom/slur.h"
111 : #include "dom/soundflag.h"
112 : #include "dom/spacer.h"
113 : #include "dom/staff.h"
114 : #include "dom/stafflines.h"
115 : #include "dom/staffstate.h"
116 : #include "dom/stafftext.h"
117 : #include "dom/stafftype.h"
118 : #include "dom/stafftypechange.h"
119 : #include "dom/stavesharingchange.h"
120 : #include "dom/stavesharinglabel.h"
121 : #include "dom/stem.h"
122 : #include "dom/stemslash.h"
123 : #include "dom/sticking.h"
124 : #include "dom/stringtunings.h"
125 : #include "dom/symbol.h"
126 : #include "dom/systemdivider.h"
127 : #include "dom/systemtext.h"
128 :
129 : #include "dom/tapping.h"
130 : #include "dom/tempotext.h"
131 : #include "dom/text.h"
132 : #include "dom/textbase.h"
133 : #include "dom/textline.h"
134 : #include "dom/textlinebase.h"
135 : #include "dom/tie.h"
136 : #include "dom/timesig.h"
137 : #include "dom/tremolosinglechord.h"
138 : #include "dom/tremolotwochord.h"
139 : #include "dom/tremolobar.h"
140 : #include "dom/trill.h"
141 : #include "dom/tripletfeel.h"
142 : #include "dom/tuplet.h"
143 :
144 : #include "dom/vibrato.h"
145 : #include "dom/volta.h"
146 :
147 : #include "dom/whammybar.h"
148 :
149 : #include "editing/mscoreview.h"
150 :
151 : #include "rendering/score/stemlayout.h"
152 :
153 : #include "infrastructure/rtti.h"
154 :
155 : using namespace mu::engraving::rendering::single;
156 : using namespace mu::engraving;
157 : using namespace mu::engraving::rtti;
158 : using namespace muse;
159 : using namespace muse::draw;
160 :
161 0 : void SingleDraw::drawItem(const EngravingItem* item, Painter* painter, const PaintOptions& opt)
162 : {
163 0 : switch (item->type()) {
164 0 : case ElementType::ACCIDENTAL: draw(item_cast<const Accidental*>(item), painter, opt);
165 0 : break;
166 0 : case ElementType::ACTION_ICON: draw(item_cast<const ActionIcon*>(item), painter, opt);
167 0 : break;
168 0 : case ElementType::AMBITUS: draw(item_cast<const Ambitus*>(item), painter, opt);
169 0 : break;
170 0 : case ElementType::ARPEGGIO: draw(item_cast<const Arpeggio*>(item), painter, opt);
171 0 : break;
172 0 : case ElementType::CHORD_BRACKET: draw(item_cast<const ChordBracket*>(item), painter, opt);
173 0 : break;
174 0 : case ElementType::ARTICULATION: draw(item_cast<const Articulation*>(item), painter, opt);
175 0 : break;
176 :
177 0 : case ElementType::BAGPIPE_EMBELLISHMENT: draw(item_cast<const BagpipeEmbellishment*>(item), painter, opt);
178 0 : break;
179 0 : case ElementType::BAR_LINE: draw(item_cast<const BarLine*>(item), painter, opt);
180 0 : break;
181 0 : case ElementType::BEAM: draw(item_cast<const Beam*>(item), painter, opt);
182 0 : break;
183 0 : case ElementType::BEND: draw(item_cast<const Bend*>(item), painter, opt);
184 0 : break;
185 0 : case ElementType::BRACKET: draw(item_cast<const Bracket*>(item), painter, opt);
186 0 : break;
187 0 : case ElementType::BREATH: draw(item_cast<const Breath*>(item), painter, opt);
188 0 : break;
189 :
190 0 : case ElementType::CHORDLINE: draw(item_cast<const ChordLine*>(item), painter, opt);
191 0 : break;
192 0 : case ElementType::CLEF: draw(item_cast<const Clef*>(item), painter, opt);
193 0 : break;
194 0 : case ElementType::CAPO: draw(item_cast<const Capo*>(item), painter, opt);
195 0 : break;
196 :
197 0 : case ElementType::DEAD_SLAPPED: draw(item_cast<const DeadSlapped*>(item), painter, opt);
198 0 : break;
199 0 : case ElementType::DYNAMIC: draw(item_cast<const Dynamic*>(item), painter, opt);
200 0 : break;
201 :
202 0 : case ElementType::EXPRESSION: draw(item_cast<const Expression*>(item), painter, opt);
203 0 : break;
204 :
205 0 : case ElementType::FERMATA: draw(item_cast<const Fermata*>(item), painter, opt);
206 0 : break;
207 0 : case ElementType::FIGURED_BASS: draw(item_cast<const FiguredBass*>(item), painter, opt);
208 0 : break;
209 0 : case ElementType::FINGERING: draw(item_cast<const Fingering*>(item), painter, opt);
210 0 : break;
211 0 : case ElementType::FRET_DIAGRAM: draw(item_cast<const FretDiagram*>(item), painter, opt);
212 0 : break;
213 0 : case ElementType::FSYMBOL: draw(item_cast<const FSymbol*>(item), painter, opt);
214 0 : break;
215 :
216 0 : case ElementType::GLISSANDO_SEGMENT: draw(item_cast<const GlissandoSegment*>(item), painter, opt);
217 0 : break;
218 0 : case ElementType::GRADUAL_TEMPO_CHANGE_SEGMENT: draw(item_cast<const GradualTempoChangeSegment*>(item), painter, opt);
219 0 : break;
220 0 : case ElementType::GUITAR_BEND_SEGMENT: draw(item_cast<const GuitarBendSegment*>(item), painter, opt);
221 0 : break;
222 0 : case ElementType::GUITAR_BEND_TEXT: drawTextBase(toTextBase(item), painter, opt);
223 0 : break;
224 :
225 0 : case ElementType::HAIRPIN_SEGMENT: draw(item_cast<const HairpinSegment*>(item), painter, opt);
226 0 : break;
227 0 : case ElementType::HAMMER_ON_PULL_OFF_SEGMENT: draw(item_cast<const HammerOnPullOffSegment*>(item), painter, opt);
228 0 : break;
229 0 : case ElementType::HAMMER_ON_PULL_OFF_TEXT: draw(item_cast<const HammerOnPullOffText*>(item), painter, opt);
230 0 : break;
231 0 : case ElementType::HARP_DIAGRAM: draw(item_cast<const HarpPedalDiagram*>(item), painter, opt);
232 0 : break;
233 0 : case ElementType::HARMONIC_MARK_SEGMENT: draw(item_cast<const HarmonicMarkSegment*>(item), painter, opt);
234 0 : break;
235 0 : case ElementType::HARMONY: draw(item_cast<const Harmony*>(item), painter, opt);
236 0 : break;
237 0 : case ElementType::HOOK: draw(item_cast<const Hook*>(item), painter, opt);
238 0 : break;
239 :
240 0 : case ElementType::IMAGE: draw(item_cast<const Image*>(item), painter, opt);
241 0 : break;
242 0 : case ElementType::INSTRUMENT_CHANGE: draw(item_cast<const InstrumentChange*>(item), painter, opt);
243 0 : break;
244 0 : case ElementType::INSTRUMENT_NAME: draw(item_cast<const InstrumentName*>(item), painter, opt);
245 0 : break;
246 :
247 0 : case ElementType::JUMP: draw(item_cast<const Jump*>(item), painter, opt);
248 0 : break;
249 :
250 0 : case ElementType::KEYSIG: draw(item_cast<const KeySig*>(item), painter, opt);
251 0 : break;
252 :
253 0 : case ElementType::LAYOUT_BREAK: draw(item_cast<const LayoutBreak*>(item), painter, opt);
254 0 : break;
255 0 : case ElementType::LEDGER_LINE: draw(item_cast<const LedgerLine*>(item), painter, opt);
256 0 : break;
257 0 : case ElementType::LET_RING_SEGMENT: draw(item_cast<const LetRingSegment*>(item), painter, opt);
258 0 : break;
259 0 : case ElementType::LYRICS: draw(item_cast<const Lyrics*>(item), painter, opt);
260 0 : break;
261 :
262 0 : case ElementType::MARKER: draw(item_cast<const Marker*>(item), painter, opt);
263 0 : break;
264 0 : case ElementType::MEASURE_NUMBER: draw(item_cast<const MeasureNumber*>(item), painter, opt);
265 0 : break;
266 0 : case ElementType::MEASURE_REPEAT: draw(item_cast<const MeasureRepeat*>(item), painter, opt);
267 0 : break;
268 :
269 0 : case ElementType::NOTE: draw(item_cast<const Note*>(item), painter, opt);
270 0 : break;
271 0 : case ElementType::NOTEHEAD: draw(item_cast<const NoteHead*>(item), painter, opt);
272 0 : break;
273 0 : case ElementType::NOTELINE_SEGMENT: draw(item_cast<const NoteLineSegment*>(item), painter, opt);
274 0 : break;
275 :
276 0 : case ElementType::ORNAMENT: draw(item_cast<const Ornament*>(item), painter, opt);
277 0 : break;
278 0 : case ElementType::OTTAVA_SEGMENT: draw(item_cast<const OttavaSegment*>(item), painter, opt);
279 0 : break;
280 :
281 0 : case ElementType::PALM_MUTE_SEGMENT: draw(item_cast<const PalmMuteSegment*>(item), painter, opt);
282 0 : break;
283 0 : case ElementType::PEDAL_SEGMENT: draw(item_cast<const PedalSegment*>(item), painter, opt);
284 0 : break;
285 0 : case ElementType::PICK_SCRAPE_SEGMENT: draw(item_cast<const PickScrapeSegment*>(item), painter, opt);
286 0 : break;
287 0 : case ElementType::PLAY_COUNT_TEXT: draw(item_cast<const PlayCountText*>(item), painter, opt);
288 0 : break;
289 0 : case ElementType::PLAYTECH_ANNOTATION: draw(item_cast<const PlayTechAnnotation*>(item), painter, opt);
290 0 : break;
291 :
292 0 : case ElementType::RASGUEADO_SEGMENT: draw(item_cast<const RasgueadoSegment*>(item), painter, opt);
293 0 : break;
294 0 : case ElementType::REHEARSAL_MARK: draw(item_cast<const RehearsalMark*>(item), painter, opt);
295 0 : break;
296 0 : case ElementType::REST: draw(item_cast<const Rest*>(item), painter, opt);
297 0 : break;
298 :
299 0 : case ElementType::SHADOW_NOTE: draw(item_cast<const ShadowNote*>(item), painter, opt);
300 0 : break;
301 0 : case ElementType::SLUR_SEGMENT: draw(item_cast<const SlurSegment*>(item), painter, opt);
302 0 : break;
303 0 : case ElementType::SPACER: draw(item_cast<const Spacer*>(item), painter, opt);
304 0 : break;
305 0 : case ElementType::STAFF_LINES: draw(item_cast<const StaffLines*>(item), painter, opt);
306 0 : break;
307 0 : case ElementType::STAFF_STATE: draw(item_cast<const StaffState*>(item), painter, opt);
308 0 : break;
309 0 : case ElementType::STAFF_TEXT: draw(item_cast<const StaffText*>(item), painter, opt);
310 0 : break;
311 0 : case ElementType::STAVE_SHARING_CHANGE: draw(item_cast<const StaveSharingChange*>(item), painter, opt);
312 0 : break;
313 0 : case ElementType::STAVE_SHARING_LABEL: draw(item_cast<const StaveSharingLabel*>(item), painter, opt);
314 0 : break;
315 0 : case ElementType::STAFFTYPE_CHANGE: draw(item_cast<const StaffTypeChange*>(item), painter, opt);
316 0 : break;
317 0 : case ElementType::STEM: draw(item_cast<const Stem*>(item), painter, opt);
318 0 : break;
319 0 : case ElementType::STEM_SLASH: draw(item_cast<const StemSlash*>(item), painter, opt);
320 0 : break;
321 0 : case ElementType::STICKING: draw(item_cast<const Sticking*>(item), painter, opt);
322 0 : break;
323 0 : case ElementType::STRING_TUNINGS: draw(item_cast<const StringTunings*>(item), painter, opt);
324 0 : break;
325 0 : case ElementType::SYMBOL: draw(item_cast<const Symbol*>(item), painter, opt);
326 0 : break;
327 0 : case ElementType::SYSTEM_DIVIDER: draw(item_cast<const SystemDivider*>(item), painter, opt);
328 0 : break;
329 0 : case ElementType::SYSTEM_TEXT: draw(item_cast<const SystemText*>(item), painter, opt);
330 0 : break;
331 0 : case ElementType::SOUND_FLAG: draw(item_cast<const SoundFlag*>(item), painter, opt);
332 0 : break;
333 :
334 0 : case ElementType::TAPPING: draw(item_cast<const Tapping*>(item), painter, opt);
335 0 : break;
336 0 : case ElementType::TEMPO_TEXT: draw(item_cast<const TempoText*>(item), painter, opt);
337 0 : break;
338 0 : case ElementType::TEXT: draw(item_cast<const Text*>(item), painter, opt);
339 0 : break;
340 0 : case ElementType::TEXTLINE_SEGMENT: draw(item_cast<const TextLineSegment*>(item), painter, opt);
341 0 : break;
342 0 : case ElementType::TIE_SEGMENT: draw(item_cast<const TieSegment*>(item), painter, opt);
343 0 : break;
344 0 : case ElementType::TIMESIG: draw(item_cast<const TimeSig*>(item), painter, opt);
345 0 : break;
346 0 : case ElementType::TREMOLO_SINGLECHORD: draw(item_cast<const TremoloSingleChord*>(item), painter, opt);
347 0 : break;
348 0 : case ElementType::TREMOLO_TWOCHORD: draw(item_cast<const TremoloTwoChord*>(item), painter, opt);
349 0 : break;
350 0 : case ElementType::TREMOLOBAR: draw(item_cast<const TremoloBar*>(item), painter, opt);
351 0 : break;
352 0 : case ElementType::TRILL_SEGMENT: draw(item_cast<const TrillSegment*>(item), painter, opt);
353 0 : break;
354 0 : case ElementType::TRIPLET_FEEL: draw(item_cast<const TripletFeel*>(item), painter, opt);
355 0 : break;
356 0 : case ElementType::TUPLET: draw(item_cast<const Tuplet*>(item), painter, opt);
357 0 : break;
358 :
359 0 : case ElementType::VIBRATO_SEGMENT: draw(item_cast<const VibratoSegment*>(item), painter, opt);
360 0 : break;
361 0 : case ElementType::VOLTA_SEGMENT: draw(item_cast<const VoltaSegment*>(item), painter, opt);
362 0 : break;
363 :
364 0 : case ElementType::WHAMMY_BAR_SEGMENT: draw(item_cast<const WhammyBarSegment*>(item), painter, opt);
365 0 : break;
366 0 : default:
367 0 : NOT_IMPLEMENTED << item->typeName();
368 0 : UNREACHABLE;
369 : }
370 0 : }
371 :
372 0 : void SingleDraw::draw(const Accidental* item, Painter* painter, const PaintOptions& opt)
373 : {
374 0 : IF_ASSERT_FAILED(item->ldata()) {
375 0 : return;
376 : }
377 :
378 0 : painter->setPen(item->curColor(opt));
379 0 : for (const Accidental::LayoutData::Sym& e : item->ldata()->syms) {
380 0 : item->drawSymbol(e.sym, painter, PointF(e.x, e.y));
381 : }
382 : }
383 :
384 0 : void SingleDraw::draw(const ActionIcon* item, Painter* painter, const PaintOptions&)
385 : {
386 : TRACE_DRAW_ITEM;
387 0 : painter->setFont(item->iconFont());
388 0 : painter->drawText(PointF(), Char(item->icon()));
389 0 : }
390 :
391 0 : void SingleDraw::draw(const Ambitus* item, Painter* painter, const PaintOptions& opt)
392 : {
393 : TRACE_DRAW_ITEM;
394 :
395 0 : const Ambitus::LayoutData* layoutData = item->ldata();
396 0 : IF_ASSERT_FAILED(layoutData) {
397 0 : return;
398 : }
399 :
400 0 : double spatium = item->spatium();
401 0 : double lw = item->lineWidth().val() * spatium;
402 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
403 :
404 0 : item->drawSymbol(item->noteHead(), painter, layoutData->topPos);
405 0 : item->drawSymbol(item->noteHead(), painter, layoutData->bottomPos);
406 0 : if (item->hasLine()) {
407 0 : painter->drawLine(layoutData->line);
408 : }
409 : }
410 :
411 0 : void SingleDraw::draw(const Arpeggio* item, Painter* painter, const PaintOptions& opt)
412 : {
413 : TRACE_DRAW_ITEM;
414 :
415 0 : const Arpeggio::LayoutData* ldata = item->ldata();
416 0 : IF_ASSERT_FAILED(ldata) {
417 0 : return;
418 : }
419 :
420 0 : const double y1 = ldata->bbox().top();
421 0 : const double y2 = ldata->bbox().bottom();
422 0 : const double lineWidth = item->style().styleAbsolute(Sid::arpeggioLineWidth);
423 :
424 0 : painter->setPen(Pen(item->curColor(opt), lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
425 0 : painter->save();
426 :
427 0 : switch (item->arpeggioType()) {
428 0 : case ArpeggioType::NORMAL:
429 : case ArpeggioType::UP:
430 : {
431 0 : const RectF& r = ldata->symsBBox;
432 0 : painter->rotate(-90.0);
433 0 : item->drawSymbols(ldata->symbols, painter, PointF(-r.right() - y1, -r.bottom() + r.height()));
434 0 : } break;
435 :
436 0 : case ArpeggioType::DOWN:
437 : {
438 0 : const RectF& r = ldata->symsBBox;
439 0 : painter->rotate(90.0);
440 0 : item->drawSymbols(ldata->symbols, painter, PointF(-r.left() + y1, -r.top() - r.height()));
441 0 : } break;
442 :
443 0 : case ArpeggioType::UP_STRAIGHT:
444 : {
445 0 : const RectF& r = ldata->symsBBox;
446 0 : double x1 = item->spatium() * 0.5;
447 0 : item->drawSymbol(SymId::arrowheadBlackUp, painter, PointF(x1 - r.width() * 0.5, y1 - r.top()));
448 0 : double ny1 = y1 - r.top() * 0.5;
449 0 : painter->drawLine(LineF(x1, ny1, x1, y2));
450 0 : } break;
451 :
452 0 : case ArpeggioType::DOWN_STRAIGHT:
453 : {
454 0 : const RectF& r = ldata->symsBBox;
455 0 : double x1 = item->spatium() * 0.5;
456 0 : item->drawSymbol(SymId::arrowheadBlackDown, painter, PointF(x1 - r.width() * 0.5, y2 - r.bottom()));
457 0 : double ny2 = y2 + r.top() * 0.5;
458 0 : painter->drawLine(LineF(x1, y1, x1, ny2));
459 0 : } break;
460 :
461 0 : case ArpeggioType::BRACKET:
462 : {
463 0 : double w = item->style().styleS(Sid::arpeggioHookLen).val() * item->spatium();
464 0 : painter->drawLine(LineF(0.0, y1, w, y1));
465 0 : painter->drawLine(LineF(0.0, y2, w, y2));
466 0 : painter->drawLine(LineF(0.0, y1 - lineWidth / 2, 0.0, y2 + lineWidth / 2));
467 0 : } break;
468 : }
469 0 : painter->restore();
470 : }
471 :
472 0 : void SingleDraw::draw(const ChordBracket* item, muse::draw::Painter* painter, const PaintOptions& opt)
473 : {
474 0 : const Arpeggio::LayoutData* ldata = item->ldata();
475 :
476 0 : const double lineWidth = item->style().styleAbsolute(Sid::chordBracketLineWidth);
477 0 : painter->setPen(Pen(item->curColor(opt), lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
478 :
479 0 : const double halfLineWidth = 0.5 * lineWidth;
480 0 : const double y1 = ldata->bbox().top() + halfLineWidth;
481 0 : const double y2 = ldata->bbox().bottom() - halfLineWidth;
482 :
483 0 : double w = item->absoluteFromSpatium(item->hookLength());
484 0 : if (item->hookPos() != DirectionV::DOWN) {
485 0 : painter->drawLine(LineF(0.0, y1, w, y1));
486 : }
487 0 : if (item->hookPos() != DirectionV::UP) {
488 0 : painter->drawLine(LineF(0.0, y2, w, y2));
489 : }
490 :
491 0 : const double x = halfLineWidth;
492 0 : painter->drawLine(LineF(x, y1, x, y2));
493 0 : }
494 :
495 0 : void SingleDraw::draw(const Articulation* item, Painter* painter, const PaintOptions& opt)
496 : {
497 : TRACE_DRAW_ITEM;
498 :
499 0 : painter->setPen(item->curColor(opt));
500 :
501 0 : if (item->textType() == ArticulationTextType::NO_TEXT) {
502 0 : item->drawSymbol(item->symId(), painter, PointF(-0.5 * item->width(), 0.0));
503 : } else {
504 0 : item->text()->setColor(item->curColor(opt));
505 0 : drawTextBase(item->text(), painter, opt);
506 : }
507 0 : }
508 :
509 0 : void SingleDraw::draw(const Note* item, Painter* painter, const PaintOptions& opt)
510 : {
511 : TRACE_DRAW_ITEM;
512 0 : if (item->hidden()) {
513 0 : return;
514 : }
515 :
516 0 : const Note::LayoutData* ldata = item->ldata();
517 0 : auto config = item->configuration();
518 :
519 0 : bool negativeFret = item->negativeFretUsed() && item->staff()->isTabStaff(item->tick());
520 :
521 0 : Color c(negativeFret && !opt.isPrinting ? config->criticalColor() : item->curColor(opt));
522 0 : painter->setPen(c);
523 0 : bool tablature = item->staff() && item->staff()->isTabStaff(item->chord()->tick());
524 :
525 : // tablature
526 0 : if (tablature) {
527 0 : if (item->displayFret() == Note::DisplayFretOption::Hide) {
528 0 : return;
529 : }
530 0 : const Staff* st = item->staff();
531 0 : const StaffType* tab = st->staffTypeForElement(item);
532 0 : if (item->tieBackNonPartial() && !tab->showBackTied()) {
533 0 : if (item->chord()->measure()->system() == item->tieBack()->startNote()->chord()->measure()->system() && item->el().empty()) {
534 : // fret should be hidden, so return without drawing it
535 0 : return;
536 : }
537 : }
538 : // draw background, if required (to hide a segment of string line or to show a fretting conflict)
539 0 : if (!tab->linesThrough() || item->fretConflict()) {
540 0 : double d = item->spatium() * .1;
541 0 : RectF bb = RectF(ldata->bbox().x() - d,
542 0 : tab->fretMaskY() * item->magS(),
543 0 : ldata->bbox().width() + 2 * d,
544 0 : tab->fretMaskH() * item->magS());
545 : // we do not know which viewer did this draw() call
546 : // so update all:
547 0 : if (!item->score()->getViewer().empty()) {
548 0 : for (MuseScoreView* view : item->score()->getViewer()) {
549 0 : view->drawBackground(painter, bb);
550 : }
551 : } else {
552 0 : painter->fillRect(bb, config->noteBackgroundColor());
553 : }
554 :
555 0 : if (item->fretConflict() && !opt.isPrinting && item->score()->showUnprintable()) { //on fret conflict, draw on red background
556 0 : painter->save();
557 0 : painter->setPen(config->criticalColor());
558 0 : painter->setBrush(config->criticalColor());
559 0 : painter->drawRect(bb);
560 0 : painter->restore();
561 : }
562 : }
563 0 : Font f(tab->fretFont());
564 0 : f.setPointSizeF(f.pointSizeF() * item->magS());
565 0 : painter->setFont(f);
566 0 : painter->setPen(c);
567 0 : double startPosX = ldata->bbox().x();
568 :
569 0 : painter->drawText(PointF(startPosX, tab->fretFontYOffset() * item->magS()), item->fretString());
570 0 : }
571 : // NOT tablature
572 : else {
573 : // skip drawing, if second note of a cross-measure value
574 0 : if (item->chord() && item->chord()->crossMeasure() == CrossMeasure::SECOND) {
575 0 : return;
576 : }
577 : // warn if pitch extends usable range of instrument
578 : // by coloring the notehead
579 0 : if (item->chord() && item->chord()->segment() && item->staff() && !opt.isPrinting
580 0 : && MScore::warnPitchRange && !item->staff()->isDrumStaff(item->chord()->tick())) {
581 0 : const Instrument* in = item->originPart()->instrument(item->chord()->tick());
582 0 : int i = item->ppitch();
583 0 : if (i < in->minPitchP() || i > in->maxPitchP()) {
584 0 : painter->setPen(
585 0 : item->selected() ? config->criticalSelectedColor() : config->criticalColor());
586 0 : } else if (i < in->minPitchA() || i > in->maxPitchA()) {
587 0 : painter->setPen(item->selected() ? config->warningSelectedColor() : config->warningColor());
588 : }
589 : }
590 : // Warn if notes are unplayable based on previous harp diagram setting
591 0 : if (item->chord() && item->chord()->segment() && item->staff() && !opt.isPrinting
592 0 : && !item->staff()->isDrumStaff(item->chord()->tick())) {
593 0 : HarpPedalDiagram* prevDiagram = item->originPart()->currentHarpDiagram(item->chord()->segment()->tick());
594 0 : if (prevDiagram && !prevDiagram->isTpcPlayable(item->tpc())) {
595 0 : painter->setPen(item->selected() ? config->criticalSelectedColor() : config->criticalColor());
596 : }
597 : }
598 : // draw blank notehead to avoid staff and ledger lines
599 0 : if (ldata->cachedSymNull() != SymId::noSym) {
600 0 : painter->save();
601 0 : painter->setPen(config->noteBackgroundColor());
602 0 : item->drawSymbol(ldata->cachedSymNull(), painter);
603 0 : painter->restore();
604 : }
605 0 : item->drawSymbol(ldata->cachedNoteheadSym.value(), painter);
606 : }
607 0 : }
608 :
609 0 : void SingleDraw::draw(const NoteHead* item, Painter* painter, const PaintOptions& opt)
610 : {
611 0 : draw(static_cast<const Symbol*>(item), painter, opt);
612 0 : }
613 :
614 0 : void SingleDraw::draw(const NoteLineSegment*, Painter*, const PaintOptions&)
615 : {
616 : // TRACE_DRAW_ITEM;
617 : // To be implemented
618 0 : }
619 :
620 0 : void SingleDraw::draw(const Ornament* item, Painter* painter, const PaintOptions& opt)
621 : {
622 0 : draw(static_cast<const Articulation*>(item), painter, opt);
623 0 : }
624 :
625 0 : void SingleDraw::draw(const BagpipeEmbellishment* item, Painter* painter, const PaintOptions& opt)
626 : {
627 : TRACE_DRAW_ITEM;
628 :
629 0 : const BagpipeEmbellishment::LayoutData* data = item->ldata();
630 0 : IF_ASSERT_FAILED(data) {
631 0 : return;
632 : }
633 0 : const BagpipeEmbellishment::LayoutData::BeamData& dataBeam = data->beamData;
634 :
635 0 : Pen pen(item->curColor(opt), data->stemLineW, PenStyle::SolidLine, PenCapStyle::FlatCap);
636 0 : painter->setPen(pen);
637 :
638 : // draw the notes including stem, (optional) flag and (optional) ledger line
639 0 : for (const auto& p : data->notesData) {
640 0 : const BagpipeEmbellishment::LayoutData::NoteData& noteData = p.second;
641 :
642 : // Draw Grace Note
643 : {
644 : // draw head
645 0 : item->drawSymbol(data->headsym, painter, noteData.headXY);
646 :
647 : // draw stem
648 0 : painter->drawLine(noteData.stemLine);
649 :
650 0 : if (data->isDrawFlag) {
651 : // draw flag
652 0 : item->drawSymbol(data->flagsym, painter, noteData.flagXY);
653 : }
654 : }
655 :
656 : // draw the ledger line for high A
657 0 : if (!noteData.ledgerLine.isNull()) {
658 0 : painter->drawLine(noteData.ledgerLine);
659 : }
660 : }
661 :
662 0 : if (data->isDrawBeam) {
663 0 : Pen beamPen(item->curColor(opt), dataBeam.width, PenStyle::SolidLine, PenCapStyle::FlatCap);
664 0 : painter->setPen(beamPen);
665 : // draw the beams
666 0 : auto drawBeams = [](Painter* painter, const double spatium,
667 : const double x1, const double x2, double y)
668 : {
669 : // draw the beams
670 0 : painter->drawLine(LineF(x1, y, x2, y));
671 0 : y += spatium / 1.5;
672 0 : painter->drawLine(LineF(x1, y, x2, y));
673 0 : y += spatium / 1.5;
674 0 : painter->drawLine(LineF(x1, y, x2, y));
675 0 : };
676 :
677 0 : drawBeams(painter, data->spatium, dataBeam.x1, dataBeam.x2, dataBeam.y);
678 0 : }
679 0 : }
680 :
681 0 : static void drawDots(const BarLine* item, Painter* painter, double x)
682 : {
683 0 : double spatium = item->spatium();
684 :
685 0 : double y1l = 1.5 * spatium;
686 0 : double y2l = 2.5 * spatium;
687 :
688 0 : item->drawSymbol(SymId::repeatDot, painter, PointF(x, y1l));
689 0 : item->drawSymbol(SymId::repeatDot, painter, PointF(x, y2l));
690 0 : }
691 :
692 0 : static void drawTips(const BarLine* item, Painter* painter, bool reversed, double x)
693 : {
694 0 : const BarLine::LayoutData* ldata = item->ldata();
695 0 : if (reversed) {
696 0 : if (item->isTop()) {
697 0 : item->drawSymbol(SymId::reversedBracketTop, painter, PointF(x - item->symWidth(SymId::reversedBracketTop), ldata->y1));
698 : }
699 0 : if (item->isBottom()) {
700 0 : item->drawSymbol(SymId::reversedBracketBottom, painter, PointF(x - item->symWidth(SymId::reversedBracketBottom), ldata->y2));
701 : }
702 : } else {
703 0 : if (item->isTop()) {
704 0 : item->drawSymbol(SymId::bracketTop, painter, PointF(x, ldata->y1));
705 : }
706 0 : if (item->isBottom()) {
707 0 : item->drawSymbol(SymId::bracketBottom, painter, PointF(x, ldata->y2));
708 : }
709 : }
710 0 : }
711 :
712 0 : void SingleDraw::draw(const BarLine* item, Painter* painter, const PaintOptions& opt)
713 : {
714 : TRACE_DRAW_ITEM;
715 0 : const BarLine::LayoutData* ldata = item->ldata();
716 0 : switch (item->barLineType()) {
717 0 : case BarLineType::NORMAL: {
718 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
719 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
720 0 : painter->drawLine(LineF(lw * .5, ldata->y1, lw * .5, ldata->y2));
721 : }
722 0 : break;
723 :
724 0 : case BarLineType::BROKEN: {
725 0 : double lw = item->style().styleAbsolute(Sid::dashBarWidth) * item->mag();
726 0 : double dl = RealIsNull(lw) ? 0.0 : item->style().styleAbsolute(Sid::dashBarDash) * item->mag() / lw;
727 0 : double gl = RealIsNull(lw) ? 0.0 : item->style().styleAbsolute(Sid::dashBarGap) * item->mag() / lw;
728 0 : Pen pen(item->curColor(opt), lw, PenStyle::DashLine, PenCapStyle::FlatCap);
729 0 : pen.setDashPattern({ dl, gl });
730 0 : painter->setPen(pen);
731 0 : painter->drawLine(LineF(lw * .5, ldata->y1, lw * .5, ldata->y2));
732 0 : }
733 0 : break;
734 :
735 0 : case BarLineType::DOTTED: {
736 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
737 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::DotLine, PenCapStyle::FlatCap));
738 0 : painter->drawLine(LineF(lw * .5, ldata->y1, lw * .5, ldata->y2));
739 : }
740 0 : break;
741 :
742 0 : case BarLineType::END: {
743 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
744 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
745 0 : double x = lw * .5;
746 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
747 :
748 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
749 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
750 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
751 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
752 : }
753 0 : break;
754 :
755 0 : case BarLineType::DOUBLE: {
756 0 : double lw = item->style().styleAbsolute(Sid::doubleBarWidth) * item->mag();
757 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
758 0 : double x = lw * .5;
759 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
760 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::doubleBarDistance) + (lw * .5)) * item->mag();
761 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
762 : }
763 0 : break;
764 :
765 0 : case BarLineType::REVERSE_END: {
766 0 : double lw = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
767 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
768 0 : double x = lw * .5;
769 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
770 :
771 0 : double lw2 = item->style().styleAbsolute(Sid::barWidth) * item->mag();
772 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
773 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
774 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
775 : }
776 0 : break;
777 :
778 0 : case BarLineType::HEAVY: {
779 0 : double lw = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
780 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
781 0 : painter->drawLine(LineF(lw * .5, ldata->y1, lw * .5, ldata->y2));
782 : }
783 0 : break;
784 :
785 0 : case BarLineType::DOUBLE_HEAVY: {
786 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
787 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
788 0 : double x = lw2 * .5;
789 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
790 0 : x += ((lw2 * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
791 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
792 : }
793 0 : break;
794 :
795 0 : case BarLineType::START_REPEAT: {
796 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
797 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
798 0 : double x = lw2 * .5;
799 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
800 :
801 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
802 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
803 0 : x += ((lw2 * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw * .5)) * item->mag();
804 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
805 :
806 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::repeatBarlineDotSeparation)) * item->mag();
807 0 : drawDots(item, painter, x);
808 :
809 0 : if (item->style().styleB(Sid::repeatBarTips)) {
810 0 : drawTips(item, painter, false, 0.0);
811 : }
812 : }
813 0 : break;
814 :
815 0 : case BarLineType::END_REPEAT: {
816 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
817 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
818 :
819 0 : double x = 0.0;
820 0 : drawDots(item, painter, x);
821 :
822 0 : x += item->symBbox(SymId::repeatDot).width();
823 0 : x += (item->style().styleAbsolute(Sid::repeatBarlineDotSeparation) + (lw * .5)) * item->mag();
824 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
825 :
826 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
827 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
828 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
829 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
830 :
831 0 : if (item->style().styleB(Sid::repeatBarTips)) {
832 0 : drawTips(item, painter, true, x + lw2 * .5);
833 : }
834 : }
835 0 : break;
836 0 : case BarLineType::END_START_REPEAT: {
837 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
838 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
839 :
840 0 : double x = 0.0;
841 0 : drawDots(item, painter, x);
842 :
843 0 : x += item->symBbox(SymId::repeatDot).width();
844 0 : x += (item->style().styleAbsolute(Sid::repeatBarlineDotSeparation) + (lw * .5)) * item->mag();
845 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
846 :
847 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
848 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
849 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
850 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
851 :
852 0 : if (item->style().styleB(Sid::repeatBarTips)) {
853 0 : drawTips(item, painter, true, x + lw2 * .5);
854 : }
855 :
856 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
857 0 : x += ((lw2 * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw * .5)) * item->mag();
858 0 : painter->drawLine(LineF(x, ldata->y1, x, ldata->y2));
859 :
860 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::repeatBarlineDotSeparation)) * item->mag();
861 0 : drawDots(item, painter, x);
862 :
863 0 : if (item->style().styleB(Sid::repeatBarTips)) {
864 0 : drawTips(item, painter, false, 0.0);
865 : }
866 : }
867 0 : break;
868 : }
869 0 : }
870 :
871 0 : void SingleDraw::draw(const Beam* item, Painter* painter, const PaintOptions& opt)
872 : {
873 : TRACE_DRAW_ITEM;
874 0 : if (item->beamSegments().empty()) {
875 0 : return;
876 : }
877 0 : painter->setBrush(Brush(item->curColor(opt)));
878 0 : painter->setNoPen();
879 :
880 : // make beam thickness independent of slant
881 : // (expression can be simplified?)
882 :
883 0 : const LineF bs = item->beamSegments().front()->line;
884 0 : double d = (std::abs(bs.y2() - bs.y1())) / (bs.x2() - bs.x1());
885 0 : if (item->beamSegments().size() > 1 && d > M_PI / 6.0) {
886 0 : d = M_PI / 6.0;
887 : }
888 0 : double ww = (item->beamWidth() / 2.0) / sin(M_PI_2 - atan(d));
889 :
890 0 : for (const BeamSegment* bs1 : item->beamSegments()) {
891 0 : painter->drawPolygon(
892 0 : PolygonF({
893 0 : PointF(bs1->line.x1(), bs1->line.y1() - ww),
894 0 : PointF(bs1->line.x2(), bs1->line.y2() - ww),
895 0 : PointF(bs1->line.x2(), bs1->line.y2() + ww),
896 0 : PointF(bs1->line.x1(), bs1->line.y1() + ww),
897 0 : }),
898 : FillRule::OddEvenFill);
899 : }
900 : }
901 :
902 0 : void SingleDraw::draw(const Bend* item, Painter* painter, const PaintOptions& opt)
903 : {
904 : TRACE_DRAW_ITEM;
905 :
906 0 : const Bend::LayoutData* ldata = item->ldata();
907 0 : double _spatium = item->spatium();
908 0 : double _lw = item->absoluteFromSpatium(item->lineWidth());
909 :
910 0 : Pen pen(item->curColor(opt), _lw, PenStyle::SolidLine, PenCapStyle::RoundCap, PenJoinStyle::RoundJoin);
911 0 : painter->setPen(pen);
912 0 : painter->setBrush(Brush(item->curColor(opt)));
913 :
914 0 : Font f = item->font(_spatium);
915 0 : painter->setFont(f);
916 :
917 0 : double x = ldata->noteWidth + _spatium * .2;
918 0 : double y = -_spatium * .8;
919 : double x2, y2;
920 :
921 0 : double aw = item->style().styleAbsolute(Sid::bendArrowWidth);
922 0 : PolygonF arrowUp;
923 0 : arrowUp << PointF(0, 0) << PointF(aw * .5, aw) << PointF(-aw * .5, aw);
924 0 : PolygonF arrowDown;
925 0 : arrowDown << PointF(0, 0) << PointF(aw * .5, -aw) << PointF(-aw * .5, -aw);
926 :
927 0 : size_t n = item->points().size();
928 0 : for (size_t pt = 0; pt < n - 1; ++pt) {
929 0 : int pitch = item->points()[pt].pitch;
930 0 : if (pt == 0 && pitch) {
931 0 : y2 = -ldata->notePos.y() - _spatium * 2;
932 0 : x2 = x;
933 0 : painter->drawLine(LineF(x, y, x2, y2));
934 :
935 0 : painter->setBrush(item->curColor(opt));
936 0 : painter->drawPolygon(arrowUp.translated(x2, y2));
937 :
938 0 : int idx = (pitch + 12) / 25;
939 0 : const char* l = item->label[idx];
940 0 : painter->drawText(RectF(x2, y2, .0, .0),
941 : muse::draw::AlignHCenter | muse::draw::AlignBottom,
942 : muse::draw::TextDontClip,
943 0 : String::fromAscii(l));
944 :
945 0 : y = y2;
946 : }
947 0 : if (pitch == item->points()[pt + 1].pitch) {
948 0 : if (pt == (n - 2)) {
949 0 : break;
950 : }
951 0 : x2 = x + _spatium;
952 0 : y2 = y;
953 0 : painter->drawLine(LineF(x, y, x2, y2));
954 0 : } else if (pitch < item->points()[pt + 1].pitch) {
955 : // up
956 0 : x2 = x + _spatium * .5;
957 0 : y2 = -ldata->notePos.y() - _spatium * 2;
958 0 : double dx = x2 - x;
959 0 : double dy = y2 - y;
960 :
961 0 : PainterPath path;
962 0 : path.moveTo(x, y);
963 0 : path.cubicTo(x + dx / 2, y, x2, y + dy / 4, x2, y2);
964 0 : painter->setBrush(BrushStyle::NoBrush);
965 0 : painter->drawPath(path);
966 :
967 0 : painter->setBrush(item->curColor(opt));
968 0 : painter->drawPolygon(arrowUp.translated(x2, y2));
969 :
970 0 : int idx = (item->points()[pt + 1].pitch + 12) / 25;
971 0 : const char* l = item->label[idx];
972 0 : double ty = y2; // - _spatium;
973 0 : painter->drawText(RectF(x2, ty, .0, .0),
974 : muse::draw::AlignHCenter | muse::draw::AlignBottom,
975 : muse::draw::TextDontClip,
976 0 : String::fromAscii(l));
977 0 : } else {
978 : // down
979 0 : x2 = x + _spatium * .5;
980 0 : y2 = y + _spatium * 3;
981 0 : double dx = x2 - x;
982 0 : double dy = y2 - y;
983 :
984 0 : PainterPath path;
985 0 : path.moveTo(x, y);
986 0 : path.cubicTo(x + dx / 2, y, x2, y + dy / 4, x2, y2);
987 0 : painter->setBrush(BrushStyle::NoBrush);
988 0 : painter->drawPath(path);
989 :
990 0 : painter->setBrush(item->curColor(opt));
991 0 : painter->drawPolygon(arrowDown.translated(x2, y2));
992 0 : }
993 0 : x = x2;
994 0 : y = y2;
995 : }
996 0 : }
997 :
998 0 : void SingleDraw::draw(const Bracket* item, Painter* painter, const PaintOptions& opt)
999 : {
1000 : TRACE_DRAW_ITEM;
1001 :
1002 0 : const Bracket::LayoutData* ldata = item->ldata();
1003 :
1004 0 : painter->save();
1005 0 : setMask(item, painter);
1006 :
1007 0 : switch (item->bracketType()) {
1008 0 : case BracketType::BRACE: {
1009 0 : double h = ldata->bracketHeight;
1010 0 : double glyphHeight = item->symHeight(ldata->braceSymbol);
1011 0 : double mag = h / glyphHeight;
1012 0 : painter->setPen(item->curColor(opt));
1013 0 : painter->save();
1014 0 : painter->scale(item->magx(), mag);
1015 0 : item->drawSymbol(ldata->braceSymbol, painter, PointF(0, glyphHeight));
1016 0 : painter->restore();
1017 : }
1018 0 : break;
1019 0 : case BracketType::NORMAL: {
1020 0 : double h = ldata->bracketHeight;
1021 0 : double _spatium = item->spatium();
1022 0 : double w = item->style().styleAbsolute(Sid::bracketWidth);
1023 0 : double bd = (item->style().styleSt(Sid::musicalSymbolFont) == "Leland") ? _spatium * .5 : _spatium * .25;
1024 0 : Pen pen(item->curColor(opt), w, PenStyle::SolidLine, PenCapStyle::FlatCap);
1025 0 : painter->setPen(pen);
1026 0 : painter->drawLine(LineF(0.0, -bd - w * .5, 0.0, h + bd + w * .5));
1027 0 : double x = -w * .5;
1028 0 : double y1 = -bd;
1029 0 : double y2 = h + bd;
1030 0 : item->drawSymbol(SymId::bracketTop, painter, PointF(x, y1));
1031 0 : item->drawSymbol(SymId::bracketBottom, painter, PointF(x, y2));
1032 0 : }
1033 0 : break;
1034 0 : case BracketType::SQUARE:
1035 : {
1036 0 : double h = ldata->bracketHeight;
1037 0 : double lineW = item->style().styleAbsolute(Sid::staffLineWidth);
1038 0 : double bracketWidth = ldata->bracketWidth - lineW / 2;
1039 0 : Pen pen(item->curColor(opt), lineW, PenStyle::SolidLine, PenCapStyle::FlatCap);
1040 0 : painter->setPen(pen);
1041 0 : painter->drawLine(LineF(0.0, 0.0, 0.0, h));
1042 0 : painter->drawLine(LineF(-lineW / 2, 0.0, lineW / 2 + bracketWidth, 0.0));
1043 0 : painter->drawLine(LineF(-lineW / 2, h, lineW / 2 + bracketWidth, h));
1044 0 : }
1045 0 : break;
1046 0 : case BracketType::LINE: {
1047 0 : double h = ldata->bracketHeight;
1048 0 : double w = 0.67 * item->style().styleAbsolute(Sid::bracketWidth);
1049 0 : Pen pen(item->curColor(opt), w, PenStyle::SolidLine, PenCapStyle::FlatCap);
1050 0 : painter->setPen(pen);
1051 0 : double bd = item->style().styleAbsolute(Sid::staffLineWidth) * 0.5;
1052 0 : painter->drawLine(LineF(0.0, -bd, 0.0, h + bd));
1053 0 : }
1054 0 : break;
1055 0 : case BracketType::GROUP:
1056 : {
1057 0 : double h = ldata->bracketHeight;
1058 0 : double lineW = item->style().styleAbsolute(Sid::staffLineWidth);
1059 0 : double bracketWidth = ldata->bracketWidth;
1060 0 : Pen pen(item->curColor(opt), lineW, PenStyle::SolidLine, PenCapStyle::FlatCap);
1061 0 : painter->setPen(pen);
1062 0 : painter->drawLine(LineF(0.5 * lineW, 0.0, 0.5 * lineW, h));
1063 0 : painter->drawLine(LineF(0.0, 0.0, bracketWidth, 0.0));
1064 0 : painter->drawLine(LineF(0.0, h, bracketWidth, h));
1065 0 : }
1066 0 : break;
1067 0 : case BracketType::NO_BRACKET:
1068 0 : break;
1069 : }
1070 :
1071 0 : painter->restore();
1072 0 : }
1073 :
1074 0 : void SingleDraw::draw(const Breath* item, Painter* painter, const PaintOptions& opt)
1075 : {
1076 : TRACE_DRAW_ITEM;
1077 0 : painter->setPen(item->curColor(opt));
1078 0 : item->drawSymbol(item->symId(), painter);
1079 0 : }
1080 :
1081 0 : void SingleDraw::draw(const ChordLine* item, Painter* painter, const PaintOptions& opt)
1082 : {
1083 : TRACE_DRAW_ITEM;
1084 0 : const ChordLine::LayoutData* ldata = item->ldata();
1085 0 : IF_ASSERT_FAILED(ldata) {
1086 0 : return;
1087 : }
1088 :
1089 0 : if (!item->isWavy()) {
1090 0 : painter->setPen(Pen(item->curColor(opt), item->style().styleAbsolute(Sid::chordlineThickness) * item->mag(), PenStyle::SolidLine));
1091 0 : painter->setBrush(BrushStyle::NoBrush);
1092 0 : painter->drawPath(ldata->path);
1093 : } else {
1094 0 : painter->save();
1095 0 : painter->rotate((item->chordLineType() == ChordLineType::FALL ? 1 : -1));
1096 0 : item->drawSymbol(item->waveSym(), painter);
1097 0 : painter->restore();
1098 : }
1099 : }
1100 :
1101 0 : void SingleDraw::draw(const Clef* item, Painter* painter, const PaintOptions& opt)
1102 : {
1103 : TRACE_DRAW_ITEM;
1104 0 : const Clef::LayoutData* ldata = item->ldata();
1105 0 : IF_ASSERT_FAILED(ldata) {
1106 0 : return;
1107 : }
1108 :
1109 0 : if (ldata->symId == SymId::noSym) {
1110 0 : return;
1111 : }
1112 0 : painter->setPen(item->curColor(opt));
1113 0 : item->drawSymbol(ldata->symId, painter);
1114 : }
1115 :
1116 0 : void SingleDraw::draw(const Capo* item, Painter* painter, const PaintOptions& opt)
1117 : {
1118 0 : drawTextBase(item, painter, opt);
1119 0 : }
1120 :
1121 0 : void SingleDraw::draw(const DeadSlapped* item, Painter* painter, const PaintOptions& opt)
1122 : {
1123 : TRACE_DRAW_ITEM;
1124 0 : const DeadSlapped::LayoutData* ldata = item->ldata();
1125 0 : IF_ASSERT_FAILED(ldata) {
1126 0 : return;
1127 : }
1128 :
1129 0 : painter->setPen(PenStyle::NoPen);
1130 0 : painter->setBrush(item->curColor(opt));
1131 0 : painter->drawPath(ldata->path1);
1132 0 : painter->drawPath(ldata->path2);
1133 : }
1134 :
1135 0 : void SingleDraw::draw(const Dynamic* item, Painter* painter, const PaintOptions& opt)
1136 : {
1137 0 : drawTextBase(item, painter, opt);
1138 0 : }
1139 :
1140 0 : void SingleDraw::draw(const Expression* item, Painter* painter, const PaintOptions& opt)
1141 : {
1142 0 : drawTextBase(item, painter, opt);
1143 0 : }
1144 :
1145 0 : void SingleDraw::draw(const Fermata* item, Painter* painter, const PaintOptions& opt)
1146 : {
1147 : TRACE_DRAW_ITEM;
1148 0 : painter->setPen(item->curColor(opt));
1149 0 : item->drawSymbol(item->symId(), painter, PointF(-0.5 * item->width(), 0.0));
1150 0 : }
1151 :
1152 0 : void SingleDraw::draw(const FiguredBass* item, Painter* painter, const PaintOptions& opt)
1153 : {
1154 : TRACE_DRAW_ITEM;
1155 0 : if (item->items().size() < 1) { // if not parseable into f.b. items
1156 0 : drawTextBase(item, painter, opt); // draw as standard text
1157 : } else {
1158 0 : for (FiguredBassItem* fi : item->items()) { // if parseable into f.b. items
1159 0 : painter->translate(fi->pos()); // draw each item in its proper position
1160 0 : draw(fi, painter, opt);
1161 0 : painter->translate(-fi->pos());
1162 : }
1163 : }
1164 0 : }
1165 :
1166 0 : void SingleDraw::draw(const FiguredBassItem* item, Painter* painter, const PaintOptions& opt)
1167 : {
1168 : TRACE_DRAW_ITEM;
1169 :
1170 0 : const FiguredBassItem::LayoutData* ldata = item->ldata();
1171 0 : int font = 0;
1172 0 : double _spatium = item->spatium();
1173 : // set font from general style
1174 0 : Font f(FiguredBass::FBFonts().at(font).family, Font::Type::Tablature);
1175 :
1176 : // (use the same font selection as used in layout() above)
1177 0 : double m = item->style().styleD(Sid::figuredBassFontSize) * item->spatium() / item->defaultSpatium();
1178 0 : f.setPointSizeF(m);
1179 :
1180 0 : painter->setFont(f);
1181 0 : painter->setBrush(BrushStyle::NoBrush);
1182 0 : Pen pen(item->figuredBass()->curColor(opt), FiguredBass::FB_CONTLINE_THICKNESS.toAbsolute(_spatium), PenStyle::SolidLine,
1183 0 : PenCapStyle::RoundCap);
1184 0 : painter->setPen(pen);
1185 0 : painter->drawText(ldata->bbox(),
1186 : muse::draw::AlignLeft | muse::draw::AlignTop,
1187 : muse::draw::TextDontClip,
1188 0 : ldata->displayText);
1189 :
1190 : // continuation line
1191 0 : double lineEndX = 0.0;
1192 0 : if (item->contLine() != FiguredBassItem::ContLine::NONE) {
1193 0 : double lineStartX = ldata->textWidth; // by default, line starts right after text
1194 0 : if (lineStartX > 0.0) {
1195 0 : lineStartX += FiguredBass::FB_CONTLINE_LEFT_PADDING.toAbsolute(_spatium); // if some text, give some room after it
1196 : }
1197 0 : lineEndX = item->figuredBass()->ldata()->printedLineLength; // by default, line ends with item duration
1198 0 : if (lineEndX - lineStartX < 1.0) { // if line length < 1 sp, ignore it
1199 0 : lineEndX = 0.0;
1200 : }
1201 :
1202 : // if extended cont.line and no closing parenthesis: look at next FB element
1203 0 : if (item->contLine() > FiguredBassItem::ContLine::SIMPLE && item->parenth5() == FiguredBassItem::Parenthesis::NONE) {
1204 : FiguredBass* nextFB;
1205 : // if there is a contiguous FB element
1206 0 : if ((nextFB = item->figuredBass()->nextFiguredBass()) != 0) {
1207 : // retrieve the X position (in page coords) of a possible cont. line of nextFB
1208 : // on the same line of 'this'
1209 0 : PointF pgPos = item->pagePos();
1210 0 : double nextContPageX = nextFB->additionalContLineX(pgPos.y());
1211 : // if an additional cont. line has been found, extend up to its initial X coord
1212 0 : if (nextContPageX > 0) {
1213 0 : lineEndX = nextContPageX - pgPos.x() + FiguredBass::FB_CONTLINE_OVERLAP.toAbsolute(_spatium);
1214 : }
1215 : // with a little bit of overlap
1216 : else {
1217 0 : lineEndX = item->figuredBass()->ldata()->lineLength(0); // if none found, draw to the duration end
1218 : }
1219 : }
1220 : }
1221 : // if some line, draw it
1222 0 : if (lineEndX > 0.0) {
1223 0 : double h = ldata->bbox().height() * FiguredBass::FB_CONTLINE_HEIGHT;
1224 0 : painter->drawLine(lineStartX, h, lineEndX - ldata->pos().x(), h);
1225 : }
1226 : }
1227 :
1228 : // closing cont.line parenthesis
1229 0 : if (item->parenth5() != FiguredBassItem::Parenthesis::NONE) {
1230 0 : int x = lineEndX > 0.0 ? lineEndX : ldata->textWidth;
1231 0 : painter->drawText(RectF(x, 0, ldata->bbox().width(), ldata->bbox().height()),
1232 : muse::draw::AlignLeft | muse::draw::AlignTop,
1233 : muse::draw::TextDontClip,
1234 0 : Char(FiguredBass::FBFonts().at(font).displayParenthesis[int(item->parenth5())].unicode()));
1235 : }
1236 0 : }
1237 :
1238 0 : void SingleDraw::draw(const Fingering* item, Painter* painter, const PaintOptions& opt)
1239 : {
1240 : TRACE_DRAW_ITEM;
1241 0 : drawTextBase(item, painter, opt);
1242 0 : }
1243 :
1244 0 : void SingleDraw::draw(const FretDiagram* item, Painter* painter, const PaintOptions& opt)
1245 : {
1246 : TRACE_DRAW_ITEM;
1247 0 : const FretDiagram::LayoutData* ldata = item->ldata();
1248 0 : PointF translation = -PointF(ldata->stringDist * (item->strings() - 1), 0);
1249 0 : if (item->orientation() == Orientation::HORIZONTAL) {
1250 0 : painter->save();
1251 0 : painter->rotate(-90);
1252 0 : painter->translate(translation);
1253 : }
1254 :
1255 : // Init pen and other values
1256 0 : Pen pen(item->curColor(opt));
1257 0 : pen.setCapStyle(PenCapStyle::FlatCap);
1258 0 : painter->setBrush(Brush(Color(painter->pen().color())));
1259 :
1260 : // x2 is the x val of the rightmost string
1261 0 : double x2 = (item->strings() - 1) * ldata->stringDist;
1262 :
1263 : // Draw the nut
1264 0 : pen.setWidthF(ldata->nutLineWidth);
1265 0 : painter->setPen(pen);
1266 0 : painter->drawLine(LineF(-ldata->stringLineWidth * .5, 0.0, x2 + ldata->stringLineWidth * .5, 0.0));
1267 :
1268 : // Draw strings and frets
1269 0 : pen.setWidthF(ldata->stringLineWidth);
1270 0 : painter->setPen(pen);
1271 :
1272 : // y2 is the y val of the bottom fretline
1273 0 : double y2 = ldata->fretDist * item->frets();
1274 0 : for (int i = 0; i < item->strings(); ++i) {
1275 0 : double x = ldata->stringDist * i;
1276 0 : painter->drawLine(LineF(x, 0.0, x, y2));
1277 : }
1278 0 : for (int i = 1; i <= item->frets(); ++i) {
1279 0 : double y = ldata->fretDist * i;
1280 0 : painter->drawLine(LineF(0.0, y, x2, y));
1281 : }
1282 :
1283 : // dotd is the diameter of a dot
1284 0 : double dotd = item->style().styleAbsolute(Sid::fretDotSpatiumSize);
1285 :
1286 : // Draw dots, sym pen is used to draw them (and markers)
1287 0 : Pen symPen(pen);
1288 0 : symPen.setCapStyle(PenCapStyle::RoundCap);
1289 0 : double symPenWidth = ldata->stringLineWidth * 1.2;
1290 0 : symPen.setWidthF(symPenWidth);
1291 :
1292 0 : for (auto const& i : item->dots()) {
1293 0 : for (auto const& d : i.second) {
1294 0 : if (!d.exists()) {
1295 0 : continue;
1296 : }
1297 :
1298 0 : int string = i.first;
1299 0 : int fret = d.fret - 1;
1300 :
1301 : // Calculate coords of the top left corner of the dot
1302 0 : double x = ldata->stringDist * string - dotd * .5;
1303 0 : double y = ldata->fretDist * fret + ldata->fretDist * .5 - dotd * .5;
1304 :
1305 : // Draw different symbols
1306 0 : painter->setPen(symPen);
1307 0 : switch (d.dtype) {
1308 0 : case FretDotType::CROSS:
1309 : // Give the cross a slightly larger width
1310 0 : symPen.setWidthF(symPenWidth * 1.5);
1311 0 : painter->setPen(symPen);
1312 0 : painter->drawLine(LineF(x, y, x + dotd, y + dotd));
1313 0 : painter->drawLine(LineF(x + dotd, y, x, y + dotd));
1314 0 : symPen.setWidthF(symPenWidth);
1315 0 : break;
1316 0 : case FretDotType::SQUARE:
1317 0 : painter->setBrush(BrushStyle::NoBrush);
1318 0 : painter->drawRect(RectF(x, y, dotd, dotd));
1319 0 : break;
1320 0 : case FretDotType::TRIANGLE:
1321 0 : painter->drawLine(LineF(x, y + dotd, x + .5 * dotd, y));
1322 0 : painter->drawLine(LineF(x + .5 * dotd, y, x + dotd, y + dotd));
1323 0 : painter->drawLine(LineF(x + dotd, y + dotd, x, y + dotd));
1324 0 : break;
1325 0 : case FretDotType::NORMAL:
1326 : default:
1327 0 : painter->setBrush(symPen.color());
1328 0 : painter->setNoPen();
1329 0 : painter->drawEllipse(RectF(x, y, dotd, dotd));
1330 0 : break;
1331 : }
1332 : }
1333 : }
1334 :
1335 : // Draw markers
1336 0 : symPen.setWidthF(symPenWidth * 1.2);
1337 0 : painter->setBrush(BrushStyle::NoBrush);
1338 0 : painter->setPen(symPen);
1339 0 : for (auto const& i : item->markers()) {
1340 0 : int string = i.first;
1341 0 : FretItem::Marker marker = i.second;
1342 0 : if (!marker.exists()) {
1343 0 : continue;
1344 : }
1345 :
1346 0 : double x = ldata->stringDist * string - ldata->markerSize * .5;
1347 0 : double y = -ldata->fretDist - ldata->markerSize * .5;
1348 0 : if (marker.mtype == FretMarkerType::CIRCLE) {
1349 0 : painter->drawEllipse(RectF(x, y, ldata->markerSize, ldata->markerSize));
1350 0 : } else if (marker.mtype == FretMarkerType::CROSS) {
1351 0 : painter->drawLine(PointF(x, y), PointF(x + ldata->markerSize, y + ldata->markerSize));
1352 0 : painter->drawLine(PointF(x, y + ldata->markerSize), PointF(x + ldata->markerSize, y));
1353 : }
1354 : }
1355 :
1356 : // Draw barres
1357 0 : for (auto const& i : item->barres()) {
1358 0 : int fret = i.first;
1359 0 : int startString = i.second.startString;
1360 0 : int endString = i.second.endString;
1361 :
1362 0 : double x1 = ldata->stringDist * startString;
1363 0 : double newX2 = endString == -1 ? x2 : ldata->stringDist * endString;
1364 0 : double y = ldata->fretDist * (fret - 1) + ldata->fretDist * .5;
1365 0 : pen.setWidthF(dotd * item->style().styleD(Sid::barreLineWidth));
1366 0 : pen.setCapStyle(PenCapStyle::RoundCap);
1367 0 : painter->setPen(pen);
1368 0 : painter->drawLine(LineF(x1, y, newX2, y));
1369 : }
1370 :
1371 : // Draw fret offset number
1372 0 : if (item->fretOffset() > 0) {
1373 0 : Font scaledFont(item->fretNumFont());
1374 0 : scaledFont.setPointSizeF(scaledFont.pointSizeF() * (item->spatium() / item->defaultSpatium()));
1375 0 : painter->setFont(scaledFont);
1376 0 : String text = String::number(item->fretOffset() + 1);
1377 :
1378 0 : if (item->orientation() == Orientation::VERTICAL) {
1379 0 : if (item->numPos() == 0) {
1380 0 : painter->drawText(RectF(-ldata->stringDist * .4, .0, .0, ldata->fretDist),
1381 : muse::draw::AlignVCenter | muse::draw::AlignRight,
1382 : muse::draw::TextDontClip,
1383 : text);
1384 : } else {
1385 0 : painter->drawText(RectF(x2 + (ldata->stringDist * .4), .0, .0, ldata->fretDist),
1386 : muse::draw::AlignVCenter | muse::draw::AlignLeft,
1387 : muse::draw::TextDontClip,
1388 0 : String::number(item->fretOffset() + 1));
1389 : }
1390 0 : } else if (item->orientation() == Orientation::HORIZONTAL) {
1391 0 : painter->save();
1392 0 : painter->translate(-translation);
1393 0 : painter->rotate(90);
1394 0 : if (item->numPos() == 0) {
1395 0 : painter->drawText(RectF(.0, ldata->stringDist * (item->strings() - 1), .0, .0),
1396 : muse::draw::AlignLeft,
1397 : muse::draw::TextDontClip,
1398 : text);
1399 : } else {
1400 0 : painter->drawText(RectF(.0, .0, .0, .0),
1401 : muse::draw::AlignBottom | muse::draw::AlignLeft,
1402 : muse::draw::TextDontClip,
1403 : text);
1404 : }
1405 0 : painter->restore();
1406 : }
1407 0 : painter->setFont(item->fretNumFont());
1408 0 : }
1409 :
1410 : // NOTE:JT possible future todo - draw fingerings
1411 :
1412 0 : if (item->orientation() == Orientation::HORIZONTAL) {
1413 0 : painter->restore();
1414 : }
1415 0 : }
1416 :
1417 0 : void SingleDraw::draw(const GlissandoSegment* item, Painter* painter, const PaintOptions& opt)
1418 : {
1419 : TRACE_DRAW_ITEM;
1420 :
1421 0 : if (item->pos2().x() <= 0) {
1422 0 : return;
1423 : }
1424 :
1425 0 : painter->save();
1426 0 : double _spatium = item->spatium();
1427 0 : const Glissando* glissando = item->glissando();
1428 :
1429 0 : Pen pen(item->curColor(item->visible(), glissando->lineColor(), opt));
1430 0 : pen.setWidthF(item->absoluteFromSpatium(item->lineWidth()));
1431 0 : pen.setCapStyle(PenCapStyle::FlatCap);
1432 0 : painter->setPen(pen);
1433 :
1434 : // rotate painter so that the line become horizontal
1435 0 : double w = item->pos2().x();
1436 0 : double h = item->pos2().y();
1437 0 : double l = sqrt(w * w + h * h);
1438 0 : double wi = asin(-h / l) * 180.0 / M_PI;
1439 0 : painter->rotate(-wi);
1440 :
1441 0 : if (glissando->glissandoType() == GlissandoType::STRAIGHT) {
1442 0 : painter->drawLine(LineF(0.0, 0.0, l, 0.0));
1443 0 : } else if (glissando->glissandoType() == GlissandoType::WAVY) {
1444 0 : RectF b = item->symBbox(SymId::wiggleTrill);
1445 0 : double a = item->symAdvance(SymId::wiggleTrill);
1446 0 : int n = static_cast<int>(l / a); // always round down (truncate) to avoid overlap
1447 0 : double x = (l - n * a) * 0.5; // centre line in available space
1448 0 : SymIdList ids;
1449 0 : for (int i = 0; i < n; ++i) {
1450 0 : ids.push_back(SymId::wiggleTrill);
1451 : }
1452 :
1453 0 : item->drawSymbols(ids, painter, PointF(x, -(b.y() + b.height() * 0.5)));
1454 0 : }
1455 :
1456 0 : if (glissando->showText()) {
1457 0 : Font f(glissando->fontFace(), Font::Type::Unknown);
1458 0 : f.setPointSizeF(glissando->fontSize() * _spatium / item->defaultSpatium());
1459 0 : f.setBold(glissando->fontStyle() & FontStyle::Bold);
1460 0 : f.setItalic(glissando->fontStyle() & FontStyle::Italic);
1461 0 : f.setUnderline(glissando->fontStyle() & FontStyle::Underline);
1462 0 : f.setStrike(glissando->fontStyle() & FontStyle::Strike);
1463 0 : FontMetrics fm(f);
1464 0 : RectF r = fm.boundingRect(glissando->text());
1465 :
1466 : // if text longer than available space, skip it
1467 0 : if (r.width() < l) {
1468 0 : double yOffset = r.height() + r.y(); // find text descender height
1469 : // raise text slightly above line and slightly more with WAVY than with STRAIGHT
1470 0 : yOffset += _spatium * (glissando->glissandoType() == GlissandoType::WAVY ? 0.4 : 0.1);
1471 :
1472 0 : painter->setFont(f);
1473 :
1474 0 : double x = (l - r.width()) * 0.5;
1475 0 : painter->drawText(PointF(x, -yOffset), glissando->text());
1476 : }
1477 0 : }
1478 0 : painter->restore();
1479 0 : }
1480 :
1481 0 : void SingleDraw::draw(const Stem* item, Painter* painter, const PaintOptions& opt)
1482 : {
1483 : TRACE_DRAW_ITEM;
1484 0 : if (!item->chord()) { // may be need assert?
1485 0 : return;
1486 : }
1487 :
1488 : // hide if second chord of a cross-measure pair
1489 0 : if (item->chord()->crossMeasure() == CrossMeasure::SECOND) {
1490 0 : return;
1491 : }
1492 :
1493 0 : const Stem::LayoutData* ldata = item->ldata();
1494 0 : const Staff* staff = item->staff();
1495 0 : const StaffType* staffType = staff ? staff->staffTypeForElement(item->chord()) : nullptr;
1496 0 : const bool isTablature = staffType && staffType->isTabStaff();
1497 :
1498 0 : painter->setPen(Pen(item->curColor(opt), item->lineWidthMag(), PenStyle::SolidLine, PenCapStyle::FlatCap));
1499 0 : painter->drawLine(ldata->line);
1500 :
1501 0 : if (!isTablature) {
1502 0 : return;
1503 : }
1504 :
1505 : // TODO: adjust bounding rectangle in layout() for dots and for slash
1506 0 : double sp = item->spatium();
1507 0 : bool isUp = item->up();
1508 :
1509 : // slashed half note stem
1510 0 : if (item->chord()->durationType().type() == DurationType::V_HALF
1511 0 : && staffType->minimStyle() == TablatureMinimStyle::SLASHED) {
1512 : // position slashes onto stem
1513 0 : double y = isUp ? -item->length() + score::StemLayout::STAFFTYPE_TAB_SLASH_2STARTY_UP * sp
1514 0 : : item->length() - score::StemLayout::STAFFTYPE_TAB_SLASH_2STARTY_DN * sp;
1515 : // if stems through, try to align slashes within or across lines
1516 0 : if (staffType->stemThrough()) {
1517 0 : double halfLineDist = staffType->lineDistance().val() * sp * 0.5;
1518 0 : double halfSlashHgt = score::StemLayout::STAFFTYPE_TAB_SLASH_2TOTHEIGHT * sp * 0.5;
1519 0 : y = lrint((y + halfSlashHgt) / halfLineDist) * halfLineDist - halfSlashHgt;
1520 : }
1521 : // draw slashes
1522 0 : double hlfWdt= sp * score::StemLayout::STAFFTYPE_TAB_SLASH_WIDTH * 0.5;
1523 0 : double sln = sp * score::StemLayout::STAFFTYPE_TAB_SLASH_SLANTY;
1524 0 : double thk = sp * score::StemLayout::STAFFTYPE_TAB_SLASH_THICK;
1525 0 : double displ = sp * score::StemLayout::STAFFTYPE_TAB_SLASH_DISPL;
1526 0 : PainterPath path;
1527 0 : for (int i = 0; i < 2; ++i) {
1528 0 : path.moveTo(hlfWdt, y); // top-right corner
1529 0 : path.lineTo(hlfWdt, y + thk); // bottom-right corner
1530 0 : path.lineTo(-hlfWdt, y + thk + sln); // bottom-left corner
1531 0 : path.lineTo(-hlfWdt, y + sln); // top-left corner
1532 0 : path.closeSubpath();
1533 0 : y += displ;
1534 : }
1535 0 : painter->setBrush(Brush(item->curColor(opt)));
1536 0 : painter->setNoPen();
1537 0 : painter->drawPath(path);
1538 0 : }
1539 :
1540 : // dots
1541 : // NOT THE BEST PLACE FOR THIS?
1542 : // with tablatures and stems beside staves, dots are not drawn near 'notes', but near stems
1543 0 : int nDots = item->chord()->dots();
1544 0 : if (nDots > 0 && !staffType->stemThrough()) {
1545 0 : double x = item->chord()->dotPosX();
1546 0 : double y = ((score::StemLayout::STAFFTYPE_TAB_DEFAULTSTEMLEN_DN * 0.2) * sp) * (isUp ? -1.0 : 1.0);
1547 0 : double step = item->style().styleS(Sid::dotDotDistance).val() * sp;
1548 0 : for (int dot = 0; dot < nDots; dot++, x += step) {
1549 0 : item->drawSymbol(SymId::augmentationDot, painter, PointF(x, y));
1550 : }
1551 : }
1552 : }
1553 :
1554 0 : void SingleDraw::draw(const StemSlash* item, Painter* painter, const PaintOptions& opt)
1555 : {
1556 : TRACE_DRAW_ITEM;
1557 :
1558 0 : const StemSlash::LayoutData* ldata = item->ldata();
1559 0 : painter->setPen(Pen(item->curColor(opt), ldata->stemWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
1560 0 : painter->drawLine(ldata->line);
1561 0 : }
1562 :
1563 0 : void SingleDraw::draw(const Sticking* item, Painter* painter, const PaintOptions& opt)
1564 : {
1565 : TRACE_DRAW_ITEM;
1566 0 : drawTextBase(item, painter, opt);
1567 0 : }
1568 :
1569 0 : void SingleDraw::draw(const StringTunings* item, Painter* painter, const PaintOptions& opt)
1570 : {
1571 : TRACE_DRAW_ITEM;
1572 0 : drawTextBase(item, painter, opt);
1573 0 : }
1574 :
1575 0 : void SingleDraw::drawTextBase(const TextBase* item, Painter* painter, const PaintOptions& opt)
1576 : {
1577 : TRACE_DRAW_ITEM;
1578 :
1579 0 : painter->save();
1580 0 : painter->rotate(item->textAngle());
1581 :
1582 0 : const TextBase::LayoutData* ldata = item->ldata();
1583 :
1584 0 : if (item->hasFrame()) {
1585 0 : double baseSpatium = DefaultStyle::baseStyle().value(Sid::spatium).toReal();
1586 0 : if (!RealIsNull(item->frameWidth().val())) {
1587 0 : Color fColor = item->curColor(item->visible(), item->frameColor(), opt);
1588 0 : double frameWidthVal = item->frameWidth().val() * (item->sizeIsSpatiumDependent() ? item->spatium() : baseSpatium);
1589 :
1590 0 : Pen pen(fColor, frameWidthVal, PenStyle::SolidLine, PenCapStyle::SquareCap, PenJoinStyle::MiterJoin);
1591 0 : painter->setPen(pen);
1592 0 : } else {
1593 0 : painter->setNoPen();
1594 : }
1595 0 : Color bg(item->bgColor());
1596 0 : painter->setBrush(bg.alpha() ? Brush(bg) : BrushStyle::NoBrush);
1597 0 : if (item->circle()) {
1598 0 : painter->drawEllipse(ldata->frame);
1599 : } else {
1600 0 : double frameRadius = item->frameRound().val() * (item->sizeIsSpatiumDependent() ? item->spatium() : baseSpatium);
1601 0 : painter->drawRoundedRect(ldata->frame, frameRadius, frameRadius);
1602 : }
1603 : }
1604 0 : painter->setBrush(BrushStyle::NoBrush);
1605 0 : painter->setPen(item->textColor(opt));
1606 0 : for (const TextBlock& t : ldata->blocks) {
1607 0 : draw(t, item, painter);
1608 : }
1609 :
1610 0 : painter->restore();
1611 0 : }
1612 :
1613 0 : void SingleDraw::draw(const TextBlock& textBlock, const TextBase* item, muse::draw::Painter* painter)
1614 : {
1615 0 : painter->translate(0.0, textBlock.y());
1616 0 : for (const TextFragment& f : textBlock.fragments()) {
1617 0 : draw(f, item, painter);
1618 : }
1619 0 : painter->translate(0.0, -textBlock.y());
1620 0 : }
1621 :
1622 0 : void SingleDraw::draw(const TextFragment& textFragment, const TextBase* item, muse::draw::Painter* painter)
1623 : {
1624 0 : painter->setFont(textFragment.font(item));
1625 0 : painter->drawText(textFragment.pos, textFragment.text);
1626 0 : }
1627 :
1628 0 : static void setDashAndGapLen(const SLine* line, double& dash, double& gap, Pen& pen)
1629 : {
1630 : static constexpr double DOTTED_DASH_LEN = 0.01;
1631 : static constexpr double DOTTED_GAP_LEN = 1.99;
1632 0 : switch (line->lineStyle()) {
1633 0 : case LineType::SOLID:
1634 0 : break;
1635 0 : case LineType::DASHED:
1636 0 : dash = line->dashLineLen(), gap = line->dashGapLen();
1637 0 : break;
1638 0 : case LineType::DOTTED:
1639 0 : dash = DOTTED_DASH_LEN, gap = DOTTED_GAP_LEN;
1640 0 : pen.setCapStyle(PenCapStyle::RoundCap); // round dots
1641 0 : break;
1642 : }
1643 0 : }
1644 :
1645 0 : static std::vector<double> distributedDashPattern(double dash, double gap, double lineLength)
1646 : {
1647 0 : int numPairs = std::max(1.0, lineLength / (dash + gap));
1648 0 : double newGap = (lineLength - dash * (numPairs + 1)) / numPairs;
1649 :
1650 0 : return { dash, newGap };
1651 : }
1652 :
1653 0 : void SingleDraw::drawTextLineBaseSegment(const TextLineBaseSegment* item, Painter* painter, const PaintOptions& opt)
1654 : {
1655 0 : const TextLineBase* tl = item->textLineBase();
1656 0 : const TextLineBaseSegment::LayoutData* ldata = item->ldata();
1657 :
1658 0 : if (!item->text()->empty()) {
1659 0 : painter->translate(item->text()->pos());
1660 0 : item->text()->setVisible(tl->visible());
1661 0 : draw(item->text(), painter, opt);
1662 0 : painter->translate(-item->text()->pos());
1663 : }
1664 :
1665 0 : if (!item->endText()->empty()) {
1666 0 : painter->translate(item->endText()->pos());
1667 0 : item->endText()->setVisible(tl->visible());
1668 0 : draw(item->endText(), painter, opt);
1669 0 : painter->translate(-item->endText()->pos());
1670 : }
1671 :
1672 0 : if (ldata->npoints == 0) {
1673 0 : return;
1674 : }
1675 :
1676 : // color for line (text color comes from the text properties)
1677 0 : Color color = item->curColor(tl->visible() && tl->lineVisible(), tl->lineColor(), opt);
1678 :
1679 0 : double lineWidth = tl->absoluteFromSpatium(tl->lineWidth());
1680 :
1681 0 : const Pen solidPen(color, lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap, PenJoinStyle::MiterJoin);
1682 0 : Pen pen(solidPen);
1683 :
1684 0 : double dash = 0;
1685 0 : double gap = 0;
1686 :
1687 0 : setDashAndGapLen(tl, dash, gap, pen);
1688 :
1689 0 : const bool isNonSolid = tl->lineStyle() != LineType::SOLID;
1690 :
1691 : // Draw lines
1692 0 : if (item->twoLines()) { // hairpins
1693 0 : if (isNonSolid) {
1694 0 : pen.setDashPattern({ dash, gap });
1695 : }
1696 :
1697 0 : pen.setJoinStyle(PenJoinStyle::BevelJoin);
1698 0 : painter->setPen(pen);
1699 0 : if (!ldata->joinedHairpin.empty() && !isNonSolid) {
1700 0 : painter->drawPolyline(ldata->joinedHairpin);
1701 : } else {
1702 0 : painter->drawLines(&ldata->points[0], 2);
1703 : }
1704 0 : return;
1705 : }
1706 :
1707 0 : int start = 0, end = ldata->npoints;
1708 :
1709 : // Draw begin hook, if it needs to be drawn separately
1710 0 : if (item->isSingleBeginType() && tl->beginHookType() != HookType::NONE) {
1711 0 : if (tl->beginHookType() == HookType::ARROW_FILLED) {
1712 0 : Brush brush;
1713 0 : brush.setStyle(BrushStyle::SolidPattern);
1714 0 : brush.setColor(item->curColor(opt));
1715 0 : painter->setBrush(brush);
1716 0 : painter->setNoPen();
1717 0 : painter->drawPolygon(ldata->beginArrow);
1718 0 : } else if (tl->beginHookType() == HookType::ARROW) {
1719 0 : pen.setJoinStyle(PenJoinStyle::MiterJoin);
1720 0 : painter->setPen(pen);
1721 0 : painter->drawPolyline(ldata->beginArrow);
1722 : } else {
1723 0 : bool isTHook = tl->beginHookType() == HookType::HOOK_90T;
1724 :
1725 0 : if (isNonSolid || isTHook) {
1726 0 : const PointF& p1 = ldata->points[start++];
1727 0 : const PointF& p2 = ldata->points[start++];
1728 :
1729 0 : if (isTHook) {
1730 0 : painter->setPen(solidPen);
1731 : } else {
1732 0 : double hookLength = sqrt(PointF::dotProduct(p2 - p1, p2 - p1));
1733 0 : pen.setDashPattern(distributedDashPattern(dash, gap, hookLength / lineWidth));
1734 0 : painter->setPen(pen);
1735 : }
1736 :
1737 0 : painter->drawLine(p1, p2);
1738 : }
1739 : }
1740 : }
1741 :
1742 : // Draw end hook, if it needs to be drawn separately
1743 0 : if (item->isSingleEndType() && tl->endHookType() != HookType::NONE) {
1744 0 : if (tl->endHookType() == HookType::ARROW_FILLED) {
1745 0 : Brush brush;
1746 0 : brush.setStyle(BrushStyle::SolidPattern);
1747 0 : brush.setColor(item->curColor(opt));
1748 0 : painter->setBrush(brush);
1749 0 : painter->setNoPen();
1750 0 : painter->drawPolygon(ldata->endArrow);
1751 0 : } else if (tl->endHookType() == HookType::ARROW) {
1752 0 : pen.setJoinStyle(PenJoinStyle::MiterJoin);
1753 0 : painter->setPen(pen);
1754 0 : painter->drawPolyline(ldata->endArrow);
1755 : } else {
1756 0 : bool isTHook = tl->endHookType() == HookType::HOOK_90T;
1757 :
1758 0 : if (isNonSolid || isTHook) {
1759 0 : const PointF& p1 = ldata->points[--end];
1760 0 : const PointF& p2 = ldata->points[--end];
1761 :
1762 0 : if (isTHook) {
1763 0 : painter->setPen(solidPen);
1764 : } else {
1765 0 : double hookLength = sqrt(PointF::dotProduct(p2 - p1, p2 - p1));
1766 0 : pen.setDashPattern(distributedDashPattern(dash, gap, hookLength / lineWidth));
1767 0 : painter->setPen(pen);
1768 : }
1769 :
1770 0 : painter->drawLine(p1, p2);
1771 : }
1772 : }
1773 : }
1774 :
1775 : // Draw the rest
1776 0 : if (isNonSolid) {
1777 0 : pen.setDashPattern(distributedDashPattern(dash, gap, ldata->lineLength / lineWidth));
1778 : }
1779 :
1780 0 : painter->setPen(pen);
1781 0 : painter->drawPolyline(&ldata->points[start], end - start);
1782 0 : }
1783 :
1784 0 : void SingleDraw::draw(const GradualTempoChangeSegment* item, Painter* painter, const PaintOptions& opt)
1785 : {
1786 : TRACE_DRAW_ITEM;
1787 0 : drawTextLineBaseSegment(item, painter, opt);
1788 0 : }
1789 :
1790 0 : void SingleDraw::draw(const GuitarBendSegment*, Painter*, const PaintOptions&)
1791 : {
1792 : // TRACE_DRAW_ITEM;
1793 : // To be implemented
1794 0 : }
1795 :
1796 0 : void SingleDraw::draw(const HairpinSegment* item, Painter* painter, const PaintOptions& opt)
1797 : {
1798 : TRACE_DRAW_ITEM;
1799 :
1800 0 : drawTextLineBaseSegment(item, painter, opt);
1801 :
1802 0 : if (item->drawCircledTip()) {
1803 0 : Color color = item->curColor(item->hairpin()->visible(), item->hairpin()->lineColor(), opt);
1804 0 : double w = item->absoluteFromSpatium(item->lineWidth());
1805 0 : if (item->staff()) {
1806 0 : w *= item->staff()->staffMag(item->hairpin()->tick());
1807 : }
1808 :
1809 0 : Pen pen(color, w);
1810 0 : painter->setPen(pen);
1811 0 : painter->setBrush(BrushStyle::NoBrush);
1812 0 : painter->drawEllipse(item->circledTip(), item->circledTipRadius(), item->circledTipRadius());
1813 0 : }
1814 0 : }
1815 :
1816 0 : void SingleDraw::draw(const HammerOnPullOffSegment* item, muse::draw::Painter* painter, const PaintOptions& opt)
1817 : {
1818 0 : draw(toSlurSegment(item), painter, opt);
1819 0 : }
1820 :
1821 0 : void SingleDraw::draw(const HammerOnPullOffText* item, Painter* painter, const PaintOptions& opt)
1822 : {
1823 0 : drawTextBase(item, painter, opt);
1824 0 : }
1825 :
1826 0 : void SingleDraw::draw(const HarpPedalDiagram* item, Painter* painter, const PaintOptions& opt)
1827 : {
1828 : TRACE_DRAW_ITEM;
1829 0 : drawTextBase(item, painter, opt);
1830 0 : }
1831 :
1832 0 : void SingleDraw::draw(const HarmonicMarkSegment* item, Painter* painter, const PaintOptions& opt)
1833 : {
1834 : TRACE_DRAW_ITEM;
1835 0 : drawTextLineBaseSegment(item, painter, opt);
1836 0 : }
1837 :
1838 0 : void SingleDraw::draw(const Harmony* item, Painter* painter, const PaintOptions& opt)
1839 : {
1840 : TRACE_DRAW_ITEM;
1841 :
1842 0 : const Harmony::LayoutData* ldata = item->ldata();
1843 0 : if (ldata->renderItemList().empty()) {
1844 0 : drawTextBase(item, painter, opt);
1845 0 : return;
1846 : }
1847 :
1848 0 : if (item->hasFrame()) {
1849 0 : if (!RealIsNull(item->frameWidth().val())) {
1850 0 : Color color = item->frameColor();
1851 0 : Pen pen(color, item->frameWidth().val() * item->spatium(), PenStyle::SolidLine,
1852 0 : PenCapStyle::SquareCap, PenJoinStyle::MiterJoin);
1853 0 : painter->setPen(pen);
1854 0 : } else {
1855 0 : painter->setNoPen();
1856 : }
1857 0 : Color bg(item->bgColor());
1858 0 : painter->setBrush(bg.alpha() ? Brush(bg) : BrushStyle::NoBrush);
1859 0 : if (item->circle()) {
1860 0 : painter->drawArc(ldata->frame, 0, 5760);
1861 : } else {
1862 0 : double baseSpatium = DefaultStyle::baseStyle().value(Sid::spatium).toReal();
1863 0 : double frameRadius = item->frameRound().val() * (item->sizeIsSpatiumDependent() ? item->spatium() : baseSpatium);
1864 0 : painter->drawRoundedRect(ldata->frame, frameRadius, frameRadius);
1865 : }
1866 : }
1867 0 : painter->setBrush(BrushStyle::NoBrush);
1868 0 : Color color = item->textColor(opt);
1869 0 : painter->setPen(color);
1870 0 : for (const HarmonyRenderItem* renderItem : ldata->renderItemList()) {
1871 0 : if (const TextSegment* ts = dynamic_cast<const TextSegment*>(renderItem)) {
1872 0 : painter->setFont(ts->font());
1873 0 : painter->drawText(ts->pos(), ts->text());
1874 : }
1875 : }
1876 : }
1877 :
1878 0 : void SingleDraw::draw(const Hook* item, Painter* painter, const PaintOptions& opt)
1879 : {
1880 : TRACE_DRAW_ITEM;
1881 0 : painter->setPen(item->curColor(opt));
1882 0 : item->drawSymbol(item->sym(), painter);
1883 0 : }
1884 :
1885 0 : void SingleDraw::draw(const Image* item, Painter* painter, const PaintOptions&)
1886 : {
1887 : TRACE_DRAW_ITEM;
1888 0 : const Image::LayoutData* ldata = item->ldata();
1889 0 : bool emptyImage = false;
1890 0 : if (item->imageType() == ImageType::SVG) {
1891 0 : if (!item->svgRenderer()) {
1892 0 : emptyImage = true;
1893 : } else {
1894 0 : item->svgRenderer()->render(painter, ldata->bbox());
1895 : }
1896 0 : } else if (item->imageType() == ImageType::RASTER) {
1897 0 : if (item->rasterImage() == nullptr) {
1898 0 : emptyImage = true;
1899 : } else {
1900 0 : painter->save();
1901 0 : SizeF s;
1902 0 : if (item->sizeIsSpatium()) {
1903 0 : s = item->size() * item->spatium();
1904 : } else {
1905 0 : s = item->size() * DPMM;
1906 : }
1907 :
1908 0 : painter->scale(s.width() / item->rasterImage()->width(), s.height() / item->rasterImage()->height());
1909 0 : painter->drawPixmap(PointF(0, 0), *item->rasterImage());
1910 :
1911 0 : painter->restore();
1912 : }
1913 : }
1914 :
1915 0 : if (emptyImage) {
1916 0 : painter->setBrush(BrushStyle::NoBrush);
1917 0 : painter->setPen(item->configuration()->defaultColor());
1918 0 : painter->drawRect(ldata->bbox());
1919 0 : painter->drawLine(0.0, 0.0, ldata->bbox().width(), ldata->bbox().height());
1920 0 : painter->drawLine(ldata->bbox().width(), 0.0, 0.0, ldata->bbox().height());
1921 : }
1922 0 : }
1923 :
1924 0 : void SingleDraw::draw(const InstrumentChange* item, Painter* painter, const PaintOptions& opt)
1925 : {
1926 : TRACE_DRAW_ITEM;
1927 0 : drawTextBase(item, painter, opt);
1928 0 : }
1929 :
1930 0 : void SingleDraw::draw(const InstrumentName* item, Painter* painter, const PaintOptions& opt)
1931 : {
1932 : TRACE_DRAW_ITEM;
1933 0 : drawTextBase(item, painter, opt);
1934 0 : }
1935 :
1936 0 : void SingleDraw::draw(const Jump* item, Painter* painter, const PaintOptions& opt)
1937 : {
1938 : TRACE_DRAW_ITEM;
1939 0 : drawTextBase(item, painter, opt);
1940 0 : }
1941 :
1942 0 : void SingleDraw::draw(const KeySig* item, Painter* painter, const PaintOptions& opt)
1943 : {
1944 : TRACE_DRAW_ITEM;
1945 :
1946 0 : const KeySig::LayoutData* ldata = item->ldata();
1947 :
1948 0 : painter->setPen(item->curColor(opt));
1949 0 : double _spatium = item->spatium();
1950 0 : double step = _spatium * 0.5;
1951 0 : int lines = 5;
1952 0 : double ledgerLineWidth = item->style().styleAbsolute(Sid::ledgerLineWidth) * item->mag();
1953 0 : double ledgerExtraLen = item->style().styleS(Sid::ledgerLineLength).val() * _spatium;
1954 0 : for (const KeySym& ks : ldata->keySymbols) {
1955 0 : double x = ks.xPos.toAbsolute(_spatium);
1956 0 : double y = ks.line * step;
1957 0 : item->drawSymbol(ks.sym, painter, PointF(x, y));
1958 : // ledger lines
1959 0 : double _symWidth = item->symWidth(ks.sym);
1960 0 : double x1 = x - ledgerExtraLen;
1961 0 : double x2 = x + _symWidth + ledgerExtraLen;
1962 0 : painter->setPen(Pen(item->curColor(opt), ledgerLineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
1963 0 : for (int i = -2; i >= ks.line; i -= 2) { // above
1964 0 : y = i * step;
1965 0 : painter->drawLine(LineF(x1, y, x2, y));
1966 : }
1967 0 : for (int i = lines * 2; i <= ks.line; i += 2) { // below
1968 0 : y = i * step;
1969 0 : painter->drawLine(LineF(x1, y, x2, y));
1970 : }
1971 : }
1972 :
1973 0 : if (!item->ownershipParent() && (item->isAtonal() || item->isCustom()) && ldata->keySymbols.empty()) {
1974 : // empty custom or atonal key signature - draw something for palette
1975 0 : painter->setPen(item->configuration()->scoreGreyColor());
1976 0 : item->drawSymbol(SymId::timeSigX, painter, PointF(item->symWidth(SymId::timeSigX) * -0.5, 2.0 * item->spatium()));
1977 : }
1978 0 : }
1979 :
1980 0 : void SingleDraw::draw(const LayoutBreak* item, Painter* painter, const PaintOptions&)
1981 : {
1982 : TRACE_DRAW_ITEM;
1983 :
1984 0 : Pen pen(item->configuration()->fontPrimaryColor());
1985 0 : painter->setPen(pen);
1986 :
1987 0 : painter->setFont(item->font());
1988 :
1989 0 : painter->drawSymbol(PointF(0.0, 0.0), item->iconCode());
1990 0 : }
1991 :
1992 0 : void SingleDraw::draw(const LedgerLine* item, Painter* painter, const PaintOptions& opt)
1993 : {
1994 : TRACE_DRAW_ITEM;
1995 0 : const LedgerLine::LayoutData* ldata = item->ldata();
1996 :
1997 0 : painter->setPen(Pen(item->curColor(opt), ldata->lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
1998 0 : if (item->vertical()) {
1999 0 : painter->drawLine(LineF(0.0, 0.0, 0.0, item->len()));
2000 : } else {
2001 0 : painter->drawLine(LineF(0.0, 0.0, item->len(), 0.0));
2002 : }
2003 0 : }
2004 :
2005 0 : void SingleDraw::draw(const LetRingSegment* item, Painter* painter, const PaintOptions& opt)
2006 : {
2007 : TRACE_DRAW_ITEM;
2008 0 : drawTextLineBaseSegment(item, painter, opt);
2009 0 : }
2010 :
2011 0 : void SingleDraw::draw(const Lyrics* item, muse::draw::Painter* painter, const PaintOptions& opt)
2012 : {
2013 : TRACE_DRAW_ITEM;
2014 0 : drawTextBase(item, painter, opt);
2015 0 : }
2016 :
2017 0 : void SingleDraw::draw(const Marker* item, Painter* painter, const PaintOptions& opt)
2018 : {
2019 : TRACE_DRAW_ITEM;
2020 0 : drawTextBase(item, painter, opt);
2021 0 : }
2022 :
2023 0 : void SingleDraw::draw(const MeasureNumber* item, Painter* painter, const PaintOptions& opt)
2024 : {
2025 : TRACE_DRAW_ITEM;
2026 0 : drawTextBase(item, painter, opt);
2027 0 : }
2028 :
2029 0 : void SingleDraw::draw(const MeasureRepeat* item, Painter* painter, const PaintOptions& opt)
2030 : {
2031 : TRACE_DRAW_ITEM;
2032 :
2033 0 : const MeasureRepeat::LayoutData* ldata = item->ldata();
2034 0 : painter->setPen(item->curColor(opt));
2035 0 : item->drawSymbol(ldata->symId, painter);
2036 0 : }
2037 :
2038 0 : void SingleDraw::draw(const OttavaSegment* item, Painter* painter, const PaintOptions& opt)
2039 : {
2040 : TRACE_DRAW_ITEM;
2041 0 : drawTextLineBaseSegment(item, painter, opt);
2042 0 : }
2043 :
2044 0 : void SingleDraw::draw(const PalmMuteSegment* item, Painter* painter, const PaintOptions& opt)
2045 : {
2046 : TRACE_DRAW_ITEM;
2047 0 : drawTextLineBaseSegment(item, painter, opt);
2048 0 : }
2049 :
2050 0 : void SingleDraw::draw(const PedalSegment* item, Painter* painter, const PaintOptions& opt)
2051 : {
2052 : TRACE_DRAW_ITEM;
2053 0 : drawTextLineBaseSegment(item, painter, opt);
2054 0 : }
2055 :
2056 0 : void SingleDraw::draw(const PickScrapeSegment* item, Painter* painter, const PaintOptions& opt)
2057 : {
2058 : TRACE_DRAW_ITEM;
2059 0 : drawTextLineBaseSegment(item, painter, opt);
2060 0 : }
2061 :
2062 0 : void SingleDraw::draw(const PlayCountText* item, Painter* painter, const PaintOptions& opt)
2063 : {
2064 : TRACE_DRAW_ITEM;
2065 0 : drawTextBase(item, painter, opt);
2066 0 : }
2067 :
2068 0 : void SingleDraw::draw(const PlayTechAnnotation* item, Painter* painter, const PaintOptions& opt)
2069 : {
2070 : TRACE_DRAW_ITEM;
2071 0 : drawTextBase(item, painter, opt);
2072 0 : }
2073 :
2074 0 : void SingleDraw::draw(const RasgueadoSegment* item, Painter* painter, const PaintOptions& opt)
2075 : {
2076 : TRACE_DRAW_ITEM;
2077 0 : drawTextLineBaseSegment(item, painter, opt);
2078 0 : }
2079 :
2080 0 : void SingleDraw::draw(const RehearsalMark* item, Painter* painter, const PaintOptions& opt)
2081 : {
2082 : TRACE_DRAW_ITEM;
2083 0 : drawTextBase(item, painter, opt);
2084 0 : }
2085 :
2086 0 : void SingleDraw::draw(const Rest* item, Painter* painter, const PaintOptions& opt)
2087 : {
2088 : TRACE_DRAW_ITEM;
2089 0 : if (item->shouldNotBeDrawn()) {
2090 0 : return;
2091 : }
2092 0 : const Rest::LayoutData* ldata = item->ldata();
2093 0 : painter->setPen(item->curColor(opt));
2094 0 : item->drawSymbol(ldata->sym, painter);
2095 : }
2096 :
2097 0 : void SingleDraw::draw(const ShadowNote* item, Painter* painter, const PaintOptions&)
2098 : {
2099 : TRACE_DRAW_ITEM;
2100 :
2101 0 : if (!item->visible() || !item->isValid()) {
2102 0 : return;
2103 : }
2104 :
2105 0 : PointF ap(item->pagePos());
2106 0 : painter->translate(ap);
2107 0 : double lw = item->style().styleAbsolute(Sid::stemWidth) * item->mag();
2108 0 : Pen pen(item->color(), lw, PenStyle::SolidLine, PenCapStyle::FlatCap);
2109 0 : painter->setPen(pen);
2110 :
2111 0 : bool up = item->computeUp();
2112 :
2113 : // Draw the accidental
2114 0 : SymId acc = Accidental::subtype2symbol(item->accidentalType());
2115 0 : if (acc != SymId::noSym) {
2116 0 : PointF posAcc;
2117 0 : posAcc.rx() -= item->symWidth(acc) + item->style().styleAbsolute(Sid::accidentalNoteDistance) * item->mag();
2118 0 : item->drawSymbol(acc, painter, posAcc);
2119 : }
2120 :
2121 : // Draw the notehead
2122 0 : item->drawSymbol(item->noteheadSymbol(), painter);
2123 :
2124 : // Draw the dots
2125 0 : double sp = item->spatium();
2126 0 : double sp2 = sp / 2;
2127 0 : double noteheadWidth = item->symWidth(item->noteheadSymbol());
2128 :
2129 0 : PointF posDot;
2130 0 : if (item->duration().dots() > 0) {
2131 0 : double d = item->style().styleAbsolute(Sid::dotNoteDistance) * item->mag();
2132 0 : double dd = item->style().styleAbsolute(Sid::dotDotDistance) * item->mag();
2133 0 : posDot.rx() += (noteheadWidth + d);
2134 :
2135 0 : if (item->isRest()) {
2136 0 : posDot.ry() += Rest::getDotline(item->duration().type()) * sp2;
2137 : } else {
2138 0 : posDot.ry() -= (item->lineIndex() % 2 == 0 ? sp2 : 0);
2139 : }
2140 :
2141 0 : if (item->hasFlag() && up) {
2142 0 : posDot.rx() = std::max(posDot.x(), noteheadWidth + item->symBbox(item->flagSym()).right());
2143 : }
2144 :
2145 0 : for (int i = 0; i < item->duration().dots(); i++) {
2146 0 : posDot.rx() += dd * i;
2147 0 : item->drawSymbol(SymId::augmentationDot, painter, posDot);
2148 0 : posDot.rx() -= dd * i;
2149 : }
2150 : }
2151 :
2152 : // Draw stem and flag
2153 0 : if (item->hasStem()) {
2154 0 : double x = up ? (noteheadWidth - (lw / 2)) : lw / 2;
2155 0 : double y1 = item->symSmuflAnchor(item->noteheadSymbol(), up ? SmuflAnchorId::stemUpSE : SmuflAnchorId::stemDownNW).y();
2156 0 : double y2 = (up ? -3.5 : 3.5) * sp;
2157 :
2158 0 : if (item->hasFlag()) {
2159 0 : SymId flag = item->flagSym();
2160 0 : item->drawSymbol(flag, painter, PointF(x - (lw / 2), y2));
2161 0 : y2 += item->symSmuflAnchor(flag, up ? SmuflAnchorId::stemUpNW : SmuflAnchorId::stemDownSW).y();
2162 : }
2163 0 : painter->drawLine(LineF(x, y1, x, y2));
2164 : }
2165 :
2166 : // Draw ledger lines if needed
2167 0 : if (item->ledgerLinesVisible()) {
2168 0 : double extraLen = item->style().styleS(Sid::ledgerLineLength).val() * sp;
2169 0 : double x1 = -extraLen;
2170 0 : double x2 = noteheadWidth + extraLen;
2171 0 : double yOffset = item->staffOffsetY();
2172 0 : double step = sp2 * item->staffType()->lineDistance().val();
2173 :
2174 0 : lw = item->style().styleAbsolute(Sid::ledgerLineWidth) * item->mag();
2175 0 : pen.setWidthF(lw);
2176 0 : painter->setPen(pen);
2177 :
2178 0 : const int topLine = -2 + yOffset / step;
2179 0 : for (int i = topLine; i >= item->lineIndex(); i -= 2) {
2180 0 : double y = step * (i - item->lineIndex());
2181 0 : painter->drawLine(LineF(x1, y, x2, y));
2182 : }
2183 0 : int l = item->staffType()->lines() * 2 + yOffset / step; // first ledger line below staff
2184 0 : for (int i = l; i <= item->lineIndex(); i += 2) {
2185 0 : double y = step * (i - item->lineIndex());
2186 0 : painter->drawLine(LineF(x1, y, x2, y));
2187 : }
2188 : }
2189 :
2190 0 : item->drawArticulations(painter);
2191 :
2192 0 : painter->translate(-ap);
2193 0 : }
2194 :
2195 0 : void SingleDraw::draw(const SlurSegment* item, Painter* painter, const PaintOptions& opt)
2196 : {
2197 : TRACE_DRAW_ITEM;
2198 :
2199 0 : Pen pen(item->curColor(opt));
2200 0 : double mag = item->staff() ? item->staff()->staffMag(item->slur()->tick()) : 1.0;
2201 :
2202 : //Replace generic Qt dash patterns with improved equivalents to show true dots (keep in sync with tie.cpp)
2203 0 : std::vector<double> dotted = { 0.01, 1.99 }; // tighter than Qt PenStyle::DotLine equivalent - would be { 0.01, 2.99 }
2204 0 : std::vector<double> dashed = { 3.00, 3.00 }; // Compensating for caps. Qt default PenStyle::DashLine is { 4.0, 2.0 }
2205 0 : std::vector<double> wideDashed = { 5.00, 6.00 };
2206 :
2207 0 : switch (item->slurTie()->styleType()) {
2208 0 : case SlurStyleType::Solid:
2209 0 : painter->setBrush(Brush(pen.color()));
2210 0 : pen.setCapStyle(PenCapStyle::RoundCap);
2211 0 : pen.setJoinStyle(PenJoinStyle::RoundJoin);
2212 0 : pen.setWidthF(item->style().styleAbsolute(Sid::slurEndWidth) * mag);
2213 0 : break;
2214 0 : case SlurStyleType::Dotted:
2215 0 : painter->setBrush(BrushStyle::NoBrush);
2216 0 : pen.setCapStyle(PenCapStyle::RoundCap); // round dots
2217 0 : pen.setDashPattern(dotted);
2218 0 : pen.setWidthF(item->style().styleAbsolute(Sid::slurDottedWidth) * mag);
2219 0 : break;
2220 0 : case SlurStyleType::Dashed:
2221 0 : painter->setBrush(BrushStyle::NoBrush);
2222 0 : pen.setDashPattern(dashed);
2223 0 : pen.setWidthF(item->style().styleAbsolute(Sid::slurDottedWidth) * mag);
2224 0 : break;
2225 0 : case SlurStyleType::WideDashed:
2226 0 : painter->setBrush(BrushStyle::NoBrush);
2227 0 : pen.setDashPattern(wideDashed);
2228 0 : pen.setWidthF(item->style().styleAbsolute(Sid::slurDottedWidth) * mag);
2229 0 : break;
2230 0 : case SlurStyleType::Undefined:
2231 0 : break;
2232 : }
2233 0 : painter->setPen(pen);
2234 0 : painter->drawPath(item->ldata()->path());
2235 0 : }
2236 :
2237 0 : void SingleDraw::draw(const Spacer* item, Painter* painter, const PaintOptions&)
2238 : {
2239 : TRACE_DRAW_ITEM;
2240 :
2241 0 : auto conf = item->configuration();
2242 :
2243 0 : Pen pen(conf->fontPrimaryColor(), item->spatium() * 0.3);
2244 :
2245 0 : painter->setPen(pen);
2246 0 : painter->setBrush(BrushStyle::NoBrush);
2247 0 : painter->drawPath(item->ldata()->path);
2248 0 : }
2249 :
2250 0 : void SingleDraw::draw(const StaffLines* item, Painter* painter, const PaintOptions& opt)
2251 : {
2252 : TRACE_DRAW_ITEM;
2253 0 : painter->setPen(Pen(item->curColor(opt), item->lw(), PenStyle::SolidLine, PenCapStyle::FlatCap));
2254 0 : painter->drawLines(item->lines());
2255 0 : }
2256 :
2257 0 : void SingleDraw::draw(const StaffState* item, Painter* painter, const PaintOptions&)
2258 : {
2259 : TRACE_DRAW_ITEM;
2260 :
2261 0 : const StaffState::LayoutData* ldata = item->ldata();
2262 0 : auto conf = item->configuration();
2263 :
2264 0 : Pen pen(item->selected() ? conf->selectionColor() : conf->formattingColor(),
2265 0 : ldata->lw, PenStyle::SolidLine, PenCapStyle::RoundCap, PenJoinStyle::RoundJoin);
2266 0 : painter->setPen(pen);
2267 0 : painter->setBrush(BrushStyle::NoBrush);
2268 0 : painter->drawPath(ldata->path);
2269 0 : }
2270 :
2271 0 : void SingleDraw::draw(const StaffText* item, Painter* painter, const PaintOptions& opt)
2272 : {
2273 : TRACE_DRAW_ITEM;
2274 :
2275 0 : drawTextBase(item, painter, opt);
2276 :
2277 0 : if (item->hasSoundFlag()) {
2278 0 : draw(item->soundFlag(), painter, opt);
2279 : }
2280 0 : }
2281 :
2282 0 : void SingleDraw::draw(const StaveSharingChange* item, muse::draw::Painter* painter, const PaintOptions& opt)
2283 : {
2284 0 : if (opt.isPrinting || !item->score()->showUnprintable()) {
2285 0 : return;
2286 : }
2287 :
2288 0 : Pen pen(item->configuration()->formattingColor());
2289 0 : painter->setPen(pen);
2290 0 : painter->setFont(item->font());
2291 0 : painter->drawSymbol(PointF(), item->iconCode());
2292 0 : }
2293 :
2294 0 : void SingleDraw::draw(const StaveSharingLabel* item, muse::draw::Painter* painter, const PaintOptions& opt)
2295 : {
2296 : TRACE_DRAW_ITEM;
2297 :
2298 0 : drawTextBase(item, painter, opt);
2299 0 : }
2300 :
2301 0 : void SingleDraw::draw(const StaffTypeChange* item, Painter* painter, const PaintOptions&)
2302 : {
2303 : TRACE_DRAW_ITEM;
2304 :
2305 0 : auto conf = item->configuration();
2306 :
2307 0 : double _spatium = item->style().spatium();
2308 0 : double h = _spatium * 2.5;
2309 0 : double w = _spatium * 2.5;
2310 0 : double lineDist = 0.35; // line distance for the icon 'staff lines'
2311 : // draw icon rectangle
2312 0 : painter->setPen(Pen(item->selected() ? conf->selectionColor() : conf->formattingColor(),
2313 0 : item->lw(), PenStyle::SolidLine, PenCapStyle::SquareCap, PenJoinStyle::MiterJoin));
2314 0 : painter->setBrush(BrushStyle::NoBrush);
2315 0 : painter->drawRect(0, 0, w, h);
2316 :
2317 : // draw icon contents
2318 0 : int lines = 5;
2319 0 : if (item->staffType()) {
2320 0 : if (item->staffType()->stemless()) { // a single notehead represents a stemless staff
2321 0 : item->drawSymbol(SymId::noteheadBlack, painter, PointF(w * 0.5 - 0.33 * _spatium, h * 0.5), 0.5);
2322 : }
2323 0 : if (item->staffType()->invisible()) { // no lines needed. It's done.
2324 0 : return;
2325 : }
2326 : // show up to 6 lines
2327 0 : lines = std::min(item->staffType()->lines(), 6);
2328 : }
2329 : // calculate starting point Y for the lines from half the icon height (2.5) so staff lines appear vertically centered
2330 0 : double startY = 1.25 - (lines - 1) * lineDist * 0.5;
2331 0 : painter->setPen(Pen(item->selected() ? conf->selectionColor() : conf->formattingColor(),
2332 0 : 2.5, PenStyle::SolidLine, PenCapStyle::SquareCap, PenJoinStyle::MiterJoin));
2333 0 : for (int i=0; i < lines; i++) {
2334 0 : int y = (startY + i * lineDist) * _spatium;
2335 0 : painter->drawLine(0, y, w, y);
2336 : }
2337 0 : }
2338 :
2339 0 : void SingleDraw::draw(const Symbol* item, Painter* painter, const PaintOptions& opt)
2340 : {
2341 : TRACE_DRAW_ITEM;
2342 0 : if (!item->isNoteDot() || !item->staff()->isTabStaff(item->tick())) {
2343 0 : painter->setPen(item->curColor(opt));
2344 0 : if (item->scoreFont()) {
2345 0 : item->scoreFont()->draw(item->sym(), painter, item->magS(), PointF());
2346 : } else {
2347 0 : item->drawSymbol(item->sym(), painter);
2348 : }
2349 : }
2350 0 : }
2351 :
2352 0 : void SingleDraw::draw(const FSymbol* item, Painter* painter, const PaintOptions& opt)
2353 : {
2354 : TRACE_DRAW_ITEM;
2355 :
2356 0 : painter->setFont(item->font());
2357 0 : painter->setPen(item->curColor(opt));
2358 0 : painter->drawText(PointF(0, 0), item->toString());
2359 0 : }
2360 :
2361 0 : void SingleDraw::draw(const SystemDivider* item, Painter* painter, const PaintOptions& opt)
2362 : {
2363 0 : draw(static_cast<const Symbol*>(item), painter, opt);
2364 0 : }
2365 :
2366 0 : void SingleDraw::draw(const SystemText* item, Painter* painter, const PaintOptions& opt)
2367 : {
2368 : TRACE_DRAW_ITEM;
2369 0 : drawTextBase(item, painter, opt);
2370 0 : }
2371 :
2372 0 : void SingleDraw::draw(const SoundFlag* item, Painter* painter, const PaintOptions&)
2373 : {
2374 : TRACE_DRAW_ITEM;
2375 :
2376 0 : painter->setFont(item->iconFont());
2377 0 : painter->drawText(item->ldata()->bbox(), muse::draw::AlignCenter, muse::draw::TextDontClip, Char(item->iconCode()));
2378 0 : }
2379 :
2380 0 : void SingleDraw::draw(const Tapping* item, muse::draw::Painter* painter, const PaintOptions& opt)
2381 : {
2382 0 : drawTextBase(item->text(), painter, opt);
2383 0 : }
2384 :
2385 0 : void SingleDraw::draw(const TempoText* item, Painter* painter, const PaintOptions& opt)
2386 : {
2387 : TRACE_DRAW_ITEM;
2388 0 : drawTextBase(item, painter, opt);
2389 0 : }
2390 :
2391 0 : void SingleDraw::draw(const Text* item, Painter* painter, const PaintOptions& opt)
2392 : {
2393 : TRACE_DRAW_ITEM;
2394 0 : drawTextBase(item, painter, opt);
2395 0 : }
2396 :
2397 0 : void SingleDraw::draw(const TextLineSegment* item, Painter* painter, const PaintOptions& opt)
2398 : {
2399 : TRACE_DRAW_ITEM;
2400 0 : drawTextLineBaseSegment(item, painter, opt);
2401 0 : }
2402 :
2403 0 : void SingleDraw::draw(const TieSegment* item, Painter* painter, const PaintOptions& opt)
2404 : {
2405 : TRACE_DRAW_ITEM;
2406 :
2407 : // hide tie toward the second chord of a cross-measure value
2408 0 : if (item->tie()->endNote() && item->tie()->endNote()->chord()->crossMeasure() == CrossMeasure::SECOND) {
2409 0 : return;
2410 : }
2411 :
2412 0 : Pen pen(item->curColor(opt));
2413 0 : double mag = item->staff() ? item->staff()->staffMag(item->tie()->tick()) : 1.0;
2414 :
2415 : //Replace generic Qt dash patterns with improved equivalents to show true dots (keep in sync with slur.cpp)
2416 0 : std::vector<double> dotted = { 0.01, 1.99 }; // tighter than Qt PenStyle::DotLine equivalent - would be { 0.01, 2.99 }
2417 0 : std::vector<double> dashed = { 3.00, 3.00 }; // Compensating for caps. Qt default PenStyle::DashLine is { 4.0, 2.0 }
2418 0 : std::vector<double> wideDashed = { 5.00, 6.00 };
2419 :
2420 0 : switch (item->slurTie()->styleType()) {
2421 0 : case SlurStyleType::Solid:
2422 0 : painter->setBrush(Brush(pen.color()));
2423 0 : pen.setCapStyle(PenCapStyle::RoundCap);
2424 0 : pen.setJoinStyle(PenJoinStyle::RoundJoin);
2425 0 : pen.setWidthF(item->endWidth() * mag);
2426 0 : break;
2427 0 : case SlurStyleType::Dotted:
2428 0 : painter->setBrush(BrushStyle::NoBrush);
2429 0 : pen.setCapStyle(PenCapStyle::RoundCap); // True dots
2430 0 : pen.setDashPattern(dotted);
2431 0 : pen.setWidthF(item->dottedWidth() * mag);
2432 0 : break;
2433 0 : case SlurStyleType::Dashed:
2434 0 : painter->setBrush(BrushStyle::NoBrush);
2435 0 : pen.setDashPattern(dashed);
2436 0 : pen.setWidthF(item->dottedWidth() * mag);
2437 0 : break;
2438 0 : case SlurStyleType::WideDashed:
2439 0 : painter->setBrush(BrushStyle::NoBrush);
2440 0 : pen.setDashPattern(wideDashed);
2441 0 : pen.setWidthF(item->dottedWidth() * mag);
2442 0 : break;
2443 0 : case SlurStyleType::Undefined:
2444 0 : break;
2445 : }
2446 0 : painter->setPen(pen);
2447 0 : painter->drawPath(item->ldata()->path());
2448 0 : }
2449 :
2450 0 : void SingleDraw::draw(const TimeSig* item, Painter* painter, const PaintOptions& opt)
2451 : {
2452 : TRACE_DRAW_ITEM;
2453 :
2454 0 : if (item->staff() && !const_cast<const Staff*>(item->staff())->staffType(item->tick())->genTimesig()) {
2455 0 : return;
2456 : }
2457 0 : painter->setPen(item->curColor(opt));
2458 :
2459 0 : const TimeSig::LayoutData* ldata = item->ldata();
2460 :
2461 0 : item->drawSymbols(ldata->ns, painter, ldata->pz, item->scale());
2462 0 : item->drawSymbols(ldata->ds, painter, ldata->pn, item->scale());
2463 :
2464 0 : if (item->largeParentheses()) {
2465 0 : item->drawSymbol(SymId::timeSigParensLeft, painter, ldata->pointLargeLeftParen, item->scale().width());
2466 0 : item->drawSymbol(SymId::timeSigParensRight, painter, ldata->pointLargeRightParen, item->scale().width());
2467 : }
2468 : }
2469 :
2470 0 : void SingleDraw::draw(const TremoloSingleChord* item, Painter* painter, const PaintOptions& opt)
2471 : {
2472 : TRACE_DRAW_ITEM;
2473 :
2474 0 : const TremoloSingleChord::LayoutData* ldata = item->ldata();
2475 :
2476 0 : if (item->isBuzzRoll()) {
2477 0 : painter->setPen(item->curColor(opt));
2478 0 : item->drawSymbol(SymId::buzzRoll, painter);
2479 : } else {
2480 0 : painter->setBrush(Brush(item->curColor(opt)));
2481 0 : painter->setNoPen();
2482 0 : painter->drawPath(item->path());
2483 : }
2484 :
2485 : // vertical line (stem)
2486 : {
2487 0 : double x = 0.0; // bbox().width() * .25;
2488 0 : Pen pen(item->curColor(opt), item->absoluteFromSpatium(item->style().styleS(Sid::stemWidth)));
2489 0 : painter->setPen(pen);
2490 0 : const double sp = item->spatium();
2491 0 : if (item->isBuzzRoll()) {
2492 0 : painter->drawLine(LineF(x, -sp, x, ldata->bbox().bottom() + sp));
2493 : } else {
2494 0 : painter->drawLine(LineF(x, -sp * .5, x, item->path().boundingRect().height() + sp));
2495 : }
2496 0 : }
2497 0 : }
2498 :
2499 0 : void SingleDraw::draw(const TremoloTwoChord* item, Painter* painter, const PaintOptions& opt)
2500 : {
2501 : TRACE_DRAW_ITEM;
2502 :
2503 0 : painter->setBrush(Brush(item->curColor(opt)));
2504 0 : painter->setNoPen();
2505 0 : painter->drawPath(item->path());
2506 0 : }
2507 :
2508 0 : void SingleDraw::draw(const TremoloBar* item, Painter* painter, const PaintOptions& opt)
2509 : {
2510 : TRACE_DRAW_ITEM;
2511 0 : const TremoloBar::LayoutData* ldata = item->ldata();
2512 0 : const double lw = item->absoluteFromSpatium(item->lineWidth());
2513 0 : Pen pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::RoundCap, PenJoinStyle::RoundJoin);
2514 0 : painter->setPen(pen);
2515 0 : painter->drawPolyline(ldata->polygon);
2516 0 : }
2517 :
2518 0 : void SingleDraw::draw(const TrillSegment* item, Painter* painter, const PaintOptions& opt)
2519 : {
2520 : TRACE_DRAW_ITEM;
2521 0 : painter->setPen(item->spanner()->curColor(opt));
2522 0 : item->drawSymbols(item->symbols(), painter);
2523 0 : }
2524 :
2525 0 : void SingleDraw::draw(const TripletFeel* item, Painter* painter, const PaintOptions& opt)
2526 : {
2527 : TRACE_DRAW_ITEM;
2528 0 : drawTextBase(item, painter, opt);
2529 0 : }
2530 :
2531 0 : void SingleDraw::draw(const Tuplet* item, Painter* painter, const PaintOptions& opt)
2532 : {
2533 : TRACE_DRAW_ITEM;
2534 :
2535 : // if in a TAB without stems, tuplets are not shown
2536 0 : const StaffType* stt = item->staffType();
2537 0 : if (stt && stt->isTabStaff() && stt->stemless()) {
2538 0 : return;
2539 : }
2540 :
2541 0 : Color color(item->curColor(opt));
2542 0 : if (item->number()) {
2543 0 : painter->setPen(color);
2544 0 : PointF pos(item->number()->pos());
2545 0 : painter->translate(pos);
2546 0 : draw(item->number(), painter, opt);
2547 0 : painter->translate(-pos);
2548 : }
2549 0 : if (item->hasBracket()) {
2550 0 : painter->setPen(Pen(color, item->absoluteFromSpatium(item->bracketWidth()) * item->mag()));
2551 0 : if (!item->number()) {
2552 0 : painter->drawPolyline(item->bracketL, 4);
2553 : } else {
2554 0 : painter->drawPolyline(item->bracketL, 3);
2555 0 : painter->drawPolyline(item->bracketR, 3);
2556 : }
2557 : }
2558 : }
2559 :
2560 0 : void SingleDraw::draw(const VibratoSegment* item, Painter* painter, const PaintOptions& opt)
2561 : {
2562 : TRACE_DRAW_ITEM;
2563 0 : painter->setPen(item->spanner()->curColor(opt));
2564 0 : item->drawSymbols(item->symbols(), painter);
2565 0 : }
2566 :
2567 0 : void SingleDraw::draw(const VoltaSegment* item, Painter* painter, const PaintOptions& opt)
2568 : {
2569 : TRACE_DRAW_ITEM;
2570 0 : drawTextLineBaseSegment(item, painter, opt);
2571 0 : }
2572 :
2573 0 : void SingleDraw::draw(const WhammyBarSegment* item, Painter* painter, const PaintOptions& opt)
2574 : {
2575 : TRACE_DRAW_ITEM;
2576 0 : drawTextLineBaseSegment(item, painter, opt);
2577 0 : }
2578 :
2579 0 : void SingleDraw::setMask(const EngravingItem* item, Painter* painter)
2580 : {
2581 0 : const EngravingItem::LayoutData* ldata = item->ldata();
2582 :
2583 0 : const Shape& mask = ldata->mask();
2584 0 : if (mask.empty()) {
2585 0 : return;
2586 : }
2587 :
2588 0 : RectF background = ldata->bbox().padded(item->spatium());
2589 :
2590 0 : painter->setMask(background, mask.toRects());
2591 : }
|