/*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: expandActiontext: root.state === "expanded"? i18nc("@action:button Collapse shortcuts view", "Collapse"): i18nc("@action:button", "Expand to configure shortcuts")icon.name: root.state === "expanded" ? "collapse" : "expand"onTriggered: {shortcutsList.selectedIndex = (root.state === "expanded") ? -1 : index;}}Accessible.name: root.state === "expanded" ? i18nc("@info:whatsthis accessible name %1 is shortcut label (not sequence)", "Editing shortcut: %1", displayLabel.text) : displayLabel.text + keySequenceList.textAccessible.onPressAction: action.trigger()Kirigami.Theme.useAlternateBackgroundColor: truecontentItem: 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.fillWidth: trueLayout.horizontalStretchFactor: 1color: {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: {let noShortcuts = i18nc("@info:status", "No active shortcuts")if (model?.activeShortcuts?.length !== 0) {return model?.activeShortcuts?.map(s => kcm.keySequenceToString(s)).join(", ") ?? noShortcuts} else {return noShortcuts}}textFormat: Text.PlainText}Rectangle {id: defaultIndicatorradius: width * 0.5implicitWidth: Kirigami.Units.largeSpacingimplicitHeight: Kirigami.Units.largeSpacingvisible: kcm.defaultsIndicatorsVisibleopacity: !model.isDefaultcolor: Kirigami.Theme.neutralTextColor}QQC2.Button {Layout.alignment: Qt.AlignRightvisible: root.showExpandButtondisplay: QQC2.AbstractButton.IconOnlyaction: expandActionactiveFocusOnTab: falseQQC2.ToolTip.text: textQQC2.ToolTip.visible: hovered || activeFocusQQC2.ToolTip.delay: Kirigami.Units.toolTipDelay}}}Loader {id: editLoaderactive: falsevisible: falseLayout.fillWidth: truesourceComponent: ColumnLayout {readonly property var originalIndex : {const concatenatedIndex = kcm.filteredModel.mapToSource(dm.modelIndex(index))return kcm.shortcutsModel.mapToSource(concatenatedIndex)}spacing: Kirigami.Units.smallSpacingRowLayout {Layout.fillWidth: truespacing: 0Kirigami.Heading {Layout.fillWidth: truelevel: 4text: model.defaultShortcuts && model.defaultShortcuts.length !== 0 ?i18ncp("@title:column %1 decides if singular or plural will be used", "Default shortcut","Default shortcuts", model.defaultShortcuts.length) :i18nc("@label for shortcut with no default bindings", "No default shortcuts")textFormat: Text.PlainTextelide: Text.ElideRight}Kirigami.Heading {Layout.fillWidth: trueLayout.alignment: Qt.AlignRightlevel: 4text: i18nc("@title:column", "Custom shortcuts")textFormat: Text.PlainTextelide: Text.ElideRighthorizontalAlignment: Text.AlignRight}}Kirigami.Separator {Layout.fillWidth: true}RowLayout {Layout.fillWidth: truespacing: 0ColumnLayout {Layout.alignment: Qt.AlignTopLayout.fillWidth: truespacing: Kirigami.Units.smallSpacingRepeater {model: defaultShortcutsQQC2.CheckBox {Layout.fillWidth: trueAccessible.name: checked ? i18nc("@info:whatsthis accessible name", "Default shortcut %1 is enabled.", modelData) : i18nc("@info:whatsthis accessible name", "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.AlignRightLayout.fillWidth: truespacing: Kirigami.Units.smallSpacingRepeater {model: customShortcutsRowLayout {spacing: Kirigami.Units.smallSpacingLayout.alignment: Qt.AlignRightKeySequenceItem {id: keySequenceEditorLayout.alignment: Qt.AlignRightkeySequence: modelDatashowClearButton: falsepatterns: ShortcutPattern.ModifierAndKey | ShortcutPattern.ModifiermultiKeyShortcutsAllowed: supportsMultipleKeyscheckForConflictsAgainst: ShortcutType.NoneonCaptureFinished: {kcm.requestKeySequence(this, originalIndex, keySequence, modelData)}KCM.SettingHighlighter {highlight: true}Connections {target: kcmfunction onShortcutChangeRejected() {if (keySequenceEditor.keySequence !== modelData) {keySequenceEditor.keySequence = Qt.binding(() => modelData)}}}}QQC2.Button {icon.name: "edit-delete"text: i18nc("@action:button accessible", "Delete shortcut")display: QQC2.AbstractButton.IconOnlyonClicked: originalIndex.model.disableShortcut(originalIndex, modelData)QQC2.ToolTip.text: textQQC2.ToolTip.visible: hovered || activeFocusQQC2.ToolTip.delay: Kirigami.Units.toolTipDelay}}}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: falsepatterns: ShortcutPattern.Modifier | ShortcutPattern.ModifierAndKeymultiKeyShortcutsAllowed: model.supportsMultipleKeyscheckForConflictsAgainst: ShortcutType.NoneonCaptureFinished: {kcm.requestKeySequence(this, originalIndex, keySequence)parent.finished()}}QQC2.Button {icon.name: "dialog-cancel"text: i18nc("@action:button accessible", "Cancel capturing shortcut")display: QQC2.AbstractButton.IconOnlyonClicked: parent.finished()QQC2.ToolTip.text: textQQC2.ToolTip.visible: hovered || activeFocusQQC2.ToolTip.delay: Kirigami.Units.toolTipDelay}}}}}}}}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: editLoaderactive: truevisible: true}}]Behavior on height {NumberAnimation {properties: "height"duration: Kirigami.Units.shortDuration}}}