231 lines
7.1 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
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
//
2020-12-26 01:30:18 -06:00
signal dataClicked()
2021-01-20 15:06:40 -05:00
signal setupClicked()
2020-12-26 01:30:18 -06:00
signal consoleClicked()
signal widgetsClicked()
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
//
2020-12-26 01:30:18 -06:00
property alias dataChecked: dataBt.checked
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 widgetsChecked: widgetsBt.checked
2020-10-18 06:50:26 -05:00
//
// Background gradient
//
Rectangle {
border.width: 1
2021-01-20 14:54:45 -05:00
border.color: palette.midlight
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
}
}
//
// 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-09-05 15:37:11 -05:00
icon.color: palette.brightText
2021-01-20 15:06:40 -05:00
onClicked: root.setupClicked()
text: qsTr("Setup") + _btSpacer
2021-09-05 15:37:11 -05:00
palette.buttonText: palette.brightText
icon.source: "qrc:/icons/settings.svg"
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
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
2021-09-05 15:37:11 -05:00
icon.color: palette.brightText
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
2021-09-05 15:37:11 -05:00
palette.buttonText: palette.brightText
enabled: dataBt.enabled || widgetsBt.enabled
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
2020-10-18 06:50:26 -05:00
}
Button {
2020-12-26 01:30:18 -06:00
id: dataBt
2020-10-18 06:50:26 -05:00
flat: true
icon.width: 24
icon.height: 24
Layout.fillHeight: true
2020-12-27 17:21:19 -06:00
onClicked: root.dataClicked()
2021-09-05 15:37:11 -05:00
icon.color: palette.brightText
2021-02-17 14:36:39 -05:00
enabled: app.dashboardAvailable
text: qsTr("Dashboard") + _btSpacer
2021-09-05 15:37:11 -05:00
icon.source: "qrc:/icons/equalizer.svg"
palette.buttonText: palette.brightText
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
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
}
Button {
2020-12-26 01:30:18 -06:00
id: widgetsBt
2020-10-18 06:50:26 -05:00
flat: true
icon.width: 24
icon.height: 24
Layout.fillHeight: true
2021-02-17 14:36:39 -05:00
enabled: app.widgetsAvailable
2021-09-05 15:37:11 -05:00
icon.color: palette.brightText
2020-12-27 17:21:19 -06:00
onClicked: root.widgetsClicked()
2020-12-26 01:30:18 -06:00
icon.source: "qrc:/icons/chart.svg"
text: qsTr("Widgets") + _btSpacer
2021-09-05 15:37:11 -05:00
palette.buttonText: palette.brightText
palette.button: Cpp_ThemeManager.toolbarGradient1
palette.window: Cpp_ThemeManager.toolbarGradient1
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-05 15:37:11 -05:00
icon.color: palette.brightText
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
2021-09-05 15:37:11 -05:00
palette.buttonText: palette.brightText
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
}
}
}