2020-10-18 06:50:26 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Alex Spataru <https://github.com/alex-spataru>
|
|
|
|
*
|
|
|
|
* 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
|
2020-12-26 01:30:18 -06:00
|
|
|
import QtQuick.Window 2.12
|
2020-10-18 06:50:26 -05:00
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
|
2020-12-27 17:21:19 -06:00
|
|
|
import Qt.labs.settings 1.0
|
|
|
|
|
2020-12-26 01:30:18 -06:00
|
|
|
import "Windows"
|
2020-10-18 06:50:26 -05:00
|
|
|
|
2020-12-27 17:21:19 -06:00
|
|
|
ApplicationWindow {
|
2020-10-18 06:50:26 -05:00
|
|
|
id: app
|
|
|
|
|
|
|
|
//
|
|
|
|
// Global properties
|
|
|
|
//
|
|
|
|
readonly property int spacing: 8
|
2020-12-27 23:53:09 -06:00
|
|
|
property bool firstValidPacket: false
|
2020-12-27 17:21:19 -06:00
|
|
|
readonly property color windowBackgroundColor: Qt.rgba(18/255, 25/255, 32/255, 1)
|
2020-10-18 06:50:26 -05:00
|
|
|
readonly property string monoFont: {
|
|
|
|
switch (Qt.platform.os) {
|
|
|
|
case "osx":
|
|
|
|
return "Menlo"
|
|
|
|
case "windows":
|
|
|
|
return "Consolas"
|
|
|
|
default:
|
|
|
|
return "Monospace"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
// Window geometry
|
2020-10-18 06:50:26 -05:00
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
visible: false
|
2020-12-30 16:11:51 -06:00
|
|
|
minimumWidth: 1080
|
2021-01-04 22:11:59 -06:00
|
|
|
minimumHeight: 680
|
2020-12-27 17:21:19 -06:00
|
|
|
title: CppAppName + " v" + CppAppVersion
|
2020-10-18 06:50:26 -05:00
|
|
|
|
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
// Theme options
|
2020-10-18 06:50:26 -05:00
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
palette.text: Qt.rgba(1, 1, 1, 1)
|
|
|
|
palette.buttonText: Qt.rgba(1, 1, 1, 1)
|
|
|
|
palette.windowText: Qt.rgba(1, 1, 1, 1)
|
|
|
|
background: Rectangle {
|
|
|
|
color: app.windowBackgroundColor
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
// Startup code
|
2020-12-26 01:30:18 -06:00
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
Component.onCompleted: {
|
|
|
|
timer.start()
|
2020-12-26 21:15:40 -06:00
|
|
|
|
2020-12-27 17:21:19 -06:00
|
|
|
about.hide()
|
|
|
|
devices.show()
|
2020-12-26 21:15:40 -06:00
|
|
|
|
2020-12-27 17:21:19 -06:00
|
|
|
data.opacity = 0
|
|
|
|
console.opacity = 1
|
|
|
|
widgets.opacity = 0
|
|
|
|
|
|
|
|
CppJsonParser.readSettings()
|
2020-12-26 01:30:18 -06:00
|
|
|
}
|
2020-10-18 06:50:26 -05:00
|
|
|
|
2021-01-04 22:11:59 -06:00
|
|
|
//
|
|
|
|
// Clears the console text & displays a mini-tutorial
|
|
|
|
//
|
|
|
|
function showWelcomeGuide() {
|
|
|
|
console.text = CppTranslator.welcomeConsoleText() + "\n\n"
|
|
|
|
}
|
|
|
|
|
2020-10-18 06:50:26 -05:00
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
// Startup timer
|
|
|
|
//
|
|
|
|
Timer {
|
|
|
|
id: timer
|
|
|
|
interval: 500
|
|
|
|
onTriggered: {
|
|
|
|
// Startup verifications to ensure that bad settings
|
|
|
|
// do not make our app reside outside screen
|
|
|
|
if (x < 0 || x >= Screen.desktopAvailableWidth)
|
|
|
|
x = 100
|
|
|
|
if (y < 0 || y >= Screen.desktopAvailableHeight)
|
|
|
|
y = 100
|
2020-10-18 06:50:26 -05:00
|
|
|
|
2020-12-27 17:21:19 -06:00
|
|
|
// Startup verifications to ensure that app fits in current screen
|
|
|
|
if (width > Screen.desktopAvailableWidth) {
|
|
|
|
x = 100
|
|
|
|
width = Screen.desktopAvailableWidth - x
|
|
|
|
}
|
2020-12-26 01:30:18 -06:00
|
|
|
|
2020-12-27 17:21:19 -06:00
|
|
|
// Startup verifications to ensure that app fits in current screen
|
|
|
|
if (height > Screen.desktopAvailableHeight) {
|
|
|
|
y = 100
|
|
|
|
height = Screen.desktopAvailableHeight - y
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
2020-12-27 17:21:19 -06:00
|
|
|
|
|
|
|
// Show app window
|
|
|
|
app.visible = true
|
2021-01-04 22:11:59 -06:00
|
|
|
app.showWelcomeGuide()
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-27 23:53:09 -06:00
|
|
|
//
|
|
|
|
// Hide console & device manager when we receive first valid packet
|
|
|
|
//
|
|
|
|
Connections {
|
|
|
|
target: CppJsonParser
|
|
|
|
enabled: !app.firstValidPacket
|
|
|
|
function onPacketReceived() {
|
|
|
|
app.firstValidPacket = true
|
|
|
|
uiConfigTimer.start()
|
|
|
|
}
|
|
|
|
} Timer {
|
|
|
|
id: uiConfigTimer
|
|
|
|
interval: 250
|
|
|
|
onTriggered: {
|
|
|
|
devices.hide()
|
|
|
|
toolbar.dataClicked()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 06:50:26 -05:00
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
// Save window size & position
|
2020-10-18 06:50:26 -05:00
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
Settings {
|
|
|
|
property alias appX: app.x
|
|
|
|
property alias appY: app.y
|
|
|
|
property alias appW: app.width
|
|
|
|
property alias appH: app.height
|
2020-12-26 01:30:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
// About window
|
|
|
|
//
|
|
|
|
About {
|
|
|
|
id: about
|
2020-12-26 01:30:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
// Main layout
|
2020-12-26 01:30:18 -06:00
|
|
|
//
|
2020-12-27 17:21:19 -06:00
|
|
|
ColumnLayout {
|
|
|
|
spacing: 0
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
Toolbar {
|
|
|
|
z: 1
|
|
|
|
id: toolbar
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.minimumHeight: 48
|
|
|
|
Layout.maximumHeight: 48
|
|
|
|
dataChecked: data.visible
|
|
|
|
aboutChecked: about.visible
|
|
|
|
consoleChecked: console.visible
|
|
|
|
widgetsChecked: widgets.visible
|
|
|
|
devicesChecked: devices.visible
|
|
|
|
onAboutClicked: about.visible ? about.hide() : about.show()
|
|
|
|
onDevicesClicked: devices.visible ? devices.hide() : devices.show()
|
|
|
|
|
|
|
|
onDataClicked: {
|
2020-12-27 23:42:23 -06:00
|
|
|
data.opacity = 1
|
2020-12-27 17:21:19 -06:00
|
|
|
console.opacity = 0
|
|
|
|
widgets.opacity = 0
|
2020-12-27 23:42:23 -06:00
|
|
|
dataChecked = true
|
|
|
|
consoleChecked = false
|
|
|
|
widgetsChecked = false
|
2020-12-27 17:21:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
onConsoleClicked: {
|
2020-12-27 23:42:23 -06:00
|
|
|
data.opacity = 0
|
2020-12-27 17:21:19 -06:00
|
|
|
console.opacity = 1
|
|
|
|
widgets.opacity = 0
|
2020-12-27 23:42:23 -06:00
|
|
|
consoleChecked = true
|
2020-12-27 23:53:09 -06:00
|
|
|
dataChecked = false
|
2020-12-27 23:42:23 -06:00
|
|
|
widgetsChecked = false
|
2020-12-27 17:21:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
onWidgetsClicked: {
|
2020-12-27 23:42:23 -06:00
|
|
|
data.opacity = 0
|
2020-12-27 17:21:19 -06:00
|
|
|
console.opacity = 0
|
|
|
|
widgets.opacity = 1
|
2020-12-27 23:42:23 -06:00
|
|
|
dataChecked = false
|
|
|
|
widgetsChecked = true
|
|
|
|
consoleChecked = false
|
2020-12-27 17:21:19 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
RowLayout {
|
|
|
|
spacing: 0
|
|
|
|
clip: true
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
|
|
|
Console {
|
|
|
|
id: console
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
// Animate on show
|
|
|
|
enabled: opacity > 0
|
|
|
|
visible: opacity > 0
|
|
|
|
Behavior on opacity {NumberAnimation{}}
|
2021-01-04 22:11:59 -06:00
|
|
|
|
|
|
|
// Show translated welcome text on lang. change
|
|
|
|
Connections {
|
|
|
|
target: CppTranslator
|
|
|
|
function onLanguageChanged() {
|
|
|
|
app.showWelcomeGuide()
|
|
|
|
}
|
|
|
|
}
|
2020-12-27 17:21:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
DataGrid {
|
|
|
|
id: data
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
// Animate on show
|
|
|
|
visible: opacity > 0
|
|
|
|
Behavior on opacity {NumberAnimation{}}
|
|
|
|
}
|
|
|
|
|
|
|
|
Widgets {
|
|
|
|
id: widgets
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
// Animate on show
|
|
|
|
enabled: opacity > 0
|
|
|
|
visible: opacity > 0
|
|
|
|
Behavior on opacity {NumberAnimation{}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DeviceManager {
|
|
|
|
id: devices
|
|
|
|
property int displayedWidth: 320
|
|
|
|
|
|
|
|
function show() {
|
|
|
|
opacity = 1
|
|
|
|
displayedWidth = 320
|
|
|
|
}
|
|
|
|
|
|
|
|
function hide() {
|
|
|
|
opacity = 0
|
|
|
|
displayedWidth = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
visible: opacity > 0
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.minimumWidth: displayedWidth
|
|
|
|
Layout.maximumWidth: displayedWidth
|
|
|
|
|
|
|
|
Behavior on opacity {NumberAnimation{}}
|
|
|
|
Behavior on displayedWidth {NumberAnimation{}}
|
|
|
|
}
|
2020-12-26 01:53:38 -06:00
|
|
|
}
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|
2021-01-04 23:33:50 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// CSV player window
|
|
|
|
//
|
|
|
|
CsvPlayer {
|
|
|
|
id: csvPlayer
|
|
|
|
}
|
2020-10-18 06:50:26 -05:00
|
|
|
}
|