Lomiri
Loading...
Searching...
No Matches
windowinputfilter.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 LOMIRI_WINDOWINPUTFILTER_H
20#define LOMIRI_WINDOWINPUTFILTER_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 WindowInputFilter 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 WindowInputFilter per QML scene.
35 */
36class WindowInputFilter : public QQuickItem
37{
38 Q_OBJECT
39 Q_PROPERTY(ulong lastInputTimestamp READ lastInputTimestamp NOTIFY lastInputTimestampChanged)
40public:
41 WindowInputFilter(QQuickItem *parent = 0);
42
43 bool eventFilter(QObject *watched, QEvent *event) override;
44
45 ulong lastInputTimestamp() const;
46
47Q_SIGNALS:
48 void lastInputTimestampChanged();
49
50private Q_SLOTS:
51 void setupFilterOnWindow(QQuickWindow *window);
52
53private:
54 QPointer<QQuickWindow> m_filteredWindow;
55 ulong m_lastInputTimestamp;
56};
57
58#endif // LOMIRI_WINDOWINPUTFILTER_H