/*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.FormLayout {id: rootrequired property KCM.InputDevice devicefunction settingsRestored(): void {// we have to reload this manually because it's function-basedoutputsCombo.currentIndex = outputsCombo.findCurrentIndex();}function reloadOutputView(): void {const initialOutputArea = root.device.outputArea;if (initialOutputArea === Qt.rect(0, 0, 1, 1)) {outputAreaCombo.currentIndex = 0;} else if (initialOutputArea.x === 0 && initialOutputArea.y === 0 && initialOutputArea.width === 1) {outputAreaCombo.currentIndex = 1;} else {outputAreaCombo.currentIndex = 2;}const initialInputArea = root.device.inputArea;if (outputsCombo.currentIndex !== 0) {mapping.setOutputAreaMode(outputAreaCombo.currentIndex);mapping.setOutputArea(initialOutputArea);}mapping.setInputArea(initialInputArea);}QQC2.ComboBox {id: outputsComboKirigami.FormData.label: i18ndc("kcm_tablet", "@label:listbox", "Map to screen:")model: KCM.OutputsModel {id: outputsModel}currentIndex: findCurrentIndex()textRole: "display"onActivated: index => {root.device.outputName = outputsModel.outputNameAt(index)root.device.mapToWorkspace = outputsModel.isMapToWorkspaceAt(index)// If we are switching to "Follow current screen", ensure we're force switched to "Stretch to Fill"if (index === 0) {mapping.setOutputAreaMode(0);outputAreaCombo.currentIndex = 0;}root.reloadOutputView();}function findCurrentIndex(): int {if (count === 0) {return -1;}return outputsModel.rowForDevice(root.device);}}QQC2.ComboBox {Kirigami.FormData.label: i18ndc("kcm_tablet", "@label:listbox", "Orientation:")model: KCM.OrientationsModel {id: orientationsModel}enabled: root.device && root.device.supportsOrientationcurrentIndex: orientationsModel.rowForOrientation(root.device.orientation)displayText: root.device.supportsOrientation ? currentText : i18ndc("kcm_tablet", "@label substitute for unavailable orientation change", "Not Applicable")textRole: "display"onActivated: {root.device.orientation = orientationsModel.orientationAt(currentIndex)}SettingHighlighter {// First index is "Default"highlight: root.device.supportsOrientation && parent.currentIndex !== 0}}QQC2.ComboBox {id: outputAreaComboLayout.fillWidth: trueKirigami.FormData.label: i18ndc("kcm_tablet", "@label:listbox", "Mapped Area:")enabled: outputsCombo.currentIndex !== 0model: outputsCombo.currentIndex === 0 ?// We don't support mapping to a portion of the screen with follow current screen, since we have no way to visualize that[i18nc("@item:inlistbox Stretch and fill to the screen", "Stretch and Fill")] :[i18nc("@item:inlistbox Stretch and fill to the screen", "Stretch and Fill"),i18nc("@item:inlistbox Keep aspect ratio and fit within the screen", "Keep Aspect Ratio and Fit"),i18nc("@item:inlistbox Map to portion of the screen", "Map to Portion")]onActivated: index => {mapping.outputChanged = true;mapping.setOutputAreaMode(index);}SettingHighlighter {// The default is stretch to screenhighlight: outputAreaCombo.currentIndex !== 0}}// Mapping a tablet onto another displayExternalScreenMapping {id: mappingvisible: root.devicedisplayVisible: outputsCombo.currentIndex !== 0device: root.devicemode: outputAreaCombo.currentIndexLayout.fillWidth: true}}