428 lines
13 KiB
QML
Raw Normal View History

2020-10-18 06:50:26 -05:00
/*
* Copyright (c) 2020-2021 Alex Spataru <https://github.com/alex-spataru>
2020-10-18 06:50:26 -05:00
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import Qt.labs.settings 1.0
2020-12-26 01:30:18 -06:00
import QtGraphicalEffects 1.0
2020-10-18 06:50:26 -05:00
import "../Widgets" as Widgets
Control {
2020-12-27 17:21:19 -06:00
id: root
2020-12-26 01:30:18 -06:00
background: Rectangle {
2020-12-27 17:21:19 -06:00
color: app.windowBackgroundColor
2020-12-26 01:30:18 -06:00
}
2020-10-18 06:50:26 -05:00
//
// Save settings
//
Settings {
2021-01-20 15:06:40 -05:00
category: "Setup"
property alias dmAuto: commAuto.checked
property alias dmManual: commManual.checked
2020-10-18 06:50:26 -05:00
property alias dmParity: parity.currentIndex
2021-02-01 18:55:15 -05:00
property alias dmCsvExport: csvLogging.checked
2020-10-18 06:50:26 -05:00
property alias dmStopBits: stopBits.currentIndex
property alias dmDataBits: dataBits.currentIndex
2021-02-01 18:55:15 -05:00
property alias dmBaudValue: baudRate.currentIndex
2020-10-18 06:50:26 -05:00
property alias dmFlowControl: flowControl.currentIndex
2021-01-04 22:11:59 -06:00
property alias appLanguage: languageCombo.currentIndex
2020-10-18 06:50:26 -05:00
}
//
// Update listbox models when translation is changed
//
Connections {
target: Cpp_Misc_Translator
function onLanguageChanged() {
var portIndex = portSelector.currentIndex
var oldParityIndex = parity.currentIndex
2021-01-30 14:12:03 -05:00
var oldDisplayModeIndex = displayMode.currentIndex
var oldFlowControlIndex = flowControl.currentIndex
parity.model = Cpp_IO_Serial.parityList
portSelector.model = Cpp_IO_Serial.portList
flowControl.model = Cpp_IO_Serial.flowControlList
displayMode.model = Cpp_IO_Serial.consoleDisplayModes
parity.currentIndex = oldParityIndex
flowControl.currentIndex = oldFlowControlIndex
2021-01-30 14:12:03 -05:00
displayMode.currentIndex = oldDisplayModeIndex
portSelector.currentIndex = portIndex
}
}
//
// Update manual/auto checkboxes
//
Connections {
target: Cpp_JSON_Generator
function onOperationModeChanged() {
commAuto.checked = (Cpp_JSON_Generator.operationMode == 1)
commManual.checked = (Cpp_JSON_Generator.operationMode == 0)
}
}
2020-10-18 06:50:26 -05:00
//
// Control arrangement
//
ColumnLayout {
2020-12-26 01:30:18 -06:00
id: column
2020-10-18 06:50:26 -05:00
anchors.fill: parent
spacing: app.spacing / 2
2020-12-26 01:30:18 -06:00
anchors.margins: app.spacing * 1.5
2020-10-18 06:50:26 -05:00
//
// Comm mode selector
//
Label {
font.bold: true
text: qsTr("Communication Mode") + ":" + Cpp_Misc_Translator.dummy
} RadioButton {
id: commAuto
checked: true
text: qsTr("Auto (JSON from serial device)") + Cpp_Misc_Translator.dummy
onCheckedChanged: {
if (checked)
Cpp_JSON_Generator.setOperationMode(1)
2021-01-04 23:33:50 -06:00
else
Cpp_JSON_Generator.setOperationMode(0)
}
} RadioButton {
id: commManual
checked: false
text: qsTr("Manual (use JSON map file)") + Cpp_Misc_Translator.dummy
onCheckedChanged: {
if (checked)
Cpp_JSON_Generator.setOperationMode(0)
2021-01-04 23:33:50 -06:00
else
Cpp_JSON_Generator.setOperationMode(1)
}
}
//
// Map file selector button
//
Button {
Layout.fillWidth: true
opacity: enabled ? 1 : 0.5
enabled: commManual.checked
onClicked: Cpp_JSON_Generator.loadJsonMap()
Behavior on opacity {NumberAnimation{}}
text: Cpp_Misc_Translator.dummy +
(Cpp_JSON_Generator.jsonMapFilename.length ? qsTr("Change map file (%1)").arg(Cpp_JSON_Generator.jsonMapFilename) :
qsTr("Select map file") + "...")
}
2021-02-01 18:55:15 -05:00
//
// Spacer
//
Item {
height: app.spacing / 2
}
//
// Enable/disable CSV logging
2021-02-01 18:55:15 -05:00
//
RowLayout {
Layout.fillWidth: true
CheckBox {
id: csvLogging
checked: true
palette.highlight: "#2e895c"
Layout.leftMargin: -app.spacing
Layout.alignment: Qt.AlignVCenter
text: qsTr("Create CSV file") + Cpp_Misc_Translator.dummy
onCheckedChanged: Cpp_CSV_Export.exportEnabled = checked
2021-02-01 18:55:15 -05:00
}
Item {
2021-02-01 18:55:15 -05:00
Layout.fillWidth: true
}
2021-02-01 18:55:15 -05:00
RoundButton {
icon.width: 24
icon.height: 24
icon.color: "#fff"
icon.source: "qrc:/icons/help.svg"
Layout.alignment: Qt.AlignVCenter
onClicked: Qt.openUrlExternally("https://github.com/Serial-Studio/Serial-Studio/wiki")
2021-02-01 18:55:15 -05:00
}
}
//
// Spacer
//
Item {
height: app.spacing / 2
}
//
// A lot of comboboxes
2020-10-18 06:50:26 -05:00
//
GridLayout {
columns: 2
2020-10-18 06:50:26 -05:00
Layout.fillWidth: true
rowSpacing: app.spacing
columnSpacing: app.spacing
2020-10-18 06:50:26 -05:00
//
// COM port selector
//
Label {
2021-02-01 18:55:15 -05:00
opacity: enabled ? 1 : 0.5
enabled: !Cpp_IO_Serial.connected
2021-02-01 18:55:15 -05:00
Behavior on opacity {NumberAnimation{}}
text: qsTr("COM Port") + ":" + Cpp_Misc_Translator.dummy
} ComboBox {
id: portSelector
Layout.fillWidth: true
model: Cpp_IO_Serial.portList
currentIndex: Cpp_IO_Serial.portIndex
2021-02-01 18:55:15 -05:00
onCurrentIndexChanged: {
if (currentIndex !== Cpp_IO_Serial.portIndex)
Cpp_IO_Serial.portIndex = currentIndex
2021-02-01 18:55:15 -05:00
}
opacity: enabled ? 1 : 0.5
enabled: !Cpp_IO_Serial.connected
2021-02-01 18:55:15 -05:00
Behavior on opacity {NumberAnimation{}}
2020-10-18 06:50:26 -05:00
}
//
// Baud rate selector
//
Label {
2021-02-01 12:32:22 -05:00
opacity: enabled ? 1 : 0.5
enabled: !Cpp_IO_Serial.connected
2021-02-01 12:32:22 -05:00
Behavior on opacity {NumberAnimation{}}
text: qsTr("Baud Rate") + ":" + Cpp_Misc_Translator.dummy
} ComboBox {
id: baudRate
2021-02-01 18:55:15 -05:00
editable: true
currentIndex: 3
Layout.fillWidth: true
model: Cpp_IO_Serial.baudRateList
2021-02-01 18:55:15 -05:00
validator: IntValidator {
bottom: 1
}
onAccepted: {
if (find(editText) === -1)
Cpp_IO_Serial.appendBaudRate(editText)
2021-02-01 18:55:15 -05:00
}
onCurrentTextChanged: {
var value = currentText
Cpp_IO_Serial.baudRate = value
2021-01-30 14:12:03 -05:00
}
}
//
// Spacer
//
Item {
Layout.minimumHeight: app.spacing / 2
Layout.maximumHeight: app.spacing / 2
} Item {
Layout.minimumHeight: app.spacing / 2
Layout.maximumHeight: app.spacing / 2
2020-10-18 06:50:26 -05:00
}
//
// Data bits selector
//
Label {
text: qsTr("Data Bits") + ":" + Cpp_Misc_Translator.dummy
} ComboBox {
id: dataBits
Layout.fillWidth: true
model: Cpp_IO_Serial.dataBitsList
currentIndex: Cpp_IO_Serial.dataBitsIndex
onCurrentIndexChanged: {
if (Cpp_IO_Serial.dataBitsIndex !== currentIndex)
Cpp_IO_Serial.dataBitsIndex = currentIndex
}
2020-10-18 06:50:26 -05:00
}
//
// Parity selector
//
Label {
text: qsTr("Parity") + ":" + Cpp_Misc_Translator.dummy
} ComboBox {
id: parity
Layout.fillWidth: true
model: Cpp_IO_Serial.parityList
currentIndex: Cpp_IO_Serial.parityIndex
onCurrentIndexChanged: {
if (Cpp_IO_Serial.parityIndex !== currentIndex)
Cpp_IO_Serial.parityIndex = currentIndex
}
2020-10-18 06:50:26 -05:00
}
//
// Stop bits selector
//
Label {
text: qsTr("Stop Bits") + ":" + Cpp_Misc_Translator.dummy
} ComboBox {
id: stopBits
Layout.fillWidth: true
model: Cpp_IO_Serial.stopBitsList
currentIndex: Cpp_IO_Serial.stopBitsIndex
onCurrentIndexChanged: {
if (Cpp_IO_Serial.stopBitsIndex !== currentIndex)
Cpp_IO_Serial.stopBitsIndex = currentIndex
}
}
2021-01-04 22:11:59 -06:00
//
// Flow control selector
//
Label {
text: qsTr("Flow Control") + ":" + Cpp_Misc_Translator.dummy
} ComboBox {
id: flowControl
Layout.fillWidth: true
model: Cpp_IO_Serial.flowControlList
currentIndex: Cpp_IO_Serial.flowControlIndex
onCurrentIndexChanged: {
if (Cpp_IO_Serial.flowControlIndex !== currentIndex)
Cpp_IO_Serial.flowControlIndex = currentIndex
}
}
//
// Spacer
//
Item {
Layout.minimumHeight: app.spacing / 2
Layout.maximumHeight: app.spacing / 2
} Item {
Layout.minimumHeight: app.spacing / 2
Layout.maximumHeight: app.spacing / 2
}
//
// Language selector
//
Label {
text: qsTr("Language") + ":" + Cpp_Misc_Translator.dummy
} ComboBox {
id: languageCombo
Layout.fillWidth: true
model: Cpp_Misc_Translator.availableLanguages
onCurrentIndexChanged: Cpp_Misc_Translator.setLanguage(currentIndex)
}
2021-01-04 22:11:59 -06:00
}
2020-10-18 06:50:26 -05:00
//
// Spacer
//
Item {
Layout.fillHeight: true
2021-01-04 22:11:59 -06:00
Layout.minimumHeight: app.spacing * 2
2020-10-18 06:50:26 -05:00
}
//
// RX/TX LEDs
//
RowLayout {
spacing: app.spacing
Layout.alignment: Qt.AlignHCenter
Widgets.LED {
id: _rx
enabled: false
Layout.alignment: Qt.AlignVCenter
Connections {
target: Cpp_IO_Manager
2020-10-18 06:50:26 -05:00
function onRx() {
_rx.flash()
}
}
}
Label {
text: "RX"
font.bold: true
font.pixelSize: 18
font.family: app.monoFont
Layout.alignment: Qt.AlignVCenter
color: _rx.enabled ? palette.highlight : _rx.offColor
}
Image {
width: sourceSize.width
height: sourceSize.height
sourceSize: Qt.size(32, 32)
source: "qrc:/icons/ethernet.svg"
Layout.alignment: Qt.AlignVCenter
ColorOverlay {
source: parent
anchors.fill: parent
color: _rx.offColor
}
}
Label {
text: "TX"
font.bold: true
font.pixelSize: 18
font.family: app.monoFont
Layout.alignment: Qt.AlignVCenter
color: _tx.enabled ? palette.highlight : _tx.offColor
}
Widgets.LED {
id: _tx
enabled: false
layoutDirection: Qt.RightToLeft
Layout.alignment: Qt.AlignVCenter
Connections {
target: Cpp_IO_Manager
2020-10-18 06:50:26 -05:00
function onTx() {
_tx.flash()
}
}
}
}
//
// Spacer
//
Item {
Layout.fillHeight: true
2021-01-04 22:11:59 -06:00
Layout.minimumHeight: app.spacing * 2
2020-10-18 06:50:26 -05:00
}
}
}