/*SPDX-FileCopyrightText: 2020 David Redondo <david@david-redondo.de>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport QtQuick.Layoutsimport QtQuick.Controls as QQC2import org.kde.kirigami as Kirigamiimport org.kde.kquickcontrolsimport org.kde.kcmutils as KCMQQC2.ItemDelegate {id: rootproperty bool showExpandButton: truereadonly property bool selected: highlighted || downhighlighted: false// If it's the only one in the list, clicking it won't do anything, so don't provide any visual feedback.hoverEnabled: showExpandButtondown: showExpandButton ? undefined : falsewidth: shortcutsList.widthaction: QQC2.Action {id: expandActiononTriggered: {shortcutsList.selectedIndex = (root.state === "expanded") ? -1 : index;}}Accessible.name: root.state === "expanded" ? i18n("Editing shortcut: %1", displayLabel.text) : displayLabel.text + keySequenceList.textcontentItem: ColumnLayout {clip: trueKirigami.Theme.textColor: root.selected ? root.Kirigami.Theme.highlightedTextColor : undefinedKirigami.Theme.inherit: !root.selectedspacing: Kirigami.Units.smallSpacingItem {Layout.alignment: Qt.AlignTopLayout.preferredHeight: topRow.implicitHeightLayout.fillWidth: trueRowLayout {id: topRowanchors.fill: parentspacing: Kirigami.Units.smallSpacingKirigami.Heading {id: displayLabelLayout.minimumWidth: Kirigami.Units.gridUnit * 8Layout.fillWidth: truetext: i18nc("%1 is the name action that is triggered by the key sequences following after :", "%1:", model.display)wrapMode: Text.WraptextFormat: Text.PlainTextlevel: 5}QQC2.Label {id: keySequenceListLayout.maximumWidth: parent.width - displayLabel.width - expandButton.widthcolor: {if (root.selected) {return Kirigami.Theme.highlightedTextColor;} else if (model?.activeShortcuts?.length !== 0) {return Kirigami.Theme.textColor;} else {return Kirigami.Theme.disabledTextColor;}}elide: Text.ElideRighthorizontalAlignment: Text.AlignRighttext: {if (model?.activeShortcuts?.length !== 0) {return model?.activeShortcuts?.map(s => kcm.keySequenceToString(s)).join(", ")} else {return i18n("No active shortcuts")}}textFormat: Text.PlainText}Rectangle {id: defaultIndicatorradius: width * 0.5implicitWidth: Kirigami.Units.largeSpacingimplicitHeight: Kirigami.Units.largeSpacingvisible: kcm.defaultsIndicatorsVisibleopacity: !model.isDefaultcolor: Kirigami.Theme.neutralTextColor}QQC2.ToolButton {Layout.alignment: Qt.AlignRightid: expandButtonvisible: root.showExpandButtonicon.name: "expand"activeFocusOnTab: falseonClicked: expandAction.trigger()}}}Loader {id: editLoaderactive: falsevisible: falseLayout.fillWidth: truesourceComponent: RowLayout {readonly property var originalIndex : {const concatenatedIndex = kcm.filteredModel.mapToSource(dm.modelIndex(index))return kcm.shortcutsModel.mapToSource(concatenatedIndex)}spacing: 0ColumnLayout {Layout.alignment: Qt.AlignTopLayout.preferredWidth: parent.width * 0.5spacing: Kirigami.Units.smallSpacingKirigami.Heading {level: 4text: model.defaultShortcuts && model.defaultShortcuts.length !== 0 ?i18ncp("%1 decides if singular or plural will be used", "Default shortcut","Default shortcuts", model.defaultShortcuts.length) :i18n("No default shortcuts")textFormat: Text.PlainText}Kirigami.Separator {Layout.fillWidth: true}Repeater {model: defaultShortcutsQQC2.CheckBox {Accessible.name: checked ? i18n("Default shortcut %1 is enabled.", modelData) : i18n("Default shortcut %1 is disabled.", modelData)checked: activeShortcuts.indexOf(modelData) !== -1text: modelDataonToggled: {if (checked) {kcm.requestKeySequence(this, originalIndex, modelData)} else {originalIndex.model.disableShortcut(originalIndex, modelData)}}KCM.SettingHighlighter {highlight: !checked}}}}ColumnLayout {Layout.alignment: Qt.AlignTop | Qt.AlignRightspacing: Kirigami.Units.smallSpacingKirigami.Heading {level: 4Layout.alignment: Qt.AlignRighttext: i18n("Custom shortcuts")textFormat: Text.PlainText}Kirigami.Separator {Layout.fillWidth: true}Repeater {model: customShortcutsRowLayout {spacing: Kirigami.Units.smallSpacingLayout.alignment: Qt.AlignRightKeySequenceItem {Layout.alignment: Qt.AlignRightkeySequence: modelDatashowClearButton: falsemodifierOnlyAllowed: truemultiKeyShortcutsAllowed: supportsMultipleKeyscheckForConflictsAgainst: ShortcutType.NoneonCaptureFinished: {kcm.requestKeySequence(this, originalIndex, keySequence, modelData)}KCM.SettingHighlighter {highlight: true}}QQC2.Button {Accessible.name: i18nc("@action:button accessible", "Delete shortcut")icon.name: "edit-delete"onClicked: originalIndex.model.disableShortcut(originalIndex, modelData)QQC2.ToolTip {text: i18nc("@info:tooltip", "Delete this shortcut")}}}}QQC2.Button {text: i18nc("@action:button Add custom shortcut", "Add…")Accessible.name: i18nc("@action:button accessible", "Add custom shortcut")icon.name: "list-add-symbolic"Layout.alignment: Qt.AlignRightonClicked: {this.visible = falsevar newKeySequenceItem = newKeySequenceComponent.createObject(parent)for (var i = 0; i < newKeySequenceItem.children.length; i++) {if (newKeySequenceItem.children[i] instanceof KeySequenceItem) {var keySequenceItem = newKeySequenceItem.children[i]}}newKeySequenceItem.finished.connect(() => {newKeySequenceItem.destroy()this.visible = true})keySequenceItem.startCapturing()}}Component {id: newKeySequenceComponentRowLayout {signal finishedLayout.alignment: Qt.AlignRightspacing: Kirigami.Units.smallSpacingKeySequenceItem {showClearButton: falsemodifierOnlyAllowed: truemultiKeyShortcutsAllowed: model.supportsMultipleKeyscheckForConflictsAgainst: ShortcutType.NoneonCaptureFinished: {kcm.requestKeySequence(this, originalIndex, keySequence)parent.finished()}}QQC2.Button {Accessible.name: i18nc("@action:button accessible", "Cancel capturing shortcut")icon.name: "dialog-cancel"onClicked: parent.finished()QQC2.ToolTip {text: i18nc("@info:tooltip", "Cancel capturing of new shortcut")}}}}}}}}states: [State {name: "expanded"when: shortcutsList.selectedIndex === index || shortcutsList.count == 1PropertyChanges {target: roothoverEnabled: false}PropertyChanges {target: displayLabellevel: 3Layout.fillWidth: true}PropertyChanges {target: keySequenceListvisible: false}PropertyChanges {target: expandButtonicon.name: "collapse"}PropertyChanges {target: editLoaderactive: truevisible: true}}]Behavior on height {NumberAnimation {properties: "height"duration: Kirigami.Units.shortDuration}}}