MuseScore  3.4
Music composition and notation
nativemenu.h
Go to the documentation of this file.
1 //=============================================================================
2 // MuseScore
3 // Music Composition & Notation
4 //
5 // Copyright (C) 2019 MuseScore BVBA
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License version 2.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //=============================================================================
19 
20 #ifndef __QML_NATIVEMENU_H__
21 #define __QML_NATIVEMENU_H__
22 
23 namespace Ms {
24 
25 //---------------------------------------------------------
26 // QmlNativeMenu
27 //---------------------------------------------------------
28 
29 class QmlNativeMenu : public QQuickItem {
30  Q_OBJECT
31 
32  QList<QObject*> _contentData;
33  QPoint pos;
34 
35  bool _visible = false;
36 
37  Q_PROPERTY(QQmlListProperty<QObject> contentData READ contentData CONSTANT)
38  Q_CLASSINFO("DefaultProperty", "contentData")
39 
40  Q_PROPERTY(int x READ x WRITE setX)
41  Q_PROPERTY(int y READ y WRITE setY)
42 
43  Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged)
44 
45  QQmlListProperty<QObject> contentData() { return QQmlListProperty<QObject>(this, _contentData); } // TODO: use different QQmlListProperty constructor?
46 
47  QMenu* createMenu() const;
48  void showMenu(QPoint p);
49 
50  signals:
51  void visibleChanged();
52 
53  public:
54  QmlNativeMenu(QQuickItem* parent = nullptr);
55 
56  int x() const { return pos.x(); }
57  int y() const { return pos.y(); }
58  void setX(int val) { pos.setX(val); }
59  void setY(int val) { pos.setY(val); }
60 
61  bool visible() const { return _visible; };
62 
63  Q_INVOKABLE void open();
64  Q_INVOKABLE void popup();
65  };
66 
67 //---------------------------------------------------------
68 // QmlMenuSeparator
69 //---------------------------------------------------------
70 
71 class QmlMenuSeparator : public QObject {
72  Q_OBJECT
73  public:
74  QmlMenuSeparator(QObject* parent = nullptr) : QObject(parent) {}
75  };
76 
77 //---------------------------------------------------------
78 // QmlMenuItem
79 //---------------------------------------------------------
80 
81 class QmlMenuItem : public QObject {
82  Q_OBJECT
83 
84  QString _text;
85  bool _checkable = false;
86  bool _checked = false;
87  bool _enabled = true;
88 
89  Q_PROPERTY(QString text MEMBER _text)
90  Q_PROPERTY(bool checkable MEMBER _checkable)
91  Q_PROPERTY(bool checked MEMBER _checked)
92  Q_PROPERTY(bool enabled MEMBER _enabled)
93 
94  signals:
95  void triggered(bool checked);
96 
97  public:
98  QmlMenuItem(QObject* parent = nullptr) : QObject(parent) {}
99 
100  const QString& text() const { return _text; }
101  bool checkable() const { return _checkable; }
102  bool checked() const { return _checked; }
103  bool enabled() const { return _enabled; }
104  };
105 
106 } // namespace Ms
107 #endif
bool enabled() const
Definition: nativemenu.h:103
bool _visible
Definition: nativemenu.h:35
bool visible() const
Definition: nativemenu.h:61
QList< QObject * > _contentData
Definition: nativemenu.h:32
Q_CLASSINFO("DefaultProperty", "contentData") Q_PROPERTY(int x READ x WRITE setX) Q_PROPERTY(int y READ y WRITE setY) Q_PROPERTY(bool visible READ visible NOTIFY visibleChanged) QQmlListProperty< QObject > contentData()
Definition: nativemenu.h:38
void showMenu(QPoint p)
Definition: nativemenu.cpp:59
QmlMenuSeparator(QObject *parent=nullptr)
Definition: nativemenu.h:74
Definition: nativemenu.h:81
Definition: nativemenu.h:29
QmlNativeMenu(QQuickItem *parent=nullptr)
Definition: nativemenu.cpp:28
void setY(int val)
Definition: nativemenu.h:59
QMenu * createMenu() const
Definition: nativemenu.cpp:36
int y() const
Definition: nativemenu.h:57
QQmlListProperty< QObject > contentData
Definition: nativemenu.h:37
Definition: aeolus.cpp:26
QString _text
Definition: nativemenu.h:84
void setX(int val)
Definition: nativemenu.h:58
Definition: nativemenu.h:71
Q_INVOKABLE void open()
Definition: nativemenu.cpp:76
Q_INVOKABLE void popup()
Definition: nativemenu.cpp:86
const QString & text() const
Definition: nativemenu.h:100
bool checked() const
Definition: nativemenu.h:102
int x() const
Definition: nativemenu.h:56
bool checkable() const
Definition: nativemenu.h:101
QPoint pos
Definition: nativemenu.h:33