2020-10-18 06:50:26 -05:00
|
|
|
/*
|
2021-01-05 22:48:49 -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
|
2020-12-26 01:30:18 -06:00
|
|
|
import QtQuick.Controls 2.12
|
2020-10-18 06:50:26 -05:00
|
|
|
|
2021-02-04 22:36:33 -05:00
|
|
|
import SerialStudio 1.0
|
2021-01-30 14:12:03 -05:00
|
|
|
import Qt.labs.settings 1.0
|
|
|
|
|
2020-10-18 06:50:26 -05:00
|
|
|
import "../Widgets" as Widgets
|
|
|
|
|
2020-12-27 18:38:26 -06:00
|
|
|
Control {
|
2020-12-27 17:21:19 -06:00
|
|
|
id: root
|
2021-02-06 01:40:53 -05:00
|
|
|
|
2020-12-27 17:21:19 -06:00
|
|
|
background: Rectangle {
|
|
|
|
color: app.windowBackgroundColor
|
|
|
|
}
|
2021-02-05 16:39:16 -05:00
|
|
|
|
2021-01-25 13:12:22 -05:00
|
|
|
//
|
|
|
|
// Function to send through serial port data
|
|
|
|
//
|
2021-02-04 16:44:54 -05:00
|
|
|
function sendData() {
|
|
|
|
Cpp_IO_Console.send(send.text)
|
|
|
|
send.clear()
|
2021-01-25 13:12:22 -05:00
|
|
|
}
|
2020-10-18 06:50:26 -05:00
|
|
|
|
2021-02-09 01:22:56 -05:00
|
|
|
//
|
|
|
|
// Clears console output
|
|
|
|
//
|
|
|
|
function clearConsole() {
|
|
|
|
Cpp_IO_Console.clear()
|
|
|
|
textEdit.clear()
|
|
|
|
}
|
|
|
|
|
2021-01-30 14:12:03 -05:00
|
|
|
//
|
|
|
|
// Save settings
|
|
|
|
//
|
|
|
|
Settings {
|
2021-02-04 22:36:33 -05:00
|
|
|
property alias echo: echoCheck.checked
|
2021-01-30 14:12:03 -05:00
|
|
|
property alias hex: hexCheckbox.checked
|
2021-02-04 22:36:33 -05:00
|
|
|
property alias timestamp: timestampCheck.checked
|
|
|
|
property alias autoscroll: autoscrollCheck.checked
|
|
|
|
property alias lineEnding: lineEndingCombo.currentIndex
|
|
|
|
property alias displayMode: displayModeCombo.currentIndex
|
2021-01-30 14:12:03 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 23:09:46 -05:00
|
|
|
//
|
2021-02-07 21:37:40 -05:00
|
|
|
// Save shortcut
|
2021-02-05 23:09:46 -05:00
|
|
|
//
|
|
|
|
Shortcut {
|
|
|
|
sequence: StandardKey.Save
|
|
|
|
onActivated: Cpp_IO_Console.save()
|
|
|
|
}
|
|
|
|
|
2021-02-06 21:58:08 -05:00
|
|
|
//
|
|
|
|
// Clear console data shortcut
|
|
|
|
//
|
|
|
|
Shortcut {
|
|
|
|
sequence: StandardKey.Delete
|
2021-02-09 01:22:56 -05:00
|
|
|
onActivated: root.clearConsole()
|
2021-02-06 21:58:08 -05:00
|
|
|
}
|
|
|
|
|
2021-02-05 23:09:46 -05:00
|
|
|
//
|
|
|
|
// Right-click context menu
|
|
|
|
//
|
2021-02-09 01:57:04 -05:00
|
|
|
Menu {
|
2021-02-05 23:09:46 -05:00
|
|
|
id: menu
|
|
|
|
|
|
|
|
MenuItem {
|
2021-02-06 21:41:32 -05:00
|
|
|
id: copyMenu
|
2021-02-05 23:09:46 -05:00
|
|
|
text: qsTr("Copy")
|
2021-02-06 21:41:32 -05:00
|
|
|
opacity: enabled ? 1 : 0.5
|
2021-02-09 17:50:01 -05:00
|
|
|
onClicked: textEdit.copy()
|
2021-02-09 22:37:01 -05:00
|
|
|
enabled: textEdit.copyAvailable
|
2021-02-09 01:57:04 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Select all")
|
|
|
|
opacity: enabled ? 1 : 0.5
|
|
|
|
onTriggered: textEdit.selectAll()
|
|
|
|
enabled: textEdit.text.length > 0
|
2021-02-05 23:09:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
text: qsTr("Clear")
|
|
|
|
opacity: enabled ? 1 : 0.5
|
2021-02-09 01:57:04 -05:00
|
|
|
onTriggered: root.clearConsole()
|
2021-02-05 23:09:46 -05:00
|
|
|
enabled: Cpp_IO_Console.saveAvailable
|
|
|
|
}
|
|
|
|
|
|
|
|
MenuItem {
|
|
|
|
opacity: enabled ? 1 : 0.5
|
|
|
|
text: qsTr("Save as") + "..."
|
|
|
|
onTriggered: Cpp_IO_Console.save()
|
|
|
|
enabled: Cpp_IO_Console.saveAvailable
|
|
|
|
}
|
2021-02-09 01:57:04 -05:00
|
|
|
}
|
2021-02-05 23:09:46 -05:00
|
|
|
|
2020-10-18 06:50:26 -05:00
|
|
|
//
|
|
|
|
// Controls
|
|
|
|
//
|
|
|
|
ColumnLayout {
|
|
|
|
anchors.fill: parent
|
|
|
|
spacing: app.spacing
|
|
|
|
anchors.margins: app.spacing * 1.5
|
|
|
|
|
|
|
|
//
|
2021-02-04 16:44:54 -05:00
|
|
|
// Console display
|
2020-10-18 06:50:26 -05:00
|
|
|
//
|
2021-02-09 01:22:56 -05:00
|
|
|
QmlPlainTextEdit {
|
|
|
|
id: textEdit
|
|
|
|
focus: true
|
|
|
|
readOnly: true
|
|
|
|
color: "#8ecd9d"
|
2021-02-05 23:09:46 -05:00
|
|
|
font.pixelSize: 12
|
2021-02-09 22:37:01 -05:00
|
|
|
centerOnScroll: false
|
2021-02-09 01:22:56 -05:00
|
|
|
undoRedoEnabled: false
|
2020-10-18 06:50:26 -05:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2021-02-09 21:03:20 -05:00
|
|
|
maximumBlockCount: 1000
|
2021-02-05 23:09:46 -05:00
|
|
|
font.family: app.monoFont
|
2021-02-09 01:22:56 -05:00
|
|
|
autoscroll: Cpp_IO_Console.autoscroll
|
|
|
|
wordWrapMode: Text.WrapAtWordBoundaryOrAnywhere
|
|
|
|
placeholderText: qsTr("No data received so far") + "..."
|
|
|
|
|
2021-02-10 13:25:14 -05:00
|
|
|
onFocusChanged: {
|
|
|
|
textEdit.focusWidget()
|
|
|
|
textEdit.forceActiveFocus()
|
|
|
|
}
|
|
|
|
|
2021-02-09 01:22:56 -05:00
|
|
|
Connections {
|
|
|
|
target: Cpp_IO_Console
|
2021-02-10 00:51:47 -05:00
|
|
|
|
|
|
|
function onLineReceived(text) {
|
|
|
|
textEdit.append(text)
|
|
|
|
}
|
|
|
|
|
|
|
|
function onStringReceived(text) {
|
|
|
|
textEdit.insertText(text)
|
2021-02-09 01:22:56 -05:00
|
|
|
}
|
|
|
|
}
|
2021-02-09 01:57:04 -05:00
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
2021-02-10 13:25:14 -05:00
|
|
|
enabled: false
|
2021-02-09 01:57:04 -05:00
|
|
|
propagateComposedEvents: false
|
|
|
|
acceptedButtons: Qt.RightButton | Qt.LeftButton
|
|
|
|
onClicked: {
|
|
|
|
if (mouse.button == Qt.RightButton)
|
|
|
|
menu.popup()
|
|
|
|
}
|
|
|
|
}
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Data-write controls
|
|
|
|
//
|
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
TextField {
|
2021-02-04 16:44:54 -05:00
|
|
|
id: send
|
2020-10-18 06:50:26 -05:00
|
|
|
height: 24
|
2021-02-09 01:22:56 -05:00
|
|
|
font: textEdit.font
|
|
|
|
color: textEdit.color
|
2020-10-18 06:50:26 -05:00
|
|
|
Layout.fillWidth: true
|
2021-02-04 16:44:54 -05:00
|
|
|
enabled: Cpp_IO_Manager.readWrite
|
2021-02-05 09:34:28 -05:00
|
|
|
placeholderText: qsTr("Send data to device") + "..."
|
|
|
|
|
2021-02-05 23:09:46 -05:00
|
|
|
//
|
|
|
|
// Validate hex strings
|
|
|
|
//
|
2021-02-05 09:34:28 -05:00
|
|
|
validator: RegExpValidator {
|
|
|
|
regExp: hexCheckbox.checked ? /^[a-fA-F0-9]+$/ : /[\s\S]*/
|
|
|
|
}
|
2021-02-04 16:44:54 -05:00
|
|
|
|
2021-02-05 23:09:46 -05:00
|
|
|
//
|
|
|
|
// Send data on <enter>
|
|
|
|
//
|
2021-02-04 16:44:54 -05:00
|
|
|
Keys.onReturnPressed: root.sendData()
|
|
|
|
|
2021-02-05 23:09:46 -05:00
|
|
|
//
|
|
|
|
// Navigate command history upwards with <up>
|
|
|
|
//
|
2021-02-04 16:44:54 -05:00
|
|
|
Keys.onUpPressed: {
|
|
|
|
Cpp_IO_Console.historyUp()
|
|
|
|
send.text = Cpp_IO_Console.currentHistoryString
|
|
|
|
}
|
|
|
|
|
2021-02-05 23:09:46 -05:00
|
|
|
//
|
|
|
|
// Navigate command history downwards with <down>
|
|
|
|
//
|
2021-02-04 16:44:54 -05:00
|
|
|
Keys.onDownPressed: {
|
|
|
|
Cpp_IO_Console.historyDown()
|
|
|
|
send.text = Cpp_IO_Console.currentHistoryString
|
|
|
|
}
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
|
|
|
|
2021-02-04 16:44:54 -05:00
|
|
|
CheckBox {
|
|
|
|
id: hexCheckbox
|
|
|
|
text: "Hex"
|
2020-10-18 06:50:26 -05:00
|
|
|
opacity: enabled ? 1 : 0.5
|
2021-02-04 16:44:54 -05:00
|
|
|
enabled: Cpp_IO_Manager.readWrite
|
|
|
|
checked: Cpp_IO_Console.dataMode === 1
|
|
|
|
onCheckedChanged: {
|
|
|
|
if (checked)
|
|
|
|
Cpp_IO_Console.dataMode = 1
|
|
|
|
else
|
|
|
|
Cpp_IO_Console.dataMode = 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBox {
|
|
|
|
id: echoCheck
|
|
|
|
text: qsTr("Echo")
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
checked: Cpp_IO_Console.echo
|
|
|
|
onCheckedChanged: {
|
|
|
|
if (Cpp_IO_Console.echo != checked)
|
|
|
|
Cpp_IO_Console.echo = checked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Terminal output options
|
|
|
|
//
|
|
|
|
RowLayout {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
|
|
|
|
CheckBox {
|
|
|
|
id: autoscrollCheck
|
|
|
|
text: qsTr("Autoscroll")
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
checked: Cpp_IO_Console.autoscroll
|
|
|
|
onCheckedChanged: {
|
|
|
|
if (Cpp_IO_Console.autoscroll != checked)
|
|
|
|
Cpp_IO_Console.autoscroll = checked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CheckBox {
|
|
|
|
id: timestampCheck
|
|
|
|
text: qsTr("Show timestamp")
|
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
checked: Cpp_IO_Console.showTimestamp
|
|
|
|
onCheckedChanged: {
|
|
|
|
if (Cpp_IO_Console.showTimestamp != checked)
|
|
|
|
Cpp_IO_Console.showTimestamp = checked
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
}
|
|
|
|
|
|
|
|
ComboBox {
|
2021-02-04 22:36:33 -05:00
|
|
|
id: lineEndingCombo
|
2021-02-04 16:44:54 -05:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
model: Cpp_IO_Console.lineEndings()
|
|
|
|
currentIndex: Cpp_IO_Console.lineEnding
|
|
|
|
onCurrentIndexChanged: {
|
|
|
|
if (currentIndex != Cpp_IO_Console.lineEnding)
|
|
|
|
Cpp_IO_Console.lineEnding = currentIndex
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ComboBox {
|
2021-02-04 22:36:33 -05:00
|
|
|
id: displayModeCombo
|
2021-02-04 16:44:54 -05:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
|
|
|
model: Cpp_IO_Console.displayModes()
|
|
|
|
currentIndex: Cpp_IO_Console.displayMode
|
|
|
|
onCurrentIndexChanged: {
|
|
|
|
if (currentIndex != Cpp_IO_Console.displayMode)
|
|
|
|
Cpp_IO_Console.displayMode = currentIndex
|
|
|
|
}
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
2021-01-20 10:47:48 -05:00
|
|
|
|
|
|
|
Button {
|
|
|
|
height: 24
|
2021-02-05 10:48:29 -05:00
|
|
|
Layout.maximumWidth: 32
|
|
|
|
icon.color: palette.text
|
|
|
|
opacity: enabled ? 1 : 0.5
|
|
|
|
onClicked: Cpp_IO_Console.save()
|
|
|
|
icon.source: "qrc:/icons/save.svg"
|
|
|
|
enabled: Cpp_IO_Console.saveAvailable
|
|
|
|
Behavior on opacity {NumberAnimation{}}
|
|
|
|
}
|
|
|
|
|
|
|
|
Button {
|
|
|
|
height: 24
|
|
|
|
Layout.maximumWidth: 32
|
2021-01-20 10:47:48 -05:00
|
|
|
icon.color: palette.text
|
|
|
|
opacity: enabled ? 1 : 0.5
|
2021-02-09 01:22:56 -05:00
|
|
|
onClicked: root.clearConsole()
|
2021-01-20 10:47:48 -05:00
|
|
|
icon.source: "qrc:/icons/delete.svg"
|
2021-02-05 16:39:16 -05:00
|
|
|
enabled: Cpp_IO_Console.lineCount > 0
|
2021-01-20 10:47:48 -05:00
|
|
|
Behavior on opacity {NumberAnimation{}}
|
|
|
|
}
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|