mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
quicksettings: add ability to enable/disable qs
This commit is contained in:
parent
2962a8b81c
commit
e21354bf63
5 changed files with 153 additions and 60 deletions
|
|
@ -98,6 +98,28 @@ SavedQuickSettingsModel *SavedQuickSettings::disabledQuickSettingsModel() const
|
||||||
return m_disabledQSModel;
|
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()
|
void SavedQuickSettings::refreshModel()
|
||||||
{
|
{
|
||||||
QList<QString> enabledQS = m_settings->enabledQuickSettings();
|
QList<QString> enabledQS = m_settings->enabledQuickSettings();
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,9 @@ public:
|
||||||
SavedQuickSettingsModel *enabledQuickSettingsModel() const;
|
SavedQuickSettingsModel *enabledQuickSettingsModel() const;
|
||||||
SavedQuickSettingsModel *disabledQuickSettingsModel() const;
|
SavedQuickSettingsModel *disabledQuickSettingsModel() const;
|
||||||
|
|
||||||
|
Q_INVOKABLE void enableQS(int index);
|
||||||
|
Q_INVOKABLE void disableQS(int index);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void refreshModel();
|
void refreshModel();
|
||||||
void saveModel();
|
void saveModel();
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,21 @@ void SavedQuickSettingsModel::insertRow(KPluginMetaData *metaData, int index)
|
||||||
Q_EMIT dataUpdated(m_data);
|
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)
|
void SavedQuickSettingsModel::removeRow(int index)
|
||||||
{
|
{
|
||||||
if (index < 0 || index >= m_data.size()) {
|
if (index < 0 || index >= m_data.size()) {
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ public:
|
||||||
|
|
||||||
Q_INVOKABLE void moveRow(int oldIndex, int newIndex);
|
Q_INVOKABLE void moveRow(int oldIndex, int newIndex);
|
||||||
Q_INVOKABLE void insertRow(KPluginMetaData *metaData, int index);
|
Q_INVOKABLE void insertRow(KPluginMetaData *metaData, int index);
|
||||||
|
Q_INVOKABLE KPluginMetaData *takeRow(int index);
|
||||||
Q_INVOKABLE void removeRow(int index);
|
Q_INVOKABLE void removeRow(int index);
|
||||||
|
|
||||||
QList<KPluginMetaData *> list() const;
|
QList<KPluginMetaData *> list() const;
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,88 @@ Kirigami.ScrollablePage {
|
||||||
topPadding: Kirigami.Units.gridUnit
|
topPadding: Kirigami.Units.gridUnit
|
||||||
bottomPadding: 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 {
|
ColumnLayout {
|
||||||
spacing: 0
|
spacing: Kirigami.Units.smallSpacing
|
||||||
width: root.width
|
width: root.width
|
||||||
|
|
||||||
MobileForm.FormCard {
|
MobileForm.FormCard {
|
||||||
|
|
@ -32,69 +112,41 @@ Kirigami.ScrollablePage {
|
||||||
|
|
||||||
MobileForm.FormCardHeader {
|
MobileForm.FormCardHeader {
|
||||||
title: i18n("Quick Settings")
|
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 {
|
Loader {
|
||||||
id: enabledQSListView
|
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
Layout.preferredHeight: contentHeight
|
Layout.preferredHeight: item ? item.contentHeight : 0
|
||||||
interactive: false
|
|
||||||
|
asynchronous: true
|
||||||
model: savedQuickSettings.enabledModel
|
sourceComponent: listViewComponent
|
||||||
|
|
||||||
moveDisplaced: Transition {
|
onLoaded: item.isEnabled = true
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue