Serial-Studio/assets/qml/Windows/MainWindow.qml

353 lines
10 KiB
QML
Raw Normal View History

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.
*/
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"
import "../FramelessWindow" as FramelessWindow
2021-10-05 03:45:34 -05:00
import "../PlatformDependent" as PlatformDependent
2021-09-05 02:41:48 -05: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
//
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
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()
// Increment app launch count & hide splash screen
++appLaunchCount
2021-09-25 21:48:06 -05:00
// Show app window
if (root.isFullscreen)
2021-09-25 21:48:06 -05:00
root.showFullScreen()
else if (root.isMaximized)
root.showMaximized()
else {
// 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-09-05 02:41:48 -05: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
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)
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
}
//
// 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-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
}
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 {
property alias wx: root.x
property alias wy: root.y
property alias ww: root.width
property alias wh: root.height
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
//
// macOS menubar loader
2021-09-25 21:48:06 -05:00
//
Loader {
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 {
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
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
//
Page {
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
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
background: Rectangle {
radius: root.radius
color: Cpp_ThemeManager.windowBackground
}
2021-09-05 02:41:48 -05: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()
onSetupClicked: setup.visible ? setup.hide() : setup.show()
onDashboardClicked: {
if (Cpp_UI_Dashboard.available) {
consoleChecked = 0
dashboardChecked = 1
if (stack.currentItem != dashboard)
stack.push(dashboard)
}
2021-09-05 02:41:48 -05:00
else
root.showConsole()
}
2021-09-05 02:41:48 -05:00
onConsoleClicked: {
consoleChecked = 1
dashboardChecked = 0
stack.pop()
}
2021-09-05 02:41:48 -05:00
}
//
// Console, dashboard & setup panel
//
RowLayout {
z: 0
spacing: 0
2021-09-05 02:41:48 -05:00
Layout.fillWidth: true
Layout.fillHeight: true
StackView {
id: stack
clip: true
initialItem: terminal
Layout.fillWidth: true
Layout.fillHeight: true
data: [
Console {
id: terminal
visible: false
width: parent.width
height: parent.height
},
Dashboard {
id: dashboard
visible: false
width: parent.width
height: parent.height
}
]
2021-09-05 02:41:48 -05:00
}
Setup {
id: setup
Layout.fillHeight: true
Layout.rightMargin: setupMargin
Layout.minimumWidth: displayedWidth
Layout.maximumWidth: displayedWidth
2021-09-05 02:41:48 -05:00
}
}
}
}
//
// JSON project drop area
2021-09-05 02:41:48 -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
}
//
// Resize handler
//
FramelessWindow.ResizeHandles {
window: root
anchors.fill: parent
handleSize: root.handleSize
}
2021-09-05 02:41:48 -05:00
}