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 * \qmltype Settings
21 * \inqmlmodule org.kde.kirigami.platform
22 *
23 * \brief Provides global kirigami settings about
24 * the current device setup under the singleton "Settings".
25 */
26class KIRIGAMIPLATFORM_EXPORT Settings : public QObject
27{
28 Q_OBJECT
29 QML_ELEMENT
30 QML_SINGLETON
31
32 /*!
33 * \qmlproperty bool Settings::tabletModeAvailable
34 *
35 * This property holds whether the system can dynamically enter and exit tablet mode
36 * (or the device is actually a tablet).
37 * This is the case for foldable convertibles and transformable laptops that support
38 * keyboard detachment.
39 */
40 Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged FINAL)
41
42 /*!
43 * \qmlproperty bool Settings::isMobile
44 *
45 * This property holds whether the application is running on a small mobile device
46 * such as a mobile phone. This is used when we want to do specific adaptations to
47 * the UI for small screen form factors, such as having bigger touch areas.
48 */
49 Q_PROPERTY(bool isMobile READ isMobile NOTIFY isMobileChanged FINAL)
50
51 /*!
52 * \qmlproperty bool Settings::tabletMode
53 *
54 * This property holds whether the application is running on a device that is
55 * behaving like a tablet.
56 *
57 * \note This doesn't mean exactly a tablet form factor, but
58 * that the preferred input mode for the device is the touch screen
59 * and that pointer and keyboard are either secondary or not available.
60 */
61 Q_PROPERTY(bool tabletMode READ tabletMode NOTIFY tabletModeChanged FINAL)
62
63 /*!
64 * \qmlproperty bool Settings::hasPlatformMenuBar
65 *
66 * This property holds whether the system has a platform menu bar; e.g. a user is
67 * on macOS or has a global menu on KDE Plasma.
68 *
69 * \warning Android has a platform menu bar; which may not be what you expected.
70 */
71 Q_PROPERTY(bool hasPlatformMenuBar READ hasPlatformMenuBar CONSTANT FINAL)
72
73 /*!
74 * \qmlproperty bool Settings::hasTransientTouchInput
75 *
76 * This property holds whether the user in this moment is interacting with the app
77 * with the touch screen.
78 */
79 Q_PROPERTY(bool hasTransientTouchInput READ hasTransientTouchInput NOTIFY hasTransientTouchInputChanged FINAL)
80
81 /*!
82 * \qmlproperty string Settings::style
83 *
84 * This property holds the name of the QtQuickControls2 style the application is using,
85 * for instance org.kde.desktop, Plasma, Material, Universal etc
86 */
87 Q_PROPERTY(QString style READ style CONSTANT FINAL)
88
89 // TODO: make this adapt without file watchers?
90 /*!
91 * \qmlproperty int Settings::mouseWheelScrollLines
92 *
93 * This property holds the number of lines of text the mouse wheel should scroll.
94 */
95 Q_PROPERTY(int mouseWheelScrollLines READ mouseWheelScrollLines CONSTANT FINAL)
96
97 /*!
98 * \qmlproperty bool Settings::smoothScroll
99 *
100 * This property holds whether to display animated transitions when scrolling with a
101 * mouse wheel or the keyboard.
102 */
103 Q_PROPERTY(bool smoothScroll READ smoothScroll NOTIFY smoothScrollChanged FINAL)
104
105 /*!
106 * \qmlproperty list<string> Settings::information
107 *
108 * This property holds the runtime information about the libraries in use.
109 *
110 * \since 5.52
111 * \since org.kde.kirigami 2.6
112 */
113 Q_PROPERTY(QStringList information READ information CONSTANT FINAL)
114
115 /*!
116 * \qmlproperty var Settings::applicationWindowIcon
117 * This property holds the name of the application window icon.
118 * \sa QGuiApplication::windowIcon()
119 *
120 * \since 5.62
121 * \since org.kde.kirigami 2.10
122 */
123 Q_PROPERTY(QVariant applicationWindowIcon READ applicationWindowIcon CONSTANT FINAL)
124
125public:
126 Settings(QObject *parent = nullptr);
127 ~Settings() override;
128
129 void setTabletModeAvailable(bool mobile);
130 bool isTabletModeAvailable() const;
131
132 void setIsMobile(bool mobile);
133 bool isMobile() const;
134
135 void setTabletMode(bool tablet);
136 bool tabletMode() const;
137
138 void setTransientTouchInput(bool touch);
139 bool hasTransientTouchInput() const;
140
141 bool hasPlatformMenuBar() const;
142
143 QString style() const;
144 void setStyle(const QString &style);
145
146 int mouseWheelScrollLines() const;
147
148 bool smoothScroll() const;
149
150 QStringList information() const;
151
152 QVariant applicationWindowIcon() const;
153
154protected:
155 bool eventFilter(QObject *watched, QEvent *event) override;
156
157Q_SIGNALS:
158 void tabletModeAvailableChanged();
159 void tabletModeChanged();
160 void isMobileChanged();
161 void hasTransientTouchInputChanged();
162 void smoothScrollChanged();
163
164private:
165 QString m_style;
166 int m_scrollLines = 0;
167 bool m_smoothScroll : 1;
168 bool m_tabletModeAvailable : 1;
169 bool m_mobile : 1;
170 bool m_tabletMode : 1;
171 bool m_hasTouchScreen : 1;
172 bool m_hasTransientTouchInput : 1;
173 bool m_hasPlatformMenuBar : 1;
174};
175
176}
177}
178
179#endif
180

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