kcms: Port away from SwipeListItem to ItemDelegate

Let's port the remaining uses to the upstream simpler alternative
`ItemDelegate`, which provides a consistent styling and fixes some
issues such as the background and highlighting.

This affects the rules, efects and virtual desktops KCMs.
This commit is contained in:
Ismael Asensio 2023-12-06 15:59:41 +01:00
parent 022214e411
commit a26e66be4b
4 changed files with 71 additions and 58 deletions

View file

@ -31,8 +31,10 @@ KCM.ScrollViewKCM {
Component {
id: desktopsListItemComponent
Kirigami.SwipeListItem {
id: listItem
QQC2.ItemDelegate {
width: ListView.view.width
down: false // Disable press effect
hoverEnabled: false
contentItem: RowLayout {
QQC2.TextField {
@ -64,7 +66,7 @@ KCM.ScrollViewKCM {
enabled: nameField.readOnly
onDoubleClicked: {
renameAction.trigger();
renameAction.clicked();
}
}
}
@ -78,40 +80,46 @@ KCM.ScrollViewKCM {
opacity: model ? !model.IsDefault : 0.0
color: Kirigami.Theme.neutralTextColor
}
}
actions: [
Kirigami.Action {
DelegateButton {
id: renameAction
enabled: model && !model.IsMissing
visible: !applyAction.visible
icon.name: "edit-rename"
tooltip: i18nc("@info:tooltip", "Rename")
onTriggered: {
text: i18nc("@info:tooltip", "Rename")
onClicked: {
nameField.readOnly = false;
nameField.selectAll();
nameField.forceActiveFocus();
}
},
Kirigami.Action {
}
DelegateButton {
id: applyAction
visible: !nameField.readOnly
icon.name: "dialog-ok-apply"
tooltip: i18nc("@info:tooltip", "Confirm new name")
onTriggered: {
text: i18nc("@info:tooltip", "Confirm new name")
onClicked: {
nameField.readOnly = true;
}
},
Kirigami.Action {
}
DelegateButton {
enabled: model && !model.IsMissing && desktopsList.count !== 1
icon.name: "edit-delete"
tooltip: i18nc("@info:tooltip", "Remove")
onTriggered: kcm.desktopsModel.removeDesktop(model.Id)
text: i18nc("@info:tooltip", "Remove")
onClicked: kcm.desktopsModel.removeDesktop(model.Id)
}
]
}
}
}
component DelegateButton: QQC2.ToolButton {
display: QQC2.AbstractButton.IconOnly
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
}
header: ColumnLayout {
id: messagesLayout

View file

@ -13,7 +13,7 @@ import QtQuick.Layouts
import org.kde.kirigami 2 as Kirigami
import org.kde.kcmutils as KCM
Kirigami.SwipeListItem {
QQC2.ItemDelegate {
id: listItem
hoverEnabled: true
@ -118,21 +118,26 @@ Kirigami.SwipeListItem {
}
}
}
}
actions: [
Kirigami.Action {
QQC2.ToolButton {
visible: model.VideoRole.toString() !== ""
icon.name: "videoclip-amarok"
tooltip: i18nc("@info:tooltip", "Show/Hide Video")
onTriggered: videoItem.showHide()
},
Kirigami.Action {
text: i18nc("@info:tooltip", "Show/Hide Video")
display: QQC2.AbstractButton.IconOnly
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
onClicked: videoItem.showHide()
}
QQC2.ToolButton {
visible: model.ConfigurableRole
enabled: model.StatusRole != Qt.Unchecked
icon.name: "configure"
tooltip: i18nc("@info:tooltip", "Configure…")
onTriggered: kcm.configure(model.ServiceNameRole, listItem)
text: i18nc("@info:tooltip", "Configure…")
display: QQC2.AbstractButton.IconOnly
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
onClicked: kcm.configure(model.ServiceNameRole, listItem)
}
]
}
}

View file

@ -20,6 +20,7 @@ QQC2.ItemDelegate {
width: ListView.view.width
highlighted: false
hoverEnabled: false
down: false
contentItem: RowLayout {

View file

@ -140,9 +140,12 @@ KCM.ScrollViewKCM {
}
}
Kirigami.SwipeListItem {
QQC2.ItemDelegate {
id: ruleBookItem
width: ruleBookView.width
down: false // Disable press effect
contentItem: RowLayout {
Kirigami.ListItemDragHandle {
visible: !exportInfo.visible
@ -188,6 +191,24 @@ KCM.ScrollViewKCM {
}
}
DelegateButton {
text: i18n("Edit")
icon.name: "edit-entry"
onClicked: kcm.editRule(index);
}
DelegateButton {
text: i18n("Duplicate")
icon.name: "edit-duplicate"
onClicked: kcm.duplicateRule(index);
}
DelegateButton {
text: i18n("Delete")
icon.name: "entry-delete"
onClicked: kcm.removeRule(index);
}
QQC2.CheckBox {
id: itemSelectionCheck
visible: exportInfo.visible
@ -203,38 +224,16 @@ KCM.ScrollViewKCM {
}
}
}
actions: [
Kirigami.Action {
text: i18n("Edit")
icon.name: "edit-entry"
visible: !exportInfo.visible
onTriggered: {
kcm.editRule(index);
}
}
,
Kirigami.Action {
text: i18n("Duplicate")
icon.name: "edit-duplicate"
visible: !exportInfo.visible
onTriggered: {
kcm.duplicateRule(index);
}
}
,
Kirigami.Action {
text: i18n("Delete")
icon.name: "entry-delete"
visible: !exportInfo.visible
onTriggered: {
kcm.removeRule(index);
}
}
]
}
}
component DelegateButton: QQC2.ToolButton {
visible: !exportInfo.visible
display: QQC2.AbstractButton.IconOnly
QQC2.ToolTip.text: text
QQC2.ToolTip.visible: hovered
}
FileDialogLoader {
id: importDialog
title: i18n("Import Rules")