Lomiri
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 keyPressEvent(QKeyEvent * event) override;
57  void keyReleaseEvent(QKeyEvent * event) override;
58 
59 Q_SIGNALS:
60  void shortcutChanged(const QVariant &shortcut);
64  void triggered(const QString &shortcut);
68  void released(const QString &shortcut);
69  void activeChanged(bool active);
70 
71 private:
72  QVariant m_shortcut;
73  bool m_active = true;
74 };
75 
76 
77 #endif // GLOBALSHORTCUT_H
The GlobalShortcut class.
void triggered(const QString &shortcut)
void released(const QString &shortcut)
QVariant shortcut