2021-09-05 02:41:48 -05:00
|
|
|
/*
|
2023-01-22 23:51:35 -06:00
|
|
|
* Copyright (c) 2020-2023 Alex Spataru <https://github.com/alex-spataru>
|
2021-09-05 02:41:48 -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.
|
|
|
|
*/
|
|
|
|
|
2024-04-01 02:42:21 -05:00
|
|
|
import QtCore
|
2022-05-02 04:31:32 -05:00
|
|
|
import QtQuick
|
|
|
|
import QtQuick.Window
|
|
|
|
import QtQuick.Layouts
|
|
|
|
import QtQuick.Controls
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2024-08-10 12:58:21 -05:00
|
|
|
import "Panes" as Panes
|
|
|
|
import "../Widgets" as Widgets
|
2024-05-05 00:20:10 -05:00
|
|
|
|
2024-08-10 12:58:21 -05:00
|
|
|
Window {
|
|
|
|
id: root
|
2024-08-11 18:20:03 -05:00
|
|
|
title: qsTr("%1 - %2").arg(documentTitle).arg(Cpp_AppName)
|
2024-05-05 00:20:10 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// Custom properties
|
|
|
|
//
|
|
|
|
property int appLaunchCount: 0
|
2024-08-11 18:20:03 -05:00
|
|
|
property bool isMaximized: false
|
|
|
|
property string documentTitle: ""
|
2024-05-05 00:20:10 -05:00
|
|
|
property bool firstValidFrame: false
|
|
|
|
property bool automaticUpdates: false
|
2024-08-11 18:20:03 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// Global properties
|
|
|
|
//
|
|
|
|
readonly property bool setupVisible: setup.visible
|
|
|
|
readonly property bool consoleVisible: terminal.visible
|
|
|
|
readonly property bool dashboardVisible: dashboard.visible
|
2024-05-05 00:20:10 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// Toolbar functions aliases
|
|
|
|
//
|
|
|
|
function showSetup() { toolbar.setupClicked() }
|
|
|
|
function showConsole() { toolbar.consoleClicked() }
|
|
|
|
function showDashboard() { dbTimer.start() }
|
|
|
|
|
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
// Obtain document title
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
function updateDocumentTitle() {
|
|
|
|
if (Cpp_JSON_Generator.operationMode == 1)
|
|
|
|
documentTitle = qsTr("Device Defined Project")
|
2024-05-05 00:20:10 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
else if (Cpp_JSON_Generator.jsonMapFilename.length > 0)
|
|
|
|
documentTitle = Cpp_Project_Model.title
|
2024-05-05 00:20:10 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
else
|
|
|
|
documentTitle = qsTr("Empty Project")
|
|
|
|
}
|
2024-05-05 00:20:10 -05:00
|
|
|
|
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
// Ensure that window is visible
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
function displayWindow() {
|
|
|
|
if (root.isMaximized)
|
2024-05-05 00:20:10 -05:00
|
|
|
root.showMaximized()
|
2024-08-11 18:20:03 -05:00
|
|
|
|
2024-05-05 00:20:10 -05:00
|
|
|
else {
|
2024-08-11 18:20:03 -05:00
|
|
|
if (root.x > Screen.desktopAvailableWidth - root.minimumWidth || root.x <= 0)
|
|
|
|
root.x = (Screen.desktopAvailableWidth - root.minimumWidth) / 2
|
|
|
|
if (root.y > Screen.desktopAvailableHeight - root.minimumHeight || root.y <= 0)
|
|
|
|
root.y = (Screen.desktopAvailableHeight - root.minimumHeight) / 2
|
|
|
|
if (root.width >= Screen.desktopAvailableWidth - 100)
|
|
|
|
root.width = root.minimumWidth
|
|
|
|
if (root.height >= Screen.desktopAvailableHeight - 100)
|
|
|
|
root.height = root.minimumHeight
|
|
|
|
|
2024-05-05 00:20:10 -05:00
|
|
|
root.showNormal()
|
2021-12-03 23:26:20 -06:00
|
|
|
}
|
2024-08-11 18:20:03 -05:00
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
//
|
|
|
|
// React to maximize/unmaximize event
|
|
|
|
//
|
|
|
|
onVisibilityChanged: {
|
|
|
|
if (root.visible) {
|
|
|
|
if (root.visibility === Window.Maximized)
|
|
|
|
root.isMaximized = true
|
|
|
|
|
|
|
|
else if (root.isMaximized && root.visibility !== Window.Minimized) {
|
|
|
|
root.isMaximized = false
|
|
|
|
root.width = root.minimumWidth
|
|
|
|
root.height = root.minimumHeight
|
|
|
|
root.x = (Screen.desktopAvailableWidth - root.minimumWidth) / 2
|
|
|
|
root.y = (Screen.desktopAvailableHeight - root.minimumHeight) / 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
//
|
|
|
|
// Wait a little before showing the dashboard to avoid UI glitches and/or
|
|
|
|
// overloading the rendering engine
|
|
|
|
//
|
|
|
|
Timer {
|
|
|
|
id: dbTimer
|
|
|
|
interval: 500
|
|
|
|
onTriggered: toolbar.dashboardClicked()
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
//
|
|
|
|
// Update document title automatically
|
|
|
|
//
|
|
|
|
Connections {
|
|
|
|
target: Cpp_JSON_Generator
|
|
|
|
function onOperationModeChanged() {
|
|
|
|
updateDocumentTitle()
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
function onJsonFileMapChanged() {
|
|
|
|
updateDocumentTitle()
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
2024-08-11 18:20:03 -05:00
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
//
|
|
|
|
// Show console tab on serial disconnect
|
|
|
|
//
|
|
|
|
Connections {
|
|
|
|
target: Cpp_UI_Dashboard
|
|
|
|
function onDataReset() {
|
|
|
|
setup.show()
|
|
|
|
root.showConsole()
|
|
|
|
root.firstValidFrame = false
|
|
|
|
}
|
2024-05-05 00:20:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Hide console & device manager when we receive first valid frame
|
|
|
|
//
|
|
|
|
Connections {
|
|
|
|
target: Cpp_UI_Dashboard
|
|
|
|
|
|
|
|
function onUpdated() {
|
|
|
|
if (root.firstValidFrame)
|
|
|
|
return
|
|
|
|
|
|
|
|
if ((Cpp_IO_Manager.connected || Cpp_CSV_Player.isOpen) && Cpp_UI_Dashboard.frameValid()) {
|
|
|
|
setup.hide()
|
|
|
|
root.showDashboard()
|
|
|
|
root.firstValidFrame = true
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
setup.show()
|
|
|
|
root.showConsole()
|
|
|
|
root.firstValidFrame = false
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
2024-05-05 00:20:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
// Close shortcut
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
Shortcut {
|
|
|
|
sequences: [StandardKey.Close]
|
|
|
|
onActivated: root.close()
|
2024-05-05 00:20:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
// Quit shortcut
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
Shortcut {
|
|
|
|
sequences: [StandardKey.Quit]
|
|
|
|
onActivated: root.close()
|
2024-05-05 00:20:10 -05:00
|
|
|
}
|
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
//
|
|
|
|
// Loading code
|
|
|
|
//
|
|
|
|
Component.onCompleted: {
|
|
|
|
// Make window caption same color as toolbar
|
|
|
|
Cpp_NativeWindow.addWindow(root)
|
|
|
|
|
|
|
|
// Increment app launch count
|
|
|
|
++appLaunchCount
|
|
|
|
|
|
|
|
// Show donations dialog every 15 launches
|
|
|
|
if (root.appLaunchCount % 15 == 0 && !donateDialog.doNotShowAgain)
|
|
|
|
donateDialog.showAutomatically()
|
|
|
|
|
|
|
|
// Ask user if he/she wants to enable automatic updates
|
|
|
|
if (root.appLaunchCount == 2 && Cpp_UpdaterEnabled) {
|
|
|
|
if (Cpp_Misc_Utilities.askAutomaticUpdates()) {
|
|
|
|
root.automaticUpdates = true
|
|
|
|
Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
root.automaticUpdates = false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for updates (if we are allowed)
|
|
|
|
if (root.automaticUpdates && Cpp_UpdaterEnabled)
|
|
|
|
Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
|
|
|
|
|
|
|
|
// Obtain document title from JSON project editor & display the window
|
|
|
|
updateDocumentTitle()
|
|
|
|
displayWindow()
|
|
|
|
}
|
2024-05-05 00:20:10 -05:00
|
|
|
|
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
// Save settings
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
Settings {
|
|
|
|
property alias ax: root.x
|
|
|
|
property alias ay: root.y
|
|
|
|
property alias aw: root.width
|
|
|
|
property alias ah: root.height
|
|
|
|
property alias am: root.isMaximized
|
|
|
|
property alias appStatus: root.appLaunchCount
|
|
|
|
property alias autoUpdater: root.automaticUpdates
|
2024-05-05 00:20:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
// Load user interface component
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
|
|
|
Page {
|
|
|
|
anchors.fill: parent
|
2024-08-11 18:20:03 -05:00
|
|
|
palette.base: Cpp_ThemeManager.colors["base"]
|
|
|
|
palette.text: Cpp_ThemeManager.colors["text"]
|
|
|
|
palette.button: Cpp_ThemeManager.colors["button"]
|
|
|
|
palette.window: Cpp_ThemeManager.colors["window"]
|
|
|
|
palette.highlight: Cpp_ThemeManager.colors["highlight"]
|
|
|
|
palette.buttonText: Cpp_ThemeManager.colors["button_text"]
|
|
|
|
palette.placeholderText: Cpp_ThemeManager.colors["placeholder_text"]
|
|
|
|
palette.highlightedText: Cpp_ThemeManager.colors["highlighted_text"]
|
2021-12-21 23:34:58 -05:00
|
|
|
|
2024-05-05 00:20:10 -05:00
|
|
|
ColumnLayout {
|
|
|
|
spacing: 0
|
|
|
|
anchors.fill: parent
|
2021-11-09 20:18:51 -06:00
|
|
|
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
// Toolbar
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
2024-08-10 12:58:21 -05:00
|
|
|
Panes.Toolbar {
|
2024-08-11 18:20:03 -05:00
|
|
|
z: 2
|
2024-05-05 00:20:10 -05:00
|
|
|
id: toolbar
|
|
|
|
Layout.fillWidth: true
|
2024-08-11 18:20:03 -05:00
|
|
|
|
2024-05-05 00:20:10 -05:00
|
|
|
setupChecked: root.setupVisible
|
|
|
|
consoleChecked: root.consoleVisible
|
|
|
|
dashboardChecked: root.dashboardVisible
|
|
|
|
onSetupClicked: setup.visible ? setup.hide() : setup.show()
|
|
|
|
|
|
|
|
onDashboardClicked: {
|
|
|
|
if (Cpp_UI_Dashboard.available) {
|
|
|
|
consoleChecked = 0
|
|
|
|
dashboardChecked = 1
|
|
|
|
if (stack.currentItem != dashboard)
|
|
|
|
stack.push(dashboard)
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
root.showConsole()
|
2021-11-07 03:49:50 -06:00
|
|
|
}
|
|
|
|
|
2024-05-05 00:20:10 -05:00
|
|
|
onConsoleClicked: {
|
|
|
|
consoleChecked = 1
|
|
|
|
dashboardChecked = 0
|
|
|
|
stack.pop()
|
2021-11-06 13:00:11 -06:00
|
|
|
}
|
2024-05-05 00:20:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2024-08-11 18:20:03 -05:00
|
|
|
// User interface
|
2024-05-05 00:20:10 -05:00
|
|
|
//
|
|
|
|
RowLayout {
|
2024-08-11 18:20:03 -05:00
|
|
|
z: 1
|
2024-05-05 00:20:10 -05:00
|
|
|
spacing: 0
|
2024-08-11 18:20:03 -05:00
|
|
|
Layout.topMargin: -1
|
2024-05-05 00:20:10 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
//
|
|
|
|
// Dashboard + Console view
|
|
|
|
//
|
2024-05-05 00:20:10 -05:00
|
|
|
StackView {
|
|
|
|
id: stack
|
|
|
|
clip: true
|
|
|
|
initialItem: terminal
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
data: [
|
2024-08-10 12:58:21 -05:00
|
|
|
Panes.Console {
|
2024-05-05 00:20:10 -05:00
|
|
|
id: terminal
|
|
|
|
visible: false
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
|
|
|
},
|
|
|
|
|
2024-08-10 12:58:21 -05:00
|
|
|
Panes.Dashboard {
|
2024-05-05 00:20:10 -05:00
|
|
|
id: dashboard
|
|
|
|
visible: false
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
2024-05-05 00:20:10 -05:00
|
|
|
]
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
//
|
|
|
|
// Panel border rectangle
|
|
|
|
//
|
|
|
|
Rectangle {
|
|
|
|
z: 2
|
|
|
|
width: 1
|
|
|
|
Layout.fillHeight: true
|
|
|
|
color: Cpp_ThemeManager.colors["setup_border"]
|
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
width: 1
|
|
|
|
height: 32
|
|
|
|
anchors.top: parent.top
|
|
|
|
anchors.left: parent.left
|
|
|
|
color: Cpp_ThemeManager.colors["pane_caption_border"]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Setup panel
|
|
|
|
//
|
2024-08-10 12:58:21 -05:00
|
|
|
Panes.Setup {
|
2024-05-05 00:20:10 -05:00
|
|
|
id: setup
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.rightMargin: setupMargin
|
|
|
|
Layout.minimumWidth: displayedWidth
|
|
|
|
Layout.maximumWidth: displayedWidth
|
|
|
|
}
|
|
|
|
}
|
2021-11-25 02:36:52 -06:00
|
|
|
}
|
2024-05-05 00:20:10 -05:00
|
|
|
|
2024-08-11 18:20:03 -05:00
|
|
|
//
|
|
|
|
// JSON project drop area
|
|
|
|
//
|
|
|
|
Widgets.JSONDropArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
enabled: !Cpp_IO_Manager.connected
|
|
|
|
}
|
2024-05-05 00:20:10 -05:00
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|