Overte C++ Documentation
VrMenu.h
1 //
2 // VrMenu.h
3 //
4 // Created by Bradley Austin Davis on 2015/04/21
5 // Copyright 2015 High Fidelity, Inc.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #pragma once
12 #ifndef hifi_VrMenu_h
13 #define hifi_VrMenu_h
14 
15 #include <QQuickItem>
16 #include <QHash>
17 #include <QList>
18 #include <QSignalMapper>
19 #include <QAction>
20 #include <QMenu>
21 #include <QUuid>
22 #include "OffscreenUi.h"
23 
24 
25 
26 // Binds together a Qt Action or Menu with the QML Menu or MenuItem
27 //
28 // TODO On reflection, it may be pointless to use the UUID. Perhaps
29 // simply creating the bidirectional link pointing to both the widget
30 // and qml object and inject the pointer into both objects
31 class MenuUserData : public QObject {
32  Q_OBJECT
33 public:
34  MenuUserData(QAction* action, QObject* qmlObject, QObject* qmlParent);
35  ~MenuUserData();
36  void updateQmlItemFromAction();
37  void clear();
38 
39  const QUuid uuid{ QUuid::createUuid() };
40 
41  static bool hasData(QAction* object);
42 
43  static MenuUserData* forObject(QAction* object);
44 
45 private:
46  Q_DISABLE_COPY(MenuUserData);
47 
48  static constexpr const char *USER_DATA{"user_data"};
49 
50  QMetaObject::Connection _shutdownConnection;
51  QMetaObject::Connection _changedConnection;
52  QAction* _action { nullptr };
53  QObject* _qml { nullptr };
54  QObject* _qmlParent{ nullptr };
55 };
56 
57 
58 
59 // FIXME break up the rendering code (VrMenu) and the code for mirroring a Widget based menu in QML
60 class VrMenu : public QObject {
61  Q_OBJECT
62 public:
63  VrMenu(OffscreenUi* parent = nullptr);
64  void addMenu(QMenu* menu);
65  void addAction(QMenu* parent, QAction* action);
66  void addSeparator(QMenu* parent);
67  void insertAction(QAction* before, QAction* action);
68  void removeAction(QAction* action);
69 
70 protected:
71  QObject* _rootMenu{ nullptr };
72  QObject* findMenuObject(const QString& name);
73 
74  friend class MenuUserData;
75  friend class OffscreenUi;
76 };
77 
78 #endif // hifi_VrMenu_h