mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
QuickSettings: Make it possible for them not to be available
Makes it possible to QuickSettings components to only get listed if it makes sense on the specific system.
This commit is contained in:
parent
5a6559017e
commit
169cfc6354
4 changed files with 43 additions and 1 deletions
|
|
@ -20,6 +20,15 @@ void QuickSetting::setEnabled(bool enabled)
|
|||
Q_EMIT enabledChanged(enabled);
|
||||
}
|
||||
|
||||
void QuickSetting::setAvailable(bool available)
|
||||
{
|
||||
if (m_available == available)
|
||||
return;
|
||||
|
||||
m_available = available;
|
||||
Q_EMIT availableChanged(available);
|
||||
}
|
||||
|
||||
void QuickSetting::setSettingsCommand(const QString &settingsCommand)
|
||||
{
|
||||
if (m_settingsCommand == settingsCommand)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ class QuickSetting : public QObject
|
|||
Q_PROPERTY(QString icon READ iconName WRITE setIconName REQUIRED NOTIFY iconNameChanged)
|
||||
Q_PROPERTY(QString settingsCommand READ settingsCommand WRITE setSettingsCommand NOTIFY settingsCommandChanged)
|
||||
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged)
|
||||
Q_PROPERTY(bool available READ isAvailable WRITE setAvailable NOTIFY availableChanged)
|
||||
Q_PROPERTY(QQmlListProperty<QObject> children READ children CONSTANT)
|
||||
Q_CLASSINFO("DefaultProperty", "children")
|
||||
QML_NAMED_ELEMENT("QuickSetting")
|
||||
|
|
@ -44,16 +45,22 @@ public:
|
|||
{
|
||||
return m_enabled;
|
||||
}
|
||||
bool isAvailable() const
|
||||
{
|
||||
return m_available;
|
||||
}
|
||||
|
||||
void setText(const QString &text);
|
||||
void setStatus(const QString &status);
|
||||
void setIconName(const QString &iconName);
|
||||
void setSettingsCommand(const QString &settingsCommand);
|
||||
void setEnabled(bool enabled);
|
||||
void setAvailable(bool available);
|
||||
QQmlListProperty<QObject> children();
|
||||
|
||||
Q_SIGNALS:
|
||||
void enabledChanged(bool enabled);
|
||||
void availableChanged(bool available);
|
||||
void textChanged(const QString &text);
|
||||
void statusChanged(const QString &text);
|
||||
void iconNameChanged(const QString &icon);
|
||||
|
|
@ -61,6 +68,7 @@ Q_SIGNALS:
|
|||
|
||||
private:
|
||||
bool m_enabled = true;
|
||||
bool m_available = true;
|
||||
QString m_text;
|
||||
QString m_status;
|
||||
QString m_iconName;
|
||||
|
|
|
|||
|
|
@ -91,7 +91,10 @@ void QuickSettingsModel::loadQuickSettings()
|
|||
}
|
||||
delete created;
|
||||
} else {
|
||||
m_quickSettings.push_back(createdSetting);
|
||||
if (createdSetting->isAvailable()) {
|
||||
m_quickSettings.push_back(createdSetting);
|
||||
}
|
||||
connect(createdSetting, &QuickSetting::availableChanged, this, &QuickSettingsModel::availabilityChanged);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,3 +102,24 @@ void QuickSettingsModel::loadQuickSettings()
|
|||
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void QuickSettingsModel::availabilityChanged()
|
||||
{
|
||||
auto setting = qobject_cast<QuickSetting *>(sender());
|
||||
|
||||
if (setting->isAvailable()) {
|
||||
if (!m_quickSettings.contains(setting)) {
|
||||
auto idx = m_quickSettings.count();
|
||||
beginInsertRows({}, idx, idx);
|
||||
m_quickSettings.append(setting);
|
||||
endInsertRows();
|
||||
}
|
||||
} else {
|
||||
auto idx = m_quickSettings.indexOf(setting);
|
||||
if (idx >= 0) {
|
||||
beginRemoveRows({}, idx, idx);
|
||||
m_quickSettings.removeAt(idx);
|
||||
endRemoveRows();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public:
|
|||
|
||||
private:
|
||||
void loadQuickSettings();
|
||||
void availabilityChanged();
|
||||
|
||||
bool m_loaded = false;
|
||||
QList<QuickSetting *> m_quickSettings;
|
||||
|
|
|
|||
Loading…
Reference in a new issue