From e21354bf63c89bffb400f418cf4e3770607ab539 Mon Sep 17 00:00:00 2001 From: Yari Polla Date: Mon, 13 Mar 2023 14:03:17 +0100 Subject: [PATCH] quicksettings: add ability to enable/disable qs --- .../quicksettings/savedquicksettings.cpp | 22 +++ .../quicksettings/savedquicksettings.h | 3 + .../quicksettings/savedquicksettingsmodel.cpp | 15 ++ .../quicksettings/savedquicksettingsmodel.h | 1 + .../package/contents/ui/QuickSettingsForm.qml | 172 ++++++++++++------ 5 files changed, 153 insertions(+), 60 deletions(-) diff --git a/components/mobileshell/quicksettings/savedquicksettings.cpp b/components/mobileshell/quicksettings/savedquicksettings.cpp index c8e32f08..9fb22439 100644 --- a/components/mobileshell/quicksettings/savedquicksettings.cpp +++ b/components/mobileshell/quicksettings/savedquicksettings.cpp @@ -98,6 +98,28 @@ SavedQuickSettingsModel *SavedQuickSettings::disabledQuickSettingsModel() const return m_disabledQSModel; } +void SavedQuickSettings::enableQS(int index) +{ + KPluginMetaData *tmp = m_disabledQSModel->takeRow(index); + + if (!tmp) { + return; + } + + m_enabledQSModel->insertRow(tmp, m_enabledQSModel->rowCount({})); +} + +void SavedQuickSettings::disableQS(int index) +{ + KPluginMetaData *tmp = m_enabledQSModel->takeRow(index); + + if (!tmp) { + return; + } + + m_disabledQSModel->insertRow(tmp, m_disabledQSModel->rowCount({})); +} + void SavedQuickSettings::refreshModel() { QList enabledQS = m_settings->enabledQuickSettings(); diff --git a/components/mobileshell/quicksettings/savedquicksettings.h b/components/mobileshell/quicksettings/savedquicksettings.h index 62ff27d7..6fdee436 100644 --- a/components/mobileshell/quicksettings/savedquicksettings.h +++ b/components/mobileshell/quicksettings/savedquicksettings.h @@ -34,6 +34,9 @@ public: SavedQuickSettingsModel *enabledQuickSettingsModel() const; SavedQuickSettingsModel *disabledQuickSettingsModel() const; + Q_INVOKABLE void enableQS(int index); + Q_INVOKABLE void disableQS(int index); + private: void refreshModel(); void saveModel(); diff --git a/components/mobileshell/quicksettings/savedquicksettingsmodel.cpp b/components/mobileshell/quicksettings/savedquicksettingsmodel.cpp index c868c8a7..2de24db1 100644 --- a/components/mobileshell/quicksettings/savedquicksettingsmodel.cpp +++ b/components/mobileshell/quicksettings/savedquicksettingsmodel.cpp @@ -57,6 +57,21 @@ void SavedQuickSettingsModel::insertRow(KPluginMetaData *metaData, int index) Q_EMIT dataUpdated(m_data); } +KPluginMetaData *SavedQuickSettingsModel::takeRow(int index) +{ + if (index < 0 || index >= m_data.size()) { + return {}; + } + + Q_EMIT beginRemoveRows(QModelIndex(), index, index); + KPluginMetaData *tmp = m_data.takeAt(index); + Q_EMIT endRemoveRows(); + + Q_EMIT dataUpdated(m_data); + + return tmp; +} + void SavedQuickSettingsModel::removeRow(int index) { if (index < 0 || index >= m_data.size()) { diff --git a/components/mobileshell/quicksettings/savedquicksettingsmodel.h b/components/mobileshell/quicksettings/savedquicksettingsmodel.h index 775e0b5d..b76d0ee7 100644 --- a/components/mobileshell/quicksettings/savedquicksettingsmodel.h +++ b/components/mobileshell/quicksettings/savedquicksettingsmodel.h @@ -36,6 +36,7 @@ public: Q_INVOKABLE void moveRow(int oldIndex, int newIndex); Q_INVOKABLE void insertRow(KPluginMetaData *metaData, int index); + Q_INVOKABLE KPluginMetaData *takeRow(int index); Q_INVOKABLE void removeRow(int index); QList list() const; diff --git a/kcms/mobileshell/package/contents/ui/QuickSettingsForm.qml b/kcms/mobileshell/package/contents/ui/QuickSettingsForm.qml index 8877f1e8..d501ab02 100644 --- a/kcms/mobileshell/package/contents/ui/QuickSettingsForm.qml +++ b/kcms/mobileshell/package/contents/ui/QuickSettingsForm.qml @@ -20,8 +20,88 @@ Kirigami.ScrollablePage { topPadding: Kirigami.Units.gridUnit bottomPadding: Kirigami.Units.gridUnit + Component { + id: listItemComponent + + MobileForm.AbstractFormDelegate { + id: qsDelegate + + readonly property bool isEnabled: parent ? parent.parentView.isEnabled : false + + contentItem: RowLayout { + Kirigami.ListItemDragHandle { + visible: qsDelegate.isEnabled + Layout.rightMargin: Kirigami.Units.largeSpacing + listItem: qsDelegate + listView: qsDelegate.parent ? qsDelegate.parent.parentView : null + onMoveRequested: savedQuickSettings.enabledModel.moveRow(oldIndex, newIndex) + } + + Kirigami.Icon { + readonly property bool iconAvailable: model && model.icon !== "" + + visible: iconAvailable + source: model ? model.icon : "" + Layout.rightMargin: iconAvailable ? Kirigami.Units.largeSpacing : 0 + implicitWidth: iconAvailable ? Kirigami.Units.iconSizes.small : 0 + implicitHeight: iconAvailable ? Kirigami.Units.iconSizes.small : 0 + } + + ColumnLayout { + Layout.fillWidth: true + spacing: Kirigami.Units.smallSpacing + + QQC2.Label { + Layout.fillWidth: true + text: model ? model.name : "" + elide: Text.ElideRight + } + } + + QQC2.ToolButton { + icon.name: model ? qsDelegate.isEnabled ? "hide_table_row" : "show_table_row" : "" + onClicked: qsDelegate.isEnabled ? savedQuickSettings.disableQS(model.index) : savedQuickSettings.enableQS(model.index) + } + } + } + } + + Component { + id: listViewComponent + + ListView { + id: listView + Layout.fillWidth: true + Layout.preferredHeight: contentHeight + interactive: false + + property bool isEnabled: false + model: isEnabled ? savedQuickSettings.enabledModel : savedQuickSettings.disabledModel + + moveDisplaced: Transition { + YAnimator { + duration: Kirigami.Units.longDuration + easing.type: Easing.InOutQuad + } + } + + delegate: Kirigami.DelegateRecycler { + id: delegate + + width: listView.width + sourceComponent: listItemComponent + + readonly property ListView parentView: ListView.view + } + } + } + + MobileShell.SavedQuickSettings { + id: savedQuickSettings + } + ColumnLayout { - spacing: 0 + spacing: Kirigami.Units.smallSpacing width: root.width MobileForm.FormCard { @@ -32,69 +112,41 @@ Kirigami.ScrollablePage { MobileForm.FormCardHeader { title: i18n("Quick Settings") - subtitle: i18n("Customize the order of quick settings in the pull-down panel.") + subtitle: i18n("Customize the order of quick settings in the pull-down panel and hide them.") } - - ListView { - id: enabledQSListView + + Loader { Layout.fillWidth: true - Layout.preferredHeight: contentHeight - interactive: false - - model: savedQuickSettings.enabledModel - - moveDisplaced: Transition { - YAnimator { - duration: Kirigami.Units.longDuration - easing.type: Easing.InOutQuad - } - } - - Component { - id: listItemComponent - - MobileForm.AbstractFormDelegate { - id: qsDelegate - - contentItem: RowLayout { - Kirigami.ListItemDragHandle { - Layout.rightMargin: Kirigami.Units.largeSpacing - listItem: qsDelegate - listView: enabledQSListView - onMoveRequested: savedQuickSettings.enabledModel.moveRow(oldIndex, newIndex) - } - - Kirigami.Icon { - visible: model && model.icon !== "" - source: model ? model.icon : "" - Layout.rightMargin: (model && model.icon !== "") ? Kirigami.Units.largeSpacing : 0 - implicitWidth: (model && model.icon !== "") ? Kirigami.Units.iconSizes.small : 0 - implicitHeight: (model && model.icon !== "") ? Kirigami.Units.iconSizes.small : 0 - } - - ColumnLayout { - Layout.fillWidth: true - spacing: Kirigami.Units.smallSpacing - - QQC2.Label { - Layout.fillWidth: true - text: model ? model.name : "" - elide: Text.ElideRight - } - } - } - } - } - - delegate: Kirigami.DelegateRecycler { - width: enabledQSListView.width - sourceComponent: listItemComponent - } + Layout.preferredHeight: item ? item.contentHeight : 0 + + asynchronous: true + sourceComponent: listViewComponent + + onLoaded: item.isEnabled = true } } - - MobileShell.SavedQuickSettings { - id: savedQuickSettings + } + + MobileForm.FormCard { + Layout.fillWidth: true + + contentItem: ColumnLayout { + spacing: 0 + + MobileForm.FormCardHeader { + title: i18n("Disabled Quick Settings") + subtitle: i18n("Re-enable previously disabled quick settings.") + } + + Loader { + Layout.fillWidth: true + Layout.preferredHeight: item ? item.contentHeight : 0 + + asynchronous: true + sourceComponent: listViewComponent + + onLoaded: item.isEnabled = false + } } } }