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

349 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"
2021-10-05 03:45:34 -05:00
import "../PlatformDependent" as PlatformDependent
2021-09-05 02:41:48 -05:00
PlatformDependent.CustomWindow {
2021-09-25 21:48:06 -05:00
id: root
onClosing: Qt.quit()
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 menubarEnabled: true
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-09-25 21:48:06 -05:00
// Hide/show menubar
2021-09-05 02:41:48 -05:00
//
2021-09-25 21:48:06 -05:00
function toggleMenubar() {
root.menubarEnabled = !root.menubarEnabled
2021-09-05 02:41:48 -05:00
}
//
2021-09-25 21:48:06 -05:00
// Displays the main window & checks for updates
2021-09-05 02:41:48 -05:00
//
function showMainWindow() {
// Reset window size for whatever reason
if (width <= 0 || height <= 0) {
width = minimumWidth
height = minimumHeight
}
2021-09-25 21:48:06 -05:00
// Startup verifications to ensure that app is displayed inside the screen
if (x < 0 || x >= Screen.desktopAvailableWidth)
x = 100
if (y < 0 || y >= Screen.desktopAvailableHeight)
y = 100
2021-09-05 02:41:48 -05:00
2021-09-25 21:48:06 -05:00
// Startup verifications to ensure that app fits in current screen
if (width > Screen.desktopAvailableWidth) {
x = 100
width = Screen.desktopAvailableWidth - x
}
2021-09-05 02:41:48 -05:00
2021-09-25 21:48:06 -05:00
// Startup verifications to ensure that app fits in current screen
if (height > Screen.desktopAvailableHeight) {
y = 100
height = Screen.desktopAvailableHeight - y
}
2021-09-05 02:41:48 -05:00
2021-09-25 21:48:06 -05:00
// Show app window
if (root.fullScreen)
root.showFullScreen()
else if (root.windowMaximized)
root.showMaximized()
else
root.showNormal()
2021-09-05 02:41:48 -05:00
// Increment app launch count & hide splash screen
2021-09-25 21:48:06 -05:00
++appLaunchCount
Cpp_ModuleManager.hideSplashscreen()
2021-09-05 02:41:48 -05:00
2021-09-25 21:48:06 -05:00
// Show donations dialog every 15 launches
if (appLaunchCount % 15 == 0 && !donations.doNotShowAgain)
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 (appLaunchCount == 2 && Cpp_UpdaterEnabled) {
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 (automaticUpdates && Cpp_UpdaterEnabled)
Cpp_Updater.checkForUpdates(Cpp_AppUpdaterUrl)
2021-09-05 02:41:48 -05:00
}
//
2021-09-13 11:51:35 -05:00
// Window geometry (different minimum size for non-macOS
// operating systems because of the global menubar in macOS)
2021-09-05 02:41:48 -05:00
//
visible: true
2021-10-28 04:18:18 -05:00
minimumWidth: 1250
2021-09-12 17:54:26 -05:00
title: Cpp_AppName
width: minimumWidth
height: minimumHeight
minimumHeight: Cpp_IsMac ? 720 : 740
backgroundColor: Cpp_ThemeManager.windowBackground
2021-09-05 02:41:48 -05:00
//
// Startup code
//
Component.onCompleted: {
// Load welcome guide
terminal.showWelcomeGuide()
// Display the window & check for updates in 500 ms (we do this so that
// we wait for the window to read settings before showing it)
timer.start()
}
//
// 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-09-25 21:48:06 -05: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 wf: root.fullScreen
property alias wm: root.windowMaximized
2021-09-25 21:48:06 -05:00
property alias appStatus: root.appLaunchCount
property alias autoUpdater: root.automaticUpdates
property alias menubarVisible: root.menubarEnabled
}
//
2021-10-01 11:22:11 -05:00
// Startup timer
//
Timer {
id: timer
interval: 500
onTriggered: root.showMainWindow()
}
//
// macOS menubar loader
2021-09-25 21:48:06 -05:00
//
Loader {
2021-10-05 03:45:34 -05:00
asynchronous: false
active: Cpp_IsMac
2021-10-05 03:45:34 -05:00
sourceComponent: PlatformDependent.MenubarMacOS {}
2021-09-25 21:48:06 -05:00
}
2021-09-05 02:41:48 -05:00
//
// Main layout
//
Page {
anchors.margins: 5
2021-09-05 02:41:48 -05:00
anchors.fill: parent
anchors.topMargin: titlebar.height
palette.text: Cpp_ThemeManager.text
palette.buttonText: Cpp_ThemeManager.text
palette.windowText: Cpp_ThemeManager.text
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
onJsonEditorClicked: jsonEditor.show()
onSetupClicked: setup.visible ? setup.hide() : setup.show()
onDashboardClicked: {
if (Cpp_UI_Dashboard.available) {
consoleChecked = 0
dashboardChecked = 1
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 {
spacing: 0
clip: true
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
onCurrentItemChanged: {
if (currentItem === terminal) {
terminal.opacity = 1
dashboard.opacity = 0
}
else {
terminal.opacity = 0
dashboard.opacity = 1
}
}
2021-09-05 02:41:48 -05:00
Console {
id: terminal
width: parent.width
height: parent.height
enabled: opacity > 0
visible: opacity > 0
2021-09-05 02:41:48 -05:00
}
Dashboard {
opacity: 0
id: dashboard
width: parent.width
height: parent.height
enabled: opacity > 0
visible: opacity > 0
}
2021-09-05 02:41:48 -05:00
}
Setup {
id: setup
opacity: 1
setupMargin: 0
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
}
}