1/*
2 * SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#ifndef SETTINGS_H
7#define SETTINGS_H
8
9#include <QObject>
10#include <QVariant>
11#include <qqmlregistration.h>
12
13#include "kirigamiplatform_export.h"
14
15namespace Kirigami
16{
17namespace Platform
18{
19/**
20 * This class contains global kirigami settings about the current device setup
21 * It is exposed to QML as the singleton "Settings"
22 */
23class KIRIGAMIPLATFORM_EXPORT Settings : public QObject
24{
25 Q_OBJECT
26 QML_ELEMENT
27 QML_SINGLETON
28
29 /**
30 * This property holds whether the system can dynamically enter and exit tablet mode
31 * (or the device is actually a tablet).
32 * This is the case for foldable convertibles and transformable laptops that support
33 * keyboard detachment.
34 */
35 Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged FINAL)
36
37 /**
38 * This property holds whether the application is running on a small mobile device
39 * such as a mobile phone. This is used when we want to do specific adaptations to
40 * the UI for small screen form factors, such as having bigger touch areas.
41 */
42 Q_PROPERTY(bool isMobile READ isMobile NOTIFY isMobileChanged FINAL)
43
44 /**
45 * This property holds whether the application is running on a device that is
46 * behaving like a tablet.
47 *
48 * @note This doesn't mean exactly a tablet form factor, but
49 * that the preferred input mode for the device is the touch screen
50 * and that pointer and keyboard are either secondary or not available.
51 */
52 Q_PROPERTY(bool tabletMode READ tabletMode NOTIFY tabletModeChanged FINAL)
53
54 /**
55 * This property holds whether the system has a platform menu bar; e.g. a user is
56 * on macOS or has a global menu on KDE Plasma.
57 *
58 * @warning Android has a platform menu bar; which may not be what you expected.
59 */
60 Q_PROPERTY(bool hasPlatformMenuBar READ hasPlatformMenuBar CONSTANT FINAL)
61
62 /**
63 * This property holds whether the user in this moment is interacting with the app
64 * with the touch screen.
65 */
66 Q_PROPERTY(bool hasTransientTouchInput READ hasTransientTouchInput NOTIFY hasTransientTouchInputChanged FINAL)
67
68 /**
69 * This property holds the name of the QtQuickControls2 style the application is using,
70 * for instance org.kde.desktop, Plasma, Material, Universal etc
71 */
72 Q_PROPERTY(QString style READ style CONSTANT FINAL)
73
74 // TODO: make this adapt without file watchers?
75 /**
76 * This property holds the number of lines of text the mouse wheel should scroll.
77 */
78 Q_PROPERTY(int mouseWheelScrollLines READ mouseWheelScrollLines CONSTANT FINAL)
79
80 /**
81 * This property holds the runtime information about the libraries in use.
82 *
83 * @since 5.52
84 * @since org.kde.kirigami 2.6
85 */
86 Q_PROPERTY(QStringList information READ information CONSTANT FINAL)
87
88 /**
89 * This property holds the name of the application window icon.
90 * @see QGuiApplication::windowIcon()
91 *
92 * @since 5.62
93 * @since org.kde.kirigami 2.10
94 */
95 Q_PROPERTY(QVariant applicationWindowIcon READ applicationWindowIcon CONSTANT FINAL)
96
97public:
98 Settings(QObject *parent = nullptr);
99 ~Settings() override;
100
101 void setTabletModeAvailable(bool mobile);
102 bool isTabletModeAvailable() const;
103
104 void setIsMobile(bool mobile);
105 bool isMobile() const;
106
107 void setTabletMode(bool tablet);
108 bool tabletMode() const;
109
110 void setTransientTouchInput(bool touch);
111 bool hasTransientTouchInput() const;
112
113 bool hasPlatformMenuBar() const;
114
115 QString style() const;
116 void setStyle(const QString &style);
117
118 int mouseWheelScrollLines() const;
119
120 QStringList information() const;
121
122 QVariant applicationWindowIcon() const;
123
124protected:
125 bool eventFilter(QObject *watched, QEvent *event) override;
126
127Q_SIGNALS:
128 void tabletModeAvailableChanged();
129 void tabletModeChanged();
130 void isMobileChanged();
131 void hasTransientTouchInputChanged();
132
133private:
134 QString m_style;
135 int m_scrollLines = 0;
136 bool m_tabletModeAvailable : 1;
137 bool m_mobile : 1;
138 bool m_tabletMode : 1;
139 bool m_hasTouchScreen : 1;
140 bool m_hasTransientTouchInput : 1;
141 bool m_hasPlatformMenuBar : 1;
142};
143
144}
145}
146
147#endif
148

source code of kirigami/src/platform/settings.h