Changeset View
Changeset View
Standalone View
Standalone View
applets/appmenu/lib/appmenuapplet.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2016 Kai Uwe Broulik <kde@privat.broulik.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | * | ||||
20 | */ | ||||
21 | | ||||
22 | #pragma once | ||||
23 | | ||||
24 | #include <Plasma/Applet> | ||||
25 | #include <QPointer> | ||||
26 | | ||||
27 | class KDBusMenuImporter; | ||||
28 | class QQuickItem; | ||||
29 | class QMenu; | ||||
30 | class AppMenuModel; | ||||
31 | | ||||
32 | class AppMenuApplet : public Plasma::Applet | ||||
33 | { | ||||
34 | Q_OBJECT | ||||
35 | | ||||
36 | Q_PROPERTY(AppMenuModel* model READ model WRITE setModel NOTIFY modelChanged) | ||||
37 | | ||||
38 | Q_PROPERTY(int view READ view WRITE setView NOTIFY viewChanged) | ||||
39 | | ||||
40 | Q_PROPERTY(int currentIndex READ currentIndex NOTIFY currentIndexChanged) | ||||
41 | | ||||
42 | Q_PROPERTY(QQuickItem *buttonGrid READ buttonGrid WRITE setButtonGrid NOTIFY buttonGridChanged) | ||||
43 | | ||||
44 | public: | ||||
45 | enum ViewType { | ||||
46 | FullView, | ||||
47 | CompactView | ||||
48 | }; | ||||
49 | | ||||
50 | explicit AppMenuApplet(QObject *parent, const QVariantList &data); | ||||
51 | ~AppMenuApplet() override; | ||||
52 | | ||||
53 | void init() override; | ||||
54 | | ||||
55 | int currentIndex() const; | ||||
56 | | ||||
57 | QQuickItem *buttonGrid() const; | ||||
58 | void setButtonGrid(QQuickItem *buttonGrid); | ||||
59 | | ||||
60 | AppMenuModel *model() const; | ||||
61 | void setModel(AppMenuModel *model); | ||||
62 | | ||||
63 | int view() const; | ||||
64 | void setView(int type); | ||||
65 | | ||||
66 | Q_INVOKABLE void trigger(QQuickItem *ctx, int idx); | ||||
67 | | ||||
68 | signals: | ||||
69 | void modelChanged(); | ||||
70 | void viewChanged(); | ||||
71 | void currentIndexChanged(); | ||||
72 | void buttonGridChanged(); | ||||
73 | void requestActivateIndex(int index); | ||||
74 | | ||||
75 | protected: | ||||
76 | bool eventFilter(QObject *watched, QEvent *event); | ||||
77 | | ||||
78 | private: | ||||
79 | QMenu *createMenu(int idx) const; | ||||
80 | void setCurrentIndex(int currentIndex); | ||||
81 | void onMenuAboutToHide(); | ||||
82 | | ||||
83 | | ||||
84 | int m_currentIndex = -1; | ||||
85 | int m_viewType = FullView; | ||||
86 | QPointer<QMenu> m_currentMenu; | ||||
87 | QPointer<QQuickItem> m_buttonGrid; | ||||
88 | QPointer<AppMenuModel> m_model; | ||||
89 | }; |