/*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.kitemmodels as KItemModelsimport org.kde.kirigami as Kirigamiimport org.kde.kcmutils as KCMimport org.kde.plasma.private.kcm_keyboard as KCMKeyboardKirigami.Dialog {id: dialogtitle: i18nc("@title:window", "Add Layout")modal: trueimplicitWidth: Kirigami.Units.gridUnit * 32implicitHeight: Kirigami.Units.gridUnit * 24padding: Kirigami.Units.largeSpacingstandardButtons: QQC2.Dialog.Ok | QQC2.Dialog.CancelComponent.onCompleted: {let button = standardButton(QQC2.Dialog.Ok);button.enabled = Qt.binding(() => layoutsView.currentIndex >= 0);}onAccepted: {const layout = layoutsView.currentItem.shortNameconst variant = layoutsView.currentItem.variantNameconst shortcut = sequenceItem.keySequence;const displayName = layout === displayNameField.text ? "" : displayNameField.textkcm.userLayoutModel.addLayout(layout, variant, shortcut, displayName)}KItemModels.KSortFilterProxyModel {id: layoutsProxysourceModel: kcm?.layouts ?? undefinedfilterRoleName: "description"sortRoleName: "description"sortOrder: Qt.AscendingOrder}contentItem: ColumnLayout {spacing: Kirigami.Units.smallSpacingKirigami.SearchField {Layout.fillWidth: true// Likewise explicitly setting filterRegularExpression changes the current case sensitivity, thereby breaking its bindingonAccepted: layoutsProxy.filterRegularExpression = new RegExp(text, "i")}QQC2.ScrollView {clip: trueLayout.fillWidth: trueLayout.fillHeight: trueComponent.onCompleted: {if (background) {background.visible = true;}}ListView {id: layoutsViewmodel: layoutsProxyboundsBehavior: Flickable.StopAtBoundscurrentIndex: -1delegate: QQC2.ItemDelegate {id: delegatewidth: layoutsView.widthhighlighted: ListView.isCurrentItemonClicked: layoutsView.currentIndex = indexrequired property string shortNamerequired property string descriptionrequired property string variantNamerequired property int indexcontentItem: RowLayout {spacing: Kirigami.Units.smallSpacingKirigami.Icon {source: KCMKeyboard.Flags.getIcon(delegate.shortName)visible: valid}QQC2.Label {Layout.fillWidth: truetext: delegate.description}QQC2.ToolButton {icon.name: "input-keyboard-virtual-symbolic"text: i18nc("@action:button", "Preview")display: QQC2.ToolButton.IconOnlyvisible: delegate.hoveredQQC2.ToolTip.text: textQQC2.ToolTip.visible: hoveredonClicked: kcm.requestPreview(kcm.keyboardSettings.keyboardModel, delegate.shortName, delegate.variantName)}}}}}RowLayout {spacing: Kirigami.Units.smallSpacingQQC2.Label {text: i18nc("@label:textbox", "Display text:")}QQC2.TextField {id: displayNameFieldmaximumLength: 3Binding {target: displayNameFieldproperty: "text"value: layoutsView.currentItem?.shortName ?? ""}}Item {Layout.fillWidth: true}QQC2.Label {text: i18nc("@option:textbox", "Shortcut:")}KQuickControls.KeySequenceItem {id: sequenceItem// To avoid fillHeight from clear buttonLayout.fillHeight: false}}}}