Kirigami2

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

KDE's Doxygen guidelines are available online.