File indexing completed on 2024-05-05 03:56:27
0001 /* 0002 * SPDX-FileCopyrightText: 2016 Marco Martin <mart@kde.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 #ifndef SETTINGS_H 0007 #define SETTINGS_H 0008 0009 #include <QObject> 0010 #include <QVariant> 0011 #include <qqmlregistration.h> 0012 0013 #include "kirigamiplatform_export.h" 0014 0015 namespace Kirigami 0016 { 0017 namespace Platform 0018 { 0019 /** 0020 * This class contains global kirigami settings about the current device setup 0021 * It is exposed to QML as the singleton "Settings" 0022 */ 0023 class KIRIGAMIPLATFORM_EXPORT Settings : public QObject 0024 { 0025 Q_OBJECT 0026 QML_ELEMENT 0027 QML_SINGLETON 0028 0029 /** 0030 * This property holds whether the system can dynamically enter and exit tablet mode 0031 * (or the device is actually a tablet). 0032 * This is the case for foldable convertibles and transformable laptops that support 0033 * keyboard detachment. 0034 */ 0035 Q_PROPERTY(bool tabletModeAvailable READ isTabletModeAvailable NOTIFY tabletModeAvailableChanged FINAL) 0036 0037 /** 0038 * This property holds whether the application is running on a small mobile device 0039 * such as a mobile phone. This is used when we want to do specific adaptations to 0040 * the UI for small screen form factors, such as having bigger touch areas. 0041 */ 0042 Q_PROPERTY(bool isMobile READ isMobile NOTIFY isMobileChanged FINAL) 0043 0044 /** 0045 * This property holds whether the application is running on a device that is 0046 * behaving like a tablet. 0047 * 0048 * @note This doesn't mean exactly a tablet form factor, but 0049 * that the preferred input mode for the device is the touch screen 0050 * and that pointer and keyboard are either secondary or not available. 0051 */ 0052 Q_PROPERTY(bool tabletMode READ tabletMode NOTIFY tabletModeChanged FINAL) 0053 0054 /** 0055 * This property holds whether the system has a platform menu bar; e.g. a user is 0056 * on macOS or has a global menu on KDE Plasma. 0057 * 0058 * @warning Android has a platform menu bar; which may not be what you expected. 0059 */ 0060 Q_PROPERTY(bool hasPlatformMenuBar READ hasPlatformMenuBar CONSTANT FINAL) 0061 0062 /** 0063 * This property holds whether the user in this moment is interacting with the app 0064 * with the touch screen. 0065 */ 0066 Q_PROPERTY(bool hasTransientTouchInput READ hasTransientTouchInput NOTIFY hasTransientTouchInputChanged FINAL) 0067 0068 /** 0069 * This property holds the name of the QtQuickControls2 style the application is using, 0070 * for instance org.kde.desktop, Plasma, Material, Universal etc 0071 */ 0072 Q_PROPERTY(QString style READ style CONSTANT FINAL) 0073 0074 // TODO: make this adapt without file watchers? 0075 /** 0076 * This property holds the number of lines of text the mouse wheel should scroll. 0077 */ 0078 Q_PROPERTY(int mouseWheelScrollLines READ mouseWheelScrollLines CONSTANT FINAL) 0079 0080 /** 0081 * This property holds the runtime information about the libraries in use. 0082 * 0083 * @since 5.52 0084 * @since org.kde.kirigami 2.6 0085 */ 0086 Q_PROPERTY(QStringList information READ information CONSTANT FINAL) 0087 0088 /** 0089 * This property holds the name of the application window icon. 0090 * @see QGuiApplication::windowIcon() 0091 * 0092 * @since 5.62 0093 * @since org.kde.kirigami 2.10 0094 */ 0095 Q_PROPERTY(QVariant applicationWindowIcon READ applicationWindowIcon CONSTANT FINAL) 0096 0097 public: 0098 Settings(QObject *parent = nullptr); 0099 ~Settings() override; 0100 0101 void setTabletModeAvailable(bool mobile); 0102 bool isTabletModeAvailable() const; 0103 0104 void setIsMobile(bool mobile); 0105 bool isMobile() const; 0106 0107 void setTabletMode(bool tablet); 0108 bool tabletMode() const; 0109 0110 void setTransientTouchInput(bool touch); 0111 bool hasTransientTouchInput() const; 0112 0113 bool hasPlatformMenuBar() const; 0114 0115 QString style() const; 0116 void setStyle(const QString &style); 0117 0118 int mouseWheelScrollLines() const; 0119 0120 QStringList information() const; 0121 0122 QVariant applicationWindowIcon() const; 0123 0124 protected: 0125 bool eventFilter(QObject *watched, QEvent *event) override; 0126 0127 Q_SIGNALS: 0128 void tabletModeAvailableChanged(); 0129 void tabletModeChanged(); 0130 void isMobileChanged(); 0131 void hasTransientTouchInputChanged(); 0132 0133 private: 0134 QString m_style; 0135 int m_scrollLines = 0; 0136 bool m_tabletModeAvailable : 1; 0137 bool m_mobile : 1; 0138 bool m_tabletMode : 1; 0139 bool m_hasTouchScreen : 1; 0140 bool m_hasTransientTouchInput : 1; 0141 bool m_hasPlatformMenuBar : 1; 0142 }; 0143 0144 } 0145 } 0146 0147 #endif