/*SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@kde.org>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport QtQuick.Layoutsimport QtQuick.Controls as QQC2import QtQuick.Shapesimport org.kde.kirigami as Kirigamiimport org.kde.plasma.tablet.kcm as KCMimport org.kde.kcmutilsimport org.kde.kquickcontrolsKirigami.Form {id: rootrequired property KCM.InputDevice devicerequired property KCM.InputDevice padDevicerequired property KCM.TabletEvents tabletEventsKirigami.FormGroup {visible: ringRepeater.count > 0Repeater {id: ringRepeatermodel: root.padDevice.tabletPadRingCount// TODO: we should make this generic enough for all bindings// TODO: this doesn't take into account mode groups the ring is indelegate: Kirigami.FormEntry {id: ringDelegaterequired property int indextitle: i18ndc("kcm_tablet", "@label for graphics tablet ring config, % is number of ring", "Pad ring %1:", index + 1)contentItem: ColumnLayout {Layout.fillWidth: falsespacing: Kirigami.Units.smallSpacingRepeater {id: modesRepeatermodel: root.padDevice.numModes[0]delegate: RowLayout {id: modeLayoutrequired property int indexspacing: Kirigami.Units.largeSpacingQQC2.Label {text: modeLayout.index + 1color: Kirigami.Theme.disabledTextColorfont.bold: root.padDevice.currentModes[0] === modeLayout.indexvisible: modesRepeater.count > 1 // Don't show the mode number unless there's more than one mode to reduce clutter and confusion}ActionBinding {id: seqname: i18ndc("kcm_tablet", "@info Meant to be inserted into an existing sentence like 'configuring pad ring/dial 0'", "pad ring/dial %1", ringDelegate.index + 1)supportsPenButton: falsesupportsRelativeEvents: truefunction refreshInputSequence(): void {seq.inputSequence = kcm.padRingMapping(root.padDevice.name, ringDelegate.index, modeLayout.index)}inputSequence: kcm.padRingMapping(root.padDevice.name, ringDelegate.index, modeLayout.index)Connections {target: kcmfunction onSettingsRestored() {seq.refreshInputSequence();}}onGotInputSequence: sequence => {kcm.assignPadRingMapping(root.padDevice.name, ringDelegate.index, modeLayout.index, sequence)}SettingHighlighter {// Currently, application-defined is the defaulthighlight: seq.inputSequence.type !== KCM.InputSequence.ApplicationDefined}}}}}}}}Kirigami.FormGroup {visible: dialRepeater.count > 0Repeater {id: dialRepeatermodel: root.padDevice.tabletPadDialCountdelegate: Kirigami.FormEntry {id: dialDelegaterequired property int indextitle: i18ndc("kcm_tablet", "@label for graphics tablet ring config, % is number of dial", "Pad dial %1:", index + 1)contentItem: ActionBinding {id: seqname: i18ndc("kcm_tablet", "@info Meant to be inserted into an existing sentence like 'configuring pad button 0'", "pad dial %1", dialDelegate.index + 1)supportsPenButton: falsesupportsRelativeEvents: truefunction refreshInputSequence(): void {seq.inputSequence = kcm.padDialMapping(root.padDevice.name, dialDelegate.index)}inputSequence: kcm.padDialMapping(root.padDevice.name, dialDelegate.index)Connections {target: kcmfunction onSettingsRestored() {seq.refreshInputSequence();}}onGotInputSequence: sequence => {kcm.assignPadDialMapping(root.padDevice.name, dialDelegate.index, sequence)}SettingHighlighter {// Currently, application-defined is the defaulthighlight: seq.inputSequence.type !== KCM.InputSequence.ApplicationDefined}}}}}Kirigami.FormGroup {visible: buttonsRepeater.count > 0Repeater {id: buttonsRepeatermodel: root.padDevice.tabletPadButtonCountdelegate: Kirigami.FormEntry {id: buttonsDelegaterequired property int indextitle: (seq.buttonPressed ? "<b>" : "") + i18ndc("kcm_tablet", "@label for graphics tablet button config, % is number of button", "Pad button %1:", index + 1) + (seq.buttonPressed ? "</b>" : "")contentItem: ActionBinding {id: seqproperty bool buttonPressed: falsename: i18ndc("kcm_tablet", "@info Meant to be inserted into an existing sentence like 'configuring pad button 0'", "pad button %1", buttonsDelegate.index + 1)supportsPenButton: falseConnections {target: root.tabletEventsfunction onPadButtonReceived(path, button, pressed) {if (button !== buttonsDelegate.index || !path.endsWith(root.padDevice.sysName)) {return;}seq.buttonPressed = pressed}}function refreshInputSequence(): void {seq.inputSequence = kcm.padButtonMapping(root.padDevice.name, buttonsDelegate.index)}inputSequence: kcm.padButtonMapping(root.padDevice.name, buttonsDelegate.index)Connections {target: kcmfunction onSettingsRestored() {seq.refreshInputSequence();}}onGotInputSequence: sequence => {kcm.assignPadButtonMapping(root.padDevice.name, buttonsDelegate.index, sequence)}SettingHighlighter {// Currently, application-defined is the defaulthighlight: seq.inputSequence.type !== KCM.InputSequence.ApplicationDefined}}}}}ActionDialog {id: actionDialogparent: root.QQC2.Overlay.overlay}}