352 lines
8.4 KiB
QML
Raw Normal View History

2020-10-18 06:50:26 -05:00
/*
2023-01-22 23:51:35 -06:00
* Copyright (c) 2020-2023 Alex Spataru <https://github.com/alex-spataru>
2020-10-18 06:50:26 -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.
*/
2022-05-02 04:31:32 -05:00
import QtQuick
import QtQuick.Window
import QtQuick.Layouts
import QtQuick.Controls
import SerialStudio
2024-08-10 12:58:21 -05:00
import "../../Widgets" as Widgets
2020-10-18 06:50:26 -05:00
Rectangle {
id: root
implicitWidth: (layout.implicitWidth + 32)
//
// Custom signals
//
signal setupClicked()
signal consoleClicked()
signal dashboardClicked()
signal structureClicked()
signal projectEditorClicked()
//
// Aliases to button check status
//
property alias setupChecked: setupBt.checked
property alias consoleChecked: consoleBt.checked
property alias dashboardChecked: dashboardBt.checked
property alias structureChecked: structureBt.checked
//
2024-08-11 18:20:03 -05:00
// Calculate offset based on platform
//
2024-08-11 18:20:03 -05:00
property int titlebarHeight: Cpp_NativeWindow.titlebarHeight(mainWindow)
Connections {
target: mainWindow
function onVisibilityChanged() {
root.titlebarHeight = Cpp_NativeWindow.titlebarHeight(mainWindow)
}
}
2024-08-11 18:20:03 -05:00
//
// Set toolbar height
//
Layout.minimumHeight: titlebarHeight + 64 + 12
Layout.maximumHeight: titlebarHeight + 64 + 12
2024-08-11 18:20:03 -05:00
//
// Titlebar text
//
Label {
text: mainWindow.title
visible: root.titlebarHeight > 0
color: Cpp_ThemeManager.colors["titlebar_text"]
font: Cpp_Misc_CommonFonts.customUiFont(1.07, true)
2024-08-11 18:20:03 -05:00
anchors {
topMargin: 6
top: parent.top
horizontalCenter: parent.horizontalCenter
2021-09-14 16:42:18 -05:00
}
2024-08-11 18:20:03 -05:00
}
2021-09-14 16:42:18 -05:00
2024-08-11 18:20:03 -05:00
//
// Toolbar background
//
gradient: Gradient {
GradientStop {
position: 0
color: Cpp_ThemeManager.colors["toolbar_top"]
}
2024-08-11 18:20:03 -05:00
GradientStop {
position: 1
color: Cpp_ThemeManager.colors["toolbar_bottom"]
2021-10-07 03:12:37 -05:00
}
}
2021-10-07 03:12:37 -05:00
//
// Toolbar border
//
Rectangle {
height: 1
color: Cpp_ThemeManager.colors["toolbar_border"]
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
}
}
2024-08-11 18:20:03 -05:00
//
// Drag main window with the toolbar
//
DragHandler {
target: null
onActiveChanged: {
if (active)
mainWindow.startSystemMove()
2024-08-11 18:20:03 -05:00
}
}
//
2024-08-11 18:20:03 -05:00
// Toolbar controls
//
RowLayout {
id: layout
2024-08-11 18:20:03 -05:00
spacing: 8
anchors {
margins: 2
left: parent.left
right: parent.right
verticalCenter: parent.verticalCenter
verticalCenterOffset: root.titlebarHeight / 2
}
//
// Horizontal spacer
//
Item {
implicitWidth: 1
}
2024-08-11 18:20:03 -05:00
//
// Project Editor
//
Widgets.BigButton {
text: qsTr("Project Editor")
2024-08-11 18:20:03 -05:00
Layout.alignment: Qt.AlignVCenter
onClicked: app.showProjectEditor()
icon.source: "qrc:/rcc/icons/toolbar/project-setup.svg"
enabled: Cpp_JSON_FrameBuilder.operationMode == SerialStudio.ProjectFile
2024-08-11 18:20:03 -05:00
}
//
// CSV Player
//
Widgets.BigButton {
text: qsTr("CSV Player")
Layout.alignment: Qt.AlignVCenter
onClicked: Cpp_CSV_Player.openFile()
icon.source: "qrc:/rcc/icons/toolbar/csv.svg"
enabled: !Cpp_CSV_Player.isOpen && !Cpp_IO_Manager.connected
2024-08-10 12:58:21 -05:00
}
//
// Separator
//
Rectangle {
implicitWidth: 1
2024-08-10 12:58:21 -05:00
Layout.fillHeight: true
Layout.maximumHeight: 64
Layout.alignment: Qt.AlignVCenter
2024-08-11 18:20:03 -05:00
color: Cpp_ThemeManager.colors["toolbar_separator"]
}
//
// Setup
//
Widgets.BigButton {
id: setupBt
text: qsTr("Setup")
onClicked: root.setupClicked()
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/rcc/icons/toolbar/device-setup.svg"
}
2024-08-11 18:20:03 -05:00
//
// Console
//
Widgets.BigButton {
id: consoleBt
2024-08-11 18:20:03 -05:00
opacity: 1
text: qsTr("Console")
enabled: dashboardBt.enabled
onClicked: root.consoleClicked()
2024-08-11 18:20:03 -05:00
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/rcc/icons/toolbar/console.svg"
}
2024-08-11 18:20:03 -05:00
//
// Separator
//
Rectangle {
implicitWidth: 1
Layout.fillHeight: true
Layout.maximumHeight: 64
Layout.alignment: Qt.AlignVCenter
color: Cpp_ThemeManager.colors["toolbar_separator"]
}
//
// Dashboard Structure
2024-08-11 18:20:03 -05:00
//
Widgets.BigButton {
id: structureBt
text: qsTr("Widgets")
enabled: dashboardBt.checked
2024-08-11 18:20:03 -05:00
Layout.alignment: Qt.AlignVCenter
onClicked: root.structureClicked()
icon.source: "qrc:/rcc/icons/toolbar/structure.svg"
2024-08-11 18:20:03 -05:00
}
2024-08-11 18:20:03 -05:00
//
// Dashboard
//
Widgets.BigButton {
id: dashboardBt
text: qsTr("Dashboard")
onClicked: root.dashboardClicked()
2024-08-11 18:20:03 -05:00
Layout.alignment: Qt.AlignVCenter
enabled: Cpp_UI_Dashboard.available
icon.source: "qrc:/rcc/icons/toolbar/dashboard.svg"
}
2024-08-10 12:58:21 -05:00
//
// Separator
//
Rectangle {
implicitWidth: 1
2024-08-10 12:58:21 -05:00
Layout.fillHeight: true
Layout.maximumHeight: 64
Layout.alignment: Qt.AlignVCenter
2024-08-11 18:20:03 -05:00
color: Cpp_ThemeManager.colors["toolbar_separator"]
2024-08-10 12:58:21 -05:00
}
2024-08-11 18:20:03 -05:00
//
// MQTT Setup
//
Widgets.BigButton {
text: qsTr("MQTT")
2024-08-11 18:20:03 -05:00
Layout.alignment: Qt.AlignVCenter
onClicked: app.showMqttConfiguration()
2024-10-11 15:07:03 -05:00
icon.source: Cpp_MQTT_Client.isConnectedToHost ?
(Cpp_MQTT_Client.clientMode === 1 ?
"qrc:/rcc/icons/toolbar/mqtt-subscriber.svg" :
"qrc:/rcc/icons/toolbar/mqtt-publisher.svg") :
"qrc:/rcc/icons/toolbar/mqtt.svg"
2024-08-10 12:58:21 -05:00
}
2024-08-11 18:20:03 -05:00
//
// Separator
//
Rectangle {
implicitWidth: 1
2024-08-10 12:58:21 -05:00
Layout.fillHeight: true
2024-08-11 18:20:03 -05:00
Layout.maximumHeight: 64
Layout.alignment: Qt.AlignVCenter
color: Cpp_ThemeManager.colors["toolbar_separator"]
2024-08-10 12:58:21 -05:00
}
//
// Examples
//
Widgets.BigButton {
text: qsTr("Examples")
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/rcc/icons/toolbar/examples.svg"
onClicked: Qt.openUrlExternally("https://github.com/Serial-Studio/Serial-Studio/tree/master/examples")
}
2024-08-11 18:20:03 -05:00
//
// Help
//
Widgets.BigButton {
text: qsTr("Help")
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/rcc/icons/toolbar/help.svg"
2024-08-11 18:20:03 -05:00
onClicked: Qt.openUrlExternally("https://github.com/Serial-Studio/Serial-Studio/wiki")
}
2021-09-17 01:41:50 -05:00
2024-08-11 18:20:03 -05:00
//
// About
2024-08-11 18:20:03 -05:00
//
Widgets.BigButton {
text: qsTr("About")
onClicked: app.showAboutDialog()
Layout.alignment: Qt.AlignVCenter
icon.source: "qrc:/rcc/icons/toolbar/about.svg"
2024-08-11 18:20:03 -05:00
}
2024-08-11 18:20:03 -05:00
//
// Horizontal spacer
//
Item {
implicitWidth: 1
2024-08-11 18:20:03 -05:00
Layout.fillWidth: true
}
2024-08-11 18:20:03 -05:00
//
// Connect/Disconnect button
//
Widgets.BigButton {
checked: Cpp_IO_Manager.connected
2024-08-11 18:20:03 -05:00
Layout.alignment: Qt.AlignVCenter
implicitWidth: metrics.width + 16
2024-08-11 18:20:03 -05:00
font: Cpp_Misc_CommonFonts.boldUiFont
Layout.minimumWidth: metrics.width + 16
Layout.maximumWidth: metrics.width + 16
2024-11-13 17:20:42 -05:00
enabled: Cpp_IO_Manager.configurationOk && !Cpp_CSV_Player.isOpen && !Cpp_MQTT_Client.isSubscribed
2024-08-11 18:20:03 -05:00
text: checked ? qsTr("Disconnect") : qsTr("Connect")
icon.source: checked ? "qrc:/rcc/icons/toolbar/connect.svg" :
"qrc:/rcc/icons/toolbar/disconnect.svg"
2024-08-11 18:20:03 -05:00
//
// Connect/disconnect device when button is clicked
//
onClicked: Cpp_IO_Manager.toggleConnection()
//
2024-08-11 18:20:03 -05:00
// Obtain maximum width of the button
//
2024-08-11 18:20:03 -05:00
TextMetrics {
id: metrics
font: Cpp_Misc_CommonFonts.boldUiFont
text: " " + qsTr("Disconnect") + " "
}
2020-10-18 06:50:26 -05:00
}
//
// Horizontal spacer
//
Item {
implicitWidth: 1
}
}
2020-10-18 06:50:26 -05:00
}