Unity 8
windowkeysfilter.h
1 /*
2  * Copyright (C) 2014 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  * Author: Daniel d'Andrada <daniel.dandrada@canonical.com>
17  */
18 
19 #ifndef UNITY_WINDOWKEYSFILTER_H
20 #define UNITY_WINDOWKEYSFILTER_H
21 
22 #include <QQuickItem>
23 #include <QPointer>
24 
25 /*
26  Receives all key events that arrive in the QQuickWindow where this item is placed.
27 
28  Rejected key events will be allowed to be processed normally by the QQuickWindow whereas
29  accepted ones will be filtered out. Events are accepted by default, so make sure you reject
30  the keys you're not interested in.
31 
32  If more than one WindowKeysFilter exist in the same QML scene (and thus in the same QQuickWindow)
33  they will be called in the order of creation, which can be tricky to assess. So the best practice
34  is to have at most one WindowKeysFilter per QML scene.
35  */
36 class WindowKeysFilter : public QQuickItem
37 {
38  Q_OBJECT
39  Q_PROPERTY(ulong currentEventTimestamp READ currentEventTimestamp NOTIFY currentEventTimestampChanged)
40 public:
41  WindowKeysFilter(QQuickItem *parent = 0);
42 
43  bool eventFilter(QObject *watched, QEvent *event) override;
44 
45  ulong currentEventTimestamp() const;
46 
47 Q_SIGNALS:
48  void currentEventTimestampChanged();
49 
50 private Q_SLOTS:
51  void setupFilterOnWindow(QQuickWindow *window);
52 
53 private:
54  QPointer<QQuickWindow> m_filteredWindow;
55  ulong m_currentEventTimestamp;
56 };
57 
58 #endif // UNITY_WINDOWKEYSFILTER_H