/*SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.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) : nullKirigami.PlaceholderMessage {icon.name: "input-gamepad"text: i18n("No game controllers found")explanation: i18n("Connect a wired or wireless controller")anchors.centerIn: parentvisible: deviceModel.count === 0width: parent.width - (Kirigami.Units.largeSpacing * 4)}DeviceModel {id: deviceModelonDevicesChanged: {// 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;}}}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: 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}}}}}