/*SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>SPDX-FileCopyrightText: 2025 Yelsin Sepulveda <yelsin.sepulveda@kdemail.org>SPDX-FileCopyrightText: 2025 Jakob Petsovits <jpetso@petsovits.com>SPDX-License-Identifier: GPL-2.0-or-later*/import QtQuickimport QtQuick.Layoutsimport QtQuick.Controls as QQC2import org.kde.kcmutils as KCMimport org.kde.kirigami as Kirigamiimport org.kde.plasma.gamecontroller.kcmKCM.SimpleKCM {id: rootreadonly property var device: deviceCombo.currentValue !== null ? DeviceModel.device(deviceCombo.currentValue) : nullreadonly property var deviceType: device?.type ?? ""readonly property var deviceControllerType: device?.controllerTypeName ?? ""readonly property var deviceConnectionType: device?.connectionType ?? ""actions: [Kirigami.Action {displayComponent: RowLayout {spacing: Kirigami.Units.smallSpacingLayout.fillWidth: trueQQC2.Switch {id: plasmaIntegrationSwitchtext: i18nc("@option:check Allow using game controllers as a pointer and keyboard", "Allow using as pointer and keyboard")checked: kcm.pluginEnabledonToggled: {kcm.pluginEnabled = checked}}Kirigami.ContextualHelpButton {toolTipText: xi18nc("@info:tooltip", "Allow game controllers to act like pointer and keyboard devices in Plasma and non-game applications.<nl/><nl/>Games can always use the controller.")}}}]Kirigami.PlaceholderMessage {icon.name: "input-gamepad"text: i18nc("@info placeholdermessage text", "No game controllers found")explanation: i18nc("@info:usagetip placeholdermessage text", "Connect a wired or wireless controller")anchors.centerIn: parentvisible: DeviceModel.count === 0width: parent.width - (Kirigami.Units.largeSpacing * 4)}Connections {target: DeviceModelfunction onDevicesChanged() {// If there are no devices, make sure the combo box is set to no selectionif (DeviceModel.count === 0) {deviceCombo.currentIndex = -1;} else if (deviceCombo.currentIndex === -1) {// However if we didn't have a selection before, and now have a devicedeviceCombo.currentIndex = 0;} else if (deviceCombo.currentIndex >= DeviceModel.count) {// If the last device in the popup list was disconnected, select a previous onedeviceCombo.currentIndex = DeviceModel.count - 1;}}}headerPaddingEnabled: false // Let the InlineMessages touch the edgesheader: Kirigami.InlineMessage {Layout.fillWidth: truevisible: !kcm.pluginEnabled && deviceCombo.count !== 0type: Kirigami.MessageType.Warningposition: Kirigami.InlineMessage.Position.HeadershowCloseButton: truetext: i18nc("@info:usagetip", "The system may automatically go to sleep or lock the screen while the controller is in use. Consider manually blocking them while using the controller, or enable automatic blocking by allowing the use as pointer and keyboard.")}ColumnLayout {anchors.fill: parentvisible: deviceCombo.count !== 0spacing: Kirigami.Units.largeSpacingRowLayout {spacing: Kirigami.Units.largeSpacingLayout.fillWidth: trueQQC2.Label {text: i18nc("@label:textbox", "Device:")textFormat: Text.PlainText}QQC2.ComboBox {id: deviceCombomodel: DeviceModeltextRole: "text"valueRole: "id"Layout.fillWidth: true}}RowLayout {spacing: Kirigami.Units.largeSpacingLayout.fillWidth: trueQQC2.Label {text: i18nc("@label game controller device type (wheel, joystick, game controller, etc.)", "Device type:")textFormat: Text.PlainText}QQC2.Label {id: typeLabeltext: deviceType}}RowLayout {spacing: Kirigami.Units.largeSpacingLayout.fillWidth: trueQQC2.Label {text: i18nc("@label game controller controller type (which brand, etc.)", "Controller type:")textFormat: Text.PlainText}QQC2.Label {id: controllerTypeLabeltext: deviceControllerType}}RowLayout {spacing: Kirigami.Units.largeSpacingLayout.fillWidth: trueQQC2.Label {text: i18nc("@label:textbox", "Connection type:")textFormat: Text.PlainText}QQC2.Label {id: connectionTypeLabeltext: deviceConnectionType}}RowLayout {spacing: Kirigami.Units.largeSpacingLayout.fillWidth: trueLayout.fillHeight: trueColumnLayout {spacing: Kirigami.Units.largeSpacingLayout.alignment: Qt.AlignTopQQC2.Label {text: i18nc("@label Visual representation of the axis position for the left axis", "Left position:")textFormat: Text.PlainText}PositionWidget {id: leftPosWidgetdevice: root.deviceleftAxis: true}QQC2.Label {text: i18nc("@label Visual representation of the axis position for the right axis", "Right position:")textFormat: Text.PlainText}PositionWidget {id: rightPosWidgetdevice: root.deviceleftAxis: false}}ColumnLayout {spacing: Kirigami.Units.largeSpacingLayout.fillWidth: trueLayout.fillHeight: trueLayout.preferredWidth: 50 // Same space for the two columnsQQC2.Label {text: i18nc("@label Gamepad buttons", "Buttons:")textFormat: Text.PlainText}Table {model: ButtonModel {device: root.device}Layout.fillWidth: trueLayout.fillHeight: true}}ColumnLayout {spacing: Kirigami.Units.largeSpacingLayout.fillWidth: trueLayout.fillHeight: trueLayout.preferredWidth: 50 // Same space for the two columnsQQC2.Label {text: i18nc("@label Gamepad axes (sticks)", "Axes:")textFormat: Text.PlainText}Table {model: AxesProxyModel {device: root.device}Layout.fillWidth: trueLayout.fillHeight: true}}}Item { Layout.fillHeight: true }}}