File indexing completed on 2024-10-06 08:03:52

0001 /*
0002  *   SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>
0003  *
0004  *   SPDX-License-Identifier: LGPL-2.0-or-later
0005  */
0006 
0007 #pragma once
0008 
0009 #include "qqml.h"
0010 #include <QAbstractListModel>
0011 #include <QQmlListProperty>
0012 
0013 class QuickSetting : public QObject
0014 {
0015     Q_OBJECT
0016     QML_ELEMENT
0017 
0018     Q_PROPERTY(QString text READ text WRITE setText REQUIRED NOTIFY textChanged)
0019     Q_PROPERTY(QString status READ status WRITE setStatus NOTIFY statusChanged) // if no status is explicitly set, On/Off is used by default
0020     Q_PROPERTY(QString icon READ iconName WRITE setIconName REQUIRED NOTIFY iconNameChanged)
0021     Q_PROPERTY(QString settingsCommand READ settingsCommand WRITE setSettingsCommand NOTIFY settingsCommandChanged)
0022     Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
0023     Q_PROPERTY(bool available READ isAvailable WRITE setAvailable NOTIFY availableChanged)
0024     Q_PROPERTY(QQmlListProperty<QObject> children READ children CONSTANT)
0025     Q_CLASSINFO("DefaultProperty", "children")
0026 
0027 public:
0028     QuickSetting(QObject *parent = nullptr);
0029 
0030     QString text() const
0031     {
0032         return m_text;
0033     }
0034     QString status() const
0035     {
0036         return m_status;
0037     }
0038     QString iconName() const
0039     {
0040         return m_iconName;
0041     }
0042     QString settingsCommand() const
0043     {
0044         return m_settingsCommand;
0045     }
0046     bool isEnabled() const
0047     {
0048         return m_enabled;
0049     }
0050     bool isAvailable() const
0051     {
0052         return m_available;
0053     }
0054 
0055     void setText(const QString &text);
0056     void setStatus(const QString &status);
0057     void setIconName(const QString &iconName);
0058     void setSettingsCommand(const QString &settingsCommand);
0059     void setEnabled(bool enabled);
0060     void setAvailable(bool available);
0061     QQmlListProperty<QObject> children();
0062 
0063 Q_SIGNALS:
0064     void enabledChanged(bool enabled);
0065     void availableChanged(bool available);
0066     void textChanged(const QString &text);
0067     void statusChanged(const QString &text);
0068     void iconNameChanged(const QString &icon);
0069     void settingsCommandChanged(const QString &settingsCommand);
0070 
0071 private:
0072     bool m_enabled = true;
0073     bool m_available = true;
0074     QString m_text;
0075     QString m_status;
0076     QString m_iconName;
0077     QString m_settingsCommand;
0078     QList<QObject *> m_children;
0079 };