Changeset View
Changeset View
Standalone View
Standalone View
applets/appmenu/plugin/appmenumodel.h
Show All 21 Lines | |||||
22 | #ifndef APPMENUMODEL_H | 22 | #ifndef APPMENUMODEL_H | ||
23 | #define APPMENUMODEL_H | 23 | #define APPMENUMODEL_H | ||
24 | 24 | | |||
25 | #include <QAbstractListModel> | 25 | #include <QAbstractListModel> | ||
26 | #include <QAbstractNativeEventFilter> | 26 | #include <QAbstractNativeEventFilter> | ||
27 | #include <QStringList> | 27 | #include <QStringList> | ||
28 | #include <KWindowSystem> | 28 | #include <KWindowSystem> | ||
29 | #include <QPointer> | 29 | #include <QPointer> | ||
30 | #include <QRect> | ||||
30 | 31 | | |||
31 | class QMenu; | 32 | class QMenu; | ||
32 | class QAction; | 33 | class QAction; | ||
33 | class QModelIndex; | 34 | class QModelIndex; | ||
34 | class QDBusServiceWatcher; | 35 | class QDBusServiceWatcher; | ||
35 | class KDBusMenuImporter; | 36 | class KDBusMenuImporter; | ||
36 | 37 | | |||
37 | class AppMenuModel : public QAbstractListModel, public QAbstractNativeEventFilter | 38 | class AppMenuModel : public QAbstractListModel, public QAbstractNativeEventFilter | ||
38 | { | 39 | { | ||
39 | Q_OBJECT | 40 | Q_OBJECT | ||
40 | 41 | | |||
41 | Q_PROPERTY(bool menuAvailable READ menuAvailable WRITE setMenuAvailable NOTIFY menuAvailableChanged) | 42 | Q_PROPERTY(bool menuAvailable READ menuAvailable WRITE setMenuAvailable NOTIFY menuAvailableChanged) | ||
43 | Q_PROPERTY(bool menuHidden READ menuHidden NOTIFY menuHiddenChanged) | ||||
44 | | ||||
45 | Q_PROPERTY(QRect screenGeometry READ screenGeometry WRITE setScreenGeometry NOTIFY screenGeometryChanged) | ||||
42 | 46 | | |||
43 | public: | 47 | public: | ||
44 | explicit AppMenuModel(QObject *parent = nullptr); | 48 | explicit AppMenuModel(QObject *parent = nullptr); | ||
45 | ~AppMenuModel() override; | 49 | ~AppMenuModel() override; | ||
46 | 50 | | |||
47 | enum AppMenuRole { | 51 | enum AppMenuRole { | ||
48 | MenuRole = Qt::UserRole+1, // TODO this should be Qt::DisplayRole | 52 | MenuRole = Qt::UserRole+1, // TODO this should be Qt::DisplayRole | ||
49 | ActionRole | 53 | ActionRole | ||
50 | }; | 54 | }; | ||
51 | 55 | | |||
52 | QVariant data(const QModelIndex &index, int role) const override; | 56 | QVariant data(const QModelIndex &index, int role) const override; | ||
53 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | 57 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; | ||
54 | QHash<int, QByteArray> roleNames() const override; | 58 | QHash<int, QByteArray> roleNames() const override; | ||
55 | 59 | | |||
56 | void updateApplicationMenu(const QString &serviceName, const QString &menuObjectPath); | 60 | void updateApplicationMenu(const QString &serviceName, const QString &menuObjectPath); | ||
57 | 61 | | |||
58 | bool menuAvailable() const; | 62 | bool menuAvailable() const; | ||
59 | void setMenuAvailable(bool set); | 63 | void setMenuAvailable(bool set); | ||
60 | 64 | | |||
65 | bool menuHidden() const; | ||||
66 | | ||||
67 | QRect screenGeometry() const; | ||||
68 | void setScreenGeometry(QRect geometry); | ||||
69 | | ||||
61 | signals: | 70 | signals: | ||
62 | void requestActivateIndex(int index); | 71 | void requestActivateIndex(int index); | ||
63 | 72 | | |||
64 | protected: | 73 | protected: | ||
65 | bool nativeEventFilter(const QByteArray &eventType, void *message, long int *result) override; | 74 | bool nativeEventFilter(const QByteArray &eventType, void *message, long int *result) override; | ||
66 | 75 | | |||
67 | private Q_SLOTS: | 76 | private Q_SLOTS: | ||
68 | void onActiveWindowChanged(WId id); | 77 | void onActiveWindowChanged(WId id); | ||
78 | void onWindowChanged(WId id); | ||||
79 | void setMenuHidden(bool hide); | ||||
69 | void update(); | 80 | void update(); | ||
70 | 81 | | |||
71 | signals: | 82 | signals: | ||
72 | void menuAvailableChanged(); | 83 | void menuAvailableChanged(); | ||
84 | void menuHiddenChanged(); | ||||
73 | void modelNeedsUpdate(); | 85 | void modelNeedsUpdate(); | ||
86 | void screenGeometryChanged(); | ||||
74 | 87 | | |||
75 | private: | 88 | private: | ||
76 | bool m_menuAvailable; | 89 | bool m_menuAvailable; | ||
90 | bool m_menuHidden = false; | ||||
77 | bool m_updatePending = false; | 91 | bool m_updatePending = false; | ||
78 | 92 | | |||
93 | QRect m_screenGeometry; | ||||
94 | | ||||
95 | //! current active window used | ||||
79 | WId m_currentWindowId = 0; | 96 | WId m_currentWindowId = 0; | ||
97 | //! window that its menu initialization may be delayed | ||||
98 | WId m_delayedMenuWindowId = 0; | ||||
80 | 99 | | |||
81 | QPointer<QMenu> m_menu; | 100 | QPointer<QMenu> m_menu; | ||
82 | 101 | | |||
83 | QDBusServiceWatcher *m_serviceWatcher; | 102 | QDBusServiceWatcher *m_serviceWatcher; | ||
84 | QString m_serviceName; | 103 | QString m_serviceName; | ||
85 | QString m_menuObjectPath; | 104 | QString m_menuObjectPath; | ||
86 | 105 | | |||
87 | QPointer<KDBusMenuImporter> m_importer; | 106 | QPointer<KDBusMenuImporter> m_importer; | ||
88 | }; | 107 | }; | ||
89 | 108 | | |||
90 | #endif | 109 | #endif |