forked from emericg/MobileUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMobileUI.h
More file actions
158 lines (123 loc) · 5.81 KB
/
MobileUI.h
File metadata and controls
158 lines (123 loc) · 5.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*!
* Copyright (c) 2016 J-P Nurmi
* Copyright (c) 2023 Emeric Grange
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MOBILEUI_H
#define MOBILEUI_H
/* ************************************************************************** */
#include <QObject>
#include <QColor>
/* ************************************************************************** */
class MobileUI : public QObject
{
Q_OBJECT
Q_PROPERTY(Theme deviceTheme READ getDeviceTheme NOTIFY devicethemeUpdated)
Q_PROPERTY(QColor statusbarColor READ getStatusbarColor WRITE setStatusbarColor NOTIFY statusbarUpdated)
Q_PROPERTY(Theme statusbarTheme READ getStatusbarTheme WRITE setStatusbarTheme NOTIFY statusbarUpdated)
Q_PROPERTY(int statusbarHeight READ getStatusbarHeight NOTIFY statusbarUpdated)
Q_PROPERTY(QColor navbarColor READ getNavbarColor WRITE setNavbarColor NOTIFY navbarUpdated)
Q_PROPERTY(Theme navbarTheme READ getNavbarTheme WRITE setNavbarTheme NOTIFY navbarUpdated)
Q_PROPERTY(int navbarHeight READ getNavbarHeight NOTIFY navbarUpdated)
Q_PROPERTY(int safeAreaTop READ getSafeAreaTop NOTIFY safeAreaUpdated)
Q_PROPERTY(int safeAreaLeft READ getSafeAreaLeft NOTIFY safeAreaUpdated)
Q_PROPERTY(int safeAreaRight READ getSafeAreaRight NOTIFY safeAreaUpdated)
Q_PROPERTY(int safeAreaBottom READ getSafeAreaBottom NOTIFY safeAreaUpdated)
Q_PROPERTY(bool screenAlwaysOn READ getScreenAlwaysOn WRITE setScreenAlwaysOn NOTIFY screenUpdated)
Q_PROPERTY(ScreenOrientation screenOrientation READ getScreenOrientation WRITE setScreenOrientation NOTIFY screenUpdated)
Q_SIGNALS:
void devicethemeUpdated();
void statusbarUpdated();
void navbarUpdated();
void safeAreaUpdated();
void screenUpdated();
public:
explicit MobileUI(QObject *parent = nullptr) : QObject(parent) {}
static void registerQML();
// Device theme ////////////////////////////////////////////////////////////
enum Theme {
Light, //!< Light application theme, usually light background and dark texts.
Dark //!< Dark application theme, usually dark background and light texts.
};
Q_ENUM(Theme)
/*!
* \brief Get the theme currently in effect on this device.
* \note Not available yet on iOS.
* \return see MobileUI::Theme enum.
*/
static MobileUI::Theme getDeviceTheme();
// System bars /////////////////////////////////////////////////////////////
// Status bar
static QColor getStatusbarColor();
static void setStatusbarColor(const QColor &color);
static MobileUI::Theme getStatusbarTheme();
static void setStatusbarTheme(const MobileUI::Theme theme);
// Navigation bar
static QColor getNavbarColor();
static void setNavbarColor(const QColor &color);
static MobileUI::Theme getNavbarTheme();
static void setNavbarTheme(const MobileUI::Theme theme);
//! Refresh UI statusbar/navigationbar themes/colors
Q_INVOKABLE static void refreshUI();
// Screen safe areas ///////////////////////////////////////////////////////
static int getStatusbarHeight();
static int getNavbarHeight();
static int getSafeAreaTop();
static int getSafeAreaLeft();
static int getSafeAreaRight();
static int getSafeAreaBottom();
// Screen helpers //////////////////////////////////////////////////////////
enum ScreenOrientation {
Unlocked = 0,
Portrait = (1 << 0),
Portrait_upsidedown = (1 << 1),
Portrait_sensor = (1 << 2),
Landscape_left = (1 << 3),
Landscape_right = (1 << 4),
Landscape_sensor = (1 << 5),
};
Q_ENUM(ScreenOrientation)
MobileUI::ScreenOrientation getScreenOrientation();
/*!
* \brief Orientation locker.
* \param orientation: see MobileUI::ScreenOrientation enum.
* \note Portrait_sensor and Landscape_sensor aren't available on iOS.
*
* You can also achieve similar functionality through application manifest or plist:
* - https://developer.android.com/guide/topics/manifest/activity-element.html#screen
* - https://developer.apple.com/documentation/bundleresources/information_property_list/uisupportedinterfaceorientations
*/
Q_INVOKABLE static void setScreenOrientation(const MobileUI::ScreenOrientation orientation);
static bool getScreenAlwaysOn();
/*!
* \brief Lock screensaver.
* \param value: on or off
*/
Q_INVOKABLE static void setScreenAlwaysOn(const bool value);
// Other helpers ///////////////////////////////////////////////////////////
/*!
* \brief Trigger an haptic feedback.
*
* On Android the "android.permission.VIBRATE" must be added to the manifest.
*/
Q_INVOKABLE static void vibrate();
};
/* ************************************************************************** */
#endif // MOBILEUI_H