1 | /* |
2 | * SPDX-FileCopyrightText: 2018 Marco Martin <mart@kde.org> |
3 | * |
4 | * SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KIRIGAMI_TABLETMODEWATCHER_H |
8 | #define KIRIGAMI_TABLETMODEWATCHER_H |
9 | |
10 | #include <QEvent> |
11 | #include <QObject> |
12 | |
13 | #include "kirigamiplatform_export.h" |
14 | |
15 | namespace Kirigami |
16 | { |
17 | namespace Platform |
18 | { |
19 | class TabletModeWatcherPrivate; |
20 | |
21 | class KIRIGAMIPLATFORM_EXPORT TabletModeChangedEvent : public QEvent |
22 | { |
23 | public: |
24 | TabletModeChangedEvent(bool tablet) |
25 | : QEvent(TabletModeChangedEvent::type) |
26 | , tabletMode(tablet) |
27 | { |
28 | } |
29 | |
30 | bool tabletMode = false; |
31 | |
32 | inline static QEvent::Type type = QEvent::None; |
33 | }; |
34 | |
35 | /** |
36 | * @class TabletModeWatcher tabletmodewatcher.h <Kirigami/TabletModeWatcher> |
37 | * |
38 | * This class reports on the status of certain transformable |
39 | * devices which can be both tablets and laptops at the same time, |
40 | * with a detachable keyboard. |
41 | * It reports whether the device supports a tablet mode and if |
42 | * the device is currently in such mode or not, emitting a signal |
43 | * when the user switches. |
44 | */ |
45 | class KIRIGAMIPLATFORM_EXPORT TabletModeWatcher : public QObject |
46 | { |
47 | Q_OBJECT |
48 | |
49 | Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged FINAL) |
50 | Q_PROPERTY(bool tabletMode READ isTabletMode NOTIFY tabletModeChanged FINAL) |
51 | |
52 | public: |
53 | ~TabletModeWatcher() override; |
54 | static TabletModeWatcher *self(); |
55 | |
56 | /** |
57 | * @returns true if the device supports a tablet mode and has a switch |
58 | * to report when the device has been transformed. |
59 | * For debug purposes, if either the environment variable QT_QUICK_CONTROLS_MOBILE |
60 | * or KDE_KIRIGAMI_TABLET_MODE are set to true, isTabletModeAvailable will be true |
61 | */ |
62 | bool isTabletModeAvailable() const; |
63 | |
64 | /** |
65 | * @returns true if the machine is now in tablet mode, such as the |
66 | * laptop keyboard flipped away or detached. |
67 | * Note that this doesn't mean exactly a tablet form factor, but |
68 | * that the preferred input mode for the device is the touch screen |
69 | * and that pointer and keyboard are either secondary or not available. |
70 | * |
71 | * For debug purposes, if either the environment variable QT_QUICK_CONTROLS_MOBILE |
72 | * or KDE_KIRIGAMI_TABLET_MODE are set to true, isTabletMode will be true |
73 | */ |
74 | bool isTabletMode() const; |
75 | |
76 | /** |
77 | * Register an arbitrary QObject to send events from this. |
78 | * At the moment only one event will be sent: TabletModeChangedEvent |
79 | */ |
80 | void addWatcher(QObject *watcher); |
81 | |
82 | /* |
83 | * Unsubscribe watcher from receiving events from TabletModeWatcher. |
84 | */ |
85 | void removeWatcher(QObject *watcher); |
86 | |
87 | Q_SIGNALS: |
88 | void tabletModeAvailableChanged(bool tabletModeAvailable); |
89 | void tabletModeChanged(bool tabletMode); |
90 | |
91 | private: |
92 | KIRIGAMIPLATFORM_NO_EXPORT explicit TabletModeWatcher(QObject *parent = nullptr); |
93 | TabletModeWatcherPrivate *d; |
94 | friend class TabletModeWatcherSingleton; |
95 | }; |
96 | |
97 | } |
98 | } |
99 | |
100 | #endif // KIRIGAMI_TABLETMODEWATCHER |
101 | |