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 : #include "tdraw.h"
23 :
24 : #include "defer.h"
25 :
26 : #include "draw/fontmetrics.h"
27 : #include "draw/svgrenderer.h"
28 :
29 : #include "iengravingconfiguration.h" // IWYU pragma: keep
30 : #include "iengravingcontextconfiguration.h" // IWYU pragma: keep
31 :
32 : #include "rendering/paintoptions.h"
33 : #include "style/style.h"
34 : #include "style/defaultstyle.h"
35 :
36 : #include "dom/accidental.h"
37 : #include "dom/actionicon.h"
38 : #include "dom/ambitus.h"
39 : #include "dom/arpeggio.h"
40 : #include "dom/chordbracket.h"
41 : #include "dom/articulation.h"
42 :
43 : #include "dom/bagpembell.h"
44 : #include "dom/barline.h"
45 : #include "dom/beam.h"
46 : #include "dom/bend.h"
47 : #include "dom/box.h"
48 : #include "dom/bracket.h"
49 : #include "dom/breath.h"
50 :
51 : #include "dom/chord.h"
52 : #include "dom/chordline.h"
53 : #include "dom/clef.h"
54 : #include "dom/capo.h"
55 :
56 : #include "dom/deadslapped.h"
57 : #include "dom/dynamic.h"
58 :
59 : #include "dom/expression.h"
60 :
61 : #include "dom/fermata.h"
62 : #include "dom/figuredbass.h"
63 : #include "dom/fingering.h"
64 : #include "dom/fret.h"
65 :
66 : #include "dom/glissando.h"
67 : #include "dom/gradualtempochange.h"
68 : #include "dom/guitarbend.h"
69 :
70 : #include "dom/hairpin.h"
71 : #include "dom/hammeronpulloff.h"
72 : #include "dom/harppedaldiagram.h"
73 : #include "dom/harmonicmark.h"
74 : #include "dom/harmony.h"
75 : #include "dom/hook.h"
76 :
77 : #include "dom/image.h"
78 : #include "dom/instrchange.h"
79 : #include "dom/instrumentname.h"
80 :
81 : #include "dom/jianpudurationline.h"
82 : #include "dom/jianpuoctavedot.h"
83 : #include "dom/jump.h"
84 :
85 : #include "dom/keysig.h"
86 :
87 : #include "dom/laissezvib.h"
88 : #include "dom/lasso.h"
89 : #include "dom/layoutbreak.h"
90 : #include "dom/ledgerline.h"
91 : #include "dom/letring.h"
92 : #include "dom/lyrics.h"
93 :
94 : #include "dom/marker.h"
95 : #include "dom/measurenumber.h"
96 : #include "dom/measurerepeat.h"
97 : #include "dom/mmrest.h"
98 : #include "dom/mmrestrange.h"
99 :
100 : #include "dom/note.h"
101 : #include "dom/notedot.h"
102 : #include "dom/noteline.h"
103 :
104 : #include "dom/ornament.h"
105 : #include "dom/ottava.h"
106 :
107 : #include "dom/page.h"
108 : #include "dom/pagelockindicator.h"
109 : #include "dom/parenthesis.h"
110 : #include "dom/partialtie.h"
111 : #include "dom/palmmute.h"
112 : #include "dom/part.h"
113 : #include "dom/pedal.h"
114 : #include "dom/pickscrape.h"
115 : #include "dom/playcounttext.h"
116 : #include "dom/playtechannotation.h"
117 :
118 : #include "dom/rasgueado.h"
119 : #include "dom/rehearsalmark.h"
120 : #include "dom/rest.h"
121 :
122 : #include "dom/score.h"
123 : #include "dom/shadownote.h"
124 : #include "dom/slur.h"
125 : #include "dom/spacer.h"
126 : #include "dom/staff.h"
127 : #include "dom/stafflines.h"
128 : #include "dom/staffstate.h"
129 : #include "dom/stafftext.h"
130 : #include "dom/stafftype.h"
131 : #include "dom/stafftypechange.h"
132 : #include "dom/staffvisibilityindicator.h"
133 : #include "dom/stavesharingchange.h"
134 : #include "dom/stavesharinglabel.h"
135 : #include "dom/stem.h"
136 : #include "dom/stemslash.h"
137 : #include "dom/sticking.h"
138 : #include "dom/stringtunings.h"
139 : #include "dom/symbol.h"
140 : #include "dom/systemdivider.h"
141 : #include "dom/systemlockindicator.h"
142 : #include "dom/systemtext.h"
143 : #include "dom/soundflag.h"
144 :
145 : #include "dom/tabdurationsymbol.h"
146 : #include "dom/tapping.h"
147 : #include "dom/tempotext.h"
148 : #include "dom/text.h"
149 : #include "dom/textbase.h"
150 : #include "dom/textline.h"
151 : #include "dom/textlinebase.h"
152 : #include "dom/tie.h"
153 : #include "dom/timesig.h"
154 : #include "dom/anchors.h"
155 : #include "dom/tremolosinglechord.h"
156 : #include "dom/tremolotwochord.h"
157 : #include "dom/tremolobar.h"
158 : #include "dom/trill.h"
159 : #include "dom/tripletfeel.h"
160 : #include "dom/tuplet.h"
161 :
162 : #include "dom/vibrato.h"
163 : #include "dom/volta.h"
164 :
165 : #include "dom/whammybar.h"
166 :
167 : #include "editing/mscoreview.h"
168 : #include "editing/navigation.h"
169 :
170 : #include "infrastructure/rtti.h"
171 :
172 : #include "stemlayout.h"
173 :
174 : // dev
175 : #include "dom/system.h"
176 : #include "dom/measure.h"
177 : #include "dom/segment.h"
178 : #include "dom/chord.h"
179 :
180 : using namespace mu::engraving;
181 : using namespace mu::engraving::rtti;
182 : using namespace mu::engraving::rendering::score;
183 : using namespace muse;
184 : using namespace muse::draw;
185 :
186 380 : void TDraw::drawItem(const EngravingItem* item, Painter* painter, const PaintOptions& opt)
187 : {
188 380 : switch (item->type()) {
189 94 : case ElementType::ACCIDENTAL: draw(item_cast<const Accidental*>(item), painter, opt);
190 94 : break;
191 0 : case ElementType::ACTION_ICON: draw(item_cast<const ActionIcon*>(item), painter, opt);
192 0 : break;
193 0 : case ElementType::AMBITUS: draw(item_cast<const Ambitus*>(item), painter, opt);
194 0 : break;
195 0 : case ElementType::ARPEGGIO: draw(item_cast<const Arpeggio*>(item), painter, opt);
196 0 : break;
197 0 : case ElementType::CHORD_BRACKET: draw(item_cast<const ChordBracket*>(item), painter, opt);
198 0 : break;
199 0 : case ElementType::ARTICULATION: draw(item_cast<const Articulation*>(item), painter, opt);
200 0 : break;
201 :
202 0 : case ElementType::BAGPIPE_EMBELLISHMENT: draw(item_cast<const BagpipeEmbellishment*>(item), painter, opt);
203 0 : break;
204 30 : case ElementType::BAR_LINE: draw(item_cast<const BarLine*>(item), painter, opt);
205 30 : break;
206 0 : case ElementType::BEAM: draw(item_cast<const Beam*>(item), painter, opt);
207 0 : break;
208 0 : case ElementType::BEND: draw(item_cast<const Bend*>(item), painter, opt);
209 0 : break;
210 0 : case ElementType::HBOX: draw(item_cast<const HBox*>(item), painter, opt);
211 0 : break;
212 0 : case ElementType::VBOX: draw(item_cast<const VBox*>(item), painter, opt);
213 0 : break;
214 0 : case ElementType::FBOX: draw(item_cast<const FBox*>(item), painter, opt);
215 0 : break;
216 0 : case ElementType::TBOX: draw(item_cast<const TBox*>(item), painter, opt);
217 0 : break;
218 0 : case ElementType::BRACKET: draw(item_cast<const Bracket*>(item), painter, opt);
219 0 : break;
220 0 : case ElementType::BREATH: draw(item_cast<const Breath*>(item), painter, opt);
221 0 : break;
222 :
223 0 : case ElementType::CHORDLINE: draw(item_cast<const ChordLine*>(item), painter, opt);
224 0 : break;
225 10 : case ElementType::CLEF: draw(item_cast<const Clef*>(item), painter, opt);
226 10 : break;
227 0 : case ElementType::CAPO: draw(item_cast<const Capo*>(item), painter, opt);
228 0 : break;
229 :
230 0 : case ElementType::DEAD_SLAPPED: draw(item_cast<const DeadSlapped*>(item), painter, opt);
231 0 : break;
232 0 : case ElementType::DYNAMIC: draw(item_cast<const Dynamic*>(item), painter, opt);
233 0 : break;
234 :
235 0 : case ElementType::EXPRESSION: draw(item_cast<const Expression*>(item), painter, opt);
236 0 : break;
237 :
238 0 : case ElementType::FERMATA: draw(item_cast<const Fermata*>(item), painter, opt);
239 0 : break;
240 0 : case ElementType::FIGURED_BASS: draw(item_cast<const FiguredBass*>(item), painter, opt);
241 0 : break;
242 0 : case ElementType::FINGERING: draw(item_cast<const Fingering*>(item), painter, opt);
243 0 : break;
244 0 : case ElementType::FRET_DIAGRAM: draw(item_cast<const FretDiagram*>(item), painter, opt);
245 0 : break;
246 0 : case ElementType::FSYMBOL: draw(item_cast<const FSymbol*>(item), painter, opt);
247 0 : break;
248 :
249 0 : case ElementType::GLISSANDO_SEGMENT: draw(item_cast<const GlissandoSegment*>(item), painter, opt);
250 0 : break;
251 0 : case ElementType::GRADUAL_TEMPO_CHANGE_SEGMENT: draw(item_cast<const GradualTempoChangeSegment*>(item), painter, opt);
252 0 : break;
253 0 : case ElementType::GUITAR_BEND_SEGMENT: draw(item_cast<const GuitarBendSegment*>(item), painter, opt);
254 0 : break;
255 0 : case ElementType::GUITAR_BEND_HOLD_SEGMENT: draw(item_cast<const GuitarBendHoldSegment*>(item), painter, opt);
256 0 : break;
257 0 : case ElementType::GUITAR_BEND_TEXT: drawTextBase(toTextBase(item), painter, opt);
258 0 : break;
259 :
260 0 : case ElementType::HAIRPIN_SEGMENT: draw(item_cast<const HairpinSegment*>(item), painter, opt);
261 0 : break;
262 0 : case ElementType::HAMMER_ON_PULL_OFF_SEGMENT: draw(item_cast<const HammerOnPullOffSegment*>(item), painter, opt);
263 0 : break;
264 0 : case ElementType::HAMMER_ON_PULL_OFF_TEXT: draw(item_cast<const HammerOnPullOffText*>(item), painter, opt);
265 0 : break;
266 0 : case ElementType::HARP_DIAGRAM: draw(item_cast<const HarpPedalDiagram*>(item), painter, opt);
267 0 : break;
268 0 : case ElementType::HARMONIC_MARK_SEGMENT: draw(item_cast<const HarmonicMarkSegment*>(item), painter, opt);
269 0 : break;
270 0 : case ElementType::HARMONY: draw(item_cast<const Harmony*>(item), painter, opt);
271 0 : break;
272 0 : case ElementType::HOOK: draw(item_cast<const Hook*>(item), painter, opt);
273 0 : break;
274 :
275 0 : case ElementType::IMAGE: draw(item_cast<const Image*>(item), painter, opt);
276 0 : break;
277 0 : case ElementType::INSTRUMENT_CHANGE: draw(item_cast<const InstrumentChange*>(item), painter, opt);
278 0 : break;
279 0 : case ElementType::INSTRUMENT_NAME: draw(item_cast<const InstrumentName*>(item), painter, opt);
280 0 : break;
281 :
282 0 : case ElementType::JIANPU_DURATION_LINE: draw(item_cast<const JianpuDurationLine*>(item), painter, opt);
283 0 : break;
284 0 : case ElementType::JIANPU_OCTAVE_DOT: draw(item_cast<const JianpuOctaveDot*>(item), painter, opt);
285 0 : break;
286 0 : case ElementType::JUMP: draw(item_cast<const Jump*>(item), painter, opt);
287 0 : break;
288 :
289 0 : case ElementType::KEYSIG: draw(item_cast<const KeySig*>(item), painter, opt);
290 0 : break;
291 0 : case ElementType::LAISSEZ_VIB_SEGMENT: draw(item_cast<const LaissezVibSegment*>(item), painter, opt);
292 0 : break;
293 0 : case ElementType::LASSO: draw(item_cast<const Lasso*>(item), painter, opt);
294 0 : break;
295 0 : case ElementType::LAYOUT_BREAK: draw(item_cast<const LayoutBreak*>(item), painter, opt);
296 0 : break;
297 24 : case ElementType::LEDGER_LINE: draw(item_cast<const LedgerLine*>(item), painter, opt);
298 24 : break;
299 0 : case ElementType::LET_RING_SEGMENT: draw(item_cast<const LetRingSegment*>(item), painter, opt);
300 0 : break;
301 0 : case ElementType::LYRICS: draw(item_cast<const Lyrics*>(item), painter, opt);
302 0 : break;
303 0 : case ElementType::LYRICSLINE_SEGMENT: draw(item_cast<const LyricsLineSegment*>(item), painter, opt);
304 0 : break;
305 0 : case ElementType::PARTIAL_LYRICSLINE_SEGMENT: draw(item_cast<const LyricsLineSegment*>(item), painter, opt);
306 0 : break;
307 :
308 0 : case ElementType::MARKER: draw(item_cast<const Marker*>(item), painter, opt);
309 0 : break;
310 0 : case ElementType::MEASURE_NUMBER: draw(item_cast<const MeasureNumber*>(item), painter, opt);
311 0 : break;
312 0 : case ElementType::MEASURE_REPEAT: draw(item_cast<const MeasureRepeat*>(item), painter, opt);
313 0 : break;
314 0 : case ElementType::MMREST: draw(item_cast<const MMRest*>(item), painter, opt);
315 0 : break;
316 0 : case ElementType::MMREST_RANGE: draw(item_cast<const MMRestRange*>(item), painter, opt);
317 0 : break;
318 :
319 127 : case ElementType::NOTE: draw(item_cast<const Note*>(item), painter, opt);
320 127 : break;
321 0 : case ElementType::NOTEDOT: draw(item_cast<const NoteDot*>(item), painter, opt);
322 0 : break;
323 0 : case ElementType::NOTEHEAD: draw(item_cast<const NoteHead*>(item), painter, opt);
324 0 : break;
325 0 : case ElementType::NOTELINE_SEGMENT: draw(item_cast<const NoteLineSegment*>(item), painter, opt);
326 0 : break;
327 :
328 0 : case ElementType::ORNAMENT: draw(item_cast<const Ornament*>(item), painter, opt);
329 0 : break;
330 0 : case ElementType::OTTAVA_SEGMENT: draw(item_cast<const OttavaSegment*>(item), painter, opt);
331 0 : break;
332 0 : case ElementType::PAGE_LOCK_INDICATOR: draw(item_cast<const PageLockIndicator*>(item), painter, opt);
333 0 : break;
334 0 : case ElementType::PARENTHESIS: draw(item_cast<const Parenthesis*>(item), painter, opt);
335 0 : break;
336 0 : case ElementType::PARTIAL_TIE_SEGMENT: draw(item_cast<const PartialTieSegment*>(item), painter, opt);
337 0 : break;
338 0 : case ElementType::PALM_MUTE_SEGMENT: draw(item_cast<const PalmMuteSegment*>(item), painter, opt);
339 0 : break;
340 0 : case ElementType::PEDAL_SEGMENT: draw(item_cast<const PedalSegment*>(item), painter, opt);
341 0 : break;
342 0 : case ElementType::PICK_SCRAPE_SEGMENT: draw(item_cast<const PickScrapeSegment*>(item), painter, opt);
343 0 : break;
344 0 : case ElementType::PLAY_COUNT_TEXT: draw(item_cast<const PlayCountText*>(item), painter, opt);
345 0 : break;
346 0 : case ElementType::PLAYTECH_ANNOTATION: draw(item_cast<const PlayTechAnnotation*>(item), painter, opt);
347 0 : break;
348 :
349 0 : case ElementType::RASGUEADO_SEGMENT: draw(item_cast<const RasgueadoSegment*>(item), painter, opt);
350 0 : break;
351 0 : case ElementType::REHEARSAL_MARK: draw(item_cast<const RehearsalMark*>(item), painter, opt);
352 0 : break;
353 0 : case ElementType::REST: draw(item_cast<const Rest*>(item), painter, opt);
354 0 : break;
355 :
356 0 : case ElementType::SHADOW_NOTE: draw(item_cast<const ShadowNote*>(item), painter, opt);
357 0 : break;
358 0 : case ElementType::SLUR_SEGMENT: draw(item_cast<const SlurSegment*>(item), painter, opt);
359 0 : break;
360 0 : case ElementType::SPACER: draw(item_cast<const Spacer*>(item), painter, opt);
361 0 : break;
362 20 : case ElementType::STAFF_LINES: draw(item_cast<const StaffLines*>(item), painter, opt);
363 20 : break;
364 0 : case ElementType::STAFF_STATE: draw(item_cast<const StaffState*>(item), painter, opt);
365 0 : break;
366 0 : case ElementType::STAFF_TEXT: draw(item_cast<const StaffText*>(item), painter, opt);
367 0 : break;
368 0 : case ElementType::STAVE_SHARING_CHANGE: draw(item_cast<const StaveSharingChange*>(item), painter, opt);
369 0 : break;
370 0 : case ElementType::STAVE_SHARING_LABEL: draw(item_cast<const StaveSharingLabel*>(item), painter, opt);
371 0 : break;
372 0 : case ElementType::STAFFTYPE_CHANGE: draw(item_cast<const StaffTypeChange*>(item), painter, opt);
373 0 : break;
374 0 : case ElementType::STAFF_VISIBILITY_INDICATOR: draw(item_cast<const StaffVisibilityIndicator*>(item), painter, opt);
375 0 : break;
376 60 : case ElementType::STEM: draw(item_cast<const Stem*>(item), painter, opt);
377 60 : break;
378 0 : case ElementType::STEM_SLASH: draw(item_cast<const StemSlash*>(item), painter, opt);
379 0 : break;
380 0 : case ElementType::STICKING: draw(item_cast<const Sticking*>(item), painter, opt);
381 0 : break;
382 0 : case ElementType::STRING_TUNINGS: draw(item_cast<const StringTunings*>(item), painter, opt);
383 0 : break;
384 0 : case ElementType::SYMBOL: draw(item_cast<const Symbol*>(item), painter, opt);
385 0 : break;
386 0 : case ElementType::SYSTEM_DIVIDER: draw(item_cast<const SystemDivider*>(item), painter, opt);
387 0 : break;
388 0 : case ElementType::SYSTEM_TEXT: draw(item_cast<const SystemText*>(item), painter, opt);
389 0 : break;
390 0 : case ElementType::SYSTEM_LOCK_INDICATOR: draw(item_cast<const SystemLockIndicator*>(item), painter, opt);
391 0 : break;
392 0 : case ElementType::SOUND_FLAG: draw(item_cast<const SoundFlag*>(item), painter, opt);
393 0 : break;
394 :
395 0 : case ElementType::TAB_DURATION_SYMBOL: draw(item_cast<const TabDurationSymbol*>(item), painter, opt);
396 0 : break;
397 0 : case ElementType::TAPPING: draw(toTapping(item), painter, opt);
398 0 : break;
399 0 : case ElementType::TAPPING_HALF_SLUR_SEGMENT: draw(toSlurSegment(item), painter, opt);
400 0 : break;
401 0 : case ElementType::TEMPO_TEXT: draw(item_cast<const TempoText*>(item), painter, opt);
402 0 : break;
403 0 : case ElementType::TEXT: draw(item_cast<const Text*>(item), painter, opt);
404 0 : break;
405 0 : case ElementType::TEXTLINE_SEGMENT: draw(item_cast<const TextLineSegment*>(item), painter, opt);
406 0 : break;
407 0 : case ElementType::TIE_SEGMENT: draw(item_cast<const TieSegment*>(item), painter, opt);
408 0 : break;
409 10 : case ElementType::TIMESIG: draw(item_cast<const TimeSig*>(item), painter, opt);
410 10 : break;
411 0 : case ElementType::TIME_TICK_ANCHOR: draw(item_cast<const TimeTickAnchor*>(item), painter, opt);
412 0 : break;
413 0 : case ElementType::TREMOLO_SINGLECHORD: draw(item_cast<const TremoloSingleChord*>(item), painter, opt);
414 0 : break;
415 0 : case ElementType::TREMOLO_TWOCHORD: draw(item_cast<const TremoloTwoChord*>(item), painter, opt);
416 0 : break;
417 0 : case ElementType::TREMOLOBAR: draw(item_cast<const TremoloBar*>(item), painter, opt);
418 0 : break;
419 0 : case ElementType::TRILL_SEGMENT: draw(item_cast<const TrillSegment*>(item), painter, opt);
420 0 : break;
421 0 : case ElementType::TRIPLET_FEEL: draw(item_cast<const TripletFeel*>(item), painter, opt);
422 0 : break;
423 0 : case ElementType::TUPLET: draw(item_cast<const Tuplet*>(item), painter, opt);
424 0 : break;
425 :
426 0 : case ElementType::VIBRATO_SEGMENT: draw(item_cast<const VibratoSegment*>(item), painter, opt);
427 0 : break;
428 0 : case ElementType::VOLTA_SEGMENT: draw(item_cast<const VoltaSegment*>(item), painter, opt);
429 0 : break;
430 :
431 0 : case ElementType::WHAMMY_BAR_SEGMENT: draw(item_cast<const WhammyBarSegment*>(item), painter, opt);
432 0 : break;
433 :
434 5 : case ElementType::PAGE:
435 : case ElementType::SYSTEM:
436 : case ElementType::MEASURE:
437 : case ElementType::SEGMENT:
438 : case ElementType::CHORD:
439 : case ElementType::GRACE_NOTES_GROUP:
440 5 : break;
441 :
442 0 : default:
443 0 : NOT_IMPLEMENTED << " type: " << item->typeName();
444 0 : UNREACHABLE;
445 : }
446 380 : }
447 :
448 94 : void TDraw::draw(const Accidental* item, Painter* painter, const PaintOptions& opt)
449 : {
450 : TRACE_DRAW_ITEM;
451 94 : IF_ASSERT_FAILED(item->ldata()) {
452 0 : return;
453 : }
454 :
455 94 : painter->setPen(item->curColor(opt));
456 188 : for (const Accidental::LayoutData::Sym& e : item->ldata()->syms) {
457 94 : item->drawSymbol(e.sym, painter, PointF(e.x, e.y));
458 : }
459 : }
460 :
461 0 : void TDraw::draw(const ActionIcon* item, Painter* painter, const PaintOptions&)
462 : {
463 : TRACE_DRAW_ITEM;
464 0 : const ActionIcon::LayoutData* ldata = item->ldata();
465 0 : painter->setFont(item->iconFont());
466 0 : painter->drawText(ldata->bbox(), muse::draw::AlignCenter, muse::draw::TextDontClip, Char(item->icon()));
467 0 : }
468 :
469 0 : void TDraw::draw(const Ambitus* item, Painter* painter, const PaintOptions& opt)
470 : {
471 : TRACE_DRAW_ITEM;
472 :
473 0 : const Ambitus::LayoutData* ldata = item->ldata();
474 0 : IF_ASSERT_FAILED(ldata) {
475 0 : return;
476 : }
477 :
478 0 : double spatium = item->spatium();
479 0 : double lw = item->lineWidth().val() * spatium;
480 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
481 :
482 0 : item->drawSymbol(item->noteHead(), painter, ldata->topPos);
483 0 : item->drawSymbol(item->noteHead(), painter, ldata->bottomPos);
484 0 : if (item->hasLine()) {
485 0 : painter->drawLine(ldata->line);
486 : }
487 :
488 : // draw ledger lines (if not in a palette)
489 0 : if (item->segment() && item->track() != muse::nidx) {
490 0 : Fraction tick = item->segment()->tick();
491 0 : Staff* staff = item->score()->staff(item->staffIdx());
492 0 : double lineDist = staff->lineDistance(tick);
493 0 : int numOfLines = staff->lines(tick);
494 0 : double step = lineDist * spatium;
495 0 : double stepTolerance = step * 0.1;
496 0 : double ledgerLineLength = item->style().styleS(Sid::ledgerLineLength).val() * spatium;
497 0 : double ledgerLineWidth = item->style().styleS(Sid::ledgerLineWidth).val() * spatium;
498 0 : painter->setPen(Pen(item->curColor(opt), ledgerLineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
499 :
500 0 : if (ldata->topPos.y() - stepTolerance <= -step) {
501 0 : double xMin = ldata->topPos.x() - ledgerLineLength;
502 0 : double xMax = ldata->topPos.x() + item->headWidth() + ledgerLineLength;
503 0 : for (double y = -step; y >= ldata->topPos.y() - stepTolerance; y -= step) {
504 0 : painter->drawLine(PointF(xMin, y), PointF(xMax, y));
505 : }
506 : }
507 :
508 0 : if (ldata->bottomPos.y() + stepTolerance >= numOfLines * step) {
509 0 : double xMin = ldata->bottomPos.x() - ledgerLineLength;
510 0 : double xMax = ldata->bottomPos.x() + item->headWidth() + ledgerLineLength;
511 0 : for (double y = numOfLines * step; y <= ldata->bottomPos.y() + stepTolerance; y += step) {
512 0 : painter->drawLine(PointF(xMin, y), PointF(xMax, y));
513 : }
514 : }
515 : }
516 : }
517 :
518 0 : void TDraw::draw(const Arpeggio* item, Painter* painter, const PaintOptions& opt)
519 : {
520 : TRACE_DRAW_ITEM;
521 :
522 0 : const Arpeggio::LayoutData* ldata = item->ldata();
523 0 : IF_ASSERT_FAILED(ldata) {
524 0 : return;
525 : }
526 :
527 0 : const double y1 = ldata->bbox().top();
528 0 : const double y2 = ldata->bbox().bottom();
529 0 : const double lineWidth = item->style().styleAbsolute(Sid::arpeggioLineWidth);
530 :
531 0 : painter->setPen(Pen(item->curColor(opt), lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
532 0 : painter->save();
533 :
534 0 : switch (item->arpeggioType()) {
535 0 : case ArpeggioType::NORMAL:
536 : case ArpeggioType::UP:
537 : {
538 0 : const RectF& r = ldata->symsBBox;
539 0 : painter->rotate(-90.0);
540 0 : item->drawSymbols(ldata->symbols, painter, PointF(-r.right() - y1, -r.bottom() + r.height()));
541 0 : } break;
542 :
543 0 : case ArpeggioType::DOWN:
544 : {
545 0 : const RectF& r = ldata->symsBBox;
546 0 : painter->rotate(90.0);
547 0 : item->drawSymbols(ldata->symbols, painter, PointF(-r.left() + y1, -r.top() - r.height()));
548 0 : } break;
549 :
550 0 : case ArpeggioType::UP_STRAIGHT:
551 : {
552 0 : const RectF& r = ldata->symsBBox;
553 0 : double x1 = item->spatium() * 0.5;
554 0 : item->drawSymbol(SymId::arrowheadBlackUp, painter, PointF(x1 - r.width() * 0.5, y1 - r.top()));
555 0 : double ny1 = y1 - r.top() * 0.5;
556 0 : painter->drawLine(LineF(x1, ny1, x1, y2));
557 0 : } break;
558 :
559 0 : case ArpeggioType::DOWN_STRAIGHT:
560 : {
561 0 : const RectF& r = ldata->symsBBox;
562 0 : double x1 = item->spatium() * 0.5;
563 0 : item->drawSymbol(SymId::arrowheadBlackDown, painter, PointF(x1 - r.width() * 0.5, y2 - r.bottom()));
564 0 : double ny2 = y2 + r.top() * 0.5;
565 0 : painter->drawLine(LineF(x1, y1, x1, ny2));
566 0 : } break;
567 :
568 0 : case ArpeggioType::BRACKET:
569 : {
570 0 : double w = item->style().styleS(Sid::arpeggioHookLen).val() * item->spatium();
571 0 : painter->drawLine(LineF(0.0, y1, w, y1));
572 0 : painter->drawLine(LineF(0.0, y2, w, y2));
573 0 : painter->drawLine(LineF(0.0, y1 - lineWidth / 2, 0.0, y2 + lineWidth / 2));
574 0 : } break;
575 : }
576 0 : painter->restore();
577 : }
578 :
579 0 : void TDraw::draw(const ChordBracket* item, muse::draw::Painter* painter, const PaintOptions& opt)
580 : {
581 0 : const Arpeggio::LayoutData* ldata = item->ldata();
582 :
583 0 : const double lineWidth = item->style().styleAbsolute(Sid::chordBracketLineWidth);
584 0 : painter->setPen(Pen(item->curColor(opt), lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
585 :
586 0 : const double halfLineWidth = 0.5 * lineWidth;
587 0 : const double y1 = ldata->bbox().top() + halfLineWidth;
588 0 : const double y2 = ldata->bbox().bottom() - halfLineWidth;
589 :
590 0 : double w = item->absoluteFromSpatium(item->hookLength());
591 :
592 0 : if (item->hookPos() != DirectionV::DOWN) {
593 0 : painter->drawLine(LineF(0.0, y1, w, y1));
594 : }
595 0 : if (item->hookPos() != DirectionV::UP) {
596 0 : painter->drawLine(LineF(0.0, y2, w, y2));
597 : }
598 :
599 0 : const double x = item->rightSide() ? w - halfLineWidth : halfLineWidth;
600 0 : painter->drawLine(LineF(x, y1, x, y2));
601 0 : }
602 :
603 0 : void TDraw::draw(const Articulation* item, Painter* painter, const PaintOptions& opt)
604 : {
605 : TRACE_DRAW_ITEM;
606 :
607 0 : painter->setPen(item->curColor(opt));
608 :
609 0 : if (item->textType() == ArticulationTextType::NO_TEXT) {
610 0 : item->drawSymbol(item->symId(), painter);
611 : } else {
612 0 : drawTextBase(item->text(), painter, opt);
613 : }
614 0 : }
615 :
616 0 : void TDraw::draw(const Ornament* item, Painter* painter, const PaintOptions& opt)
617 : {
618 0 : draw(static_cast<const Articulation*>(item), painter, opt);
619 0 : }
620 :
621 0 : void TDraw::draw(const BagpipeEmbellishment* item, Painter* painter, const PaintOptions& opt)
622 : {
623 : TRACE_DRAW_ITEM;
624 :
625 0 : const BagpipeEmbellishment::LayoutData* data = item->ldata();
626 0 : IF_ASSERT_FAILED(data) {
627 0 : return;
628 : }
629 0 : const BagpipeEmbellishment::LayoutData::BeamData& dataBeam = data->beamData;
630 :
631 0 : Pen pen(item->curColor(opt), data->stemLineW, PenStyle::SolidLine, PenCapStyle::FlatCap);
632 0 : painter->setPen(pen);
633 :
634 : // draw the notes including stem, (optional) flag and (optional) ledger line
635 0 : for (const auto& p : data->notesData) {
636 0 : const BagpipeEmbellishment::LayoutData::NoteData& noteData = p.second;
637 :
638 : // Draw Grace Note
639 : {
640 : // draw head
641 0 : item->drawSymbol(data->headsym, painter, noteData.headXY);
642 :
643 : // draw stem
644 0 : painter->drawLine(noteData.stemLine);
645 :
646 0 : if (data->isDrawFlag) {
647 : // draw flag
648 0 : item->drawSymbol(data->flagsym, painter, noteData.flagXY);
649 : }
650 : }
651 :
652 : // draw the ledger line for high A
653 0 : if (!noteData.ledgerLine.isNull()) {
654 0 : painter->drawLine(noteData.ledgerLine);
655 : }
656 : }
657 :
658 0 : if (data->isDrawBeam) {
659 0 : Pen beamPen(item->curColor(opt), dataBeam.width, PenStyle::SolidLine, PenCapStyle::FlatCap);
660 0 : painter->setPen(beamPen);
661 : // draw the beams
662 0 : auto drawBeams = [](Painter* painter, const double spatium,
663 : const double x1, const double x2, double y)
664 : {
665 : // draw the beams
666 0 : painter->drawLine(LineF(x1, y, x2, y));
667 0 : y += spatium / 1.5;
668 0 : painter->drawLine(LineF(x1, y, x2, y));
669 0 : y += spatium / 1.5;
670 0 : painter->drawLine(LineF(x1, y, x2, y));
671 0 : };
672 :
673 0 : drawBeams(painter, data->spatium, dataBeam.x1, dataBeam.x2, dataBeam.y);
674 0 : }
675 0 : }
676 :
677 0 : static void drawDots(const BarLine* item, Painter* painter, double x)
678 : {
679 0 : double spatium = item->spatium();
680 :
681 : double y1l;
682 : double y2l;
683 0 : if (item->ownershipParent() == 0) { // for use in palette (always Bravura)
684 : //Bravura shifted repeatDot symbol 0.5sp upper in the font itself (1.272)
685 0 : y1l = 1.5 * spatium;
686 0 : y2l = 2.5 * spatium;
687 : } else {
688 0 : const StaffType* st = item->staffType();
689 0 : const int lines = st->lines();
690 0 : const double lineDistance = item->absoluteFromSpatium(st->lineDistance());
691 :
692 0 : y1l = (static_cast<double>((lines - 1) / 2) - 0.5) * lineDistance;
693 0 : y2l = (static_cast<double>(lines / 2) + 0.5) * lineDistance;
694 :
695 : //adjust for staffType offset
696 0 : double stYOffset = item->staffOffsetY();
697 0 : y1l += stYOffset;
698 0 : y2l += stYOffset;
699 : }
700 :
701 0 : item->drawSymbol(SymId::repeatDot, painter, PointF(x, y1l));
702 0 : item->drawSymbol(SymId::repeatDot, painter, PointF(x, y2l));
703 0 : }
704 :
705 0 : static void drawTips(const BarLine* item, const BarLine::LayoutData* data, Painter* painter, bool reversed, double x)
706 : {
707 0 : if (reversed) {
708 0 : if (item->isTop()) {
709 0 : item->drawSymbol(SymId::reversedBracketTop, painter, PointF(x - item->symWidth(SymId::reversedBracketTop), data->y1));
710 : }
711 0 : if (item->isBottom()) {
712 0 : item->drawSymbol(SymId::reversedBracketBottom, painter, PointF(x - item->symWidth(SymId::reversedBracketBottom), data->y2));
713 : }
714 : } else {
715 0 : if (item->isTop()) {
716 0 : item->drawSymbol(SymId::bracketTop, painter, PointF(x, data->y1));
717 : }
718 0 : if (item->isBottom()) {
719 0 : item->drawSymbol(SymId::bracketBottom, painter, PointF(x, data->y2));
720 : }
721 : }
722 0 : }
723 :
724 30 : void TDraw::draw(const BarLine* item, Painter* painter, const PaintOptions& opt)
725 : {
726 : TRACE_DRAW_ITEM;
727 :
728 30 : const BarLine::LayoutData* data = item->ldata();
729 30 : IF_ASSERT_FAILED(data) {
730 30 : return;
731 : }
732 :
733 30 : painter->save();
734 30 : DEFER {
735 30 : painter->restore();
736 30 : };
737 :
738 30 : setMask(item, painter);
739 :
740 30 : switch (item->barLineType()) {
741 20 : case BarLineType::NORMAL: {
742 20 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
743 20 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
744 20 : painter->drawLine(LineF(lw * .5, data->y1, lw * .5, data->y2));
745 : }
746 20 : break;
747 :
748 0 : case BarLineType::BROKEN: {
749 0 : double lw = item->style().styleAbsolute(Sid::dashBarWidth) * item->mag();
750 0 : double dl = RealIsNull(lw) ? 0.0 : item->style().styleAbsolute(Sid::dashBarDash) * item->mag() / lw;
751 0 : double gl = RealIsNull(lw) ? 0.0 : item->style().styleAbsolute(Sid::dashBarGap) * item->mag() / lw;
752 0 : Pen pen(item->curColor(opt), lw, PenStyle::DashLine, PenCapStyle::FlatCap);
753 0 : pen.setDashPattern({ dl, gl });
754 0 : painter->setPen(pen);
755 0 : painter->drawLine(LineF(lw * .5, data->y1, lw * .5, data->y2));
756 0 : }
757 0 : break;
758 :
759 0 : case BarLineType::DOTTED: {
760 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
761 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::DotLine, PenCapStyle::FlatCap));
762 0 : painter->drawLine(LineF(lw * .5, data->y1, lw * .5, data->y2));
763 : }
764 0 : break;
765 :
766 10 : case BarLineType::END: {
767 10 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
768 10 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
769 10 : double x = lw * .5;
770 10 : painter->drawLine(LineF(x, data->y1, x, data->y2));
771 :
772 10 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
773 10 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
774 10 : x += ((lw * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
775 10 : painter->drawLine(LineF(x, data->y1, x, data->y2));
776 : }
777 10 : break;
778 :
779 0 : case BarLineType::DOUBLE: {
780 0 : double lw = item->style().styleAbsolute(Sid::doubleBarWidth) * item->mag();
781 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
782 0 : double x = lw * .5;
783 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
784 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::doubleBarDistance) + (lw * .5)) * item->mag();
785 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
786 : }
787 0 : break;
788 :
789 0 : case BarLineType::REVERSE_END: {
790 0 : double lw = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
791 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
792 0 : double x = lw * .5;
793 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
794 :
795 0 : double lw2 = item->style().styleAbsolute(Sid::barWidth) * item->mag();
796 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
797 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
798 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
799 : }
800 0 : break;
801 :
802 0 : case BarLineType::HEAVY: {
803 0 : double lw = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
804 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
805 0 : painter->drawLine(LineF(lw * .5, data->y1, lw * .5, data->y2));
806 : }
807 0 : break;
808 :
809 0 : case BarLineType::DOUBLE_HEAVY: {
810 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
811 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
812 0 : double x = lw2 * .5;
813 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
814 0 : x += ((lw2 * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
815 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
816 : }
817 0 : break;
818 :
819 0 : case BarLineType::START_REPEAT: {
820 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
821 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
822 0 : double x = lw2 * .5;
823 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
824 :
825 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
826 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
827 0 : x += ((lw2 * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw * .5)) * item->mag();
828 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
829 :
830 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::repeatBarlineDotSeparation)) * item->mag();
831 0 : drawDots(item, painter, x);
832 :
833 0 : if (item->style().styleB(Sid::repeatBarTips)) {
834 0 : drawTips(item, data, painter, false, 0.0);
835 : }
836 : }
837 0 : break;
838 :
839 0 : case BarLineType::END_REPEAT: {
840 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
841 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
842 :
843 0 : double x = 0.0;
844 0 : drawDots(item, painter, x);
845 :
846 0 : x += item->symBbox(SymId::repeatDot).width();
847 0 : x += (item->style().styleAbsolute(Sid::repeatBarlineDotSeparation) + (lw * .5)) * item->mag();
848 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
849 :
850 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
851 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
852 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
853 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
854 :
855 0 : if (item->style().styleB(Sid::repeatBarTips)) {
856 0 : drawTips(item, data, painter, true, x + lw2 * .5);
857 : }
858 : }
859 0 : break;
860 0 : case BarLineType::END_START_REPEAT: {
861 0 : double lw = item->style().styleAbsolute(Sid::barWidth) * item->mag();
862 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
863 :
864 0 : double x = 0.0;
865 0 : drawDots(item, painter, x);
866 :
867 0 : x += item->symBbox(SymId::repeatDot).width();
868 0 : x += (item->style().styleAbsolute(Sid::repeatBarlineDotSeparation) + (lw * .5)) * item->mag();
869 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
870 :
871 0 : double lw2 = item->style().styleAbsolute(Sid::endBarWidth) * item->mag();
872 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw2 * .5)) * item->mag();
873 0 : painter->setPen(Pen(item->curColor(opt), lw2, PenStyle::SolidLine, PenCapStyle::FlatCap));
874 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
875 :
876 0 : if (item->style().styleB(Sid::repeatBarTips)) {
877 0 : drawTips(item, data, painter, true, x + lw2 * .5);
878 : }
879 :
880 0 : painter->setPen(Pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::FlatCap));
881 0 : x += ((lw2 * .5) + item->style().styleAbsolute(Sid::endBarDistance) + (lw * .5)) * item->mag();
882 0 : painter->drawLine(LineF(x, data->y1, x, data->y2));
883 :
884 0 : x += ((lw * .5) + item->style().styleAbsolute(Sid::repeatBarlineDotSeparation)) * item->mag();
885 0 : drawDots(item, painter, x);
886 :
887 0 : if (item->style().styleB(Sid::repeatBarTips)) {
888 0 : drawTips(item, data, painter, false, 0.0);
889 : }
890 : }
891 0 : break;
892 : }
893 :
894 : // draw irregular measure mark
895 :
896 30 : if (opt.isPrinting || !item->score()->markIrregularMeasures()) {
897 30 : return;
898 : }
899 :
900 0 : const Segment* s = item->segment();
901 0 : if (s && (s->isEndBarLineType() || s->isStartRepeatBarLineType())) {
902 0 : const Measure* measure = s->measure();
903 0 : if (s->isStartRepeatBarLineType()) {
904 0 : const Measure* prevMeasure = measure ? measure->prevMeasure() : nullptr;
905 0 : if (!prevMeasure) {
906 0 : return;
907 : }
908 0 : if (const BarLine* prevEndBl = prevMeasure->endBarLine(item->staffIdx())) {
909 0 : if (prevEndBl->segment() && prevEndBl->segment()->enabled()) {
910 0 : return;
911 : }
912 : }
913 0 : measure = prevMeasure;
914 : }
915 :
916 0 : if (measure && measure->isIrregular() && !measure->isMMRest()) {
917 0 : painter->setPen(item->configuration()->invisibleColor());
918 0 : Font f(u"Edwin", Font::Type::Text);
919 0 : f.setPointSizeF(12 * item->spatium() / item->defaultSpatium());
920 0 : f.setBold(true);
921 0 : Char ch = measure->ticks() > measure->timesig() ? u'+' : u'-';
922 0 : RectF r = FontMetrics(f).boundingRect(ch);
923 :
924 0 : painter->setFont(f);
925 0 : painter->drawText(-r.width(), -item->spatium(), ch);
926 0 : }
927 : }
928 30 : }
929 :
930 0 : void TDraw::draw(const Beam* item, Painter* painter, const PaintOptions& opt)
931 : {
932 : TRACE_DRAW_ITEM;
933 0 : if (item->beamSegments().empty()) {
934 0 : return;
935 : }
936 0 : painter->setBrush(Brush(item->curColor(opt)));
937 0 : painter->setNoPen();
938 :
939 : // make beam thickness independent of slant
940 : // (expression can be simplified?)
941 :
942 0 : const LineF bs = item->beamSegments().front()->line;
943 0 : double d = (std::abs(bs.y2() - bs.y1())) / (bs.x2() - bs.x1());
944 0 : if (item->beamSegments().size() > 1 && d > M_PI / 6.0) {
945 0 : d = M_PI / 6.0;
946 : }
947 0 : double ww = (item->beamWidth() / 2.0) / sin(M_PI_2 - atan(d));
948 :
949 0 : for (const BeamSegment* bs1 : item->beamSegments()) {
950 0 : painter->drawPolygon(
951 0 : PolygonF({
952 0 : PointF(bs1->line.x1(), bs1->line.y1() - ww),
953 0 : PointF(bs1->line.x2(), bs1->line.y2() - ww),
954 0 : PointF(bs1->line.x2(), bs1->line.y2() + ww),
955 0 : PointF(bs1->line.x1(), bs1->line.y1() + ww),
956 0 : }),
957 : FillRule::OddEvenFill);
958 : }
959 : }
960 :
961 0 : void TDraw::draw(const Bend* item, Painter* painter, const PaintOptions& opt)
962 : {
963 : TRACE_DRAW_ITEM;
964 :
965 0 : const Bend::LayoutData* data = item->ldata();
966 0 : IF_ASSERT_FAILED(data) {
967 0 : return;
968 : }
969 :
970 0 : double spatium = item->spatium();
971 0 : double lw = item->absoluteFromSpatium(item->lineWidth());
972 :
973 0 : Pen pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::RoundCap, PenJoinStyle::RoundJoin);
974 0 : painter->setPen(pen);
975 0 : painter->setBrush(Brush(item->curColor(opt)));
976 :
977 0 : Font f = item->font(spatium);
978 :
979 0 : double x = data->noteWidth + spatium * .2;
980 0 : double y = -spatium * .8;
981 : double x2, y2;
982 :
983 0 : double aw = item->style().styleAbsolute(Sid::bendArrowWidth);
984 0 : PolygonF arrowUp;
985 0 : arrowUp << PointF(0, 0) << PointF(aw * .5, aw) << PointF(-aw * .5, aw);
986 0 : PolygonF arrowDown;
987 0 : arrowDown << PointF(0, 0) << PointF(aw * .5, -aw) << PointF(-aw * .5, -aw);
988 :
989 0 : size_t n = item->points().size();
990 0 : for (size_t pt = 0; pt < n - 1; ++pt) {
991 0 : int pitch = item->points()[pt].pitch;
992 0 : if (pt == 0 && pitch) {
993 0 : y2 = -data->notePos.y() - spatium * 2;
994 0 : x2 = x;
995 0 : painter->drawLine(LineF(x, y, x2, y2));
996 :
997 0 : painter->setBrush(item->curColor(opt));
998 0 : painter->drawPolygon(arrowUp.translated(x2, y2));
999 :
1000 0 : int idx = (pitch + 12) / 25;
1001 0 : const char* l = item->label[idx];
1002 0 : painter->setFont(f);
1003 0 : painter->drawText(RectF(x2, y2, .0, .0),
1004 : muse::draw::AlignHCenter | muse::draw::AlignBottom,
1005 : muse::draw::TextDontClip,
1006 0 : String::fromAscii(l));
1007 :
1008 0 : y = y2;
1009 : }
1010 0 : if (pitch == item->points()[pt + 1].pitch) {
1011 0 : if (pt == (n - 2)) {
1012 0 : break;
1013 : }
1014 0 : x2 = x + spatium;
1015 0 : y2 = y;
1016 0 : painter->drawLine(LineF(x, y, x2, y2));
1017 0 : } else if (pitch < item->points()[pt + 1].pitch) {
1018 : // up
1019 0 : x2 = x + spatium * .5;
1020 0 : y2 = -data->notePos.y() - spatium * 2;
1021 0 : double dx = x2 - x;
1022 0 : double dy = y2 - y;
1023 :
1024 0 : PainterPath path;
1025 0 : path.moveTo(x, y);
1026 0 : path.cubicTo(x + dx / 2, y, x2, y + dy / 4, x2, y2);
1027 0 : painter->setBrush(BrushStyle::NoBrush);
1028 0 : painter->drawPath(path);
1029 :
1030 0 : painter->setBrush(item->curColor(opt));
1031 0 : painter->drawPolygon(arrowUp.translated(x2, y2));
1032 :
1033 0 : int idx = (item->points()[pt + 1].pitch + 12) / 25;
1034 0 : const char* l = item->label[idx];
1035 0 : double ty = y2; // - _spatium;
1036 0 : painter->setFont(f);
1037 0 : painter->drawText(RectF(x2, ty, .0, .0),
1038 : muse::draw::AlignHCenter | muse::draw::AlignBottom,
1039 : muse::draw::TextDontClip,
1040 0 : String::fromAscii(l));
1041 0 : } else {
1042 : // down
1043 0 : x2 = x + spatium * .5;
1044 0 : y2 = y + spatium * 3;
1045 0 : double dx = x2 - x;
1046 0 : double dy = y2 - y;
1047 :
1048 0 : PainterPath path;
1049 0 : path.moveTo(x, y);
1050 0 : path.cubicTo(x + dx / 2, y, x2, y + dy / 4, x2, y2);
1051 0 : painter->setBrush(BrushStyle::NoBrush);
1052 0 : painter->drawPath(path);
1053 :
1054 0 : painter->setBrush(item->curColor(opt));
1055 0 : painter->drawPolygon(arrowDown.translated(x2, y2));
1056 0 : }
1057 0 : x = x2;
1058 0 : y = y2;
1059 : }
1060 0 : }
1061 :
1062 0 : void TDraw::draw(const Box* item, Painter* painter, const PaintOptions& opt)
1063 : {
1064 : TRACE_DRAW_ITEM;
1065 0 : if (opt.isPrinting) {
1066 0 : return;
1067 : }
1068 :
1069 0 : const Box::LayoutData* ldata = item->ldata();
1070 :
1071 0 : const bool showHighlightedFrame = item->selected() || item->dropTarget();
1072 0 : const bool showFrame = showHighlightedFrame || (item->score() ? item->score()->showFrames() : false);
1073 :
1074 0 : if (showFrame) {
1075 0 : double lineWidth = item->defaultSpatium() * .10;
1076 0 : Pen pen;
1077 0 : pen.setWidthF(lineWidth);
1078 0 : pen.setJoinStyle(PenJoinStyle::RoundJoin);
1079 0 : pen.setCapStyle(PenCapStyle::RoundCap);
1080 0 : pen.setColor(showHighlightedFrame
1081 0 : ? item->configuration()->selectionColor()
1082 0 : : item->configuration()->frameColor());
1083 0 : pen.setDashPattern({ 5, 5 });
1084 :
1085 0 : painter->setBrush(BrushStyle::NoBrush);
1086 0 : painter->setPen(pen);
1087 0 : lineWidth *= 0.5;
1088 0 : painter->drawRect(ldata->bbox().adjusted(lineWidth, lineWidth, -lineWidth, -lineWidth));
1089 0 : }
1090 : }
1091 :
1092 0 : void TDraw::draw(const HBox* item, Painter* painter, const PaintOptions& opt)
1093 : {
1094 0 : draw(static_cast<const Box*>(item), painter, opt);
1095 0 : }
1096 :
1097 0 : void TDraw::draw(const VBox* item, Painter* painter, const PaintOptions& opt)
1098 : {
1099 0 : draw(static_cast<const Box*>(item), painter, opt);
1100 0 : }
1101 :
1102 0 : void TDraw::draw(const FBox* item, Painter* painter, const PaintOptions& opt)
1103 : {
1104 0 : draw(static_cast<const Box*>(item), painter, opt);
1105 0 : }
1106 :
1107 0 : void TDraw::draw(const TBox* item, Painter* painter, const PaintOptions& opt)
1108 : {
1109 0 : draw(static_cast<const Box*>(item), painter, opt);
1110 0 : }
1111 :
1112 0 : void TDraw::draw(const Bracket* item, Painter* painter, const PaintOptions& opt)
1113 : {
1114 : TRACE_DRAW_ITEM;
1115 0 : const Bracket::LayoutData* ldata = item->ldata();
1116 0 : IF_ASSERT_FAILED(ldata) {
1117 0 : return;
1118 : }
1119 :
1120 0 : switch (item->bracketType()) {
1121 0 : case BracketType::BRACE: {
1122 0 : if (ldata->braceSymbol == SymId::noSym) {
1123 0 : painter->setNoPen();
1124 0 : painter->setBrush(Brush(item->curColor(opt)));
1125 0 : painter->drawPath(ldata->path);
1126 : } else {
1127 0 : double h = ldata->bracketHeight;
1128 0 : double glyphHeight = item->symHeight(ldata->braceSymbol);
1129 0 : double mag = h / glyphHeight;
1130 0 : painter->setPen(item->curColor(opt));
1131 0 : painter->save();
1132 0 : painter->scale(item->magx(), mag);
1133 0 : item->drawSymbol(ldata->braceSymbol, painter, PointF(0.0, glyphHeight));
1134 0 : painter->restore();
1135 : }
1136 : }
1137 0 : break;
1138 0 : case BracketType::NORMAL: {
1139 0 : double h = ldata->bracketHeight;
1140 0 : double spatium = item->spatium();
1141 0 : double w = item->style().styleAbsolute(Sid::bracketWidth);
1142 0 : double bd = (item->style().styleSt(Sid::musicalSymbolFont) == "Leland") ? spatium * .5 : spatium * .25;
1143 0 : Pen pen(item->curColor(opt), w, PenStyle::SolidLine, PenCapStyle::FlatCap);
1144 0 : painter->setPen(pen);
1145 0 : painter->drawLine(LineF(0.0, -bd - w * .5, 0.0, h + bd + w * .5));
1146 0 : double x = -w * .5;
1147 0 : double y1 = -bd;
1148 0 : double y2 = h + bd;
1149 0 : item->drawSymbol(SymId::bracketTop, painter, PointF(x, y1));
1150 0 : item->drawSymbol(SymId::bracketBottom, painter, PointF(x, y2));
1151 0 : }
1152 0 : break;
1153 0 : case BracketType::SQUARE:
1154 : {
1155 0 : double h = ldata->bracketHeight;
1156 0 : double lineW = item->style().styleAbsolute(Sid::staffLineWidth);
1157 0 : double bracketWidth = ldata->bracketWidth - lineW / 2;
1158 0 : Pen pen(item->curColor(opt), lineW, PenStyle::SolidLine, PenCapStyle::FlatCap);
1159 0 : painter->setPen(pen);
1160 0 : painter->drawLine(LineF(0.0, 0.0, 0.0, h));
1161 0 : painter->drawLine(LineF(-lineW / 2, 0.0, lineW / 2 + bracketWidth, 0.0));
1162 0 : painter->drawLine(LineF(-lineW / 2, h, lineW / 2 + bracketWidth, h));
1163 0 : }
1164 0 : break;
1165 0 : case BracketType::LINE: {
1166 0 : double h = ldata->bracketHeight;
1167 0 : double w = 0.67 * item->style().styleAbsolute(Sid::bracketWidth);
1168 0 : Pen pen(item->curColor(opt), w, PenStyle::SolidLine, PenCapStyle::FlatCap);
1169 0 : painter->setPen(pen);
1170 0 : double bd = item->style().styleAbsolute(Sid::staffLineWidth) * 0.5;
1171 0 : painter->drawLine(LineF(0.0, -bd, 0.0, h + bd));
1172 0 : }
1173 0 : break;
1174 0 : case BracketType::GROUP:
1175 : {
1176 0 : if (!item->bracketItem()->showBracket() && (!item->score()->isShowInvisible() || opt.isPrinting)) {
1177 0 : return;
1178 : }
1179 :
1180 0 : painter->save();
1181 0 : setMask(item, painter);
1182 :
1183 0 : double h = ldata->bracketHeight;
1184 0 : double lineW = item->style().styleAbsolute(Sid::groupBracketLineWidth);
1185 0 : double hookLen = item->style().styleAbsolute(Sid::groupBracketHookLen);
1186 0 : Color color = item->curColor(item->visible() && item->bracketItem()->showBracket(), opt);
1187 0 : Pen pen(color, lineW, PenStyle::SolidLine, PenCapStyle::FlatCap);
1188 0 : painter->setPen(pen);
1189 0 : painter->drawLine(LineF(0.5 * lineW, 0.0, 0.5 * lineW, h));
1190 0 : painter->drawLine(LineF(0.0, 0.0, hookLen, 0.0));
1191 0 : painter->drawLine(LineF(0.0, h, hookLen, h));
1192 :
1193 0 : painter->restore();
1194 0 : }
1195 0 : break;
1196 0 : case BracketType::NO_BRACKET:
1197 0 : break;
1198 : }
1199 : }
1200 :
1201 0 : void TDraw::draw(const Breath* item, Painter* painter, const PaintOptions& opt)
1202 : {
1203 : TRACE_DRAW_ITEM;
1204 0 : painter->setPen(item->curColor(opt));
1205 0 : item->drawSymbol(item->symId(), painter);
1206 0 : }
1207 :
1208 0 : void TDraw::draw(const ChordLine* item, Painter* painter, const PaintOptions& opt)
1209 : {
1210 : TRACE_DRAW_ITEM;
1211 0 : const ChordLine::LayoutData* ldata = item->ldata();
1212 0 : IF_ASSERT_FAILED(ldata) {
1213 0 : return;
1214 : }
1215 :
1216 0 : painter->setPen(Pen(item->curColor(opt), item->style().styleAbsolute(Sid::chordlineThickness) * item->mag(), PenStyle::SolidLine));
1217 0 : painter->setBrush(BrushStyle::NoBrush);
1218 0 : if (!item->isWavy()) {
1219 0 : painter->drawPath(ldata->path);
1220 : } else {
1221 0 : painter->save();
1222 0 : painter->rotate((item->chordLineType() == ChordLineType::FALL ? 1 : -1));
1223 0 : item->drawSymbol(item->waveSym(), painter);
1224 0 : painter->restore();
1225 : }
1226 : }
1227 :
1228 10 : void TDraw::draw(const Clef* item, Painter* painter, const PaintOptions& opt)
1229 : {
1230 : TRACE_DRAW_ITEM;
1231 10 : const Clef::LayoutData* ldata = item->ldata();
1232 10 : IF_ASSERT_FAILED(ldata) {
1233 0 : return;
1234 : }
1235 :
1236 10 : if (ldata->symId == SymId::noSym || (item->staff() && !const_cast<const Staff*>(item->staff())->staffType(item->tick())->genClef())) {
1237 0 : return;
1238 : }
1239 :
1240 10 : painter->setPen(item->curColor(opt));
1241 10 : item->drawSymbol(ldata->symId, painter);
1242 : }
1243 :
1244 0 : void TDraw::draw(const Capo* item, Painter* painter, const PaintOptions& opt)
1245 : {
1246 0 : drawTextBase(item, painter, opt);
1247 0 : }
1248 :
1249 0 : void TDraw::draw(const DeadSlapped* item, Painter* painter, const PaintOptions& opt)
1250 : {
1251 : TRACE_DRAW_ITEM;
1252 0 : const DeadSlapped::LayoutData* ldata = item->ldata();
1253 0 : IF_ASSERT_FAILED(ldata) {
1254 0 : return;
1255 : }
1256 :
1257 0 : painter->setPen(PenStyle::NoPen);
1258 0 : painter->setBrush(item->curColor(opt));
1259 0 : painter->drawPath(ldata->path1);
1260 0 : painter->drawPath(ldata->path2);
1261 : }
1262 :
1263 0 : void TDraw::draw(const Dynamic* item, Painter* painter, const PaintOptions& opt)
1264 : {
1265 0 : drawTextBase(item, painter, opt);
1266 0 : }
1267 :
1268 0 : void TDraw::draw(const JianpuDurationLine* item, Painter* painter, const PaintOptions& opt)
1269 : {
1270 : TRACE_DRAW_ITEM;
1271 :
1272 0 : const JianpuDurationLine::LayoutData* ldata = item->ldata();
1273 0 : IF_ASSERT_FAILED(ldata) {
1274 0 : return;
1275 : }
1276 :
1277 0 : painter->setPen(Pen(item->curColor(opt), ldata->lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
1278 0 : painter->drawLine(LineF(0.0, 0.0, ldata->len, 0.0));
1279 : }
1280 :
1281 0 : void TDraw::draw(const Expression* item, Painter* painter, const PaintOptions& opt)
1282 : {
1283 0 : drawTextBase(item, painter, opt);
1284 0 : }
1285 :
1286 0 : void TDraw::draw(const Fermata* item, Painter* painter, const PaintOptions& opt)
1287 : {
1288 : TRACE_DRAW_ITEM;
1289 0 : painter->setPen(item->curColor(opt));
1290 0 : item->drawSymbol(item->symId(), painter);
1291 0 : }
1292 :
1293 0 : void TDraw::draw(const FiguredBass* item, Painter* painter, const PaintOptions& opt)
1294 : {
1295 : TRACE_DRAW_ITEM;
1296 0 : const FiguredBass::LayoutData* ldata = item->ldata();
1297 : // if not printing, draw duration line(s)
1298 0 : if (!opt.isPrinting && item->score()->showUnprintable()) {
1299 0 : for (double len : ldata->lineLengths) {
1300 0 : if (len > 0) {
1301 0 : painter->setPen(Pen(item->configuration()->invisibleColor(), 3));
1302 0 : painter->drawLine(0.0, -2, len, -2); // -2: 2 rast. un. above digits
1303 : }
1304 : }
1305 : }
1306 :
1307 0 : if (item->items().size() < 1) { // if not parseable into f.b. items
1308 0 : drawTextBase(item, painter, opt); // draw as standard text
1309 : } else {
1310 0 : for (FiguredBassItem* fi : item->items()) { // if parseable into f.b. items
1311 0 : painter->translate(fi->pos()); // draw each item in its proper position
1312 0 : draw(fi, painter, opt);
1313 0 : painter->translate(-fi->pos());
1314 : }
1315 : }
1316 0 : }
1317 :
1318 0 : void TDraw::draw(const FiguredBassItem* item, Painter* painter, const PaintOptions& opt)
1319 : {
1320 : TRACE_DRAW_ITEM;
1321 :
1322 0 : const FiguredBassItem::LayoutData* ldata = item->ldata();
1323 0 : int font = 0;
1324 0 : double _spatium = item->spatium();
1325 : // set font from general style
1326 0 : Font f(FiguredBass::FBFonts().at(font).family, Font::Type::Tablature);
1327 :
1328 : // (use the same font selection as used in layout() above)
1329 0 : double m = item->style().styleD(Sid::figuredBassFontSize) * item->spatium() / item->defaultSpatium();
1330 0 : f.setPointSizeF(m);
1331 :
1332 0 : painter->setFont(f);
1333 0 : painter->setBrush(BrushStyle::NoBrush);
1334 0 : Pen pen(item->figuredBass()->curColor(opt), FiguredBass::FB_CONTLINE_THICKNESS.toAbsolute(_spatium), PenStyle::SolidLine,
1335 0 : PenCapStyle::RoundCap);
1336 0 : painter->setPen(pen);
1337 0 : painter->drawText(ldata->bbox(),
1338 : muse::draw::AlignLeft | muse::draw::AlignTop,
1339 : muse::draw::TextDontClip,
1340 0 : ldata->displayText);
1341 :
1342 : // continuation line
1343 0 : double lineEndX = 0.0;
1344 0 : if (item->contLine() != FiguredBassItem::ContLine::NONE) {
1345 0 : double lineStartX = ldata->textWidth; // by default, line starts right after text
1346 0 : if (lineStartX > 0.0) {
1347 0 : lineStartX += FiguredBass::FB_CONTLINE_LEFT_PADDING.toAbsolute(_spatium); // if some text, give some room after it
1348 : }
1349 0 : lineEndX = item->figuredBass()->ldata()->printedLineLength; // by default, line ends with item duration
1350 0 : if (lineEndX - lineStartX < 1.0) { // if line length < 1 sp, ignore it
1351 0 : lineEndX = 0.0;
1352 : }
1353 :
1354 : // if extended cont.line and no closing parenthesis: look at next FB element
1355 0 : if (item->contLine() > FiguredBassItem::ContLine::SIMPLE && item->parenth5() == FiguredBassItem::Parenthesis::NONE) {
1356 : FiguredBass* nextFB;
1357 : // if there is a contiguous FB element
1358 0 : if ((nextFB = item->figuredBass()->nextFiguredBass()) != 0) {
1359 : // retrieve the X position (in page coords) of a possible cont. line of nextFB
1360 : // on the same line of 'this'
1361 0 : PointF pgPos = item->pagePos();
1362 0 : double nextContPageX = nextFB->additionalContLineX(pgPos.y());
1363 : // if an additional cont. line has been found, extend up to its initial X coord
1364 0 : if (nextContPageX > 0) {
1365 0 : lineEndX = nextContPageX - pgPos.x() + FiguredBass::FB_CONTLINE_OVERLAP.toAbsolute(_spatium);
1366 : }
1367 : // with a little bit of overlap
1368 : else {
1369 0 : lineEndX = item->figuredBass()->ldata()->lineLength(0); // if none found, draw to the duration end
1370 : }
1371 : }
1372 : }
1373 : // if some line, draw it
1374 0 : if (lineEndX > 0.0) {
1375 0 : double h = ldata->bbox().height() * FiguredBass::FB_CONTLINE_HEIGHT;
1376 0 : painter->drawLine(lineStartX, h, lineEndX - ldata->pos().x(), h);
1377 : }
1378 : }
1379 :
1380 : // closing cont.line parenthesis
1381 0 : if (item->parenth5() != FiguredBassItem::Parenthesis::NONE) {
1382 0 : int x = lineEndX > 0.0 ? lineEndX : ldata->textWidth;
1383 0 : painter->drawText(RectF(x, 0, ldata->bbox().width(), ldata->bbox().height()),
1384 : muse::draw::AlignLeft | muse::draw::AlignTop,
1385 : muse::draw::TextDontClip,
1386 0 : Char(FiguredBass::FBFonts().at(font).displayParenthesis[int(item->parenth5())].unicode()));
1387 : }
1388 0 : }
1389 :
1390 0 : void TDraw::draw(const Fingering* item, Painter* painter, const PaintOptions& opt)
1391 : {
1392 : TRACE_DRAW_ITEM;
1393 0 : drawTextBase(item, painter, opt);
1394 0 : }
1395 :
1396 0 : void TDraw::draw(const FretDiagram* item, Painter* painter, const PaintOptions& opt)
1397 : {
1398 : TRACE_DRAW_ITEM;
1399 0 : const FretDiagram::LayoutData* ldata = item->ldata();
1400 0 : PointF translation = -PointF(ldata->stringDist * (item->strings() - 1), 0);
1401 0 : if (item->orientation() == Orientation::HORIZONTAL) {
1402 0 : painter->save();
1403 0 : painter->rotate(-90);
1404 0 : painter->translate(translation);
1405 : }
1406 :
1407 : // Init pen and other values
1408 0 : Pen pen(item->curColor(opt));
1409 0 : pen.setCapStyle(PenCapStyle::FlatCap);
1410 0 : painter->setBrush(Brush(Color(painter->pen().color())));
1411 :
1412 : // x2 is the x val of the rightmost string
1413 0 : double x2 = (item->strings() - 1) * ldata->stringDist;
1414 :
1415 : // Draw the nut
1416 0 : pen.setWidthF(ldata->nutLineWidth);
1417 0 : painter->setPen(pen);
1418 0 : double nutY = ldata->nutY;
1419 0 : painter->drawLine(LineF(-ldata->stringLineWidth * .5, nutY, x2 + ldata->stringLineWidth * .5, nutY));
1420 :
1421 : // Draw strings and frets
1422 0 : pen.setWidthF(ldata->stringLineWidth);
1423 0 : painter->setPen(pen);
1424 :
1425 : // y2 is the y val of the bottom fretline
1426 0 : double y1 = ldata->stringExtendTop;
1427 0 : double y2 = ldata->fretDist * item->frets() + 0.5 * ldata->stringLineWidth + ldata->stringExtendBottom;
1428 0 : for (int i = 0; i < item->strings(); ++i) {
1429 0 : double x = ldata->stringDist * i;
1430 0 : painter->drawLine(LineF(x, y1, x, y2));
1431 : }
1432 0 : for (int i = 1; i <= item->frets(); ++i) {
1433 0 : double y = ldata->fretDist * i;
1434 0 : painter->drawLine(LineF(0.0, y, x2, y));
1435 : }
1436 :
1437 : // dotd is the diameter of a dot
1438 0 : double dotd = ldata->dotDiameter;
1439 :
1440 : // Draw dots, sym pen is used to draw them (and markers)
1441 0 : Pen symPen(pen);
1442 0 : symPen.setCapStyle(PenCapStyle::FlatCap);
1443 : // Raise the miter limit so the triangle's apex isn't bevelled (needs ~2.24)
1444 0 : symPen.setJoinStyle(PenJoinStyle::MiterJoin);
1445 0 : symPen.setMiterLimit(3.0);
1446 0 : double symPenWidth = ldata->stringLineWidth * 1.2;
1447 0 : symPen.setWidthF(symPenWidth);
1448 :
1449 0 : for (auto const& i : item->dots()) {
1450 0 : for (auto const& d : i.second) {
1451 0 : if (!d.exists()) {
1452 0 : continue;
1453 : }
1454 :
1455 0 : int string = i.first;
1456 0 : int fret = d.fret - 1;
1457 :
1458 : // Calculate coords of the top left corner of the dot
1459 0 : double x = ldata->stringDist * string - dotd * .5;
1460 0 : double y = ldata->fretDist * fret + ldata->fretDist * .5 - dotd * .5;
1461 :
1462 : // Draw different symbols
1463 0 : painter->setPen(symPen);
1464 0 : switch (d.dtype) {
1465 0 : case FretDotType::CROSS:
1466 : // Give the cross a slightly larger width
1467 0 : symPen.setWidthF(symPenWidth * 1.5);
1468 0 : painter->setPen(symPen);
1469 0 : painter->drawLine(LineF(x, y, x + dotd, y + dotd));
1470 0 : painter->drawLine(LineF(x + dotd, y, x, y + dotd));
1471 0 : symPen.setWidthF(symPenWidth);
1472 0 : break;
1473 0 : case FretDotType::SQUARE:
1474 0 : painter->setBrush(BrushStyle::NoBrush);
1475 0 : painter->drawRect(RectF(x, y, dotd, dotd));
1476 0 : break;
1477 0 : case FretDotType::TRIANGLE:
1478 0 : painter->setBrush(BrushStyle::NoBrush);
1479 0 : painter->drawPolygon(PolygonF({ PointF(x, y + dotd), PointF(x + .5 * dotd, y), PointF(x + dotd, y + dotd) }));
1480 0 : break;
1481 0 : case FretDotType::NORMAL:
1482 : default:
1483 0 : painter->setBrush(symPen.color());
1484 0 : painter->setNoPen();
1485 0 : painter->drawEllipse(RectF(x, y, dotd, dotd));
1486 0 : break;
1487 : }
1488 : }
1489 : }
1490 :
1491 : // Draw markers
1492 0 : symPen.setWidthF(ldata->stringLineWidth * 1.2);
1493 0 : painter->setBrush(BrushStyle::NoBrush);
1494 0 : painter->setPen(symPen);
1495 0 : for (auto const& i : item->markers()) {
1496 0 : int string = i.first;
1497 0 : FretItem::Marker marker = i.second;
1498 0 : if (!marker.exists()) {
1499 0 : continue;
1500 : }
1501 :
1502 0 : double x = ldata->stringDist * string - ldata->markerSize * .5;
1503 0 : double y = ldata->markerY;
1504 0 : if (marker.mtype == FretMarkerType::CIRCLE) {
1505 0 : painter->drawEllipse(RectF(x, y, ldata->markerSize, ldata->markerSize));
1506 0 : } else if (marker.mtype == FretMarkerType::CROSS) {
1507 0 : painter->drawLine(PointF(x, y), PointF(x + ldata->markerSize, y + ldata->markerSize));
1508 0 : painter->drawLine(PointF(x, y + ldata->markerSize), PointF(x + ldata->markerSize, y));
1509 : }
1510 : }
1511 :
1512 : // Draw barres
1513 0 : for (auto const& i : item->barres()) {
1514 0 : int fret = i.first;
1515 0 : int startString = i.second.startString;
1516 0 : int endString = i.second.endString;
1517 :
1518 0 : double x1 = ldata->stringDist * startString;
1519 0 : double newX2 = endString == -1 ? x2 : ldata->stringDist * endString;
1520 0 : double y = ldata->fretDist * (fret - 1) + ldata->fretDist * .5;
1521 0 : if (item->style().styleB(Sid::barreAppearanceSlur)) {
1522 0 : pen.setWidthF(0.25 * ldata->stringLineWidth);
1523 0 : pen.setCapStyle(PenCapStyle::RoundCap);
1524 0 : pen.setJoinStyle(PenJoinStyle::RoundJoin);
1525 0 : painter->setPen(pen);
1526 0 : painter->setBrush(Brush(pen.color()));
1527 0 : for (const PainterPath& path : ldata->slurPaths) {
1528 0 : painter->drawPath(path);
1529 : }
1530 : } else {
1531 0 : pen.setWidthF(dotd * item->style().styleD(Sid::barreLineWidth));
1532 0 : pen.setCapStyle(PenCapStyle::RoundCap);
1533 0 : painter->setPen(pen);
1534 0 : painter->drawLine(LineF(x1, y, newX2, y));
1535 : }
1536 : }
1537 :
1538 : // Draw fret offset number
1539 0 : if (item->fretOffset() > 0) {
1540 0 : Font scaledFont(item->fretNumFont());
1541 0 : scaledFont.setPointSizeF(scaledFont.pointSizeF() * (item->spatium() / item->defaultSpatium()));
1542 0 : painter->setFont(scaledFont);
1543 0 : String text = ldata->fretText;
1544 :
1545 0 : if (item->orientation() == Orientation::VERTICAL) {
1546 0 : if (item->numPos() == 0) {
1547 0 : painter->drawText(RectF(-ldata->fretNumPadding, .0, .0, ldata->fretDist),
1548 : muse::draw::AlignVCenter | muse::draw::AlignRight,
1549 : muse::draw::TextDontClip,
1550 : text);
1551 : } else {
1552 0 : painter->drawText(RectF(x2 + ldata->fretNumPadding, .0, .0, ldata->fretDist),
1553 : muse::draw::AlignVCenter | muse::draw::AlignLeft,
1554 : muse::draw::TextDontClip,
1555 : text);
1556 : }
1557 0 : } else if (item->orientation() == Orientation::HORIZONTAL) {
1558 0 : painter->save();
1559 0 : painter->translate(-translation);
1560 0 : painter->rotate(90);
1561 0 : if (item->numPos() == 0) {
1562 0 : painter->drawText(RectF(.0, ldata->stringDist * (item->strings() - 1), .0, .0),
1563 : muse::draw::AlignLeft,
1564 : muse::draw::TextDontClip,
1565 : text);
1566 : } else {
1567 0 : painter->drawText(RectF(.0, .0, .0, .0),
1568 : muse::draw::AlignBottom | muse::draw::AlignLeft,
1569 : muse::draw::TextDontClip,
1570 : text);
1571 : }
1572 0 : painter->restore();
1573 : }
1574 0 : painter->setFont(item->fretNumFont());
1575 0 : }
1576 :
1577 0 : for (const FretDiagram::FingeringItem& fingeringItem : item->ldata()->fingeringItems) {
1578 0 : painter->save();
1579 :
1580 0 : Font scaledFont(item->fingeringFont());
1581 0 : scaledFont.setPointSizeF(scaledFont.pointSizeF() * (item->spatium() / item->defaultSpatium()));
1582 0 : painter->setFont(scaledFont);
1583 0 : if (item->orientation() == Orientation::HORIZONTAL) {
1584 0 : painter->translate(-translation);
1585 0 : painter->rotate(90);
1586 : }
1587 :
1588 0 : painter->drawText(fingeringItem.pos, fingeringItem.fingerNumber);
1589 :
1590 0 : painter->restore();
1591 0 : }
1592 :
1593 0 : if (item->orientation() == Orientation::HORIZONTAL) {
1594 0 : painter->restore();
1595 : }
1596 0 : }
1597 :
1598 0 : static void setDashAndGapLen(const SLine* line, double& dash, double& gap, Pen& pen)
1599 : {
1600 : static constexpr double DOTTED_DASH_LEN = 0.01;
1601 : static constexpr double DOTTED_GAP_LEN = 1.99;
1602 0 : switch (line->lineStyle()) {
1603 0 : case LineType::SOLID:
1604 0 : break;
1605 0 : case LineType::DASHED:
1606 0 : dash = line->dashLineLen(), gap = line->dashGapLen();
1607 0 : break;
1608 0 : case LineType::DOTTED:
1609 0 : dash = DOTTED_DASH_LEN, gap = DOTTED_GAP_LEN;
1610 0 : pen.setCapStyle(PenCapStyle::RoundCap); // round dots
1611 0 : break;
1612 : }
1613 0 : }
1614 :
1615 0 : static std::vector<double> distributedDashPattern(double dash, double gap, double lineLength)
1616 : {
1617 0 : int numPairs = std::max(1.0, lineLength / (dash + gap));
1618 0 : double newGap = (lineLength - dash * (numPairs + 1)) / numPairs;
1619 :
1620 0 : return { dash, newGap };
1621 : }
1622 :
1623 0 : void TDraw::draw(const GlissandoSegment* item, Painter* painter, const PaintOptions& opt)
1624 : {
1625 : TRACE_DRAW_ITEM;
1626 :
1627 0 : if (item->pos2().x() <= 0) {
1628 0 : return;
1629 : }
1630 :
1631 0 : painter->save();
1632 0 : double _spatium = item->spatium();
1633 0 : const Glissando* glissando = item->glissando();
1634 :
1635 0 : Pen pen(item->curColor(item->getProperty(Pid::VISIBLE).toBool(), item->getProperty(Pid::COLOR).value<Color>(), opt));
1636 0 : pen.setWidthF(item->absoluteFromSpatium(item->lineWidth()));
1637 0 : pen.setCapStyle(PenCapStyle::FlatCap);
1638 0 : painter->setPen(pen);
1639 :
1640 : // rotate painter so that the line become horizontal
1641 0 : double w = item->pos2().x();
1642 0 : double h = item->pos2().y();
1643 0 : double l = sqrt(w * w + h * h);
1644 0 : double wi = asin(-h / l) * 180.0 / M_PI;
1645 0 : painter->rotate(-wi);
1646 :
1647 0 : if (glissando->glissandoType() == GlissandoType::STRAIGHT) {
1648 0 : const bool isNonSolid = glissando->lineStyle() != LineType::SOLID;
1649 0 : if (isNonSolid) {
1650 0 : double lineWidth = glissando->absoluteFromSpatium(glissando->lineWidth());
1651 0 : double dash = 0;
1652 0 : double gap = 0;
1653 0 : setDashAndGapLen(glissando, dash, gap, pen);
1654 0 : pen.setDashPattern(distributedDashPattern(dash, gap, l / lineWidth));
1655 0 : painter->setPen(pen);
1656 : }
1657 :
1658 0 : painter->drawLine(LineF(0.0, 0.0, l, 0.0));
1659 0 : } else if (glissando->glissandoType() == GlissandoType::WAVY) {
1660 0 : RectF b = item->symBbox(SymId::wiggleGlissando);
1661 0 : double a = item->symAdvance(SymId::wiggleGlissando);
1662 0 : int n = static_cast<int>(l / a); // always round down (truncate) to avoid overlap
1663 0 : double x = (l - n * a) * 0.5; // centre line in available space
1664 0 : SymIdList ids;
1665 0 : for (int i = 0; i < n; ++i) {
1666 0 : ids.push_back(SymId::wiggleGlissando);
1667 : }
1668 :
1669 0 : item->score()->engravingFont()->draw(ids, painter, item->magS(), PointF(x, -(b.y() + b.height() * 0.5)));
1670 0 : }
1671 :
1672 0 : if (glissando->showText()) {
1673 0 : Font f(glissando->fontFace(), Font::Type::Unknown);
1674 0 : f.setPointSizeF(glissando->fontSize() * _spatium / item->defaultSpatium());
1675 0 : f.setBold(glissando->fontStyle() & FontStyle::Bold);
1676 0 : f.setItalic(glissando->fontStyle() & FontStyle::Italic);
1677 0 : f.setUnderline(glissando->fontStyle() & FontStyle::Underline);
1678 0 : f.setStrike(glissando->fontStyle() & FontStyle::Strike);
1679 0 : FontMetrics fm(f);
1680 0 : RectF r = fm.boundingRect(glissando->text());
1681 :
1682 : // if text longer than available space, skip it
1683 0 : if (r.width() < l) {
1684 0 : double x = (l - r.width()) * 0.5;
1685 0 : double yOffset = r.height() + r.y(); // find text descender height
1686 : // raise text slightly above line and slightly more with WAVY than with STRAIGHT
1687 0 : yOffset += _spatium * (glissando->glissandoType() == GlissandoType::WAVY ? 0.4 : 0.1);
1688 :
1689 0 : painter->setFont(f);
1690 0 : painter->drawText(PointF(x, -yOffset), glissando->text());
1691 : }
1692 0 : }
1693 0 : painter->restore();
1694 0 : }
1695 :
1696 0 : void TDraw::draw(const GuitarBendSegment* item, Painter* painter, const PaintOptions& opt)
1697 : {
1698 : TRACE_DRAW_ITEM;
1699 :
1700 0 : bool tabStaff = item->staff()->isTabStaff(item->tick());
1701 0 : GuitarBend* bend = item->guitarBend();
1702 :
1703 0 : Pen pen(item->curColor(opt));
1704 0 : if (bend->bendType() == GuitarBendType::SCOOP) {
1705 0 : painter->setPen(pen);
1706 0 : item->drawSymbol(SymId::guitarVibratoBarScoop, painter);
1707 0 : return;
1708 : }
1709 :
1710 0 : pen.setWidthF(item->lineWidth());
1711 0 : pen.setCapStyle(PenCapStyle::FlatCap);
1712 0 : pen.setJoinStyle(bend->bendType() == GuitarBendType::DIP ? PenJoinStyle::BevelJoin : PenJoinStyle::MiterJoin);
1713 0 : pen.setColor(item->curColor(opt));
1714 0 : if (tabStaff && bend->bendType() == GuitarBendType::PRE_DIVE) {
1715 0 : const PainterPath& path = item->ldata()->path();
1716 0 : if (path.elementCount() > 1) {
1717 0 : double lineLength = std::abs(item->ldata()->path().elementAt(1).y);
1718 0 : pen.setDashPattern(distributedDashPattern(3, 3, lineLength / pen.widthF()));
1719 : } else {
1720 0 : pen.setDashPattern({ 3, 3 });
1721 : }
1722 : }
1723 0 : painter->setPen(pen);
1724 :
1725 0 : Brush brush;
1726 0 : brush.setStyle(BrushStyle::NoBrush);
1727 0 : painter->setBrush(brush);
1728 :
1729 0 : painter->drawPath(item->ldata()->path());
1730 :
1731 0 : if (tabStaff) {
1732 0 : brush.setStyle(BrushStyle::SolidPattern);
1733 0 : brush.setColor(item->curColor(opt));
1734 0 : painter->setBrush(brush);
1735 0 : painter->setNoPen();
1736 0 : painter->drawPolygon(item->ldata()->arrow());
1737 : }
1738 0 : }
1739 :
1740 0 : void TDraw::draw(const GuitarBendHoldSegment* item, Painter* painter, const PaintOptions& opt)
1741 : {
1742 : TRACE_DRAW_ITEM;
1743 :
1744 0 : Pen pen(item->curColor(item->visible(), opt));
1745 0 : if (!item->ldata()->symIds().empty()) {
1746 0 : painter->setPen(pen);
1747 0 : item->drawSymbols(item->ldata()->symIds(), painter);
1748 0 : return;
1749 : }
1750 :
1751 0 : pen.setWidthF(item->lineWidth());
1752 0 : pen.setCapStyle(PenCapStyle::FlatCap);
1753 :
1754 0 : switch (item->getProperty(Pid::LINE_STYLE).value<LineType>()) {
1755 0 : case LineType::DASHED:
1756 : {
1757 0 : double dash = item->dashLength();
1758 0 : pen.setDashPattern(distributedDashPattern(dash, dash, item->pos2().x() / pen.widthF()));
1759 0 : break;
1760 : }
1761 0 : case LineType::DOTTED:
1762 0 : pen.setCapStyle(PenCapStyle::RoundCap); // True dots
1763 0 : pen.setDashPattern({ 0.01, 1.99 });
1764 0 : break;
1765 0 : default:
1766 0 : break;
1767 : }
1768 :
1769 0 : pen.setJoinStyle(PenJoinStyle::MiterJoin);
1770 0 : painter->setPen(pen);
1771 :
1772 0 : painter->drawLine(PointF(), item->pos2());
1773 0 : }
1774 :
1775 0 : void TDraw::drawTextBase(const TextBase* item, Painter* painter, const PaintOptions& opt)
1776 : {
1777 : TRACE_DRAW_ITEM;
1778 :
1779 0 : painter->save();
1780 0 : painter->rotate(item->textAngle());
1781 :
1782 0 : const TextBase::LayoutData* ldata = item->ldata();
1783 0 : if (item->hasFrame()) {
1784 0 : double baseSpatium = DefaultStyle::baseStyle().value(Sid::spatium).toReal();
1785 0 : if (!RealIsNull(item->frameWidth().val())) {
1786 0 : Color fColor = item->curColor(item->visible(), item->frameColor(), opt);
1787 0 : double frameWidthVal = item->frameWidth().val() * (item->sizeIsSpatiumDependent() ? item->spatium() : baseSpatium);
1788 :
1789 0 : Pen pen(fColor, frameWidthVal, PenStyle::SolidLine, PenCapStyle::SquareCap, PenJoinStyle::MiterJoin);
1790 0 : painter->setPen(pen);
1791 0 : } else {
1792 0 : painter->setNoPen();
1793 : }
1794 0 : Color bg(item->bgColor());
1795 0 : painter->setBrush(bg.alpha() ? Brush(bg) : BrushStyle::NoBrush);
1796 0 : if (item->circle()) {
1797 0 : painter->drawEllipse(ldata->frame);
1798 : } else {
1799 0 : double frameRadius = item->frameRound().val() * (item->sizeIsSpatiumDependent() ? item->spatium() : baseSpatium);
1800 0 : painter->drawRoundedRect(ldata->frame, frameRadius, frameRadius);
1801 : }
1802 : }
1803 0 : painter->setBrush(BrushStyle::NoBrush);
1804 0 : painter->setPen(item->textColor(opt));
1805 0 : for (const TextBlock& t : ldata->blocks) {
1806 0 : draw(t, item, painter);
1807 : }
1808 :
1809 0 : painter->restore();
1810 0 : }
1811 :
1812 0 : void TDraw::draw(const TextBlock& textBlock, const TextBase* item, Painter* painter)
1813 : {
1814 0 : painter->translate(0.0, textBlock.y());
1815 0 : for (const TextFragment& f : textBlock.fragments()) {
1816 0 : draw(f, item, painter);
1817 : }
1818 0 : painter->translate(0.0, -textBlock.y());
1819 0 : }
1820 :
1821 0 : void TDraw::draw(const TextFragment& textFragment, const TextBase* item, muse::draw::Painter* painter)
1822 : {
1823 0 : painter->setFont(textFragment.font(item));
1824 0 : painter->drawText(textFragment.pos, textFragment.text);
1825 0 : }
1826 :
1827 0 : void TDraw::drawTextLineBaseSegment(const TextLineBaseSegment* item, Painter* painter, const PaintOptions& opt)
1828 : {
1829 0 : const TextLineBase* tl = item->textLineBase();
1830 0 : const TextLineBaseSegment::LayoutData* ldata = item->ldata();
1831 :
1832 0 : if (!item->text()->empty()) {
1833 0 : painter->translate(item->text()->pos());
1834 0 : item->text()->setVisible(tl->visible());
1835 0 : draw(item->text(), painter, opt);
1836 0 : painter->translate(-item->text()->pos());
1837 : }
1838 :
1839 0 : if (!item->endText()->empty()) {
1840 0 : painter->translate(item->endText()->pos());
1841 0 : item->endText()->setVisible(tl->visible());
1842 0 : draw(item->endText(), painter, opt);
1843 0 : painter->translate(-item->endText()->pos());
1844 : }
1845 :
1846 0 : if (ldata->npoints == 0
1847 0 : || ((opt.isPrinting || (item->score() && !item->score()->isShowInvisible()))
1848 0 : && !tl->lineVisible())) {
1849 0 : return;
1850 : }
1851 :
1852 : // color for line (text color comes from the text properties)
1853 0 : Color color = item->curColor(tl->visible() && tl->lineVisible(), tl->lineColor(), opt);
1854 :
1855 0 : double lineWidth = tl->absoluteFromSpatium(tl->lineWidth());
1856 :
1857 0 : const Pen solidPen(color, lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap, PenJoinStyle::MiterJoin);
1858 0 : Pen pen(solidPen);
1859 :
1860 0 : double dash = 0;
1861 0 : double gap = 0;
1862 :
1863 0 : setDashAndGapLen(tl, dash, gap, pen);
1864 :
1865 0 : const bool isNonSolid = tl->lineStyle() != LineType::SOLID;
1866 :
1867 : // Draw lines
1868 0 : if (item->twoLines()) { // hairpins
1869 0 : if (isNonSolid) {
1870 0 : pen.setDashPattern({ dash, gap });
1871 : }
1872 :
1873 0 : pen.setJoinStyle(PenJoinStyle::BevelJoin);
1874 0 : painter->setPen(pen);
1875 0 : if (!ldata->joinedHairpin.empty() && !isNonSolid) {
1876 0 : painter->drawPolyline(ldata->joinedHairpin);
1877 : } else {
1878 0 : painter->drawLines(&ldata->points[0], 2);
1879 : }
1880 0 : return;
1881 : }
1882 :
1883 0 : int start = 0, end = ldata->npoints;
1884 :
1885 : // Draw begin hook, if it needs to be drawn separately
1886 0 : if (item->isSingleBeginType() && tl->beginHookType() != HookType::NONE) {
1887 0 : if (tl->beginHookType() == HookType::ARROW_FILLED) {
1888 0 : Brush brush;
1889 0 : brush.setStyle(BrushStyle::SolidPattern);
1890 0 : brush.setColor(color);
1891 0 : painter->setBrush(brush);
1892 0 : painter->setNoPen();
1893 0 : painter->drawPolygon(ldata->beginArrow);
1894 0 : } else if (tl->beginHookType() == HookType::ARROW) {
1895 0 : pen.setJoinStyle(PenJoinStyle::MiterJoin);
1896 0 : painter->setPen(pen);
1897 0 : painter->drawPolyline(ldata->beginArrow);
1898 : } else {
1899 0 : bool isTHook = tl->beginHookType() == HookType::HOOK_90T;
1900 :
1901 0 : if (isNonSolid || isTHook) {
1902 0 : const PointF& p1 = ldata->points[start++];
1903 0 : const PointF& p2 = ldata->points[start++];
1904 :
1905 0 : if (isTHook) {
1906 0 : painter->setPen(solidPen);
1907 : } else {
1908 0 : double hookLength = sqrt(PointF::dotProduct(p2 - p1, p2 - p1));
1909 0 : pen.setDashPattern(distributedDashPattern(dash, gap, hookLength / lineWidth));
1910 0 : painter->setPen(pen);
1911 : }
1912 :
1913 0 : painter->drawLine(p1, p2);
1914 : }
1915 : }
1916 : }
1917 :
1918 : // Draw end hook, if it needs to be drawn separately
1919 0 : if (item->isSingleEndType() && tl->endHookType() != HookType::NONE) {
1920 0 : if (tl->endHookType() == HookType::ARROW_FILLED) {
1921 0 : Brush brush;
1922 0 : brush.setStyle(BrushStyle::SolidPattern);
1923 0 : brush.setColor(color);
1924 0 : painter->setBrush(brush);
1925 0 : painter->setNoPen();
1926 0 : painter->drawPolygon(ldata->endArrow);
1927 0 : } else if (tl->endHookType() == HookType::ARROW) {
1928 0 : pen.setJoinStyle(PenJoinStyle::MiterJoin);
1929 0 : painter->setPen(pen);
1930 0 : painter->drawPolyline(ldata->endArrow);
1931 : } else {
1932 0 : bool isTHook = tl->endHookType() == HookType::HOOK_90T;
1933 :
1934 0 : if (isNonSolid || isTHook) {
1935 0 : const PointF& p1 = ldata->points[--end];
1936 0 : const PointF& p2 = ldata->points[--end];
1937 :
1938 0 : if (isTHook) {
1939 0 : painter->setPen(solidPen);
1940 : } else {
1941 0 : double hookLength = sqrt(PointF::dotProduct(p2 - p1, p2 - p1));
1942 0 : pen.setDashPattern(distributedDashPattern(dash, gap, hookLength / lineWidth));
1943 0 : painter->setPen(pen);
1944 : }
1945 :
1946 0 : painter->drawLine(p1, p2);
1947 : }
1948 : }
1949 : }
1950 :
1951 : // Draw the rest
1952 0 : if (isNonSolid) {
1953 0 : pen.setDashPattern(distributedDashPattern(dash, gap, ldata->lineLength / lineWidth));
1954 : }
1955 :
1956 0 : painter->setPen(pen);
1957 0 : painter->drawPolyline(&ldata->points[start], end - start);
1958 0 : }
1959 :
1960 0 : void TDraw::draw(const GradualTempoChangeSegment* item, Painter* painter, const PaintOptions& opt)
1961 : {
1962 : TRACE_DRAW_ITEM;
1963 0 : drawTextLineBaseSegment(item, painter, opt);
1964 0 : }
1965 :
1966 0 : void TDraw::draw(const HairpinSegment* item, Painter* painter, const PaintOptions& opt)
1967 : {
1968 : TRACE_DRAW_ITEM;
1969 :
1970 0 : drawTextLineBaseSegment(item, painter, opt);
1971 :
1972 0 : if (item->drawCircledTip()) {
1973 0 : Color color = item->curColor(item->hairpin()->visible(), item->hairpin()->lineColor(), opt);
1974 0 : double w = item->absoluteFromSpatium(item->lineWidth());
1975 0 : if (item->staff()) {
1976 0 : w *= item->staff()->staffMag(item->hairpin()->tick());
1977 : }
1978 :
1979 0 : Pen pen(color, w);
1980 0 : painter->setPen(pen);
1981 0 : painter->setBrush(BrushStyle::NoBrush);
1982 0 : painter->drawEllipse(item->circledTip(), item->circledTipRadius(), item->circledTipRadius());
1983 0 : }
1984 0 : }
1985 :
1986 0 : void TDraw::draw(const HammerOnPullOffSegment* item, muse::draw::Painter* painter, const PaintOptions& opt)
1987 : {
1988 0 : draw(toSlurSegment(item), painter, opt);
1989 0 : }
1990 :
1991 0 : void TDraw::draw(const HammerOnPullOffText* item, muse::draw::Painter* painter, const PaintOptions& opt)
1992 : {
1993 : TRACE_DRAW_ITEM;
1994 0 : drawTextBase(item, painter, opt);
1995 0 : }
1996 :
1997 0 : void TDraw::draw(const HarpPedalDiagram* item, Painter* painter, const PaintOptions& opt)
1998 : {
1999 : TRACE_DRAW_ITEM;
2000 0 : drawTextBase(item, painter, opt);
2001 0 : }
2002 :
2003 0 : void TDraw::draw(const HarmonicMarkSegment* item, Painter* painter, const PaintOptions& opt)
2004 : {
2005 : TRACE_DRAW_ITEM;
2006 0 : drawTextLineBaseSegment(item, painter, opt);
2007 0 : }
2008 :
2009 0 : void TDraw::draw(const Harmony* item, Painter* painter, const PaintOptions& opt)
2010 : {
2011 : TRACE_DRAW_ITEM;
2012 :
2013 0 : const Harmony::LayoutData* ldata = item->ldata();
2014 :
2015 0 : if (ldata->renderItemList().empty()) {
2016 0 : drawTextBase(item, painter, opt);
2017 0 : return;
2018 : }
2019 :
2020 0 : if (item->hasFrame()) {
2021 0 : if (!RealIsNull(item->frameWidth().val())) {
2022 0 : Color color = item->frameColor();
2023 0 : Pen pen(color, item->frameWidth().val() * item->spatium(), PenStyle::SolidLine,
2024 0 : PenCapStyle::SquareCap, PenJoinStyle::MiterJoin);
2025 0 : painter->setPen(pen);
2026 0 : } else {
2027 0 : painter->setNoPen();
2028 : }
2029 0 : Color bg(item->bgColor());
2030 0 : painter->setBrush(bg.alpha() ? Brush(bg) : BrushStyle::NoBrush);
2031 0 : if (item->circle()) {
2032 0 : painter->drawArc(ldata->frame, 0, 5760);
2033 : } else {
2034 0 : double baseSpatium = DefaultStyle::baseStyle().value(Sid::spatium).toReal();
2035 0 : double frameRadius = item->frameRound().val() * (item->sizeIsSpatiumDependent() ? item->spatium() : baseSpatium);
2036 0 : painter->drawRoundedRect(ldata->frame, frameRadius, frameRadius);
2037 : }
2038 : }
2039 0 : painter->setBrush(BrushStyle::NoBrush);
2040 0 : Color color = item->textColor(opt);
2041 0 : painter->setPen(color);
2042 0 : for (const HarmonyRenderItem* renderItem : ldata->renderItemList()) {
2043 0 : if (const TextSegment* ts = dynamic_cast<const TextSegment*>(renderItem)) {
2044 0 : painter->setFont(ts->font());
2045 0 : painter->drawText(ts->pos(), ts->text());
2046 0 : } else if (const ChordSymbolParen* parenItem = dynamic_cast<const ChordSymbolParen*>(renderItem)) {
2047 0 : Parenthesis* p = parenItem->parenItem;
2048 0 : painter->translate(parenItem->pos());
2049 0 : draw(p, painter, opt);
2050 0 : painter->translate(-parenItem->pos());
2051 : }
2052 : }
2053 :
2054 0 : if (item->isPolychord()) {
2055 0 : Pen pen(painter->pen());
2056 0 : pen.setWidthF(item->absoluteFromSpatium(item->style().styleS(Sid::polychordDividerThickness)));
2057 0 : pen.setColor(color);
2058 0 : painter->setPen(pen);
2059 0 : for (const LineF& line : ldata->polychordDividerLines()) {
2060 0 : painter->drawLine(line.translated(PointF(0.0, ldata->polychordDividerOffset)));
2061 : }
2062 0 : }
2063 : }
2064 :
2065 0 : void TDraw::draw(const Hook* item, Painter* painter, const PaintOptions& opt)
2066 : {
2067 : TRACE_DRAW_ITEM;
2068 : // hide if belonging to the second chord of a cross-measure pair
2069 0 : if (item->chord() && item->chord()->crossMeasure() == CrossMeasure::SECOND) {
2070 0 : return;
2071 : }
2072 :
2073 0 : painter->setPen(item->curColor(opt));
2074 0 : item->drawSymbol(item->sym(), painter);
2075 : }
2076 :
2077 0 : void TDraw::draw(const Image* item, Painter* painter, const PaintOptions& opt)
2078 : {
2079 : TRACE_DRAW_ITEM;
2080 0 : const Image::LayoutData* ldata = item->ldata();
2081 0 : bool emptyImage = false;
2082 0 : if (item->imageType() == ImageType::SVG) {
2083 0 : if (!item->svgRenderer()) {
2084 0 : emptyImage = true;
2085 : } else {
2086 0 : item->svgRenderer()->render(painter, ldata->bbox());
2087 : }
2088 0 : } else if (item->imageType() == ImageType::RASTER) {
2089 0 : if (item->rasterImage() == nullptr) {
2090 0 : emptyImage = true;
2091 : } else {
2092 0 : painter->save();
2093 0 : SizeF s;
2094 0 : if (item->sizeIsSpatium()) {
2095 0 : s = item->size() * item->spatium();
2096 : } else {
2097 0 : s = item->size() * DPMM;
2098 : }
2099 0 : painter->scale(s.width() / item->rasterImage()->width(), s.height() / item->rasterImage()->height());
2100 0 : painter->drawPixmap(PointF(0, 0), *item->rasterImage());
2101 0 : painter->restore();
2102 : }
2103 : }
2104 :
2105 0 : if (emptyImage) {
2106 0 : painter->setBrush(BrushStyle::NoBrush);
2107 0 : painter->setPen(item->configuration()->defaultColor());
2108 0 : painter->drawRect(ldata->bbox());
2109 0 : painter->drawLine(0.0, 0.0, ldata->bbox().width(), ldata->bbox().height());
2110 0 : painter->drawLine(ldata->bbox().width(), 0.0, 0.0, ldata->bbox().height());
2111 : }
2112 0 : if (item->selected() && !opt.isPrinting) {
2113 0 : painter->setBrush(BrushStyle::NoBrush);
2114 0 : painter->setPen(item->configuration()->selectionColor());
2115 0 : painter->drawRect(ldata->bbox());
2116 : }
2117 0 : }
2118 :
2119 0 : void TDraw::draw(const InstrumentChange* item, Painter* painter, const PaintOptions& opt)
2120 : {
2121 : TRACE_DRAW_ITEM;
2122 0 : drawTextBase(item, painter, opt);
2123 0 : }
2124 :
2125 0 : void TDraw::draw(const InstrumentName* item, Painter* painter, const PaintOptions& opt)
2126 : {
2127 : TRACE_DRAW_ITEM;
2128 0 : drawTextBase(item, painter, opt);
2129 0 : }
2130 :
2131 0 : void TDraw::draw(const Jump* item, Painter* painter, const PaintOptions& opt)
2132 : {
2133 : TRACE_DRAW_ITEM;
2134 0 : drawTextBase(item, painter, opt);
2135 0 : }
2136 :
2137 0 : void TDraw::draw(const KeySig* item, Painter* painter, const PaintOptions& opt)
2138 : {
2139 : TRACE_DRAW_ITEM;
2140 0 : const KeySig::LayoutData* ldata = item->ldata();
2141 :
2142 0 : painter->setPen(item->curColor(opt));
2143 :
2144 0 : if (item->staff() && item->staff()->isJianpuStaff(item->tick())) {
2145 0 : if (ldata->jianpuLabel.isEmpty()) {
2146 0 : return;
2147 : }
2148 0 : const StaffType* staffType = item->staff()->staffTypeForElement(item);
2149 0 : Font f(staffType->jianpuFont());
2150 0 : f.setPointSizeF(f.pointSizeF() * item->mag());
2151 0 : painter->setFont(f);
2152 0 : painter->drawText(PointF(ldata->bbox().x(), ldata->bbox().bottom()), ldata->jianpuLabel);
2153 0 : return;
2154 0 : }
2155 :
2156 0 : double _spatium = item->spatium();
2157 0 : double step = _spatium * (item->staff() ? item->staff()->staffTypeForElement(item)->lineDistance().val() * 0.5 : 0.5);
2158 0 : int lines = item->staff() ? item->staff()->staffTypeForElement(item)->lines() : 5;
2159 0 : double ledgerLineWidth = item->style().styleAbsolute(Sid::ledgerLineWidth) * item->mag();
2160 0 : double ledgerExtraLen = item->style().styleS(Sid::ledgerLineLength).val() * _spatium;
2161 0 : for (const KeySym& ks : ldata->keySymbols) {
2162 0 : double x = ks.xPos.toAbsolute(_spatium);
2163 0 : double y = ks.line * step;
2164 0 : item->drawSymbol(ks.sym, painter, PointF(x, y));
2165 : // ledger lines
2166 0 : double _symWidth = item->symWidth(ks.sym);
2167 0 : double x1 = x - ledgerExtraLen;
2168 0 : double x2 = x + _symWidth + ledgerExtraLen;
2169 0 : painter->setPen(Pen(item->curColor(opt), ledgerLineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
2170 0 : for (int i = -2; i >= ks.line; i -= 2) { // above
2171 0 : y = i * step;
2172 0 : painter->drawLine(LineF(x1, y, x2, y));
2173 : }
2174 0 : for (int i = lines * 2; i <= ks.line; i += 2) { // below
2175 0 : y = i * step;
2176 0 : painter->drawLine(LineF(x1, y, x2, y));
2177 : }
2178 : }
2179 : }
2180 :
2181 0 : void TDraw::draw(const LaissezVibSegment* item, muse::draw::Painter* painter, const PaintOptions& opt)
2182 : {
2183 0 : const LaissezVibSegment::LayoutData* ldata = item->ldata();
2184 0 : if (item->score()->style().styleB(Sid::laissezVibUseSmuflSym)) {
2185 0 : painter->setPen(item->curColor(opt));
2186 0 : item->drawSymbol(ldata->symbol, painter);
2187 : } else {
2188 0 : draw(static_cast<const TieSegment*>(item), painter, opt);
2189 : }
2190 0 : }
2191 :
2192 0 : void TDraw::draw(const Lasso* item, Painter* painter, const PaintOptions&)
2193 : {
2194 : TRACE_DRAW_ITEM;
2195 0 : const Lasso::LayoutData* ldata = item->ldata();
2196 0 : painter->setBrush(Brush(item->configuration()->lassoColor()));
2197 : // always 2 pixel width
2198 0 : double w = 2.0 / painter->worldTransform().m11() * item->contextConfiguration()->guiScaling();
2199 0 : painter->setPen(Pen(item->configuration()->selectionColor(), w));
2200 0 : painter->drawRect(ldata->bbox());
2201 0 : }
2202 :
2203 0 : void TDraw::draw(const LayoutBreak* item, Painter* painter, const PaintOptions& opt)
2204 : {
2205 : TRACE_DRAW_ITEM;
2206 :
2207 0 : if (opt.isPrinting || !item->score()->showUnprintable()) {
2208 0 : return;
2209 : }
2210 :
2211 0 : Color selectionColor = opt.invertColors ? item->configuration()->indicatorIconInvertedSelectionColor()
2212 0 : : item->configuration()->selectionColor();
2213 0 : Color color = item->selected() ? selectionColor : item->configuration()->formattingColor();
2214 0 : Pen pen(color);
2215 0 : painter->setPen(pen);
2216 0 : painter->setFont(item->font());
2217 0 : painter->drawSymbol(PointF(), item->iconCode());
2218 0 : }
2219 :
2220 24 : void TDraw::draw(const LedgerLine* item, Painter* painter, const PaintOptions& opt)
2221 : {
2222 : TRACE_DRAW_ITEM;
2223 :
2224 24 : if (item->chord()->crossMeasure() == CrossMeasure::SECOND) {
2225 0 : return;
2226 : }
2227 :
2228 24 : const LedgerLine::LayoutData* ldata = item->ldata();
2229 :
2230 24 : painter->setPen(Pen(item->curColor(opt), ldata->lineWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
2231 24 : if (item->vertical()) {
2232 0 : painter->drawLine(LineF(0.0, 0.0, 0.0, item->len()));
2233 : } else {
2234 24 : painter->drawLine(LineF(0.0, 0.0, item->len(), 0.0));
2235 : }
2236 : }
2237 :
2238 0 : void TDraw::draw(const LetRingSegment* item, Painter* painter, const PaintOptions& opt)
2239 : {
2240 : TRACE_DRAW_ITEM;
2241 0 : drawTextLineBaseSegment(item, painter, opt);
2242 0 : }
2243 :
2244 0 : void TDraw::draw(const Lyrics* item, Painter* painter, const PaintOptions& opt)
2245 : {
2246 : TRACE_DRAW_ITEM;
2247 0 : drawTextBase(item, painter, opt);
2248 0 : }
2249 :
2250 0 : void TDraw::draw(const LyricsLineSegment* item, Painter* painter, const PaintOptions& opt)
2251 : {
2252 : TRACE_DRAW_ITEM;
2253 :
2254 0 : Pen pen(item->curColor(opt));
2255 0 : pen.setWidthF(item->absoluteFromSpatium(item->lineWidth()));
2256 0 : pen.setCapStyle(PenCapStyle::FlatCap);
2257 0 : painter->setPen(pen);
2258 0 : for (const LineF& dash : item->ldata()->dashes()) {
2259 0 : painter->drawLine(dash);
2260 : }
2261 0 : }
2262 :
2263 0 : void TDraw::draw(const Marker* item, Painter* painter, const PaintOptions& opt)
2264 : {
2265 : TRACE_DRAW_ITEM;
2266 0 : drawTextBase(item, painter, opt);
2267 0 : }
2268 :
2269 0 : void TDraw::draw(const MeasureNumber* item, Painter* painter, const PaintOptions& opt)
2270 : {
2271 : TRACE_DRAW_ITEM;
2272 0 : drawTextBase(item, painter, opt);
2273 0 : }
2274 :
2275 0 : void TDraw::draw(const MeasureRepeat* item, Painter* painter, const PaintOptions& opt)
2276 : {
2277 : TRACE_DRAW_ITEM;
2278 :
2279 0 : const MeasureRepeat::LayoutData* ldata = item->ldata();
2280 :
2281 0 : painter->setPen(item->curColor(opt));
2282 0 : item->drawSymbol(ldata->symId, painter);
2283 :
2284 0 : if (!ldata->numberSym.empty()) {
2285 0 : PointF numberPos = item->numberPosition(item->symBbox(ldata->numberSym));
2286 0 : item->drawSymbols(ldata->numberSym, painter, numberPos);
2287 : }
2288 :
2289 0 : if (item->style().styleB(Sid::fourMeasureRepeatShowExtenders) && item->numMeasures() == 4) {
2290 0 : double hBarThickness = item->style().styleAbsolute(Sid::mmRestHBarThickness);
2291 0 : Pen pen(painter->pen());
2292 0 : pen.setCapStyle(PenCapStyle::FlatCap);
2293 0 : pen.setWidthF(hBarThickness);
2294 0 : painter->setPen(pen);
2295 :
2296 0 : painter->drawLine(ldata->extenderLineLeft);
2297 0 : painter->drawLine(ldata->extenderLineRight);
2298 0 : }
2299 0 : }
2300 :
2301 0 : void TDraw::draw(const MMRest* item, Painter* painter, const PaintOptions& opt)
2302 : {
2303 : TRACE_DRAW_ITEM;
2304 0 : if (item->shouldNotBeDrawn() || (item->track() % VOICES)) { //only on voice 1
2305 0 : return;
2306 : }
2307 :
2308 0 : const MMRest::LayoutData* ldata = item->ldata();
2309 :
2310 0 : double _spatium = item->spatium();
2311 :
2312 : // draw number
2313 0 : painter->setPen(item->curColor(opt));
2314 0 : RectF numberBox = item->symBbox(ldata->numberSym);
2315 0 : PointF numberPos = item->numberPos();
2316 0 : if (item->showNumber()) {
2317 0 : item->drawSymbols(ldata->numberSym, painter, numberPos);
2318 : }
2319 :
2320 0 : numberBox.translate(numberPos);
2321 :
2322 0 : if (item->isOldStyle()) {
2323 : // draw rest symbols
2324 0 : double x = (ldata->restWidth - ldata->symsWidth) * 0.5;
2325 0 : double spacing = item->style().styleAbsolute(Sid::mmRestOldStyleSpacing);
2326 0 : for (SymId sym : ldata->restSyms) {
2327 0 : double y = (sym == SymId::restWhole ? -_spatium : 0);
2328 0 : item->drawSymbol(sym, painter, PointF(x, y));
2329 0 : x += item->symBbox(sym).width() + spacing;
2330 : }
2331 : } else {
2332 0 : double mag = item->staff()->staffMag(item->tick());
2333 0 : Pen pen(painter->pen());
2334 0 : pen.setCapStyle(PenCapStyle::FlatCap);
2335 :
2336 : // draw horizontal line
2337 0 : double hBarThickness = item->style().styleAbsolute(Sid::mmRestHBarThickness) * mag;
2338 0 : if (hBarThickness) { // don't draw at all if 0, QPainter interprets 0 pen width differently
2339 0 : pen.setWidthF(hBarThickness);
2340 0 : painter->setPen(pen);
2341 0 : double halfHBarThickness = hBarThickness * .5;
2342 0 : if (item->showNumber() // avoid painting line through number
2343 0 : && item->style().styleB(Sid::mmRestNumberMaskHBar)
2344 0 : && numberBox.bottom() >= -halfHBarThickness
2345 0 : && numberBox.top() <= halfHBarThickness) {
2346 0 : double gapDistance = (numberBox.width() + _spatium) * .5;
2347 0 : double midpoint = ldata->restWidth * .5;
2348 0 : painter->drawLine(LineF(0.0, 0.0, midpoint - gapDistance, 0.0));
2349 0 : painter->drawLine(LineF(midpoint + gapDistance, 0.0, ldata->restWidth, 0.0));
2350 : } else {
2351 0 : painter->drawLine(LineF(0.0, 0.0, ldata->restWidth, 0.0));
2352 : }
2353 : }
2354 :
2355 : // draw vertical lines
2356 0 : double vStrokeThickness = item->style().styleAbsolute(Sid::mmRestHBarVStrokeThickness) * mag;
2357 0 : if (vStrokeThickness) { // don't draw at all if 0, QPainter interprets 0 pen width differently
2358 0 : pen.setWidthF(vStrokeThickness);
2359 0 : painter->setPen(pen);
2360 0 : double halfVStrokeHeight = item->style().styleAbsolute(Sid::mmRestHBarVStrokeHeight) * .5 * mag;
2361 0 : painter->drawLine(LineF(0.0, -halfVStrokeHeight, 0.0, halfVStrokeHeight));
2362 0 : painter->drawLine(LineF(ldata->restWidth, -halfVStrokeHeight, ldata->restWidth, halfVStrokeHeight));
2363 : }
2364 0 : }
2365 : }
2366 :
2367 0 : void TDraw::draw(const MMRestRange* item, Painter* painter, const PaintOptions& opt)
2368 : {
2369 : TRACE_DRAW_ITEM;
2370 0 : drawTextBase(item, painter, opt);
2371 0 : }
2372 :
2373 : //---------------------------------------------------------
2374 : // drawJianpuAccidental
2375 : // Draws a Jianpu accidental mark smaller and above-left of the digit,
2376 : // without shifting the digit itself (which stays aligned with beams/dots).
2377 : //---------------------------------------------------------
2378 :
2379 0 : static void drawJianpuAccidental(Painter* painter, const Font& digitFont, const FontMetrics& digitFm, const String& accidental,
2380 : double digitStartX, double baselineY)
2381 : {
2382 0 : if (accidental.isEmpty()) {
2383 0 : return;
2384 : }
2385 :
2386 : static constexpr double JIANPU_ACCIDENTAL_MAG = 0.7;
2387 0 : Font accFont(digitFont);
2388 0 : accFont.setPointSizeF(digitFont.pointSizeF() * JIANPU_ACCIDENTAL_MAG);
2389 0 : painter->setFont(accFont);
2390 :
2391 0 : FontMetrics accFm(accFont);
2392 0 : const double gap = accFont.pointSizeF() * 0.1;
2393 0 : const double accX = digitStartX - accFm.width(accidental) - gap;
2394 0 : const double accY = baselineY - digitFm.ascent() * 0.5;
2395 0 : painter->drawText(PointF(accX, accY), accidental);
2396 :
2397 0 : painter->setFont(digitFont);
2398 0 : }
2399 :
2400 127 : void TDraw::draw(const Note* item, Painter* painter, const PaintOptions& opt)
2401 : {
2402 : TRACE_DRAW_ITEM;
2403 127 : if (item->hidden()) {
2404 0 : return;
2405 : }
2406 :
2407 127 : const Note::LayoutData* ldata = item->ldata();
2408 :
2409 127 : const auto config = item->configuration();
2410 127 : const StaffType* staffType = item->staff() ? item->staff()->staffTypeForElement(item) : nullptr;
2411 :
2412 127 : const bool isTabStaff = staffType && staffType->isTabStaff();
2413 127 : const bool negativeFret = isTabStaff && item->negativeFretUsed();
2414 127 : const bool useCriticalColor = negativeFret && !item->deadNote() && !opt.isPrinting;
2415 :
2416 127 : painter->setPen(useCriticalColor ? config->criticalColor() : item->curColor(opt));
2417 :
2418 : // tablature
2419 127 : if (isTabStaff) {
2420 0 : if (item->displayFret() == Note::DisplayFretOption::Hide || item->shouldHideFret()) {
2421 0 : return;
2422 : }
2423 0 : const Staff* st = item->staff();
2424 0 : const StaffType* tab = st->staffTypeForElement(item);
2425 :
2426 0 : if (!opt.isPrinting && item->score()->showUnprintable() && (negativeFret || item->fretConflict())) { // fret conflict
2427 0 : painter->save();
2428 0 : painter->setPen(config->criticalColor());
2429 0 : painter->setBrush(config->criticalBackgroundColor());
2430 0 : painter->drawRect(ldata->bbox());
2431 0 : painter->restore();
2432 : }
2433 :
2434 0 : Font f(tab->fretFont());
2435 0 : f.setPointSizeF(f.pointSizeF() * item->magS());
2436 0 : painter->setFont(f);
2437 :
2438 0 : const double startPosX = ldata->bbox().x();
2439 0 : const double yOffset = tab->fretFontYOffset();
2440 0 : painter->drawText(PointF(startPosX, yOffset * item->magS()), item->fretString());
2441 0 : }
2442 : // Jianpu
2443 127 : else if (staffType && item->onJianpuStaff()) {
2444 0 : Font f(staffType->jianpuFont());
2445 0 : f.setPointSizeF(f.pointSizeF() * item->magS());
2446 0 : painter->setFont(f);
2447 :
2448 0 : FontMetrics fm(f);
2449 0 : const double fw = fm.width(item->jianpuDigit());
2450 0 : const double bw = ldata->bbox().width();
2451 0 : const double startPosX = ldata->bbox().x() + (bw - fw) * .5;
2452 0 : const double startPosY = ldata->bbox().bottom();
2453 0 : drawJianpuAccidental(painter, f, fm, item->jianpuAccidental(), startPosX, startPosY);
2454 0 : painter->drawText(PointF(startPosX, startPosY), item->jianpuDigit());
2455 0 : } else {
2456 : // skip drawing, if second note of a cross-measure value
2457 127 : if (item->chord() && item->chord()->crossMeasure() == CrossMeasure::SECOND) {
2458 0 : return;
2459 : }
2460 : // warn if pitch extends usable range of instrument
2461 : // by coloring the notehead
2462 254 : if (item->chord() && item->chord()->segment() && item->staff() && !opt.isPrinting
2463 254 : && MScore::warnPitchRange && !item->staff()->isDrumStaff(item->chord()->tick())) {
2464 0 : const Instrument* in = item->originPart()->instrument(item->chord()->tick());
2465 0 : int i = item->ppitch();
2466 0 : if (i < in->minPitchP() || i > in->maxPitchP()) {
2467 0 : painter->setPen(item->selected() ? config->criticalSelectedColor() : config->criticalColor());
2468 0 : } else if (i < in->minPitchA() || i > in->maxPitchA()) {
2469 0 : painter->setPen(item->selected() ? config->warningSelectedColor() : config->warningColor());
2470 : }
2471 : }
2472 : // Warn if notes are unplayable based on previous harp diagram setting
2473 254 : if (item->chord() && item->chord()->segment() && item->staff() && !opt.isPrinting
2474 254 : && !item->staff()->isDrumStaff(item->chord()->tick())) {
2475 0 : HarpPedalDiagram* prevDiagram = item->originPart()->currentHarpDiagram(item->chord()->segment()->tick());
2476 0 : if (prevDiagram && !prevDiagram->isTpcPlayable(item->tpc())) {
2477 0 : painter->setPen(item->selected() ? config->criticalSelectedColor() : config->criticalColor());
2478 : }
2479 : }
2480 : // draw blank notehead to avoid staff and ledger lines
2481 127 : if (ldata->cachedSymNull.value() != SymId::noSym) {
2482 0 : painter->save();
2483 0 : painter->setPen(config->noteBackgroundColor());
2484 0 : item->drawSymbol(ldata->cachedSymNull.value(), painter);
2485 0 : painter->restore();
2486 : }
2487 127 : item->drawSymbol(ldata->cachedNoteheadSym.value(), painter);
2488 : }
2489 127 : }
2490 :
2491 0 : void TDraw::draw(const NoteDot* item, Painter* painter, const PaintOptions& opt)
2492 : {
2493 : TRACE_DRAW_ITEM;
2494 0 : if (item->note() && item->note()->dotsHidden()) { // don't draw dot if note is hidden
2495 0 : return;
2496 0 : } else if (item->rest() && item->rest()->isGap()) { // don't draw dot for gap rests
2497 0 : return;
2498 : }
2499 0 : const Note* n = item->note();
2500 0 : Fraction tick = n ? n->chord()->tick() : item->rest()->tick();
2501 : // always draw dot for non-tab
2502 : // for tab, draw if on a note and stems through staff or on a rest and rests shown
2503 0 : if (!item->staff()->isTabStaff(tick)
2504 0 : || (n && item->staff()->staffType(tick)->stemThrough())
2505 0 : || (!n && item->staff()->staffType(tick)->showRests())) {
2506 0 : painter->setPen(item->curColor(opt));
2507 0 : item->drawSymbol(SymId::augmentationDot, painter);
2508 : }
2509 : }
2510 :
2511 0 : void TDraw::draw(const NoteHead* item, Painter* painter, const PaintOptions& opt)
2512 : {
2513 0 : draw(static_cast<const Symbol*>(item), painter, opt);
2514 0 : }
2515 :
2516 0 : void TDraw::draw(const NoteLineSegment* item, Painter* painter, const PaintOptions& opt)
2517 : {
2518 : TRACE_DRAW_ITEM;
2519 0 : drawTextLineBaseSegment(item, painter, opt);
2520 0 : }
2521 :
2522 0 : void TDraw::draw(const JianpuOctaveDot* item, Painter* painter, const PaintOptions& opt)
2523 : {
2524 : TRACE_DRAW_ITEM;
2525 :
2526 0 : const JianpuOctaveDot::LayoutData* ldata = item->ldata();
2527 0 : IF_ASSERT_FAILED(ldata) {
2528 0 : return;
2529 : }
2530 :
2531 0 : double rad = ldata->radius;
2532 0 : double x = ldata->len * 0.5; // draw dot in the middle
2533 :
2534 0 : painter->setPen(Pen(item->curColor(opt)));
2535 0 : painter->setBrush(Brush(item->curColor(opt)));
2536 0 : painter->drawEllipse(PointF(x, 0), rad, rad);
2537 : }
2538 :
2539 0 : void TDraw::draw(const OttavaSegment* item, Painter* painter, const PaintOptions& opt)
2540 : {
2541 : TRACE_DRAW_ITEM;
2542 0 : drawTextLineBaseSegment(item, painter, opt);
2543 0 : }
2544 :
2545 0 : void TDraw::draw(const PageLockIndicator* item, Painter* painter, const PaintOptions& opt)
2546 : {
2547 : TRACE_DRAW_ITEM;
2548 :
2549 0 : if (opt.isPrinting || !item->score()->showUnprintable()) {
2550 0 : return;
2551 : }
2552 :
2553 0 : Color selectionColor = opt.invertColors ? item->configuration()->indicatorIconInvertedSelectionColor()
2554 0 : : item->configuration()->selectionColor();
2555 0 : Color color = item->selected() ? selectionColor : item->configuration()->formattingColor();
2556 0 : Pen pen(color);
2557 0 : painter->setPen(pen);
2558 0 : painter->setFont(item->font());
2559 0 : painter->drawSymbol(PointF(), item->iconCode());
2560 :
2561 0 : if (item->selected()) {
2562 0 : Color lockedAreaColor = selectionColor;
2563 0 : lockedAreaColor.setAlpha(opt.invertColors ? 90 : 38);
2564 0 : Brush brush(lockedAreaColor);
2565 0 : painter->setBrush(brush);
2566 0 : painter->setNoPen();
2567 0 : double radius = 0.5 * item->spatium();
2568 :
2569 0 : PainterPath path;
2570 0 : path.setFillRule(PainterPath::FillRule::OddEvenFill);
2571 0 : path.addRoundedRect(item->ldata()->rangeRect, radius, radius);
2572 0 : path.addRect(item->ldata()->innerRangeRect);
2573 0 : painter->drawPath(path);
2574 0 : }
2575 0 : }
2576 :
2577 0 : void TDraw::draw(const Parenthesis* item, muse::draw::Painter* painter, const PaintOptions& opt)
2578 : {
2579 : TRACE_DRAW_ITEM;
2580 :
2581 0 : EngravingObject* parent = item->ownershipParent();
2582 0 : TimeSig* parentTs = parent && parent->isTimeSig() ? toTimeSig(parent) : nullptr;
2583 :
2584 0 : if (parentTs && !parentTs->showOnThisStaff()) {
2585 0 : return;
2586 : }
2587 :
2588 0 : Color penColor = item->curColor(opt);
2589 :
2590 0 : Pen pen(penColor);
2591 :
2592 0 : if (item->ldata()->symId != SymId::noSym) {
2593 0 : painter->setPen(pen);
2594 0 : item->drawSymbol(item->ldata()->symId, painter, PointF(), item->ldata()->symScale);
2595 0 : return;
2596 : }
2597 :
2598 0 : painter->setBrush(Brush(pen.color()));
2599 0 : pen.setCapStyle(PenCapStyle::RoundCap);
2600 0 : pen.setJoinStyle(PenJoinStyle::RoundJoin);
2601 0 : pen.setWidthF(item->ldata()->endPointThickness * item->spatium() * item->ldata()->intrinsicMag());
2602 :
2603 0 : painter->setPen(pen);
2604 0 : painter->drawPath(item->ldata()->path());
2605 0 : }
2606 :
2607 0 : void TDraw::draw(const PartialTieSegment* item, muse::draw::Painter* painter, const PaintOptions& opt)
2608 : {
2609 0 : draw(static_cast<const TieSegment*>(item), painter, opt);
2610 0 : }
2611 :
2612 0 : void TDraw::draw(const PalmMuteSegment* item, Painter* painter, const PaintOptions& opt)
2613 : {
2614 : TRACE_DRAW_ITEM;
2615 0 : drawTextLineBaseSegment(item, painter, opt);
2616 0 : }
2617 :
2618 0 : void TDraw::draw(const PedalSegment* item, Painter* painter, const PaintOptions& opt)
2619 : {
2620 : TRACE_DRAW_ITEM;
2621 0 : drawTextLineBaseSegment(item, painter, opt);
2622 0 : }
2623 :
2624 0 : void TDraw::draw(const PickScrapeSegment* item, Painter* painter, const PaintOptions& opt)
2625 : {
2626 : TRACE_DRAW_ITEM;
2627 0 : drawTextLineBaseSegment(item, painter, opt);
2628 0 : }
2629 :
2630 0 : void TDraw::draw(const PlayCountText* item, muse::draw::Painter* painter, const PaintOptions& opt)
2631 : {
2632 : TRACE_DRAW_ITEM;
2633 0 : drawTextBase(item, painter, opt);
2634 0 : }
2635 :
2636 0 : void TDraw::draw(const PlayTechAnnotation* item, Painter* painter, const PaintOptions& opt)
2637 : {
2638 : TRACE_DRAW_ITEM;
2639 0 : drawTextBase(item, painter, opt);
2640 0 : }
2641 :
2642 0 : void TDraw::draw(const RasgueadoSegment* item, Painter* painter, const PaintOptions& opt)
2643 : {
2644 : TRACE_DRAW_ITEM;
2645 0 : drawTextLineBaseSegment(item, painter, opt);
2646 0 : }
2647 :
2648 0 : void TDraw::draw(const RehearsalMark* item, Painter* painter, const PaintOptions& opt)
2649 : {
2650 : TRACE_DRAW_ITEM;
2651 0 : drawTextBase(item, painter, opt);
2652 0 : }
2653 :
2654 0 : void TDraw::draw(const Rest* item, Painter* painter, const PaintOptions& opt)
2655 : {
2656 : TRACE_DRAW_ITEM;
2657 :
2658 0 : if (item->isGap()) {
2659 0 : drawDebugGapRest(item, painter);
2660 0 : return;
2661 : }
2662 :
2663 0 : if (item->shouldNotBeDrawn()) {
2664 0 : return;
2665 : }
2666 :
2667 0 : const Rest::LayoutData* ldata = item->ldata();
2668 :
2669 0 : painter->setPen(item->curColor(opt));
2670 :
2671 0 : bool jianpu = item->staff() && item->staff()->isJianpuStaff(item->tick());
2672 0 : if (jianpu) {
2673 0 : const Staff* staff = item->staff();
2674 0 : const StaffType* staffType = staff->staffTypeForElement(item);
2675 0 : const double height = staffType->jianpuBoxH() * item->magS();
2676 :
2677 0 : Font f(staffType->jianpuFont());
2678 0 : f.setPointSizeF(f.pointSizeF() * item->magS());
2679 0 : painter->setFont(f);
2680 0 : painter->setPen(item->curColor(opt));
2681 0 : double startPosX = ldata->bbox().x();
2682 0 : painter->drawText(PointF(startPosX, height * .5), String(u"0"));
2683 0 : return;
2684 0 : }
2685 :
2686 0 : if (DeadSlapped* ds = item->deadSlapped()) {
2687 0 : draw(ds, painter, opt);
2688 : } else {
2689 0 : item->drawSymbol(ldata->sym, painter);
2690 : }
2691 : }
2692 :
2693 0 : void TDraw::drawDebugGapRest(const Rest* item, muse::draw::Painter* painter)
2694 : {
2695 0 : IF_ASSERT_FAILED(item->debugDrawGap()) {
2696 0 : return;
2697 : }
2698 :
2699 0 : painter->setPen(Color::RED);
2700 0 : item->drawSymbol(item->ldata()->sym, painter);
2701 : }
2702 :
2703 : //! NOTE May be removed later (should be only single mode)
2704 0 : void TDraw::draw(const ShadowNote* item, Painter* painter, const PaintOptions&)
2705 : {
2706 : TRACE_DRAW_ITEM;
2707 :
2708 0 : if (!item->visible() || !item->isValid()) {
2709 0 : return;
2710 : }
2711 :
2712 0 : PointF ap(item->pagePos());
2713 0 : painter->translate(ap);
2714 0 : double lw = item->style().styleAbsolute(Sid::stemWidth) * item->mag();
2715 0 : Pen pen(item->color(), lw, PenStyle::SolidLine, PenCapStyle::FlatCap);
2716 0 : painter->setPen(pen);
2717 :
2718 0 : bool jianpu = item->staff() && item->staff()->isJianpuStaff(item->tick());
2719 0 : bool up = item->computeUp();
2720 :
2721 : // Draw the accidental (Jianpu shows its accidental as part of the digit label instead)
2722 0 : SymId acc = Accidental::subtype2symbol(item->accidentalType());
2723 0 : if (!jianpu && acc != SymId::noSym) {
2724 0 : PointF posAcc;
2725 0 : posAcc.rx() -= item->symWidth(acc) + item->style().styleAbsolute(Sid::accidentalNoteDistance) * item->mag();
2726 0 : item->drawSymbol(acc, painter, posAcc);
2727 : }
2728 :
2729 : // Draw the notehead
2730 0 : item->drawSymbol(item->noteheadSymbol(), painter);
2731 :
2732 : // Draw the dots
2733 0 : double sp = item->spatium();
2734 0 : double sp2 = sp / 2;
2735 0 : double noteheadWidth = item->symWidth(item->noteheadSymbol());
2736 :
2737 0 : PointF posDot;
2738 0 : if (item->duration().dots() > 0) {
2739 0 : double d = item->style().styleAbsolute(Sid::dotNoteDistance) * item->mag();
2740 0 : double dd = item->style().styleAbsolute(Sid::dotDotDistance) * item->mag();
2741 0 : posDot.rx() += (noteheadWidth + d);
2742 :
2743 0 : if (item->isRest()) {
2744 0 : posDot.ry() += Rest::getDotline(item->duration().type()) * sp2;
2745 : } else {
2746 0 : posDot.ry() -= (item->lineIndex() % 2 == 0 ? sp2 : 0);
2747 : }
2748 :
2749 0 : if (item->hasFlag() && up) {
2750 0 : posDot.rx() = std::max(posDot.x(), noteheadWidth + item->symBbox(item->flagSym()).right());
2751 : }
2752 :
2753 0 : for (int i = 0; i < item->duration().dots(); i++) {
2754 0 : posDot.rx() += dd * i;
2755 0 : item->drawSymbol(SymId::augmentationDot, painter, posDot);
2756 0 : posDot.rx() -= dd * i;
2757 : }
2758 : }
2759 :
2760 : // Draw stem and flag
2761 0 : if (item->hasStem()) {
2762 0 : double x = item->symSmuflAnchor(item->noteheadSymbol(), up ? SmuflAnchorId::stemUpSE : SmuflAnchorId::stemDownNW).x();
2763 0 : x += up ? -0.5 * lw : 0.5 * lw;
2764 0 : double y1 = item->symSmuflAnchor(item->noteheadSymbol(), up ? SmuflAnchorId::stemUpSE : SmuflAnchorId::stemDownNW).y();
2765 0 : double y2 = (up ? -3.5 : 3.5) * sp;
2766 :
2767 0 : if (item->hasFlag()) {
2768 0 : SymId flag = item->flagSym();
2769 0 : item->drawSymbol(flag, painter, PointF(x - (lw / 2), y2));
2770 0 : y2 += item->symSmuflAnchor(flag, up ? SmuflAnchorId::stemUpNW : SmuflAnchorId::stemDownSW).y();
2771 : }
2772 0 : painter->drawLine(LineF(x, y1, x, y2));
2773 : }
2774 :
2775 : // Draw ledger lines if needed
2776 0 : if (item->ledgerLinesVisible()) {
2777 0 : double extraLen = item->style().styleS(Sid::ledgerLineLength).val() * sp;
2778 0 : double x1 = -extraLen;
2779 0 : double x2 = noteheadWidth + extraLen;
2780 0 : double yOffset = item->staffOffsetY();
2781 0 : double step = sp2 * item->staffType()->lineDistance().val();
2782 :
2783 0 : lw = item->style().styleAbsolute(Sid::ledgerLineWidth) * item->mag();
2784 0 : pen.setWidthF(lw);
2785 0 : painter->setPen(pen);
2786 :
2787 0 : const int topLine = -2 + yOffset / step;
2788 0 : for (int i = topLine; i >= item->lineIndex(); i -= 2) {
2789 0 : double y = step * (i - item->lineIndex());
2790 0 : painter->drawLine(LineF(x1, y, x2, y));
2791 : }
2792 0 : int l = item->staffType()->lines() * 2 + yOffset / step; // first ledger line below staff
2793 0 : for (int i = l; i <= item->lineIndex(); i += 2) {
2794 0 : double y = step * (i - item->lineIndex());
2795 0 : if (jianpu && i < 9) {
2796 : // jianpu ledger line width is double in the 5-line staff
2797 0 : painter->drawLine(LineF(x1 - 2 * extraLen, y, x2 + 2 * extraLen, y));
2798 : } else {
2799 : // Normal ledger lines below staff
2800 0 : painter->drawLine(LineF(x1, y, x2, y));
2801 : }
2802 : }
2803 : }
2804 :
2805 : // Draw jianpu digit
2806 0 : if (jianpu) {
2807 0 : const Staff* staff = item->staff();
2808 0 : const StaffType* staffType = staff->staffTypeForElement(item);
2809 0 : Font f(staffType->jianpuFont());
2810 0 : f.setPointSizeF(f.pointSizeF() * item->magS());
2811 0 : painter->setFont(f);
2812 :
2813 0 : FontMetrics fm(f);
2814 0 : const double jianpuWidth = fm.width(item->jianpuDigit());
2815 0 : const double jianpuHeight = staffType->jianpuBoxH() * item->magS();
2816 :
2817 0 : auto bbox = item->ldata()->bbox();
2818 0 : double jianpuX = (noteheadWidth - jianpuWidth) * .5;
2819 0 : double jianpuY = bbox.y();
2820 0 : const bool beamAbove = item->style().styleV(Sid::jianpuDiminutionBeamPlacement).value<PlacementV>() == PlacementV::ABOVE;
2821 0 : const double beamDistance = item->style().styleAbsolute(Sid::jianpuDiminutionBeamDistance) * item->magS();
2822 0 : const double beamThickness = item->style().styleAbsolute(Sid::jianpuDiminutionBeamThickness) * item->magS();
2823 0 : const double dotDistance = item->style().styleAbsolute(Sid::jianpuOctaveDotDistance) * item->magS();
2824 0 : const double dotRadius = item->style().styleAbsolute(Sid::jianpuOctaveDotRadius) * item->magS();
2825 :
2826 0 : if (item->lineIndex() >= 0) {
2827 0 : jianpuY = bbox.height() + bbox.y();
2828 0 : jianpuY -= jianpuHeight;
2829 0 : jianpuY -= dotDistance * abs(item->jianpuOctaveDots());
2830 0 : jianpuY -= beamDistance * item->jianpuDiminutionLines();
2831 : }
2832 :
2833 : // Save painter state before drawing beams and dots, as they may change pen width
2834 0 : painter->save();
2835 0 : pen.setWidthF(1.0);
2836 0 : painter->setPen(pen);
2837 0 : painter->setBrush(Brush(pen.color()));
2838 :
2839 0 : auto drawOctaveDots = [&jianpuY, ¬eheadWidth, &dotDistance, &dotRadius, &item, &painter]() {
2840 0 : for (int i = 0; i < abs(item->jianpuOctaveDots()); i++) {
2841 0 : jianpuY += dotDistance;
2842 0 : painter->drawEllipse(PointF(noteheadWidth * .5, jianpuY), dotRadius, dotRadius);
2843 : }
2844 0 : };
2845 :
2846 0 : auto drawBeam = [&jianpuY, ¬eheadWidth, &beamDistance, &beamThickness, &item, &pen, &painter]() {
2847 0 : painter->save();
2848 0 : pen.setWidthF(beamThickness);
2849 0 : painter->setPen(pen);
2850 0 : for (int i = 0; i < item->jianpuDiminutionLines(); i++) {
2851 0 : jianpuY += beamDistance;
2852 0 : painter->drawLine(LineF(0.0, jianpuY, noteheadWidth, jianpuY));
2853 : }
2854 0 : painter->restore();
2855 0 : };
2856 :
2857 : // Draw beams above the jianpu digit
2858 0 : bool hasBeamAbove = false;
2859 0 : double toNoteDistance = 0;
2860 0 : if (beamAbove && item->jianpuDiminutionLines()) {
2861 0 : hasBeamAbove = true;
2862 0 : jianpuY -= beamDistance; // Pre offset for 1st beam
2863 0 : toNoteDistance = beamDistance;
2864 0 : drawBeam();
2865 : }
2866 :
2867 : // Draw octave dots above the jianpu digit
2868 0 : if (item->jianpuOctaveDots() < 0) {
2869 0 : jianpuY -= hasBeamAbove ? 0.0 : dotDistance; // Pre offset for 1st dot if no beam
2870 0 : toNoteDistance = dotDistance;
2871 0 : drawOctaveDots();
2872 : }
2873 :
2874 : // Draw jianpu digit
2875 0 : jianpuY += toNoteDistance; // Spacing for beams or dots to the notehead
2876 0 : jianpuY += jianpuHeight; // Spacing from jianpu digit
2877 0 : drawJianpuAccidental(painter, f, fm, item->jianpuAccidental(), jianpuX, jianpuY);
2878 0 : painter->drawText(jianpuX, jianpuY, item->jianpuDigit());
2879 :
2880 : // Draw beams below the jianpu digit
2881 0 : if (!beamAbove && item->jianpuDiminutionLines()) {
2882 0 : drawBeam();
2883 : }
2884 :
2885 : // Draw octave dots below the jianpu digit
2886 0 : if (item->jianpuOctaveDots() > 0) {
2887 0 : drawOctaveDots();
2888 : }
2889 :
2890 : // Restore painter state after drawing beams and dots
2891 0 : painter->restore();
2892 0 : }
2893 :
2894 0 : item->drawArticulations(painter);
2895 :
2896 0 : painter->translate(-ap);
2897 0 : }
2898 :
2899 0 : void TDraw::draw(const SlurSegment* item, Painter* painter, const PaintOptions& opt)
2900 : {
2901 : TRACE_DRAW_ITEM;
2902 :
2903 0 : painter->save();
2904 0 : setMask(item, painter);
2905 :
2906 0 : Pen pen(item->curColor(opt));
2907 0 : double mag = item->staff() ? item->staff()->staffMag(item->slur()->tick()) : 1.0;
2908 :
2909 : //Replace generic Qt dash patterns with improved equivalents to show true dots (keep in sync with tie.cpp)
2910 0 : std::vector<double> dotted = { 0.01, 1.99 }; // tighter than Qt PenStyle::DotLine equivalent - would be { 0.01, 2.99 }
2911 0 : std::vector<double> dashed = { 3.00, 3.00 }; // Compensating for caps. Qt default PenStyle::DashLine is { 4.0, 2.0 }
2912 0 : std::vector<double> wideDashed = { 5.00, 6.00 };
2913 :
2914 0 : switch (item->slurTie()->styleType()) {
2915 0 : case SlurStyleType::Solid:
2916 0 : painter->setBrush(Brush(pen.color()));
2917 0 : pen.setCapStyle(PenCapStyle::RoundCap);
2918 0 : pen.setJoinStyle(PenJoinStyle::RoundJoin);
2919 0 : pen.setWidthF(item->endWidth() * mag);
2920 0 : break;
2921 0 : case SlurStyleType::Dotted:
2922 0 : painter->setBrush(BrushStyle::NoBrush);
2923 0 : pen.setCapStyle(PenCapStyle::RoundCap); // round dots
2924 0 : pen.setDashPattern(dotted);
2925 0 : pen.setWidthF(item->dottedWidth() * mag);
2926 0 : break;
2927 0 : case SlurStyleType::Dashed:
2928 0 : painter->setBrush(BrushStyle::NoBrush);
2929 0 : pen.setDashPattern(dashed);
2930 0 : pen.setWidthF(item->dottedWidth() * mag);
2931 0 : break;
2932 0 : case SlurStyleType::WideDashed:
2933 0 : painter->setBrush(BrushStyle::NoBrush);
2934 0 : pen.setDashPattern(wideDashed);
2935 0 : pen.setWidthF(item->dottedWidth() * mag);
2936 0 : break;
2937 0 : case SlurStyleType::Undefined:
2938 0 : break;
2939 : }
2940 0 : painter->setPen(pen);
2941 0 : painter->drawPath(item->ldata()->path());
2942 :
2943 0 : painter->restore();
2944 0 : }
2945 :
2946 0 : void TDraw::draw(const Spacer* item, Painter* painter, const PaintOptions& opt)
2947 : {
2948 : TRACE_DRAW_ITEM;
2949 0 : if (opt.isPrinting || !item->score()->showUnprintable()) {
2950 0 : return;
2951 : }
2952 :
2953 0 : auto conf = item->configuration();
2954 :
2955 0 : Pen pen(item->selected() ? conf->selectionColor() : conf->formattingColor(), item->spatium()* 0.3);
2956 :
2957 0 : painter->setPen(pen);
2958 0 : painter->setBrush(BrushStyle::NoBrush);
2959 0 : painter->drawPath(item->ldata()->path);
2960 0 : }
2961 :
2962 20 : void TDraw::draw(const StaffLines* item, Painter* painter, const PaintOptions& opt)
2963 : {
2964 : TRACE_DRAW_ITEM;
2965 20 : painter->save();
2966 :
2967 20 : setMask(item, painter);
2968 :
2969 20 : painter->setPen(Pen(item->curColor(opt), item->lw(), PenStyle::SolidLine, PenCapStyle::FlatCap));
2970 20 : painter->drawLines(item->lines());
2971 :
2972 20 : painter->restore();
2973 20 : }
2974 :
2975 0 : void TDraw::draw(const StaffState* item, Painter* painter, const PaintOptions& opt)
2976 : {
2977 : TRACE_DRAW_ITEM;
2978 0 : if (opt.isPrinting || !item->score()->showUnprintable()) {
2979 0 : return;
2980 : }
2981 :
2982 0 : const StaffState::LayoutData* ldata = item->ldata();
2983 0 : auto conf = item->configuration();
2984 :
2985 0 : Pen pen(item->selected() ? conf->selectionColor() : conf->formattingColor(),
2986 0 : ldata->lw, PenStyle::SolidLine, PenCapStyle::RoundCap, PenJoinStyle::RoundJoin);
2987 0 : painter->setPen(pen);
2988 0 : painter->setBrush(BrushStyle::NoBrush);
2989 0 : painter->drawPath(ldata->path);
2990 0 : }
2991 :
2992 0 : void TDraw::draw(const StaffText* item, Painter* painter, const PaintOptions& opt)
2993 : {
2994 : TRACE_DRAW_ITEM;
2995 :
2996 0 : drawTextBase(item, painter, opt);
2997 :
2998 0 : if (item->hasSoundFlag()) {
2999 0 : draw(item->soundFlag(), painter, opt);
3000 : }
3001 0 : }
3002 :
3003 0 : void TDraw::draw(const StaveSharingLabel* item, muse::draw::Painter* painter, const PaintOptions& opt)
3004 : {
3005 : TRACE_DRAW_ITEM;
3006 :
3007 0 : drawTextBase(item, painter, opt);
3008 0 : }
3009 :
3010 0 : void TDraw::draw(const StaffTypeChange* item, Painter* painter, const PaintOptions& opt)
3011 : {
3012 : TRACE_DRAW_ITEM;
3013 :
3014 0 : if (opt.isPrinting || !item->score()->showUnprintable()) {
3015 0 : return;
3016 : }
3017 :
3018 0 : auto conf = item->configuration();
3019 :
3020 0 : double _spatium = item->style().spatium();
3021 0 : double h = _spatium * 2.5;
3022 0 : double w = _spatium * 2.5;
3023 0 : double lineDist = 0.35; // line distance for the icon 'staff lines'
3024 : // draw icon rectangle
3025 0 : painter->setPen(Pen(item->selected() ? conf->selectionColor() : conf->formattingColor(),
3026 0 : item->lw(), PenStyle::SolidLine, PenCapStyle::SquareCap, PenJoinStyle::MiterJoin));
3027 0 : painter->setBrush(BrushStyle::NoBrush);
3028 0 : painter->drawRect(0, 0, w, h);
3029 :
3030 : // draw icon contents
3031 0 : int lines = 5;
3032 0 : if (item->staffType()) {
3033 0 : if (item->staffType()->stemless()) { // a single notehead represents a stemless staff
3034 0 : item->drawSymbol(SymId::noteheadBlack, painter, PointF(w * 0.5 - 0.33 * _spatium, h * 0.5), 0.5);
3035 : }
3036 0 : if (item->staffType()->invisible()) { // no lines needed. It's done.
3037 0 : return;
3038 : }
3039 : // show up to 6 lines
3040 0 : lines = std::min(item->staffType()->lines(), 6);
3041 : }
3042 : // calculate starting point Y for the lines from half the icon height (2.5) so staff lines appear vertically centered
3043 0 : double startY = 1.25 - (lines - 1) * lineDist * 0.5;
3044 0 : painter->setPen(Pen(item->selected() ? conf->selectionColor() : conf->formattingColor(),
3045 0 : 2.5, PenStyle::SolidLine, PenCapStyle::SquareCap, PenJoinStyle::MiterJoin));
3046 0 : for (int i=0; i < lines; i++) {
3047 0 : int y = (startY + i * lineDist) * _spatium;
3048 0 : painter->drawLine(0, y, w, y);
3049 : }
3050 0 : }
3051 :
3052 60 : void TDraw::draw(const Stem* item, Painter* painter, const PaintOptions& opt)
3053 : {
3054 : TRACE_DRAW_ITEM;
3055 60 : if (!item->chord()) { // may be need assert?
3056 0 : return;
3057 : }
3058 :
3059 : // hide if second chord of a cross-measure pair
3060 60 : if (item->chord()->crossMeasure() == CrossMeasure::SECOND) {
3061 0 : return;
3062 : }
3063 :
3064 60 : const Stem::LayoutData* ldata = item->ldata();
3065 :
3066 60 : const Staff* staff = item->staff();
3067 60 : const StaffType* staffType = staff ? staff->staffTypeForElement(item->chord()) : nullptr;
3068 60 : const bool isTablature = staffType && staffType->isTabStaff();
3069 :
3070 60 : painter->setPen(Pen(item->curColor(opt), item->lineWidthMag(), PenStyle::SolidLine, PenCapStyle::FlatCap));
3071 60 : painter->drawLine(ldata->line);
3072 :
3073 60 : if (!isTablature) {
3074 60 : return;
3075 : }
3076 :
3077 : // TODO: adjust bounding rectangle in layout() for dots and for slash
3078 0 : double sp = item->spatium();
3079 0 : bool isUp = item->up();
3080 :
3081 : // slashed half note stem
3082 0 : if (item->chord()->durationType().type() == DurationType::V_HALF
3083 0 : && staffType->minimStyle() == TablatureMinimStyle::SLASHED) {
3084 : // position slashes onto stem
3085 0 : double y = isUp ? -item->length() + StemLayout::STAFFTYPE_TAB_SLASH_2STARTY_UP * sp
3086 0 : : item->length() - StemLayout::STAFFTYPE_TAB_SLASH_2STARTY_DN * sp;
3087 : // if stems through, try to align slashes within or across lines
3088 0 : if (staffType->stemThrough()) {
3089 0 : double halfLineDist = staffType->lineDistance().val() * sp * 0.5;
3090 0 : double halfSlashHgt = StemLayout::STAFFTYPE_TAB_SLASH_2TOTHEIGHT * sp * 0.5;
3091 0 : y = lrint((y + halfSlashHgt) / halfLineDist) * halfLineDist - halfSlashHgt;
3092 : }
3093 : // draw slashes
3094 0 : double hlfWdt= sp * StemLayout::STAFFTYPE_TAB_SLASH_WIDTH * 0.5;
3095 0 : double sln = sp * StemLayout::STAFFTYPE_TAB_SLASH_SLANTY;
3096 0 : double thk = sp * StemLayout::STAFFTYPE_TAB_SLASH_THICK;
3097 0 : double displ = sp * StemLayout::STAFFTYPE_TAB_SLASH_DISPL;
3098 0 : PainterPath path;
3099 0 : for (int i = 0; i < 2; ++i) {
3100 0 : path.moveTo(hlfWdt, y); // top-right corner
3101 0 : path.lineTo(hlfWdt, y + thk); // bottom-right corner
3102 0 : path.lineTo(-hlfWdt, y + thk + sln); // bottom-left corner
3103 0 : path.lineTo(-hlfWdt, y + sln); // top-left corner
3104 0 : path.closeSubpath();
3105 0 : y += displ;
3106 : }
3107 0 : painter->setBrush(Brush(item->curColor(opt)));
3108 0 : painter->setNoPen();
3109 0 : painter->drawPath(path);
3110 0 : }
3111 :
3112 : // dots
3113 : // NOT THE BEST PLACE FOR THIS?
3114 : // with tablatures and stems beside staves, dots are not drawn near 'notes', but near stems
3115 0 : int nDots = item->chord()->dots();
3116 0 : if (nDots > 0 && !staffType->stemThrough()) {
3117 0 : double x = item->chord()->dotPosX();
3118 0 : double y = ((StemLayout::STAFFTYPE_TAB_DEFAULTSTEMLEN_DN * 0.2) * sp) * (isUp ? -1.0 : 1.0);
3119 0 : double step = item->style().styleS(Sid::dotDotDistance).val() * sp;
3120 0 : for (int dot = 0; dot < nDots; dot++, x += step) {
3121 0 : item->drawSymbol(SymId::augmentationDot, painter, PointF(x, y));
3122 : }
3123 : }
3124 : }
3125 :
3126 0 : void TDraw::draw(const StemSlash* item, Painter* painter, const PaintOptions& opt)
3127 : {
3128 : TRACE_DRAW_ITEM;
3129 0 : const StemSlash::LayoutData* ldata = item->ldata();
3130 0 : painter->setPen(Pen(item->curColor(opt), ldata->stemWidth, PenStyle::SolidLine, PenCapStyle::FlatCap));
3131 0 : painter->drawLine(ldata->line);
3132 0 : }
3133 :
3134 0 : void TDraw::draw(const Sticking* item, Painter* painter, const PaintOptions& opt)
3135 : {
3136 : TRACE_DRAW_ITEM;
3137 0 : drawTextBase(item, painter, opt);
3138 0 : }
3139 :
3140 0 : void TDraw::draw(const StringTunings* item, Painter* painter, const PaintOptions& opt)
3141 : {
3142 : TRACE_DRAW_ITEM;
3143 :
3144 0 : if (item->noStringVisible()) {
3145 0 : const TextBase::LayoutData* data = item->ldata();
3146 :
3147 0 : const double spatium = item->spatium();
3148 0 : const double lineWidth = spatium * .15;
3149 :
3150 0 : const Pen pen(item->curColor(opt), lineWidth, PenStyle::SolidLine, PenCapStyle::RoundCap, PenJoinStyle::RoundJoin);
3151 0 : painter->setPen(pen);
3152 0 : painter->setBrush(Brush(item->curColor(opt)));
3153 :
3154 0 : const RectF rect = data->bbox();
3155 :
3156 0 : const double x = rect.x();
3157 0 : const double y = rect.y();
3158 0 : const double width = rect.width();
3159 0 : const double height = rect.height();
3160 0 : const double topPartHeight = height * .66;
3161 0 : const double cornerRadius = height * .1;
3162 :
3163 0 : PainterPath path;
3164 0 : path.moveTo(x, y);
3165 0 : path.arcTo(x, y + (topPartHeight - 2 * cornerRadius), 2 * cornerRadius, 2 * cornerRadius, 180.0, 90.0);
3166 0 : path.arcTo(x + width - 2 * cornerRadius, y + (topPartHeight - 2 * cornerRadius), 2 * cornerRadius, 2 * cornerRadius, 270, 90);
3167 0 : path.lineTo(x + width, y);
3168 0 : path.moveTo(x + width / 2, y + topPartHeight);
3169 0 : path.lineTo(x + width / 2, y + height);
3170 :
3171 0 : painter->setBrush(BrushStyle::NoBrush);
3172 0 : painter->drawPath(path);
3173 0 : } else {
3174 0 : drawTextBase(item, painter, opt);
3175 : }
3176 0 : }
3177 :
3178 0 : void TDraw::draw(const Symbol* item, Painter* painter, const PaintOptions& opt)
3179 : {
3180 : TRACE_DRAW_ITEM;
3181 0 : bool tabStaff = item->staff() ? item->staff()->isTabStaff(item->tick()) : false;
3182 :
3183 0 : if (!item->isNoteDot() || !tabStaff) {
3184 0 : painter->setPen(item->curColor(opt));
3185 0 : if (item->scoreFont()) {
3186 0 : item->scoreFont()->draw(item->sym(), painter, item->magS() * item->symbolsSize(), PointF(), item->symAngle());
3187 : } else {
3188 0 : item->drawSymbol(item->sym(), painter);
3189 : }
3190 : }
3191 0 : }
3192 :
3193 0 : void TDraw::draw(const FSymbol* item, Painter* painter, const PaintOptions& opt)
3194 : {
3195 : TRACE_DRAW_ITEM;
3196 :
3197 0 : painter->setFont(item->font());
3198 0 : painter->setPen(item->curColor(opt));
3199 0 : painter->drawText(PointF(0, 0), item->toString());
3200 0 : }
3201 :
3202 0 : void TDraw::draw(const SystemDivider* item, Painter* painter, const PaintOptions& opt)
3203 : {
3204 0 : draw(static_cast<const Symbol*>(item), painter, opt);
3205 0 : }
3206 :
3207 0 : void TDraw::draw(const SystemText* item, Painter* painter, const PaintOptions& opt)
3208 : {
3209 0 : drawTextBase(item, painter, opt);
3210 0 : }
3211 :
3212 0 : void TDraw::draw(const IndicatorIcon* item, muse::draw::Painter* painter, const PaintOptions& opt)
3213 : {
3214 : TRACE_DRAW_ITEM;
3215 :
3216 0 : if (opt.isPrinting || !item->score()->showUnprintable()) {
3217 0 : return;
3218 : }
3219 :
3220 0 : Color selectionColor = opt.invertColors ? item->configuration()->indicatorIconInvertedSelectionColor()
3221 0 : : item->configuration()->selectionColor();
3222 0 : Color color = item->selected() ? selectionColor : item->configuration()->formattingColor();
3223 0 : Pen pen(color);
3224 0 : painter->setPen(pen);
3225 0 : painter->setFont(item->font());
3226 0 : painter->drawSymbol(PointF(), item->iconCode());
3227 :
3228 0 : if (item->isSystemLockIndicator() && item->selected()) {
3229 0 : const SystemLockIndicator* sli = toSystemLockIndicator(item);
3230 :
3231 0 : Color lockedAreaColor = selectionColor;
3232 0 : lockedAreaColor.setAlpha(opt.invertColors ? 90 : 38);
3233 0 : Brush brush(lockedAreaColor);
3234 0 : painter->setBrush(brush);
3235 0 : painter->setNoPen();
3236 0 : double radius = 0.5 * sli->spatium();
3237 :
3238 0 : painter->drawRoundedRect(sli->ldata()->rangeRect, radius, radius);
3239 0 : }
3240 0 : }
3241 :
3242 0 : void TDraw::draw(const SoundFlag* item, Painter* painter, const PaintOptions& opt)
3243 : {
3244 : TRACE_DRAW_ITEM;
3245 :
3246 0 : if (item->shouldHide()) {
3247 0 : return;
3248 : }
3249 :
3250 0 : painter->setNoPen();
3251 0 : painter->setBrush(item->iconBackgroundColor());
3252 0 : painter->drawEllipse(item->ldata()->bbox().adjusted(-4.0, -4.0, 4.0, 4.0));
3253 :
3254 0 : painter->setFont(item->iconFont());
3255 0 : painter->setPen(!item->selected() ? item->curColor(true, opt) : Color::WHITE);
3256 0 : painter->drawText(item->ldata()->bbox(), muse::draw::AlignCenter, muse::draw::TextDontClip, Char(item->iconCode()));
3257 : }
3258 :
3259 0 : void TDraw::draw(const TabDurationSymbol* item, Painter* painter, const PaintOptions& opt)
3260 : {
3261 : TRACE_DRAW_ITEM;
3262 :
3263 0 : if (!item->tab()) {
3264 0 : return;
3265 : }
3266 :
3267 0 : const TabDurationSymbol::LayoutData* ldata = item->ldata();
3268 :
3269 0 : if (item->isRepeat() && (item->tab()->symRepeat() == TablatureSymbolRepeat::SYSTEM)) {
3270 0 : Chord* chord = toChord(item->ownershipParent());
3271 0 : ChordRest* prevCR = Navigation::prevChordRest(chord);
3272 0 : if (prevCR && (chord->measure()->system() == prevCR->measure()->system())) {
3273 0 : return;
3274 : }
3275 : }
3276 :
3277 0 : double mag = item->magS();
3278 0 : double imag = 1.0 / mag;
3279 :
3280 0 : Pen pen(item->curColor(opt));
3281 0 : painter->setPen(pen);
3282 0 : painter->scale(mag, mag);
3283 0 : if (ldata->beamGrid == TabBeamGrid::NONE) {
3284 : // if no beam grid, draw symbol
3285 0 : painter->setFont(item->tab()->durationFont());
3286 0 : painter->drawText(PointF(0.0, 0.0), item->text());
3287 : } else {
3288 : // if beam grid, draw stem line
3289 0 : const TablatureDurationFont& font = item->tab()->tabDurationFont();
3290 0 : double _spatium = item->spatium();
3291 0 : pen.setCapStyle(PenCapStyle::FlatCap);
3292 0 : pen.setWidthF(font.gridStemWidth.toAbsolute(_spatium));
3293 0 : painter->setPen(pen);
3294 : // take stem height from bbox, but de-magnify it, as drawing is already magnified
3295 0 : double h = ldata->bbox().y() / mag;
3296 0 : painter->drawLine(PointF(0.0, h), PointF(0.0, 0.0));
3297 : // if beam grid is medial/final, draw beam lines too: lines go from mid of
3298 : // previous stem (delta x stored in _beamLength) to mid of this' stem (0.0)
3299 0 : if (ldata->beamGrid == TabBeamGrid::MEDIALFINAL) {
3300 0 : pen.setWidthF(font.gridBeamWidth.toAbsolute(_spatium));
3301 0 : painter->setPen(pen);
3302 : // lower height available to beams by half a beam width,
3303 : // so that top beam upper border aligns with stem top
3304 0 : h += (font.gridBeamWidth.toAbsolute(_spatium)) * 0.5;
3305 : // draw beams equally spaced within the stem height (this is
3306 : // different from modern engraving, but common in historic prints)
3307 0 : double step = -h / ldata->beamLevel;
3308 0 : double y = h;
3309 0 : for (int i = 0; i < ldata->beamLevel; i++, y += step) {
3310 0 : painter->drawLine(PointF(ldata->beamLength, y), PointF(0.0, y));
3311 : }
3312 : }
3313 : }
3314 0 : painter->scale(imag, imag);
3315 0 : }
3316 :
3317 0 : void TDraw::draw(const Tapping* item, muse::draw::Painter* painter, const PaintOptions& opt)
3318 : {
3319 0 : painter->setPen(item->curColor(opt));
3320 0 : if (item->ldata()->symId != SymId::noSym) {
3321 0 : item->drawSymbol(item->ldata()->symId, painter);
3322 0 : } else if (TappingText* text = item->text()) {
3323 0 : painter->translate(text->pos());
3324 0 : drawTextBase(text, painter, opt);
3325 0 : painter->translate(-text->pos());
3326 : } else {
3327 0 : assert(false && "Drawing Tapping item without text or symbol");
3328 : }
3329 0 : }
3330 :
3331 0 : void TDraw::draw(const TempoText* item, Painter* painter, const PaintOptions& opt)
3332 : {
3333 : TRACE_DRAW_ITEM;
3334 0 : drawTextBase(item, painter, opt);
3335 0 : }
3336 :
3337 0 : void TDraw::draw(const Text* item, Painter* painter, const PaintOptions& opt)
3338 : {
3339 : TRACE_DRAW_ITEM;
3340 0 : drawTextBase(item, painter, opt);
3341 0 : }
3342 :
3343 0 : void TDraw::draw(const TextLineSegment* item, Painter* painter, const PaintOptions& opt)
3344 : {
3345 : TRACE_DRAW_ITEM;
3346 0 : drawTextLineBaseSegment(item, painter, opt);
3347 0 : }
3348 :
3349 0 : void TDraw::draw(const TieSegment* item, Painter* painter, const PaintOptions& opt)
3350 : {
3351 : TRACE_DRAW_ITEM;
3352 :
3353 : // hide tie toward the second chord of a cross-measure value
3354 0 : if (item->tie()->endNote() && item->tie()->endNote()->chord()->crossMeasure() == CrossMeasure::SECOND) {
3355 0 : return;
3356 : }
3357 :
3358 0 : painter->save();
3359 :
3360 0 : setMask(item, painter);
3361 :
3362 0 : Color penColor = item->curColor(item->getProperty(Pid::VISIBLE).toBool(), item->getProperty(Pid::COLOR).value<Color>(), opt);
3363 0 : if (!opt.isPrinting && item->ldata()->allJumpPointsInactive) {
3364 0 : penColor.setAlpha(std::min(penColor.alpha(), 85));
3365 : }
3366 :
3367 0 : Pen pen(penColor);
3368 0 : double mag = item->staff() ? item->staff()->staffMag(item->tie()->tick()) : 1.0;
3369 : //Replace generic Qt dash patterns with improved equivalents to show true dots (keep in sync with slur.cpp)
3370 0 : std::vector<double> dotted = { 0.01, 1.99 }; // tighter than Qt PenStyle::DotLine equivalent - would be { 0.01, 2.99 }
3371 0 : std::vector<double> dashed = { 3.00, 3.00 }; // Compensating for caps. Qt default PenStyle::DashLine is { 4.0, 2.0 }
3372 0 : std::vector<double> wideDashed = { 5.00, 6.00 };
3373 :
3374 0 : switch (item->slurTie()->styleType()) {
3375 0 : case SlurStyleType::Solid:
3376 0 : painter->setBrush(Brush(pen.color()));
3377 0 : pen.setCapStyle(PenCapStyle::RoundCap);
3378 0 : pen.setJoinStyle(PenJoinStyle::RoundJoin);
3379 0 : pen.setWidthF(item->endWidth() * mag);
3380 0 : break;
3381 0 : case SlurStyleType::Dotted:
3382 0 : painter->setBrush(BrushStyle::NoBrush);
3383 0 : pen.setCapStyle(PenCapStyle::RoundCap); // True dots
3384 0 : pen.setDashPattern(dotted);
3385 0 : pen.setWidthF(item->dottedWidth() * mag);
3386 0 : break;
3387 0 : case SlurStyleType::Dashed:
3388 0 : painter->setBrush(BrushStyle::NoBrush);
3389 0 : pen.setDashPattern(dashed);
3390 0 : pen.setWidthF(item->dottedWidth() * mag);
3391 0 : break;
3392 0 : case SlurStyleType::WideDashed:
3393 0 : painter->setBrush(BrushStyle::NoBrush);
3394 0 : pen.setDashPattern(wideDashed);
3395 0 : pen.setWidthF(item->dottedWidth() * mag);
3396 0 : break;
3397 0 : case SlurStyleType::Undefined:
3398 0 : break;
3399 : }
3400 0 : painter->setPen(pen);
3401 0 : painter->drawPath(item->ldata()->path());
3402 :
3403 0 : painter->restore();
3404 0 : }
3405 :
3406 10 : void TDraw::draw(const TimeSig* item, Painter* painter, const PaintOptions& opt)
3407 : {
3408 : TRACE_DRAW_ITEM;
3409 :
3410 10 : if (item->staff() && !const_cast<const Staff*>(item->staff())->staffType(item->tick())->genTimesig()) {
3411 0 : return;
3412 : }
3413 10 : if (!item->showOnThisStaff()) {
3414 0 : return;
3415 : }
3416 10 : painter->setPen(item->curColor(opt));
3417 :
3418 10 : const TimeSig::LayoutData* ldata = item->ldata();
3419 :
3420 10 : item->drawSymbols(ldata->ns, painter, ldata->pz, item->scale());
3421 10 : item->drawSymbols(ldata->ds, painter, ldata->pn, item->scale());
3422 :
3423 10 : if (item->largeParentheses()) {
3424 0 : item->drawSymbol(SymId::timeSigParensLeft, painter, ldata->pointLargeLeftParen, item->scale().width());
3425 0 : item->drawSymbol(SymId::timeSigParensRight, painter, ldata->pointLargeRightParen, item->scale().width());
3426 : }
3427 : }
3428 :
3429 0 : void TDraw::draw(const TimeTickAnchor* item, Painter* painter, const PaintOptions& opt)
3430 : {
3431 0 : if (opt.isPrinting) {
3432 0 : return;
3433 : }
3434 :
3435 0 : TimeTickAnchor::DrawRegion drawRegion = item->drawRegion();
3436 :
3437 0 : if (drawRegion == TimeTickAnchor::DrawRegion::OUT_OF_RANGE) {
3438 0 : return;
3439 : }
3440 :
3441 0 : Color voiceColor = item->configuration()->voiceColor(item->voiceIdx());
3442 :
3443 : static constexpr double TINT_MAIN_DARKER = 0.45;
3444 : static constexpr double TINT_MAIN_LIGHTER = 0.55;
3445 : static constexpr double TINT_EXTENDED_DARKER = 0.75;
3446 : static constexpr double TINT_EXTENDED_LIGHTER = 0.85;
3447 :
3448 : double tint = drawRegion == TimeTickAnchor::DrawRegion::MAIN_REGION
3449 0 : ? item->ldata()->darker() ? TINT_MAIN_DARKER : TINT_MAIN_LIGHTER
3450 0 : : item->ldata()->darker() ? TINT_EXTENDED_DARKER : TINT_EXTENDED_LIGHTER;
3451 :
3452 0 : voiceColor.applyTint(tint);
3453 :
3454 0 : Brush brush;
3455 0 : brush.setColor(voiceColor);
3456 0 : brush.setStyle(BrushStyle::SolidPattern);
3457 0 : painter->setBrush(brush);
3458 0 : painter->setNoPen();
3459 :
3460 0 : painter->drawRect(item->ldata()->bbox());
3461 0 : }
3462 :
3463 0 : void TDraw::draw(const TremoloSingleChord* item, Painter* painter, const PaintOptions& opt)
3464 : {
3465 : TRACE_DRAW_ITEM;
3466 :
3467 0 : if (item->isBuzzRoll()) {
3468 0 : painter->setPen(item->curColor(opt));
3469 0 : item->drawSymbol(SymId::buzzRoll, painter);
3470 : } else {
3471 0 : painter->setBrush(Brush(item->curColor(opt)));
3472 0 : painter->setNoPen();
3473 0 : painter->drawPath(item->path());
3474 : }
3475 0 : }
3476 :
3477 0 : void TDraw::draw(const TremoloTwoChord* item, Painter* painter, const PaintOptions& opt)
3478 : {
3479 : TRACE_DRAW_ITEM;
3480 :
3481 0 : const TremoloTwoChord::LayoutData* ldata = item->ldata();
3482 :
3483 0 : if (!item->beamSegments().empty()) {
3484 : // two-note trems act like beams
3485 :
3486 : // make beam thickness independent of slant
3487 : // (expression can be simplified?)
3488 0 : const LineF bs = item->beamSegments().front()->line;
3489 0 : double d = (std::abs(bs.y2() - bs.y1())) / (bs.x2() - bs.x1());
3490 0 : if (item->beamSegments().size() > 1 && d > M_PI / 6.0) {
3491 0 : d = M_PI / 6.0;
3492 : }
3493 0 : double ww = (ldata->beamWidth / 2.0) / sin(M_PI_2 - atan(d));
3494 0 : painter->setBrush(Brush(item->curColor(opt)));
3495 0 : painter->setNoPen();
3496 0 : for (const BeamSegment* bs1 : item->beamSegments()) {
3497 0 : painter->drawPolygon(
3498 0 : PolygonF({
3499 0 : PointF(bs1->line.x1(), bs1->line.y1() - ww),
3500 0 : PointF(bs1->line.x2(), bs1->line.y2() - ww),
3501 0 : PointF(bs1->line.x2(), bs1->line.y2() + ww),
3502 0 : PointF(bs1->line.x1(), bs1->line.y1() + ww),
3503 0 : }),
3504 : FillRule::OddEvenFill);
3505 : }
3506 : }
3507 0 : }
3508 :
3509 0 : void TDraw::draw(const TremoloBar* item, Painter* painter, const PaintOptions& opt)
3510 : {
3511 : TRACE_DRAW_ITEM;
3512 0 : const TremoloBar::LayoutData* ldata = item->ldata();
3513 0 : const double lw = item->absoluteFromSpatium(item->lineWidth());
3514 0 : Pen pen(item->curColor(opt), lw, PenStyle::SolidLine, PenCapStyle::RoundCap, PenJoinStyle::RoundJoin);
3515 0 : painter->setPen(pen);
3516 0 : painter->drawPolyline(ldata->polygon);
3517 0 : }
3518 :
3519 0 : void TDraw::draw(const TrillSegment* item, Painter* painter, const PaintOptions& opt)
3520 : {
3521 : TRACE_DRAW_ITEM;
3522 0 : painter->setPen(item->spanner()->curColor(opt));
3523 0 : item->drawSymbols(item->symbols(), painter);
3524 0 : }
3525 :
3526 0 : void TDraw::draw(const TripletFeel* item, Painter* painter, const PaintOptions& opt)
3527 : {
3528 : TRACE_DRAW_ITEM;
3529 0 : drawTextBase(item, painter, opt);
3530 0 : }
3531 :
3532 0 : void TDraw::draw(const Tuplet* item, Painter* painter, const PaintOptions& opt)
3533 : {
3534 : TRACE_DRAW_ITEM;
3535 :
3536 : // if in a TAB without stems, tuplets are not shown
3537 0 : const StaffType* stt = item->staffType();
3538 0 : if (stt && stt->isTabStaff() && stt->stemless()) {
3539 0 : return;
3540 : }
3541 :
3542 0 : Color color(item->curColor(opt));
3543 0 : if (item->number()) {
3544 0 : painter->setPen(color);
3545 0 : PointF pos(item->number()->pos());
3546 0 : painter->translate(pos);
3547 0 : draw(item->number(), painter, opt);
3548 0 : painter->translate(-pos);
3549 : }
3550 0 : if (item->hasBracket()) {
3551 0 : Pen pen(color, item->absoluteFromSpatium(item->bracketWidth()));
3552 0 : pen.setJoinStyle(PenJoinStyle::MiterJoin);
3553 0 : pen.setCapStyle(PenCapStyle::FlatCap);
3554 0 : painter->setPen(pen);
3555 0 : if (!item->number()) {
3556 0 : painter->drawPolyline(item->bracketL, 4);
3557 : } else {
3558 0 : painter->drawPolyline(item->bracketL, 3);
3559 0 : painter->drawPolyline(item->bracketR, 3);
3560 : }
3561 0 : }
3562 : }
3563 :
3564 0 : void TDraw::draw(const VibratoSegment* item, Painter* painter, const PaintOptions& opt)
3565 : {
3566 : TRACE_DRAW_ITEM;
3567 0 : painter->setPen(item->spanner()->curColor(opt));
3568 0 : item->drawSymbols(item->symbols(), painter);
3569 0 : }
3570 :
3571 0 : void TDraw::draw(const VoltaSegment* item, Painter* painter, const PaintOptions& opt)
3572 : {
3573 : TRACE_DRAW_ITEM;
3574 0 : drawTextLineBaseSegment(item, painter, opt);
3575 0 : }
3576 :
3577 0 : void TDraw::draw(const WhammyBarSegment* item, Painter* painter, const PaintOptions& opt)
3578 : {
3579 : TRACE_DRAW_ITEM;
3580 0 : drawTextLineBaseSegment(item, painter, opt);
3581 0 : }
3582 :
3583 50 : void TDraw::setMask(const EngravingItem* item, Painter* painter)
3584 : {
3585 50 : const EngravingItem::LayoutData* ldata = item->ldata();
3586 :
3587 50 : const Shape& mask = ldata->mask();
3588 50 : if (mask.empty()) {
3589 50 : return;
3590 : }
3591 :
3592 0 : RectF background = ldata->bbox().padded(item->spatium());
3593 :
3594 0 : painter->setMask(background, mask.toRects());
3595 : }
|