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) 2024 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 <QPainter>
24 : #include "paintedengravingitem.h"
25 :
26 : #include "notationscene/utilities/engravingitempreviewpainter.h"
27 :
28 : using namespace mu::notation;
29 :
30 0 : PaintedEngravingItem::PaintedEngravingItem(QQuickItem* parent)
31 0 : : QQuickPaintedItem(parent)
32 : {
33 0 : }
34 :
35 0 : QVariant PaintedEngravingItem::engravingItemVariant() const
36 : {
37 0 : return QVariant::fromValue(m_item);
38 : }
39 :
40 0 : void PaintedEngravingItem::setEngravingItemVariant(QVariant engravingItemVariant)
41 : {
42 0 : mu::engraving::ElementPtr item = engravingItemVariant.value<mu::engraving::ElementPtr>();
43 0 : if (item == m_item) {
44 0 : return;
45 : }
46 0 : m_item = item;
47 :
48 0 : update();
49 0 : emit engravingItemVariantChanged();
50 0 : }
51 :
52 0 : int PaintedEngravingItem::numStaffLines() const
53 : {
54 0 : return m_numStaffLines;
55 : }
56 :
57 0 : void PaintedEngravingItem::setNumStaffLines(int numStaffLines)
58 : {
59 0 : if (m_numStaffLines == numStaffLines) {
60 0 : return;
61 : }
62 0 : m_numStaffLines = numStaffLines;
63 :
64 0 : update();
65 0 : emit numStaffLinesChanged();
66 : }
67 :
68 0 : double PaintedEngravingItem::spatium() const
69 : {
70 0 : return m_spatium;
71 : }
72 :
73 0 : void PaintedEngravingItem::setSpatium(double spatium)
74 : {
75 0 : if (spatium == m_spatium) {
76 0 : return;
77 : }
78 0 : m_spatium = spatium;
79 :
80 0 : update();
81 0 : emit spatiumChanged();
82 : }
83 :
84 0 : void PaintedEngravingItem::paint(QPainter* painter)
85 : {
86 0 : muse::draw::Painter p(painter, "paintedengravingitem");
87 0 : p.save();
88 0 : p.setAntialiasing(true);
89 0 : paintNotationPreview(p);
90 0 : p.restore();
91 0 : }
92 :
93 0 : void PaintedEngravingItem::paintNotationPreview(muse::draw::Painter& painter) const
94 : {
95 0 : IF_ASSERT_FAILED(m_item) {
96 0 : return;
97 : }
98 :
99 0 : EngravingItemPreviewPainter::PaintParams params;
100 0 : params.painter = &painter;
101 0 : params.color = configuration()->defaultColor();
102 0 : params.rect = muse::RectF(0, 0, parentItem()->width(), parentItem()->height());
103 0 : params.spatium = m_spatium;
104 0 : params.numStaffLines = m_numStaffLines;
105 :
106 0 : EngravingItemPreviewPainter::paintPreview(renderer(), m_item.get(), params);
107 : }
|