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) 2022 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 : #pragma once
23 :
24 : #include <QObject>
25 : #include <qqmlintegration.h>
26 :
27 : #include "async/asyncable.h"
28 :
29 : #include "modularity/ioc.h"
30 : #include "project/iprojectsession.h"
31 :
32 : #include "engraving/dom/engravingitem.h"
33 :
34 : namespace mu::notation {
35 : class AbstractElementPopupModel : public QObject, public muse::Contextable, public muse::async::Asyncable
36 : {
37 : Q_OBJECT
38 : QML_ELEMENT;
39 : QML_UNCREATABLE("Not creatable as it is an abstract base class")
40 :
41 : Q_PROPERTY(PopupModelType modelType READ modelType CONSTANT)
42 : Q_PROPERTY(QRect itemRect READ itemRect NOTIFY itemRectChanged)
43 :
44 : public:
45 : muse::ContextInject<project::IProjectSession> projectSession = { this };
46 :
47 : public:
48 : enum class PopupModelType {
49 : TYPE_UNDEFINED = -1,
50 : TYPE_HARP_DIAGRAM,
51 : TYPE_CAPO,
52 : TYPE_STRING_TUNINGS,
53 : TYPE_SOUND_FLAG,
54 : TYPE_STAFF_VISIBILITY,
55 : TYPE_DYNAMIC,
56 : TYPE_TEXT,
57 : TYPE_PARTIAL_TIE,
58 : TYPE_SHADOW_NOTE,
59 : TYPE_STAVE_SHARING_CHANGE
60 : };
61 0 : Q_ENUM(PopupModelType)
62 :
63 : AbstractElementPopupModel(PopupModelType modelType, QObject* parent = nullptr);
64 :
65 : PopupModelType modelType() const;
66 : QRect itemRect() const;
67 :
68 : static bool hasElementEditPopup(const engraving::EngravingItem* element);
69 : static bool hasTextStylePopup(const engraving::EngravingItem* element);
70 : static PopupModelType modelTypeFromElement(const engraving::ElementType& elementType);
71 :
72 : Q_INVOKABLE virtual void init();
73 :
74 : signals:
75 : void dataChanged();
76 : void itemRectChanged(QRect rect);
77 :
78 : protected:
79 : virtual void updateItemRect();
80 0 : virtual bool ignoreTextEditingChanges() const { return true; }
81 :
82 : muse::PointF fromLogical(muse::PointF point) const;
83 : muse::RectF fromLogical(muse::RectF rect) const;
84 :
85 : notation::INotationUndoStackPtr undoStack() const;
86 : void beginCommand(const muse::TranslatableString& actionName);
87 : void beginMultiCommands(const muse::TranslatableString& actionName);
88 : void endCommand();
89 : void endMultiCommands();
90 : void updateNotation();
91 : notation::INotationPtr currentNotation() const;
92 : INotationInteractionPtr interaction() const;
93 :
94 : void changeItemProperty(engraving::Pid id, const engraving::PropertyValue& value);
95 : void changeItemProperty(engraving::Pid id, const engraving::PropertyValue& value, engraving::PropertyFlags flags);
96 :
97 : engraving::EngravingItem* m_item = nullptr;
98 : QRect m_itemRect;
99 :
100 : private:
101 : INotationSelectionPtr selection() const;
102 :
103 : engraving::ElementType elementType() const;
104 : const engraving::ElementTypeSet& dependentElementTypes() const;
105 :
106 : PopupModelType m_modelType = PopupModelType::TYPE_UNDEFINED;
107 : };
108 :
109 : using PopupModelType = AbstractElementPopupModel::PopupModelType;
110 :
111 : inline size_t qHash(mu::notation::PopupModelType key)
112 : {
113 : return ::qHash(int(key));
114 : }
115 : }
|