File indexing completed on 2024-04-28 15:27:44

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