| 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 | /*! |
| 22 | * \class Kirigami::Platform::TabletModeChangedEvent |
| 23 | * \inmodule KirigamiPlatform |
| 24 | * \inheaderfile Kirigami/Platform/TabletModeWatcher |
| 25 | * |
| 26 | * \brief Event sent by TabletModeWatcher when the tablet mode changes. |
| 27 | * |
| 28 | * \sa TabletModeWatcher |
| 29 | */ |
| 30 | class KIRIGAMIPLATFORM_EXPORT TabletModeChangedEvent : public QEvent |
| 31 | { |
| 32 | public: |
| 33 | TabletModeChangedEvent(bool tablet) |
| 34 | : QEvent(TabletModeChangedEvent::type) |
| 35 | , tabletMode(tablet) |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | bool tabletMode = false; |
| 40 | |
| 41 | inline static QEvent::Type type = QEvent::None; |
| 42 | }; |
| 43 | |
| 44 | /*! |
| 45 | * \class Kirigami::Platform::TabletModeWatcher |
| 46 | * \inmodule KirigamiPlatform |
| 47 | * \inheaderfile Kirigami/Platform/TabletModeWatcher |
| 48 | * |
| 49 | * \brief This class reports on the status of certain transformable |
| 50 | * devices which can be both tablets and laptops at the same time, |
| 51 | * with a detachable keyboard. |
| 52 | * |
| 53 | * It reports whether the device supports a tablet mode and if |
| 54 | * the device is currently in such mode or not, emitting a signal |
| 55 | * when the user switches. |
| 56 | */ |
| 57 | class KIRIGAMIPLATFORM_EXPORT TabletModeWatcher : public QObject |
| 58 | { |
| 59 | Q_OBJECT |
| 60 | |
| 61 | /*! |
| 62 | * \property Kirigami::Platform::TabletModeWatcher::tabletModeAvailable |
| 63 | * |
| 64 | * \c true if the device supports a tablet mode and has a switch |
| 65 | * to report when the device has been transformed. |
| 66 | * |
| 67 | * For debug purposes, if either the environment variable QT_QUICK_CONTROLS_MOBILE |
| 68 | * or KDE_KIRIGAMI_TABLET_MODE are set to true, tabletModeAvailable will be true |
| 69 | */ |
| 70 | Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged FINAL) |
| 71 | |
| 72 | /*! |
| 73 | * \property Kirigami::Platform::TabletModeWatcher::tabletMode |
| 74 | * |
| 75 | * \c true if the machine is now in tablet mode, such as the |
| 76 | * laptop keyboard flipped away or detached. |
| 77 | * |
| 78 | * Note that this doesn't mean exactly a tablet form factor, but |
| 79 | * that the preferred input mode for the device is the touch screen |
| 80 | * and that pointer and keyboard are either secondary or not available. |
| 81 | * |
| 82 | * For debug purposes, if either the environment variable QT_QUICK_CONTROLS_MOBILE |
| 83 | * or KDE_KIRIGAMI_TABLET_MODE are set to true, tabletMode will be true |
| 84 | */ |
| 85 | Q_PROPERTY(bool tabletMode READ isTabletMode NOTIFY tabletModeChanged FINAL) |
| 86 | |
| 87 | public: |
| 88 | ~TabletModeWatcher() override; |
| 89 | static TabletModeWatcher *self(); |
| 90 | |
| 91 | bool isTabletModeAvailable() const; |
| 92 | |
| 93 | bool isTabletMode() const; |
| 94 | |
| 95 | /*! |
| 96 | * Register an arbitrary QObject to send events from this. |
| 97 | * At the moment only one event will be sent: TabletModeChangedEvent |
| 98 | */ |
| 99 | void addWatcher(QObject *watcher); |
| 100 | |
| 101 | /*! |
| 102 | * Unsubscribe watcher from receiving events from TabletModeWatcher. |
| 103 | */ |
| 104 | void removeWatcher(QObject *watcher); |
| 105 | |
| 106 | Q_SIGNALS: |
| 107 | void tabletModeAvailableChanged(bool tabletModeAvailable); |
| 108 | void tabletModeChanged(bool tabletMode); |
| 109 | |
| 110 | private: |
| 111 | KIRIGAMIPLATFORM_NO_EXPORT explicit TabletModeWatcher(QObject *parent = nullptr); |
| 112 | TabletModeWatcherPrivate *d; |
| 113 | friend class TabletModeWatcherSingleton; |
| 114 | }; |
| 115 | |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | #endif // KIRIGAMI_TABLETMODEWATCHER |
| 120 | |