/*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.kquickcontrolsSimpleKCM {id: rootproperty bool testerWindowOpen: falseproperty KCM.InputDevice deviceproperty KCM.InputDevice padDeviceConfigModule.buttons: ConfigModule.Default | ConfigModule.ApplyimplicitWidth: Kirigami.Units.gridUnit * 38implicitHeight: Kirigami.Units.gridUnit * 35topPadding: 0leftPadding: 0rightPadding: 0bottomPadding: 0// So it doesn't scroll while draggingflickable.interactive: Kirigami.Settings.hasTransientTouchInputKirigami.PlaceholderMessage {icon.name: "preferences-desktop-tablet"text: i18ndc("kcm_tablet", "@info placeholdermessage text", "No drawing tablets found")explanation: i18nc("@info:usagetip placeholdermessage explanation", "Connect a drawing tablet")anchors.centerIn: parentvisible: combo.count === 0width: parent.width - (Kirigami.Units.largeSpacing * 4)}actions: [Kirigami.Action {text: i18ndc("kcm_tablet", "Tests tablet functionality like the pen", "Test Tabletβ¦")icon.name: "tool_pen-symbolic"enabled: !root.testerWindowOpen && combo.count !== 0onTriggered: {const component = Qt.createComponent("Tester.qml");if (component.status === Component.Ready) {const window = component.createObject(root, {tabletEvents: events});window.showNormal();window.closing.connect(close => {root.testerWindowOpen = false;});root.testerWindowOpen = true;} else {console.error(component.errorString());}}}]function cancelCalibration(): void {if (root.calibrationWindowOpen) {calibrationWindow.close();calibrationWindow = null;}}Connections {target: combo.modelfunction onDeviceRemoved(sysname: string): void {if (root.currentCalibrationSysName === sysname) {cancelCalibration();}}}header: Kirigami.InlineMessage {position: Kirigami.InlineMessage.Position.Headertype: Kirigami.MessageType.Warningtext: i18ndc("kcm_tablet", "@info", "This device is managed by a user-space driver that you installed. Use that driver to configure the tablet instead of using the settings here, unless specifically instructed otherwise.")visible: (root.device?.isVirtual ?? false) || (root.padDevice?.isVirtual ?? false)showCloseButton: false}ColumnLayout {id: formvisible: combo.count > 0enabled: combo.count > 0anchors.fill: parentKirigami.FormLayout {visible: combo.count > 1Layout.fillWidth: trueQQC2.ComboBox {id: comboKirigami.FormData.label: i18ndc("kcm_tablet", "@label:listbox The device we are configuring", "Device:")model: kcm.tabletsModelonCountChanged: {// If a device is added, select that device first.if (count > 0 && currentIndex < 0) {currentIndex = 0;return;}// If we had previously selected the last device (that was removed) then go back one.if (currentIndex >= count) {currentIndex = count - 1;}}onCurrentIndexChanged: reload()function reload(): void {root.device = kcm.tabletsModel.penAt(combo.currentIndex);root.padDevice = kcm.tabletsModel.padAt(combo.currentIndex);// If it is a pen device, prefer the display tab first.// Otherwise, if it's a lonely pad then we only have the pad tab available.if (root.device) {displayAction.trigger();} else if (root.padDevice) {padAction.trigger();}if (displayAction.checked) {contentLoader.item.reloadOutputView();}}Connections {target: kcm.tabletsModelfunction onDeviceChanged(index: int): void {if (index === combo.currentIndex) {combo.reload();}}}Connections {target: kcmfunction onSettingsRestored(): void {if (displayAction.checked) {contentLoader.item.reloadOutputView();}}}}}Kirigami.NavigationTabBar {Kirigami.Theme.inherit: falseKirigami.Theme.colorSet: Kirigami.Theme.Windowenabled: root.device || root.padDeviceactions: [Kirigami.Action {id: displayActionicon.name: "input-tablet-symbolic"text: i18nc("@title:tab", "Display")visible: root.devicechecked: contentLoader.sourceComponent === displayTabonTriggered: {contentLoader.sourceComponent = displayTab;contentLoader.item.reloadOutputView(); // When switching between tabs, the visual rect comes out of sync so we need to correct it again.checked = true;}},Kirigami.Action {id: penActionicon.name: "tool_pen-symbolic"text: i18nc("@title:tab", "Pen")visible: root.devicechecked: contentLoader.sourceComponent === stylusTabonTriggered: {contentLoader.sourceComponent = stylusTab;checked = true;}},Kirigami.Action {id: padActionicon.name: "tablet-symbolic"text: i18nc("@title:tab", "Pad")checked: contentLoader.sourceComponent === padTab || contentLoader.sourceComponent === missingPadTabonTriggered: {contentLoader.sourceComponent = root.padDevice ? padTab : missingPadTab;checked = true;}}]Layout.fillWidth: true}Loader {id: contentLoaderactive: root.device || root.padDeviceLayout.fillWidth: trueLayout.fillHeight: trueKCM.TabletEvents {id: eventsanchors.fill: parent}}}Component {id: displayTabDisplayTab {id: tabdevice: root.deviceConnections {target: kcmfunction onSettingsRestored(): void {tab.settingsRestored();}}}}Component {id: stylusTabStylusTab {id: tabdb: kcm.dbdevice: root.devicetabletEvents: eventsConnections {target: kcmfunction onSettingsRestored(): void {tab.settingsRestored();}}}}Component {id: padTabPadTab {device: root.devicepadDevice: root.padDevicetabletEvents: events}}Component {id: missingPadTabMissingPadTab {}}}