/*SPDX-FileCopyrightText: 2024 Evgeny Chesnokov <echesnokov@astralinux.ru>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport QtQuick.Layoutsimport QtQuick.Controls as QQC2import org.kde.kquickcontrols as KQuickControlsimport org.kde.kirigami as Kirigamiimport org.kde.plasma.private.kcm_keyboard as KCMKeyboardItem {id: itemDelegateimplicitWidth: ListView.view.widthimplicitHeight: delegate.heightproperty list<Kirigami.Action> actionsproperty bool isLoopingLayoutrequired property var modelrequired property int indexrequired property string layoutNamerequired property string layoutrequired property string variantrequired property string variantNamerequired property string shortcutrequired property string displayNamereadonly property var view: ListView.viewreadonly property int keySequenceItemWidth : keySequenceItem.implicitWidthsignal move(int oldIndex, int newIndex)// Make grayed bg for looping layoutsRectangle {anchors.fill: parentKirigami.Theme.colorSet: Kirigami.Theme.WindowKirigami.Theme.inherit: falsecolor: Kirigami.Theme.alternateBackgroundColorvisible: isLoopingLayout}QQC2.ItemDelegate {id: delegateimplicitWidth: itemDelegate.width// Because there's content on both sides of the list itemKirigami.Theme.useAlternateBackgroundColor: true// There's no need for a list item to ever be selecteddown: falsehighlighted: falsehoverEnabled: falsecontentItem: RowLayout {spacing: Kirigami.Units.smallSpacingKirigami.ListItemDragHandle {listItem: delegatelistView: itemDelegate.viewonMoveRequested: (oldIndex, newIndex) => itemDelegate.move(oldIndex, newIndex)visible: itemDelegate.view.count > 1}Kirigami.IconTitleSubtitle {icon.width: Kirigami.Units.iconSizes.smallMediumicon.height: Kirigami.Units.iconSizes.smallMediumicon.source: KCMKeyboard.Flags.getIcon(itemDelegate.layout)title: itemDelegate.layoutNamesubtitle: itemDelegate.variantNameLayout.fillWidth: true}QQC2.TextField {Layout.preferredWidth: Kirigami.Units.gridUnit * 3maximumLength: 3horizontalAlignment: Text.AlignHCenterplaceholderText: itemDelegate.layoutbackground.visible: activeFocustext: itemDelegate.displayNameonTextEdited: {// Immediate response except for "", which resets to defaultif (text.length > 0) {itemDelegate.model.displayName = text}}onEditingFinished: itemDelegate.model.displayName = textKeys.onEscapePressed: editingFinished()}// Spacer to align items to the left of the KeySequenceItemItem {Layout.preferredWidth: itemDelegate.view.maxKeySequenceItemWidth - keySequenceItem.implicitWidth}KQuickControls.KeySequenceItem {id: keySequenceItemshowCancelButton: truepatterns: KQuickControls.ShortcutPattern.Modifier | KQuickControls.ShortcutPattern.ModifierAndKeykeySequence: itemDelegate.shortcutonKeySequenceChanged: itemDelegate.view.maxKeySequenceItemWidthChanged()onCaptureFinished: itemDelegate.model.shortcut = keySequence}Kirigami.ActionToolBar {Layout.fillWidth: falseactions: itemDelegate.actionsflat: false // Only use flat buttons in window toolbars}}}}