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