2021-09-05 02:41:48 -05:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020-2021 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.
|
|
|
|
*/
|
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
import QtQuick 2.12
|
|
|
|
import QtQuick.Window 2.12
|
|
|
|
import QtQuick.Layouts 1.12
|
|
|
|
import QtQuick.Controls 2.12
|
|
|
|
|
|
|
|
import Qt.labs.settings 1.0
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-09-25 21:48:06 -05:00
|
|
|
import "../Panes"
|
|
|
|
import "../Windows"
|
|
|
|
import "../Widgets"
|
|
|
|
import "../JsonEditor"
|
2021-11-09 14:30:59 -06:00
|
|
|
import "../FramelessWindow" as FramelessWindow
|
2021-10-05 03:45:34 -05:00
|
|
|
import "../PlatformDependent" as PlatformDependent
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-11-09 14:30:59 -06:00
|
|
|
FramelessWindow.CustomWindow {
|
2021-09-25 21:48:06 -05:00
|
|
|
id: root
|
2021-11-09 16:59:53 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// Quit application when this window is closed
|
|
|
|
//
|
2021-11-09 14:30:59 -06:00
|
|
|
onClosed: Qt.quit()
|
2021-11-09 16:59:53 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// Customize window border
|
|
|
|
//
|
2021-11-14 19:52:41 -06:00
|
|
|
showIcon: true
|
2021-11-09 16:59:53 -06:00
|
|
|
borderWidth: 1
|
2021-11-09 16:37:24 -06:00
|
|
|
borderColor: Qt.darker(Cpp_ThemeManager.toolbarGradient2, 1.5)
|
2021-09-05 02:41:48 -05:00
|
|
|
|
|
|
|
//
|
|
|
|
// Global properties
|
|
|
|
//
|
2021-09-25 21:48:06 -05:00
|
|
|
readonly property bool setupVisible: setup.visible
|
|
|
|
readonly property bool consoleVisible: terminal.visible
|
|
|
|
readonly property bool dashboardVisible: dashboard.visible
|
2021-09-05 02:41:48 -05:00
|
|
|
|
|
|
|
//
|
2021-09-25 21:48:06 -05:00
|
|
|
// Custom properties
|
2021-09-05 02:41:48 -05:00
|
|
|
//
|
|
|
|
property int appLaunchCount: 0
|
2021-09-25 21:48:06 -05:00
|
|
|
property bool firstValidFrame: false
|
|
|
|
property bool automaticUpdates: false
|
2021-09-24 23:07:31 -05:00
|
|
|
property alias vt100emulation: terminal.vt100emulation
|
2021-09-05 02:41:48 -05:00
|
|
|
|
|
|
|
//
|
2021-09-25 21:48:06 -05:00
|
|
|
// Toolbar functions aliases
|
2021-09-05 02:41:48 -05:00
|
|
|
//
|
2021-09-25 21:48:06 -05:00
|
|
|
function showSetup() { toolbar.setupClicked() }
|
|
|
|
function showConsole() { toolbar.consoleClicked() }
|
|
|
|
function showDashboard() { toolbar.dashboardClicked() }
|
2021-09-05 02:41:48 -05:00
|
|
|
|
|
|
|
//
|
2021-09-25 21:48:06 -05:00
|
|
|
// Console-related functions
|
2021-09-05 02:41:48 -05:00
|
|
|
//
|
2021-09-25 21:48:06 -05:00
|
|
|
function consoleCopy() { terminal.copy() }
|
|
|
|
function consoleClear() { terminal.clear() }
|
|
|
|
function consoleSelectAll() { terminal.selectAll() }
|
2021-09-05 02:41:48 -05:00
|
|
|
|
|
|
|
//
|
2021-11-19 11:26:20 -06:00
|
|
|
// Window geometry
|
2021-09-05 02:41:48 -05:00
|
|
|
//
|
2021-11-19 11:26:20 -06:00
|
|
|
visible: false
|
|
|
|
title: Cpp_AppName
|
|
|
|
width: minimumWidth
|
|
|
|
height: minimumHeight
|
|
|
|
minimumWidth: 1250 + 2 * root.shadowMargin
|
|
|
|
backgroundColor: Cpp_ThemeManager.windowBackground
|
|
|
|
minimumHeight: 720 + 2 * root.shadowMargin + root.titlebar.height
|
|
|
|
|
|
|
|
//
|
|
|
|
// Startup code
|
|
|
|
//
|
|
|
|
Component.onCompleted: {
|
|
|
|
// Load welcome text
|
|
|
|
terminal.showWelcomeGuide()
|
|
|
|
|
2021-11-09 22:16:36 -06:00
|
|
|
// Increment app launch count & hide splash screen
|
|
|
|
++appLaunchCount
|
|
|
|
|
2021-09-25 21:48:06 -05:00
|
|
|
// Show app window
|
2021-11-09 22:16:36 -06:00
|
|
|
if (root.isFullscreen)
|
2021-09-25 21:48:06 -05:00
|
|
|
root.showFullScreen()
|
2021-11-09 22:16:36 -06:00
|
|
|
else if (root.isMaximized)
|
|
|
|
root.showMaximized()
|
|
|
|
else {
|
2021-11-12 00:01:34 -06:00
|
|
|
// Fix maximize not working on first try on macOS & Windows
|
|
|
|
root.opacity = 0
|
|
|
|
var x = root.x
|
|
|
|
var y = root.y
|
|
|
|
var w = root.width
|
|
|
|
var h = root.height
|
|
|
|
root.showMaximized()
|
|
|
|
root.showNormal()
|
|
|
|
root.setGeometry(x, y, w,h)
|
|
|
|
root.opacity = 1
|
2021-11-09 22:16:36 -06:00
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-11-09 22:16:36 -06:00
|
|
|
// Force active focus
|
|
|
|
root.requestActivate()
|
|
|
|
root.requestUpdate()
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-09-25 21:48:06 -05:00
|
|
|
// Show donations dialog every 15 launches
|
2021-11-16 15:22:26 -06:00
|
|
|
if (root.appLaunchCount % 15 == 0 && !app.donations.doNotShowAgain)
|
2021-11-07 03:49:50 -06:00
|
|
|
app.donations.showAutomatically()
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-09-25 21:48:06 -05:00
|
|
|
// Ask user if he/she wants to enable automatic updates
|
2021-11-10 02:25:21 -06:00
|
|
|
if (root.appLaunchCount == 2 && Cpp_UpdaterEnabled) {
|
2021-09-25 21:48:06 -05:00
|
|
|
if (Cpp_Misc_Utilities.askAutomaticUpdates()) {
|
|
|
|
root.automaticUpdates = true
|
|
|
|
Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-09-25 21:48:06 -05:00
|
|
|
else
|
|
|
|
root.automaticUpdates = false
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-09-25 21:48:06 -05:00
|
|
|
// Check for updates (if we are allowed)
|
2021-11-10 02:25:21 -06:00
|
|
|
if (root.automaticUpdates && Cpp_UpdaterEnabled)
|
2021-09-25 21:48:06 -05:00
|
|
|
Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2021-09-24 21:11:16 -05:00
|
|
|
// Hide console & device manager when we receive first valid frame
|
2021-09-05 02:41:48 -05:00
|
|
|
//
|
|
|
|
Connections {
|
2021-09-25 00:03:27 -05:00
|
|
|
target: Cpp_UI_Dashboard
|
2021-09-25 21:48:06 -05:00
|
|
|
enabled: !root.firstValidFrame
|
2021-09-24 21:11:16 -05:00
|
|
|
|
2021-09-05 02:41:48 -05:00
|
|
|
function onUpdated() {
|
2021-11-19 11:26:20 -06:00
|
|
|
if ((Cpp_IO_Manager.connected || Cpp_CSV_Player.isOpen) &&
|
|
|
|
Cpp_UI_Dashboard.frameValid()) {
|
2021-09-05 02:41:48 -05:00
|
|
|
setup.hide()
|
2021-09-25 21:48:06 -05:00
|
|
|
root.showDashboard()
|
|
|
|
root.firstValidFrame = true
|
2021-09-24 23:07:31 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
2021-09-05 02:41:48 -05:00
|
|
|
setup.show()
|
2021-09-25 21:48:06 -05:00
|
|
|
root.showConsole()
|
|
|
|
root.firstValidFrame = false
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Show console tab on serial disconnect
|
|
|
|
//
|
|
|
|
Connections {
|
2021-09-25 00:03:27 -05:00
|
|
|
target: Cpp_UI_Dashboard
|
2021-09-05 02:41:48 -05:00
|
|
|
function onDataReset() {
|
|
|
|
setup.show()
|
2021-09-25 21:48:06 -05:00
|
|
|
root.showConsole()
|
|
|
|
root.firstValidFrame = false
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Save window size & position
|
|
|
|
//
|
|
|
|
Settings {
|
2021-11-06 13:00:11 -06:00
|
|
|
property alias wx: root.x
|
|
|
|
property alias wy: root.y
|
|
|
|
property alias ww: root.width
|
|
|
|
property alias wh: root.height
|
2021-11-09 22:16:36 -06:00
|
|
|
property alias wm: root.isMaximized
|
|
|
|
property alias wf: root.isFullscreen
|
2021-09-25 21:48:06 -05:00
|
|
|
property alias appStatus: root.appLaunchCount
|
|
|
|
property alias autoUpdater: root.automaticUpdates
|
|
|
|
}
|
|
|
|
|
2021-10-01 11:22:11 -05:00
|
|
|
//
|
2021-11-06 13:00:11 -06:00
|
|
|
// macOS menubar loader
|
2021-09-25 21:48:06 -05:00
|
|
|
//
|
|
|
|
Loader {
|
2021-10-13 01:46:12 -05:00
|
|
|
active: Cpp_IsMac
|
2021-11-07 03:49:50 -06:00
|
|
|
asynchronous: false
|
2021-10-05 03:45:34 -05:00
|
|
|
sourceComponent: PlatformDependent.MenubarMacOS {}
|
2021-09-25 21:48:06 -05:00
|
|
|
}
|
|
|
|
|
2021-11-07 03:49:50 -06:00
|
|
|
//
|
2021-11-09 22:52:52 -06:00
|
|
|
// Menubar, shown by default on Windows & Linux and when the app is fullscreen
|
2021-11-07 03:49:50 -06:00
|
|
|
//
|
2021-11-09 20:18:51 -06:00
|
|
|
RowLayout {
|
|
|
|
spacing: app.spacing
|
2021-11-07 03:49:50 -06:00
|
|
|
height: titlebar.height
|
2021-11-09 22:52:52 -06:00
|
|
|
|
2021-11-07 03:49:50 -06:00
|
|
|
anchors {
|
2021-11-09 15:49:06 -06:00
|
|
|
top: parent.top
|
|
|
|
left: parent.left
|
|
|
|
right: parent.right
|
2021-11-09 20:18:51 -06:00
|
|
|
leftMargin: root.leftTitlebarMargin + root.shadowMargin
|
|
|
|
rightMargin: root.rightTitlebarMargin + root.shadowMargin
|
2021-11-09 22:54:54 -06:00
|
|
|
topMargin: root.shadowMargin + (!root.showMacControls ? 1 : 0)
|
2021-11-07 03:49:50 -06:00
|
|
|
}
|
|
|
|
|
2021-11-14 19:52:41 -06:00
|
|
|
//
|
|
|
|
// Menubar
|
|
|
|
//
|
2021-11-07 03:49:50 -06:00
|
|
|
PlatformDependent.Menubar {
|
|
|
|
id: menubar
|
2021-11-27 20:56:48 -06:00
|
|
|
opacity: 0.8
|
2021-11-09 20:18:51 -06:00
|
|
|
Layout.alignment: Qt.AlignVCenter
|
2021-11-14 19:52:41 -06:00
|
|
|
enabled: !root.showMacControls || isFullscreen
|
|
|
|
visible: !root.showMacControls || isFullscreen
|
|
|
|
}
|
2021-11-09 20:18:51 -06:00
|
|
|
|
2021-11-14 19:52:41 -06:00
|
|
|
//
|
|
|
|
// Spacer
|
|
|
|
//
|
2021-11-09 20:18:51 -06:00
|
|
|
Item {
|
|
|
|
Layout.fillWidth: true
|
2021-11-07 03:49:50 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-05 02:41:48 -05:00
|
|
|
//
|
|
|
|
// Main layout
|
|
|
|
//
|
2021-11-06 13:00:11 -06:00
|
|
|
Page {
|
2021-11-09 14:30:59 -06:00
|
|
|
clip: true
|
2021-09-05 02:41:48 -05:00
|
|
|
anchors.fill: parent
|
2021-11-09 15:01:30 -06:00
|
|
|
anchors.margins: root.shadowMargin
|
2021-11-06 13:00:11 -06:00
|
|
|
palette.text: Cpp_ThemeManager.text
|
|
|
|
palette.buttonText: Cpp_ThemeManager.text
|
|
|
|
palette.windowText: Cpp_ThemeManager.text
|
2021-11-09 15:01:30 -06:00
|
|
|
anchors.topMargin: titlebar.height + root.shadowMargin
|
2021-11-06 13:00:11 -06:00
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
radius: root.radius
|
|
|
|
color: Cpp_ThemeManager.windowBackground
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
ColumnLayout {
|
|
|
|
spacing: 0
|
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
//
|
|
|
|
// Application toolbar
|
|
|
|
//
|
|
|
|
Toolbar {
|
|
|
|
z: 1
|
|
|
|
id: toolbar
|
|
|
|
window: root
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.minimumHeight: 48
|
|
|
|
Layout.maximumHeight: 48
|
|
|
|
setupChecked: root.setupVisible
|
|
|
|
consoleChecked: root.consoleVisible
|
|
|
|
dashboardChecked: root.dashboardVisible
|
2021-11-07 03:49:50 -06:00
|
|
|
onJsonEditorClicked: app.jsonEditor.show()
|
2021-11-06 13:00:11 -06:00
|
|
|
onSetupClicked: setup.visible ? setup.hide() : setup.show()
|
|
|
|
|
|
|
|
onDashboardClicked: {
|
|
|
|
if (Cpp_UI_Dashboard.available) {
|
|
|
|
consoleChecked = 0
|
|
|
|
dashboardChecked = 1
|
2021-11-27 20:56:48 -06:00
|
|
|
if (stack.currentItem != dashboard)
|
|
|
|
stack.push(dashboard)
|
2021-11-06 13:00:11 -06:00
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
else
|
|
|
|
root.showConsole()
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
onConsoleClicked: {
|
|
|
|
consoleChecked = 1
|
|
|
|
dashboardChecked = 0
|
|
|
|
stack.pop()
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
//
|
|
|
|
// Console, dashboard & setup panel
|
|
|
|
//
|
|
|
|
RowLayout {
|
2021-11-06 17:36:28 -06:00
|
|
|
z: 0
|
2021-11-06 13:00:11 -06:00
|
|
|
spacing: 0
|
2021-09-05 02:41:48 -05:00
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
StackView {
|
|
|
|
id: stack
|
2021-11-27 20:56:48 -06:00
|
|
|
clip: true
|
2021-11-06 13:00:11 -06:00
|
|
|
initialItem: terminal
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.fillHeight: true
|
2021-11-27 20:56:48 -06:00
|
|
|
data: [
|
|
|
|
Console {
|
|
|
|
id: terminal
|
|
|
|
visible: false
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
|
|
|
},
|
|
|
|
|
|
|
|
Dashboard {
|
|
|
|
id: dashboard
|
|
|
|
visible: false
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
2021-11-06 13:00:11 -06:00
|
|
|
}
|
2021-11-27 20:56:48 -06:00
|
|
|
]
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
|
|
|
|
2021-11-06 13:00:11 -06:00
|
|
|
Setup {
|
|
|
|
id: setup
|
|
|
|
Layout.fillHeight: true
|
|
|
|
Layout.rightMargin: setupMargin
|
|
|
|
Layout.minimumWidth: displayedWidth
|
|
|
|
Layout.maximumWidth: displayedWidth
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2021-09-24 23:07:31 -05:00
|
|
|
// JSON project drop area
|
2021-09-05 02:41:48 -05:00
|
|
|
//
|
2021-09-24 23:07:31 -05:00
|
|
|
JSONDropArea {
|
2021-09-05 02:41:48 -05:00
|
|
|
anchors.fill: parent
|
2021-09-28 14:43:06 -05:00
|
|
|
enabled: !Cpp_IO_Manager.connected
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|
2021-11-25 02:36:52 -06:00
|
|
|
|
|
|
|
//
|
|
|
|
// Resize handler
|
|
|
|
//
|
|
|
|
FramelessWindow.ResizeHandles {
|
|
|
|
window: root
|
|
|
|
anchors.fill: parent
|
|
|
|
handleSize: root.handleSize
|
|
|
|
}
|
2021-09-05 02:41:48 -05:00
|
|
|
}
|