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) 2026 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 :
23 : #include "jianpudurationline.h"
24 :
25 : #include "chord.h"
26 : #include "measure.h"
27 : #include "rest.h"
28 : #include "staff.h"
29 : #include "system.h"
30 :
31 : #include "log.h"
32 :
33 : using namespace mu;
34 :
35 : namespace mu::engraving {
36 : //---------------------------------------------------------
37 : // JianpuDurationLine
38 : //---------------------------------------------------------
39 :
40 29 : JianpuDurationLine::JianpuDurationLine(DummyParentOr<ChordRest> parent)
41 29 : : EngravingItem(ElementType::JIANPU_DURATION_LINE, parent)
42 : {
43 29 : setSelectable(false);
44 29 : }
45 :
46 : //---------------------------------------------------------
47 : // pagePos
48 : //---------------------------------------------------------
49 :
50 1 : PointF JianpuDurationLine::pagePos() const
51 : {
52 1 : const Measure* measure = chordRest() ? chordRest()->measure() : nullptr;
53 1 : const System* system = measure ? measure->system() : nullptr;
54 1 : if (system && system->staves().size() > staffIdx()) {
55 0 : if (const SysStaff* staff = system->staff(staffIdx())) {
56 0 : const double yp = y() + staff->y() + system->y();
57 0 : return PointF(pageX(), yp);
58 : }
59 : }
60 :
61 1 : return EngravingItem::pagePos();
62 : }
63 :
64 : //---------------------------------------------------------
65 : // mag
66 : //---------------------------------------------------------
67 :
68 222 : double JianpuDurationLine::mag() const
69 : {
70 222 : const EngravingObject* parent = ownershipParent();
71 222 : if (parent && parent->isRest()) {
72 46 : return toRest(parent)->mag();
73 : }
74 176 : if (parent && parent->isChord()) {
75 176 : return toChord(parent)->mag();
76 : }
77 0 : const Staff* st = staff();
78 0 : return st ? st->staffMag(this) : 1.0;
79 : }
80 :
81 : //---------------------------------------------------------
82 : // chord
83 : //---------------------------------------------------------
84 :
85 2 : ChordRest* JianpuDurationLine::chordRest() const
86 : {
87 2 : EngravingObject* parent = ownershipParent();
88 2 : if (parent && parent->isChordRest()) {
89 1 : return toChordRest(parent);
90 : } else {
91 1 : return nullptr;
92 : }
93 : }
94 : }
|