261 lines
8.0 KiB
QML
Raw Normal View History

2020-10-18 06:50:26 -05:00
/*
* Copyright (c) 2020-2021 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.
*/
import QtQuick 2.12
import QtQuick.Layouts 1.12
import QtQuick.Controls 2.12
import "../Widgets" as Widgets
2020-10-18 06:50:26 -05:00
Control {
2020-12-27 17:21:19 -06:00
id: root
2020-10-18 06:50:26 -05:00
//
// Dummy string to increase width of buttons
//
readonly property string _btSpacer: " "
//
// Custom signals
//
2021-01-20 15:06:40 -05:00
signal setupClicked()
2020-12-26 01:30:18 -06:00
signal consoleClicked()
signal dashboardClicked()
2021-09-17 01:41:50 -05:00
signal jsonEditorClicked()
2020-10-18 06:50:26 -05:00
//
2020-12-26 01:30:18 -06:00
// Aliases to button check status
2020-10-18 06:50:26 -05:00
//
2021-01-20 15:06:40 -05:00
property alias setupChecked: setupBt.checked
2020-12-26 01:30:18 -06:00
property alias consoleChecked: consoleBt.checked
property alias dashboardChecked: dashboardBt.checked
2020-10-18 06:50:26 -05:00
2021-09-14 16:42:18 -05:00
//
// Connections with mac touchbar
//
Connections {
target: Cpp_Misc_MacExtras
function onSetupClicked() {
setupBt.clicked()
Cpp_Misc_MacExtras.setSetupChecked(setupBt.checked)
}
function onConsoleClicked() {
consoleBt.clicked()
Cpp_Misc_MacExtras.setConsoleChecked(consoleBt.checked)
}
function onDashboardClicked() {
dashboardBt.clicked()
Cpp_Misc_MacExtras.setDashboardChecked(dashboardBt.checked)
}
}
2020-10-18 06:50:26 -05:00
//
// Background gradient
//
Rectangle {
2021-09-13 11:51:35 -05:00
id: bg
2020-10-18 06:50:26 -05:00
border.width: 1
2021-09-13 11:51:35 -05:00
border.color: Cpp_ThemeManager.toolbarGradient1
2021-01-20 14:54:45 -05:00
2021-09-05 15:37:11 -05:00
Rectangle {
height: parent.border.width
2021-09-05 17:05:17 -05:00
visible: Qt.platform.os === "osx"
2021-09-05 16:03:06 -05:00
color: Cpp_ThemeManager.toolbarGradient2
2021-09-05 15:37:11 -05:00
anchors {
top: parent.top
left: parent.left
right: parent.right
}
}
2021-01-20 14:54:45 -05:00
gradient: Gradient {
2021-09-05 02:41:48 -05:00
GradientStop { position: 0; color: Cpp_ThemeManager.toolbarGradient1 }
GradientStop { position: 1; color: Cpp_ThemeManager.toolbarGradient2 }
2021-01-20 14:54:45 -05:00
}
2020-10-18 06:50:26 -05:00
anchors {
fill: parent
leftMargin: -border.width * 10
rightMargin: -border.width * 10
}
}
2021-09-13 11:51:35 -05:00
//
// Toolbar shadow
//
Widgets.Shadow {
2021-09-13 11:51:35 -05:00
source: bg
}
2020-10-18 06:50:26 -05:00
//
// Toolbar icons
//
RowLayout {
spacing: app.spacing
anchors.fill: parent
anchors.margins: app.spacing
Button {
2021-01-20 15:06:40 -05:00
id: setupBt
2020-12-26 01:30:18 -06:00
2020-10-18 06:50:26 -05:00
flat: true
icon.width: 24
icon.height: 24
Layout.fillHeight: true
2021-01-20 15:06:40 -05:00
onClicked: root.setupClicked()
text: qsTr("Setup") + _btSpacer
2021-09-05 15:37:11 -05:00
icon.source: "qrc:/icons/settings.svg"
icon.color: Cpp_ThemeManager.brightText
palette.buttonText: Cpp_ThemeManager.brightText
2021-09-05 15:37:11 -05:00
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
2021-09-14 16:42:18 -05:00
onCheckedChanged: Cpp_Misc_MacExtras.setSetupChecked(checked)
2020-10-18 06:50:26 -05:00
}
Button {
2020-12-26 01:30:18 -06:00
id: consoleBt
2020-10-18 06:50:26 -05:00
flat: true
icon.width: 24
icon.height: 24
Layout.fillHeight: true
enabled: dashboardBt.enabled
2020-12-27 17:21:19 -06:00
onClicked: root.consoleClicked()
2020-10-18 06:50:26 -05:00
icon.source: "qrc:/icons/code.svg"
text: qsTr("Console") + _btSpacer
icon.color: Cpp_ThemeManager.brightText
palette.buttonText: Cpp_ThemeManager.brightText
2021-09-05 15:37:11 -05:00
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
2021-09-14 16:42:18 -05:00
onCheckedChanged: Cpp_Misc_MacExtras.setConsoleChecked(checked)
2020-10-18 06:50:26 -05:00
}
Button {
2021-09-14 16:42:18 -05:00
id: dashboardBt
2020-12-26 01:30:18 -06:00
2020-10-18 06:50:26 -05:00
flat: true
icon.width: 24
icon.height: 24
Layout.fillHeight: true
onClicked: root.dashboardClicked()
2021-09-25 00:03:27 -05:00
enabled: Cpp_UI_Dashboard.available
text: qsTr("Dashboard") + _btSpacer
icon.source: "qrc:/icons/dashboard.svg"
icon.color: Cpp_ThemeManager.brightText
palette.buttonText: Cpp_ThemeManager.brightText
2021-09-05 15:37:11 -05:00
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
2021-09-14 16:42:18 -05:00
onCheckedChanged: Cpp_Misc_MacExtras.setDashboardChecked(checked)
onEnabledChanged: Cpp_Misc_MacExtras.setDashboardEnabled(enabled)
2020-12-27 17:21:19 -06:00
opacity: enabled ? 1 : 0.5
Behavior on opacity {NumberAnimation{}}
2020-10-18 06:50:26 -05:00
}
Item {
Layout.fillWidth: true
}
Button {
flat: true
icon.width: 24
icon.height: 24
Layout.fillHeight: true
2021-09-17 01:41:50 -05:00
icon.source: "qrc:/icons/json.svg"
onClicked: root.jsonEditorClicked()
text: qsTr("JSON Editor") + _btSpacer
icon.color: Cpp_ThemeManager.brightText
palette.buttonText: Cpp_ThemeManager.brightText
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
}
Button {
flat: true
icon.width: 24
icon.height: 24
Layout.fillHeight: true
2020-10-18 06:50:26 -05:00
opacity: enabled ? 1 : 0.5
enabled: !Cpp_CSV_Player.isOpen
2021-02-01 18:55:15 -05:00
icon.source: "qrc:/icons/open.svg"
text: qsTr("Open CSV") + _btSpacer
icon.color: Cpp_ThemeManager.brightText
palette.buttonText: Cpp_ThemeManager.brightText
2021-09-05 15:37:11 -05:00
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
2020-11-26 20:43:25 -06:00
onClicked: {
if (Cpp_CSV_Export.isOpen)
Cpp_CSV_Export.openCurrentCsv()
else
Cpp_CSV_Player.openFile()
}
2020-11-26 20:43:25 -06:00
Behavior on opacity {NumberAnimation{}}
}
Button {
2021-02-01 18:55:15 -05:00
id: connectBt
//
// Button properties
//
2020-11-26 20:43:25 -06:00
flat: true
icon.width: 24
icon.height: 24
2021-02-01 18:55:15 -05:00
font.bold: true
2020-11-26 20:43:25 -06:00
Layout.fillHeight: true
2021-02-01 18:55:15 -05:00
icon.color: palette.buttonText
//
// Connection-dependent
2021-02-01 18:55:15 -05:00
//
checked: Cpp_IO_Manager.connected
2021-09-04 23:26:04 -05:00
text: (checked ? qsTr("Disconnect") :
qsTr("Connect")) + _btSpacer
icon.source: checked ? "qrc:/icons/disconnect.svg" :
"qrc:/icons/connect.svg"
2021-09-05 15:37:11 -05:00
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
2021-09-05 02:41:48 -05:00
palette.buttonText: checked ? Cpp_ThemeManager.connectButtonChecked :
Cpp_ThemeManager.connectButtonUnchecked
2021-02-01 18:55:15 -05:00
//
// Only enable button if it can be clicked
//
2020-11-26 20:43:25 -06:00
opacity: enabled ? 1 : 0.5
2020-10-18 06:50:26 -05:00
Behavior on opacity {NumberAnimation{}}
2021-02-15 14:35:46 -05:00
enabled: Cpp_IO_Manager.configurationOk
2021-02-01 18:55:15 -05:00
//
// Connect/disconnect device when button is clicked
2021-02-01 18:55:15 -05:00
//
onClicked: Cpp_IO_Manager.toggleConnection()
2020-10-18 06:50:26 -05:00
}
}
}