Unity 8
globalshortcut.h
1 /*
2  * Copyright (C) 2015 Canonical, Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 3.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef GLOBALSHORTCUT_H
18 #define GLOBALSHORTCUT_H
19 
20 #include <QVariant>
21 #include <QQuickWindow>
22 #include <QQuickItem>
23 
33 class GlobalShortcut: public QQuickItem
34 {
35  Q_OBJECT
39  Q_PROPERTY(QVariant shortcut READ shortcut WRITE setShortcut NOTIFY shortcutChanged)
43  Q_PROPERTY(bool active READ isActive WRITE setActive NOTIFY activeChanged)
44 
45 public:
46  GlobalShortcut(QQuickItem *parent = nullptr);
47  ~GlobalShortcut() = default;
48 
49  QVariant shortcut() const;
50  void setShortcut(const QVariant &shortcut);
51 
52  bool isActive() const;
53  void setActive(bool active);
54 
55 protected:
56  void componentComplete() override;
57  void keyPressEvent(QKeyEvent * event) override;
58 
59 Q_SIGNALS:
60  void shortcutChanged(const QVariant &shortcut);
64  void triggered(const QString &shortcut);
65  void activeChanged(bool active);
66 
67 private Q_SLOTS:
68  void setupFilterOnWindow(QQuickWindow* window);
69 
70 private:
71  QVariant m_shortcut;
72  bool m_active = true;
73 };
74 
75 
76 #endif // GLOBALSHORTCUT_H
void triggered(const QString &shortcut)
The GlobalShortcut class.