|
| 1 | +// -*- coding: utf-8; -*- |
| 2 | +// |
| 3 | +// Copyright (C) 2015 - 2025 Lionel Ott |
| 4 | +// |
| 5 | +// This program is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// This program is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + |
| 18 | + |
| 19 | +import QtQuick |
| 20 | +import QtQuick.Controls |
| 21 | +import QtQuick.Layouts |
| 22 | +import QtQuick.Window |
| 23 | + |
| 24 | +import QtQuick.Controls.Universal |
| 25 | + |
| 26 | +import Gremlin.Device |
| 27 | +import Gremlin.Profile |
| 28 | +import Gremlin.UI |
| 29 | + |
| 30 | + |
| 31 | +Window { |
| 32 | + id: _root |
| 33 | + |
| 34 | + minimumWidth: 900 |
| 35 | + minimumHeight: 300 |
| 36 | + |
| 37 | + title: "Auto Mapper" |
| 38 | + |
| 39 | + DeviceListModel { |
| 40 | + id: physicalDevices |
| 41 | + deviceType: "physical" |
| 42 | + } |
| 43 | + |
| 44 | + DeviceListModel { |
| 45 | + id: virtualDevices |
| 46 | + deviceType: "virtual" |
| 47 | + } |
| 48 | + |
| 49 | + property AutoMapper autoMapper: backend.getAutoMapper() |
| 50 | + |
| 51 | + // Properties to track the selected devices |
| 52 | + property var selectedPhysicalDevices: ({}) |
| 53 | + property var selectedVJoyDevices: ({}) |
| 54 | + property bool overwriteNonEmpty: false |
| 55 | + property bool repeatVJoy: false |
| 56 | + |
| 57 | + Rectangle { |
| 58 | + id: mainWindow |
| 59 | + anchors.fill: parent |
| 60 | + anchors.margins: 10 |
| 61 | + |
| 62 | + Column { |
| 63 | + id: mainColumn |
| 64 | + anchors.fill: parent |
| 65 | + spacing: 10 |
| 66 | + |
| 67 | + Row { |
| 68 | + id: devicesRow |
| 69 | + width: parent.width |
| 70 | + height: parent.height - 60 // Leave space for the button |
| 71 | + spacing: 20 |
| 72 | + |
| 73 | + Column { |
| 74 | + id: physicalDevicesColumn |
| 75 | + width: parent.width * 0.45 |
| 76 | + height: parent.height |
| 77 | + spacing: 5 |
| 78 | + |
| 79 | + CheckBox { |
| 80 | + id: overwriteNonEmptyPhysicalInputsCheckbox |
| 81 | + width: parent.width |
| 82 | + text: qsTr("Overwrite non-empty physical inputs") |
| 83 | + checked: overwriteNonEmpty |
| 84 | + onCheckedChanged: overwriteNonEmpty = checked |
| 85 | + } |
| 86 | + |
| 87 | + GroupBox { |
| 88 | + id: physicalDevicesGroupBox |
| 89 | + width: parent.width |
| 90 | + height: parent.height - overwriteNonEmptyPhysicalInputsCheckbox.height - 5 |
| 91 | + title: qsTr("Physical Devices") |
| 92 | + |
| 93 | + ScrollView { |
| 94 | + id: physicalDevicesScroll |
| 95 | + anchors.fill: parent |
| 96 | + clip: true |
| 97 | + |
| 98 | + Column { |
| 99 | + width: physicalDevicesScroll.width - 20 |
| 100 | + spacing: 5 |
| 101 | + padding: 5 |
| 102 | + |
| 103 | + Repeater { |
| 104 | + model: physicalDevices |
| 105 | + delegate: CheckBox { |
| 106 | + width: parent.width - 10 |
| 107 | + text: model.name |
| 108 | + checked: false |
| 109 | + onCheckedChanged: { |
| 110 | + selectedPhysicalDevices[model.guid] = checked; |
| 111 | + } |
| 112 | + } |
| 113 | + } |
| 114 | + } |
| 115 | + } |
| 116 | + } |
| 117 | + } |
| 118 | + |
| 119 | + Column { |
| 120 | + id: vjoyDevicesColumn |
| 121 | + width: parent.width * 0.45 |
| 122 | + height: parent.height |
| 123 | + spacing: 5 |
| 124 | + |
| 125 | + CheckBox { |
| 126 | + id: repeatVJoyCheckbox |
| 127 | + width: parent.width |
| 128 | + text: qsTr("Repeat vJoy devices") |
| 129 | + checked: repeatVJoy |
| 130 | + onCheckedChanged: repeatVJoy = checked |
| 131 | + } |
| 132 | + |
| 133 | + GroupBox { |
| 134 | + id: vjoyDevicesGroupBox |
| 135 | + width: parent.width |
| 136 | + height: parent.height - repeatVJoyCheckbox.height - 5 |
| 137 | + title: qsTr("vJoy Devices") |
| 138 | + |
| 139 | + ScrollView { |
| 140 | + id: vjoyDevicesScroll |
| 141 | + anchors.fill: parent |
| 142 | + clip: true |
| 143 | + |
| 144 | + Column { |
| 145 | + width: vjoyDevicesScroll.width - 20 |
| 146 | + spacing: 5 |
| 147 | + padding: 5 |
| 148 | + |
| 149 | + Repeater { |
| 150 | + model: virtualDevices |
| 151 | + delegate: CheckBox { |
| 152 | + width: parent.width - 10 |
| 153 | + text: model.name |
| 154 | + checked: false |
| 155 | + onCheckedChanged: { |
| 156 | + selectedVJoyDevices[model.vjoy_id] = checked; |
| 157 | + } |
| 158 | + } |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + } |
| 163 | + } |
| 164 | + } |
| 165 | + |
| 166 | + Row { |
| 167 | + id: buttonRow |
| 168 | + width: Math.min(600, parent.width * 0.8) |
| 169 | + height: 60 |
| 170 | + spacing: 10 |
| 171 | + anchors.horizontalCenter: parent.horizontalCenter |
| 172 | + |
| 173 | + Button { |
| 174 | + id: createButton |
| 175 | + text: qsTr("Create 1:1 mappings") |
| 176 | + onClicked: { |
| 177 | + var result = autoMapper.create_mappings( |
| 178 | + selectedPhysicalDevices, selectedVJoyDevices, |
| 179 | + overwriteNonEmpty, repeatVJoy); |
| 180 | + resultText.text = result ? result : ""; |
| 181 | + } |
| 182 | + height: parent.height |
| 183 | + width: 200 |
| 184 | + } |
| 185 | + |
| 186 | + TextArea { |
| 187 | + id: resultText |
| 188 | + width: parent.width - createButton.width - parent.spacing |
| 189 | + height: parent.height |
| 190 | + readOnly: true |
| 191 | + wrapMode: Text.WordWrap |
| 192 | + horizontalAlignment: Text.AlignRight |
| 193 | + placeholderText: qsTr("Awaiting user selections and button press") |
| 194 | + background: Rectangle { |
| 195 | + color: "#f5f5f5" |
| 196 | + border.color: "#cccccc" |
| 197 | + border.width: 1 |
| 198 | + radius: 2 |
| 199 | + } |
| 200 | + } |
| 201 | + } |
| 202 | + } |
| 203 | + } |
| 204 | +} |
0 commit comments