mobileshell-kcm: Port to FormCard

This commit is contained in:
Carl Schwan 2023-09-21 19:24:32 +02:00
parent ca0f8797eb
commit 886ef153de
3 changed files with 294 additions and 363 deletions

View file

@ -9,145 +9,117 @@ import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.19 as Kirigami import org.kde.kirigami 2.19 as Kirigami
import org.kde.kcmutils as KCM import org.kde.kcmutils as KCM
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm import org.kde.kirigamiaddons.formcard as FormCard
import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS import org.kde.plasma.private.mobileshell.quicksettingsplugin as QS
Kirigami.ScrollablePage { FormCard.FormCardPage {
id: root id: root
title: i18n("Quick Settings") title: i18n("Quick Settings")
leftPadding: 0
rightPadding: 0
topPadding: Kirigami.Units.gridUnit
bottomPadding: Kirigami.Units.gridUnit
Component { component Delegate : FormCard.AbstractFormDelegate {
id: listItemComponent id: qsDelegate
MobileForm.AbstractFormDelegate { property bool isEnabled: false
id: qsDelegate
readonly property bool isEnabled: parent ? parent.parentView.isEnabled : false width: ListView.view.width
contentItem: RowLayout { background: null
Kirigami.ListItemDragHandle { contentItem: RowLayout {
visible: qsDelegate.isEnabled Kirigami.ListItemDragHandle {
Layout.rightMargin: Kirigami.Units.gridUnit visible: qsDelegate.isEnabled
listItem: qsDelegate Layout.rightMargin: Kirigami.Units.gridUnit
listView: qsDelegate.parent ? qsDelegate.parent.parentView : null listItem: qsDelegate
onMoveRequested: savedQuickSettings.enabledModel.moveRow(oldIndex, newIndex) listView: qsDelegate.ListView.view
} onMoveRequested: savedQuickSettings.enabledModel.moveRow(oldIndex, newIndex)
}
Kirigami.Icon { Kirigami.Icon {
readonly property bool iconAvailable: model && model.icon !== "" readonly property bool iconAvailable: model && model.icon !== ""
visible: iconAvailable visible: iconAvailable
source: model ? model.icon : "" source: model ? model.icon : ""
Layout.rightMargin: iconAvailable ? Kirigami.Units.gridUnit : 0 Layout.rightMargin: iconAvailable ? Kirigami.Units.gridUnit : 0
implicitWidth: iconAvailable ? Kirigami.Units.iconSizes.small : 0 implicitWidth: iconAvailable ? Kirigami.Units.iconSizes.small : 0
implicitHeight: iconAvailable ? Kirigami.Units.iconSizes.small : 0 implicitHeight: iconAvailable ? Kirigami.Units.iconSizes.small : 0
} }
ColumnLayout { QQC2.Label {
Layout.fillWidth: true Layout.fillWidth: true
spacing: Kirigami.Units.smallSpacing text: model ? model.name : ""
elide: Text.ElideRight
}
QQC2.Label { QQC2.ToolButton {
Layout.fillWidth: true display: QQC2.AbstractButton.IconOnly
text: model ? model.name : "" text: qsDelegate.isEnabled ? i18nc("@action:button", "Hide") : i18nc("@action:button", "Show")
elide: Text.ElideRight icon.name: qsDelegate.isEnabled ? "hide_table_row" : "show_table_row"
} onClicked: qsDelegate.isEnabled ? savedQuickSettings.disableQS(model.index) : savedQuickSettings.enableQS(model.index)
}
QQC2.ToolButton { QQC2.ToolTip.visible: hovered
icon.name: model ? qsDelegate.isEnabled ? "hide_table_row" : "show_table_row" : "" QQC2.ToolTip.text: text
onClicked: qsDelegate.isEnabled ? savedQuickSettings.disableQS(model.index) : savedQuickSettings.enableQS(model.index) QQC2.ToolTip.delay: Kirigami.Units.toolTipDelay
}
} }
} }
} }
Component { data: QS.SavedQuickSettings {
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
}
}
}
QS.SavedQuickSettings {
id: savedQuickSettings id: savedQuickSettings
} }
ColumnLayout { FormCard.FormHeader {
spacing: Kirigami.Units.smallSpacing title: i18n("Quick Settings")
width: root.width visible: enabledRepeater.count > 0
}
MobileForm.FormCard { FormCard.FormSectionText {
Layout.fillWidth: true text: i18n("Customize the order of quick settings in the pull-down panel and hide them.")
visible: enabledRepeater.count > 0
}
contentItem: ColumnLayout { FormCard.FormCard {
spacing: 0 visible: enabledRepeater.count > 0
MobileForm.FormCardHeader { ListView {
title: i18n("Quick Settings") id: enabledRepeater
subtitle: i18n("Customize the order of quick settings in the pull-down panel and hide them.")
}
Loader { interactive: false
Layout.fillWidth: true
Layout.preferredHeight: item ? item.contentHeight : 0
asynchronous: true model: savedQuickSettings.enabledModel
sourceComponent: listViewComponent delegate: Delegate {
isEnabled: true
onLoaded: item.isEnabled = true
}
} }
Layout.fillWidth: true
Layout.preferredHeight: contentHeight
} }
}
MobileForm.FormCard { FormCard.FormHeader {
Layout.fillWidth: true title: i18n("Disabled Quick Settings")
visible: disabledRepeater.count > 0
}
contentItem: ColumnLayout { FormCard.FormSectionText {
spacing: 0 text: i18n("Re-enable previously disabled quick settings.")
visible: disabledRepeater.count > 0
}
MobileForm.FormCardHeader { FormCard.FormCard {
title: i18n("Disabled Quick Settings") visible: disabledRepeater.count > 0
subtitle: i18n("Re-enable previously disabled quick settings.")
}
Loader { ListView {
Layout.fillWidth: true id: disabledRepeater
Layout.preferredHeight: item ? item.contentHeight : 0
asynchronous: true interactive: false
sourceComponent: listViewComponent
onLoaded: item.isEnabled = false model: savedQuickSettings.disabledModel
} delegate: Delegate {
isEnabled: false
} }
Layout.fillWidth: true
Layout.preferredHeight: contentHeight
} }
} }
} }

View file

@ -3,111 +3,99 @@
* SPDX-License-Identifier: LGPL-2.0-or-later * SPDX-License-Identifier: LGPL-2.0-or-later
*/ */
import QtQuick 2.15 import QtQuick
import QtQuick.Layouts 1.15 import QtQuick.Layouts
import QtQuick.Controls 2.15 as QQC2 import QtQuick.Controls as QQC2
import org.kde.kirigami 2.19 as Kirigami import org.kde.kirigami as Kirigami
import org.kde.kcmutils as KCM import org.kde.kcmutils as KCM
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm import org.kde.kirigamiaddons.formcard 1 as FormCard
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
Kirigami.ScrollablePage { FormCard.FormCardPage {
id: root id: root
title: i18n("Shell Vibrations") title: i18n("Shell Vibrations")
leftPadding: 0
rightPadding: 0
topPadding: Kirigami.Units.gridUnit
bottomPadding: Kirigami.Units.gridUnit
ColumnLayout { FormCard.FormCard {
spacing: 0 Layout.topMargin: Kirigami.Units.gridUnit
width: root.width
MobileForm.FormCard { FormCard.FormSwitchDelegate {
Layout.fillWidth: true id: shellVibrationsSwitch
text: i18n("Shell Vibrations")
contentItem: ColumnLayout { description: i18n("Whether to have vibrations enabled in the shell.")
spacing: 0 checked: ShellSettings.Settings.vibrationsEnabled
onCheckedChanged: {
MobileForm.FormSwitchDelegate { if (checked != ShellSettings.Settings.vibrationsEnabled) {
id: shellVibrationsSwitch ShellSettings.Settings.vibrationsEnabled = checked;
text: i18n("Shell Vibrations")
description: i18n("Whether to have vibrations enabled in the shell.")
checked: ShellSettings.Settings.vibrationsEnabled
onCheckedChanged: {
if (checked != ShellSettings.Settings.vibrationsEnabled) {
ShellSettings.Settings.vibrationsEnabled = checked;
}
}
}
MobileForm.FormDelegateSeparator { above: shellVibrationsSwitch; below: vibrationIntensityDelegate }
MobileForm.FormComboBoxDelegate {
id: vibrationIntensityDelegate
text: i18n("Vibration Intensity")
description: i18n("How intense shell vibrations should be.")
property string lowIntensityString: i18nc("Low intensity", "Low")
property string mediumIntensityString: i18nc("Medium intensity", "Medium")
property string highIntensityString: i18nc("High intensity", "High")
currentIndex: indexOfValue(ShellSettings.Settings.vibrationIntensity)
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: {
append({"name": vibrationIntensityDelegate.highIntensityString, "value": 1.0});
append({"name": vibrationIntensityDelegate.mediumIntensityString, "value": 0.5});
append({"name": vibrationIntensityDelegate.lowIntensityString, "value": 0.2});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
vibrationIntensityDelegate.currentIndex = vibrationIntensityDelegate.indexOfValue(ShellSettings.Settings.vibrationIntensity)
}
}
textRole: "name"
valueRole: "value"
Component.onCompleted: dialog.parent = root
onCurrentValueChanged: ShellSettings.Settings.vibrationIntensity = currentValue;
}
MobileForm.FormDelegateSeparator { above: vibrationIntensityDelegate; below: vibrationDurationDelegate }
MobileForm.FormComboBoxDelegate {
id: vibrationDurationDelegate
text: i18n("Vibration Duration")
description: i18n("How long shell vibrations should be.")
property string longString: i18nc("Long duration", "Long")
property string mediumString: i18nc("Medium duration", "Medium")
property string shortString: i18nc("Short duration", "Short")
currentIndex: indexOfValue(ShellSettings.Settings.vibrationDuration)
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: {
append({"name": vibrationDurationDelegate.longString, "value": 100});
append({"name": vibrationDurationDelegate.mediumString, "value": 50});
append({"name": vibrationDurationDelegate.shortString, "value": 15});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
vibrationDurationDelegate.currentIndex = vibrationDurationDelegate.indexOfValue(ShellSettings.Settings.vibrationDuration)
}
}
textRole: "name"
valueRole: "value"
Component.onCompleted: dialog.parent = root
onCurrentValueChanged: ShellSettings.Settings.vibrationDuration = currentValue;
} }
} }
} }
MobileForm.FormSectionText { FormCard.FormDelegateSeparator { above: shellVibrationsSwitch; below: vibrationIntensityDelegate }
text: i18n("Keyboard vibrations are controlled separately in the keyboard settings module.")
FormCard.FormComboBoxDelegate {
id: vibrationIntensityDelegate
text: i18n("Vibration Intensity")
description: i18n("How intense shell vibrations should be.")
property string lowIntensityString: i18nc("Low intensity", "Low")
property string mediumIntensityString: i18nc("Medium intensity", "Medium")
property string highIntensityString: i18nc("High intensity", "High")
currentIndex: indexOfValue(ShellSettings.Settings.vibrationIntensity)
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: {
append({"name": vibrationIntensityDelegate.highIntensityString, "value": 1.0});
append({"name": vibrationIntensityDelegate.mediumIntensityString, "value": 0.5});
append({"name": vibrationIntensityDelegate.lowIntensityString, "value": 0.2});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
vibrationIntensityDelegate.currentIndex = vibrationIntensityDelegate.indexOfValue(ShellSettings.Settings.vibrationIntensity)
}
}
textRole: "name"
valueRole: "value"
Component.onCompleted: dialog.parent = root
onCurrentValueChanged: ShellSettings.Settings.vibrationIntensity = currentValue;
}
FormCard.FormDelegateSeparator { above: vibrationIntensityDelegate; below: vibrationDurationDelegate }
FormCard.FormComboBoxDelegate {
id: vibrationDurationDelegate
text: i18n("Vibration Duration")
description: i18n("How long shell vibrations should be.")
property string longString: i18nc("Long duration", "Long")
property string mediumString: i18nc("Medium duration", "Medium")
property string shortString: i18nc("Short duration", "Short")
currentIndex: indexOfValue(ShellSettings.Settings.vibrationDuration)
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: {
append({"name": vibrationDurationDelegate.longString, "value": 100});
append({"name": vibrationDurationDelegate.mediumString, "value": 50});
append({"name": vibrationDurationDelegate.shortString, "value": 15});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
vibrationDurationDelegate.currentIndex = vibrationDurationDelegate.indexOfValue(ShellSettings.Settings.vibrationDuration)
}
}
textRole: "name"
valueRole: "value"
Component.onCompleted: dialog.parent = root
onCurrentValueChanged: ShellSettings.Settings.vibrationDuration = currentValue;
} }
} }
FormCard.FormSectionText {
text: i18n("Keyboard vibrations are controlled separately in the keyboard settings module.")
}
} }

View file

@ -9,7 +9,7 @@ import QtQuick.Controls 2.15 as QQC2
import org.kde.kirigami 2.19 as Kirigami import org.kde.kirigami 2.19 as Kirigami
import org.kde.kcmutils as KCM import org.kde.kcmutils as KCM
import org.kde.kirigamiaddons.labs.mobileform 0.1 as MobileForm import org.kde.kirigamiaddons.formcard 1.0 as FormCard
import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings import org.kde.plasma.private.mobileshell.shellsettingsplugin as ShellSettings
KCM.SimpleKCM { KCM.SimpleKCM {
@ -17,169 +17,140 @@ KCM.SimpleKCM {
title: i18n("Shell") title: i18n("Shell")
topPadding: 0
bottomPadding: 0
leftPadding: 0 leftPadding: 0
rightPadding: 0 rightPadding: 0
topPadding: Kirigami.Units.gridUnit
bottomPadding: Kirigami.Units.gridUnit
ColumnLayout { ColumnLayout {
spacing: 0 FormCard.FormHeader {
width: root.width title: i18n("General")
}
MobileForm.FormCard { FormCard.FormCard {
Layout.fillWidth: true FormCard.FormButtonDelegate {
id: shellVibrationsButton
text: i18n("Shell Vibrations")
onClicked: kcm.push("VibrationForm.qml")
}
contentItem: ColumnLayout { FormCard.FormDelegateSeparator { above: shellVibrationsButton; below: animationsSwitch }
spacing: 0
MobileForm.FormCardHeader { FormCard.FormSwitchDelegate {
title: i18n("General") id: animationsSwitch
} text: i18n("Animations")
description: i18n("If this is off, animations will be reduced as much as possible.")
MobileForm.FormButtonDelegate { checked: ShellSettings.Settings.animationsEnabled
id: shellVibrationsButton onCheckedChanged: {
text: i18n("Shell Vibrations") if (checked != ShellSettings.Settings.animationsEnabled) {
onClicked: kcm.push("VibrationForm.qml") ShellSettings.Settings.animationsEnabled = checked;
}
MobileForm.FormDelegateSeparator { above: shellVibrationsButton; below: animationsSwitch }
MobileForm.FormSwitchDelegate {
id: animationsSwitch
text: i18n("Animations")
description: i18n("If this is off, animations will be reduced as much as possible.")
checked: ShellSettings.Settings.animationsEnabled
onCheckedChanged: {
if (checked != ShellSettings.Settings.animationsEnabled) {
ShellSettings.Settings.animationsEnabled = checked;
}
} }
} }
} }
} }
MobileForm.FormCard { FormCard.FormHeader {
Layout.fillWidth: true title: i18n("Navigation Panel")
Layout.topMargin: Kirigami.Units.gridUnit }
contentItem: ColumnLayout { FormCard.FormCard {
spacing: 0 FormCard.FormSwitchDelegate {
id: gestureDelegate
MobileForm.FormCardHeader { text: i18n("Gesture-only Mode")
title: i18n("Navigation Panel") description: i18n("Whether to hide the navigation panel.")
} checked: !ShellSettings.Settings.navigationPanelEnabled
onCheckedChanged: {
MobileForm.FormSwitchDelegate { if (checked != !ShellSettings.Settings.navigationPanelEnabled) {
id: gestureDelegate ShellSettings.Settings.navigationPanelEnabled = !checked;
text: i18n("Gesture-only Mode")
description: i18n("Whether to hide the navigation panel.")
checked: !ShellSettings.Settings.navigationPanelEnabled
onCheckedChanged: {
if (checked != !ShellSettings.Settings.navigationPanelEnabled) {
ShellSettings.Settings.navigationPanelEnabled = !checked;
}
} }
} }
} }
} }
MobileForm.FormCard { FormCard.FormHeader {
Layout.fillWidth: true title: i18n("Task Switcher")
Layout.topMargin: Kirigami.Units.gridUnit }
contentItem: ColumnLayout { FormCard.FormCard {
spacing: 0 FormCard.FormSwitchDelegate {
text: i18n("Show Application Previews")
MobileForm.FormCardHeader { description: i18n("Turning this off may help improve performance.")
title: i18n("Task Switcher") checked: ShellSettings.Settings.taskSwitcherPreviewsEnabled
} onCheckedChanged: {
if (checked != ShellSettings.Settings.taskSwitcherPreviewsEnabled) {
MobileForm.FormSwitchDelegate { ShellSettings.Settings.taskSwitcherPreviewsEnabled = checked;
text: i18n("Show Application Previews")
description: i18n("Turning this off may help improve performance.")
checked: ShellSettings.Settings.taskSwitcherPreviewsEnabled
onCheckedChanged: {
if (checked != ShellSettings.Settings.taskSwitcherPreviewsEnabled) {
ShellSettings.Settings.taskSwitcherPreviewsEnabled = checked;
}
} }
} }
} }
} }
MobileForm.FormCard { FormCard.FormHeader {
Layout.fillWidth: true title: i18n("Action Drawer")
Layout.topMargin: Kirigami.Units.gridUnit }
contentItem: ColumnLayout { FormCard.FormCard {
id: parentCol id: quickSettings
spacing: 0
MobileForm.FormCardHeader { property string pinnedString: i18nc("Pinned action drawer mode", "Pinned Mode")
title: i18n("Action Drawer") property string expandedString: i18nc("Expanded action drawer mode", "Expanded Mode")
}
MobileForm.FormButtonDelegate { FormCard.FormButtonDelegate {
id: quickSettingsButton id: quickSettingsButton
text: i18n("Quick Settings") text: i18n("Quick Settings")
onClicked: kcm.push("QuickSettingsForm.qml") onClicked: kcm.push("QuickSettingsForm.qml")
} }
MobileForm.FormDelegateSeparator { above: quickSettingsButton; below: topLeftActionDrawerModeDelegate } FormCard.FormDelegateSeparator { above: quickSettingsButton; below: topLeftActionDrawerModeDelegate }
property string pinnedString: i18nc("Pinned action drawer mode", "Pinned Mode") FormCard.FormComboBoxDelegate {
property string expandedString: i18nc("Expanded action drawer mode", "Expanded Mode") id: topLeftActionDrawerModeDelegate
text: i18n("Top Left Drawer Mode")
MobileForm.FormComboBoxDelegate { description: i18n("Mode when opening from the top left.")
id: topLeftActionDrawerModeDelegate
text: i18n("Top Left Drawer Mode")
description: i18n("Mode when opening from the top left.")
currentIndex: indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode)
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: {
append({"name": parentCol.pinnedString, "value": ShellSettings.Settings.Pinned});
append({"name": parentCol.expandedString, "value": ShellSettings.Settings.Expanded});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
topLeftActionDrawerModeDelegate.currentIndex = topLeftActionDrawerModeDelegate.indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode)
}
}
textRole: "name"
valueRole: "value"
Component.onCompleted: dialog.parent = root
onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopLeftMode = currentValue
}
MobileForm.FormDelegateSeparator { above: topLeftActionDrawerModeDelegate; below: topRightActionDrawerModeDelegate }
MobileForm.FormComboBoxDelegate {
id: topRightActionDrawerModeDelegate
text: i18n("Top Right Drawer Mode")
description: i18n("Mode when opening from the top right.")
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: {
append({"name": parentCol.pinnedString, "value": ShellSettings.Settings.Pinned});
append({"name": parentCol.expandedString, "value": ShellSettings.Settings.Expanded});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
topRightActionDrawerModeDelegate.currentIndex = topRightActionDrawerModeDelegate.indexOfValue(ShellSettings.Settings.actionDrawerTopRightMode)
}
}
textRole: "name"
valueRole: "value"
currentIndex: indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode)
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: { Component.onCompleted: {
dialog.parent = root append({"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned});
append({"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
topLeftActionDrawerModeDelegate.currentIndex = topLeftActionDrawerModeDelegate.indexOfValue(ShellSettings.Settings.actionDrawerTopLeftMode)
} }
onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopRightMode = currentValue
} }
textRole: "name"
valueRole: "value"
Component.onCompleted: dialog.parent = root
onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopLeftMode = currentValue
}
FormCard.FormDelegateSeparator { above: topLeftActionDrawerModeDelegate; below: topRightActionDrawerModeDelegate }
FormCard.FormComboBoxDelegate {
id: topRightActionDrawerModeDelegate
text: i18n("Top Right Drawer Mode")
description: i18n("Mode when opening from the top right.")
model: ListModel {
// we can't use i18n with ListElement
Component.onCompleted: {
append({"name": quickSettings.pinnedString, "value": ShellSettings.Settings.Pinned});
append({"name": quickSettings.expandedString, "value": ShellSettings.Settings.Expanded});
// indexOfValue doesn't bind to model changes unfortunately, set currentIndex manually here
topRightActionDrawerModeDelegate.currentIndex = topRightActionDrawerModeDelegate.indexOfValue(ShellSettings.Settings.actionDrawerTopRightMode)
}
}
textRole: "name"
valueRole: "value"
Component.onCompleted: {
dialog.parent = root
}
onCurrentValueChanged: ShellSettings.Settings.actionDrawerTopRightMode = currentValue
} }
} }
} }