MauiMan

formfactormanager.h
1#pragma once
2
3#include <QObject>
4#include <QRect>
5#include <QList>
6
7#include "mauiman_export.h"
8
9class QInputDevice;
10
11class QDBusInterface;
12namespace MauiMan
13{
14 class SettingsStore;
15
16 /**
17 * @brief The FormFactoInfo class contains information about the input devices available in the current system.
18 */
19 class MAUIMAN_EXPORT FormFactorInfo : public QObject
20 {
21 Q_OBJECT
22 /**
23 * The best fitted mode according to the available input devices and the screen size.
24 */
25 Q_PROPERTY(uint bestMode READ bestMode NOTIFY bestModeChanged FINAL)
26
27 /**
28 * The system preferred mode. This is picked up from the env var `QT_QUICK_CONTROLS_MOBILE`
29 */
30 Q_PROPERTY(uint defaultMode READ defaultMode CONSTANT FINAL)
31
32 /**
33 * Whether the device has a physical keyboard.
34 */
35 Q_PROPERTY(bool hasKeyboard READ hasKeyboard NOTIFY hasKeyboardChanged FINAL)
36
37 /**
38 * Whether the device has a touch screen.
39 */
40 Q_PROPERTY(bool hasTouchscreen READ hasTouchscreen NOTIFY hasTouchscreenChanged FINAL)
41
42 /**
43 * Whether the device has a physical mouse.
44 */
45 Q_PROPERTY(bool hasMouse READ hasMouse NOTIFY hasMouseChanged FINAL)
46
47 /**
48 * Whether the device has a trackpad or touchpad
49 */
50 Q_PROPERTY(bool hasTouchpad READ hasTouchpad NOTIFY hasTouchpadChanged)
51
52 /**
53 * The size of the main screen.
54 */
55 Q_PROPERTY(QRect screenSize READ screenSize NOTIFY screenSizeChanged)
56
57 /**
58 * The current orientation of the main screen.
59 */
60 Q_PROPERTY(Qt::ScreenOrientation screenOrientation READ screenOrientation NOTIFY screenOrientationChanged)
61
62 public:
63 /**
64 * @brief The possible form factor modes the system can have based on the device capabilities.
65 */
66 enum Mode
67 {
68 /**
69 * Is a desktop when the screen size if relative big, has a physical keyboard, mouse.
70 */
71 Desktop = 0,
72
73 /**
74 * Is a tablet when the devices has a relative big screen size, and it is a touch screen. There is not mouse present.
75 */
77
78 /**
79 * Is a mobile phone, the the screen size is small, has a touch screen and not peripheral input devices such as a a keyboard or mouse.
80 */
81 Phone
82 };
83
84 struct DefaultValues
85 {
86 [[nodiscard]] static uint getDefaultMode()
87 {
88
89 #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(UBUNTU_TOUCH)
91 #else
92
93 return QByteArrayList{"1", "true"}.contains(qgetenv("QT_QUICK_CONTROLS_MOBILE")) ? MauiMan::FormFactorInfo::Mode::Phone : MauiMan::FormFactorInfo::Mode::Desktop;
94 #endif
95 }
96
97 [[nodiscard]] static bool getHasTouchScreen()
98 {
99
100 #if defined(Q_OS_ANDROID) || defined(Q_OS_IOS) || defined(UBUNTU_TOUCH)
101 return true;
102 #else
103
104 return false;
105 #endif
106 }
107
108 static inline const uint defaultMode = DefaultValues::getDefaultMode();
109 static inline const bool hasTouchscreen = DefaultValues::getHasTouchScreen();
110 } ;
111
112 explicit FormFactorInfo(QObject *parent);
113
114 [[nodiscard]] uint bestMode() const;
115
116 [[nodiscard]] uint defaultMode() const;
117
118 [[nodiscard]] bool hasKeyboard() const;
119
120 [[nodiscard]] bool hasTouchscreen() const;
121
122 [[nodiscard]] bool hasMouse() const;
123
124 [[nodiscard]] bool hasTouchpad() const;
125
126 [[nodiscard]] QRect screenSize();
127 [[nodiscard]] Qt::ScreenOrientation screenOrientation();
128
129 private:
130 uint m_bestMode = FormFactorInfo::DefaultValues::defaultMode;
131
132 uint m_defaultMode = FormFactorInfo::DefaultValues::defaultMode;
133
134 bool m_hasKeyboard = true;
135
136 bool m_hasTouchscreen = FormFactorInfo::DefaultValues::hasTouchscreen;
137
138 bool m_hasMouse = true;
139 bool m_hasTouchpad = true;
140
141 QRect m_screenSize;
142 Qt::ScreenOrientation m_screenOrientation;
143
144 void checkInputs(const QList<const QInputDevice *> &devices);
145 void findBestMode();
146
147 Q_SIGNALS:
148 void bestModeChanged(uint bestMode);
149 void defaultModeChanged(uint defaultMode);
150
151 void hasKeyboardChanged(bool hasKeyboard);
152 void hasTouchscreenChanged(bool hasTouchscreen);
153 void hasMouseChanged(bool hasMouse);
154 void hasTouchpadChanged(bool hasTouchpad);
155
156 void screenSizeChanged(QRect screenSize);
157 void screenOrientationChanged(Qt::ScreenOrientation screenOrientation);
158 };
159
160 /**
161 * @brief The FormFactorManager class exposes all the system form factor properties.
162 */
163 class MAUIMAN_EXPORT FormFactorManager : public FormFactorInfo
164 {
165 Q_OBJECT
166 /**
167 * The preferred mode to display information. The possible values are:
168 * - 0 Desktop
169 * - 1 Tablet
170 * - 2 Phone
171 */
172 Q_PROPERTY(uint preferredMode READ preferredMode WRITE setPreferredMode NOTIFY preferredModeChanged FINAL)
173
174 /**
175 * If a device is not detected to have a touch screen , and still it has it, this property can be used to force allow the touch screen interactions.
176 */
177 Q_PROPERTY(bool forceTouchScreen READ forceTouchScreen WRITE setForceTouchScreen NOTIFY forceTouchScreenChanged)
178
179
180 public:
181 explicit FormFactorManager(QObject *parent = nullptr);
182
183 [[nodiscard]] uint preferredMode() const;
184 void setPreferredMode(uint preferredMode);
185
186 [[nodiscard]] bool forceTouchScreen() const;
187 void setForceTouchScreen(bool newForceTouchScreen);
188
189 private Q_SLOTS:
190 void onPreferredModeChanged(uint preferredMode);
191 void onForceTouchScreenChanged(bool value);
192
193 private:
194 #if !defined Q_OS_ANDROID
195 QDBusInterface *m_interface = nullptr;
196 #endif
197 MauiMan::SettingsStore *m_settings;
198 FormFactorInfo *m_info;
199
200 uint m_preferredMode;
201 bool m_forceTouchScreen = false;
202
203 void sync(const QString &key, const QVariant &value);
204 void setConnections();
205 void loadSettings();
206
207 Q_SIGNALS:
208 void preferredModeChanged(uint preferredMode);
209 void forceTouchScreenChanged(bool forceTouchScreen);
210 };
211}
The FormFactoInfo class contains information about the input devices available in the current system.
Mode
The possible form factor modes the system can have based on the device capabilities.
@ Desktop
Is a desktop when the screen size if relative big, has a physical keyboard, mouse.
@ Phone
Is a mobile phone, the the screen size is small, has a touch screen and not peripheral input devices ...
@ Tablet
Is a tablet when the devices has a relative big screen size, and it is a touch screen.
The FormFactorManager class exposes all the system form factor properties.
The SettingsStore class Allows to store and read settings for MauiMan from the local conf file.
The MauiMan name-space contains all of the available modules for configuring the Maui Applications an...
bool contains(const AT &value) const const
ScreenOrientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 20 2024 11:51:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.