app/resources/qml/MainPage/TopToolBar.qml

308 lines
8.1 KiB
QML
Raw Normal View History

2020-10-01 14:19:47 +02:00
import QtQuick 2.9
2020-10-06 14:01:11 +02:00
import QtQuick.Controls 2.9
import "../components"
import "../components/layout"
2020-10-01 14:19:47 +02:00
import de.itsblue.ScStw 2.0
import de.itsblue.ScStw.Styling 2.0
import de.itsblue.ScStw.Styling.Components 1.0
ToolBar {
id: control
2020-10-01 14:19:47 +02:00
property string statusText
2020-10-01 14:19:47 +02:00
Loader {
id: topContentLoader
2020-10-01 14:19:47 +02:00
anchors.fill: parent
2020-10-01 14:19:47 +02:00
Behavior on state {
FadeAnimation {
target: topContentLoader
fadeDuration: 300
}
}
2020-10-01 14:19:47 +02:00
Component {
id: raceStatusLabelComponent
Text {
id: raceStatusLabel
padding: app.landscape() ? width * 0.2 : height * 0.25
2020-10-01 14:19:47 +02:00
text: control.statusText
2020-10-01 14:19:47 +02:00
color: appTheme.theme.colors.text
2020-10-01 14:19:47 +02:00
fontSizeMode: Text.Fit
2020-10-01 14:19:47 +02:00
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
2020-10-01 14:19:47 +02:00
font.pixelSize: height
2020-10-01 14:19:47 +02:00
minimumPixelSize: 1
2020-10-01 14:19:47 +02:00
Behavior on text {
FadeAnimation {
target: raceStatusLabel
fadeDuration: 100
}
}
}
}
2020-10-01 14:19:47 +02:00
Component {
id: timerColumnComponent
TimerColumn {
id: timerColumn
2020-10-01 14:19:47 +02:00
anchors.fill: parent
anchors.topMargin: app.landscape() ? 0:parent.height * 0.1
anchors.bottomMargin: app.landscape() ? 0:parent.height * 0.1
timers: scStwRemoteRace.timers
2020-10-01 14:19:47 +02:00
colors: appTheme.theme.colors
fontName: appTheme.theme.fonts.timers
showTimerLetter: true
2020-10-01 14:19:47 +02:00
// make text smaller for much better performance
textScale: app.landscape() ? 0.7 : 0.5
2020-10-01 14:19:47 +02:00
Behavior on opacity {
NumberAnimation {
duration: 200
}
}
}
}
2020-10-01 14:19:47 +02:00
}
Item {
id: connectionIconContainer
anchors {
top: parent.top
left: parent.left
right: parent.right
bottom: parent.bottom
2020-10-01 14:19:47 +02:00
bottomMargin: app.landscape() ? parent.height * 0.8:0
rightMargin: app.landscape() ? 0:parent.width * 0.8
}
opacity: scStwRemoteRace.state === ScStwRace.IDLE ? 1:0
ConnectionIcon {
id: baseConnConnIcon
function clientStateToString(state) {
switch(state) {
case ScStwClient.DISCONNECTED:
return "disconnected"
case ScStwClient.CONNECTING:
return "connecting"
case ScStwClient.INITIALISING:
return "connecting"
case ScStwClient.CONNECTED:
return "connected"
}
}
status: clientStateToString(speedBackend.scStwClient.state)
source: appTheme.theme.images.baseStationIcon
2020-10-01 14:19:47 +02:00
anchors {
top: parent.top
topMargin: 10
left: parent.left
leftMargin: 10
}
2020-10-01 14:19:47 +02:00
height: !app.landscape()? parent.height*0.4:parent.width*0.4
}
Row {
id: extensionStatusRow
anchors {
top: parent.top
topMargin: 10
left: baseConnConnIcon.right
leftMargin: 1
}
height: baseConnConnIcon.height * 0.4
spacing: 5
Repeater {
id: extensionStatusRep
model: Object.keys(speedBackend.scStwClient.extensions)
delegate: Rectangle {
2020-10-06 14:01:11 +02:00
id: statusRect
property string thisLetter: modelData
2020-10-06 14:01:11 +02:00
property var thisExtensions: speedBackend.scStwClient.extensions[modelData]
2020-10-06 16:29:34 +02:00
property int thisLaneState: getLaneState(thisExtensions)
width: height
height: parent.height
radius: width * 0.1
2020-10-06 14:01:11 +02:00
color: appTheme.theme.colors.background
2020-10-06 16:29:34 +02:00
border.color: [appTheme.theme.colors.success, appTheme.theme.colors.warning, appTheme.theme.colors.error][thisLaneState]
2020-10-06 14:01:11 +02:00
border.width: width * 0.08
2020-10-06 14:01:11 +02:00
onThisExtensionsChanged: {
2020-10-06 16:29:34 +02:00
thisLaneState = getLaneState(thisExtensions)
2020-10-06 14:01:11 +02:00
}
2020-10-06 16:29:34 +02:00
function getLaneState(extensions) {
2020-10-07 13:00:01 +02:00
var batteryWarning = false;
for(var i = 0; i < extensions.length; i++) {
2020-10-06 16:29:34 +02:00
if(extensions[i]["state"] !== ScStw.ExtensionConnected || extensions[i]["batteryState"] === ScStw.BatteryCritical)
return 2
if(extensions[i]["batteryState"] === ScStw.BatteryWarning)
2020-10-07 13:00:01 +02:00
batteryWarning = true
2020-10-01 14:19:47 +02:00
}
2020-10-07 13:00:01 +02:00
return batteryWarning ? 1:0
2020-10-01 14:19:47 +02:00
}
2020-10-06 14:01:11 +02:00
Behavior on border.color {
ColorAnimation {
duration: 200
}
}
2020-10-01 14:19:47 +02:00
2020-10-06 14:01:11 +02:00
Behavior on color {
2020-10-01 14:19:47 +02:00
ColorAnimation {
duration: 200
}
}
Text {
anchors.fill: parent
text: parent.thisLetter
fontSizeMode: Text.Fit
2020-10-06 14:01:11 +02:00
font.pixelSize: height * 0.7
font.bold: true
2020-10-06 14:01:11 +02:00
color: statusRect.border.color
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
}
}
}
}
Behavior on opacity {
NumberAnimation {
duration: 200
}
}
}
2020-10-01 14:19:47 +02:00
states: [
State {
name: ScStwRace.IDLE
PropertyChanges {
target: control
statusText: app.landscape() ? "Press\nstart":"Press start"
2020-10-01 14:19:47 +02:00
}
PropertyChanges {
target: topContentLoader
sourceComponent: raceStatusLabelComponent
}
},
State {
name: ScStwRace.PREPAIRING
PropertyChanges {
target: control
statusText: "At your\nmarks"
}
PropertyChanges {
target: topContentLoader
sourceComponent: raceStatusLabelComponent
}
},
State {
name: ScStwRace.WAITING
PropertyChanges {
target: control
statusText: "Ready"
}
PropertyChanges {
target: topContentLoader
sourceComponent: raceStatusLabelComponent
}
},
State {
name: ScStwRace.STARTING
PropertyChanges {
target: control
statusText: "Starting"
}
PropertyChanges {
target: topContentLoader
sourceComponent: raceStatusLabelComponent
}
},
State {
name: ScStwRace.RUNNING
PropertyChanges {
target: topContentLoader
sourceComponent: timerColumnComponent
}
},
State {
name: ScStwRace.STOPPED
PropertyChanges {
target: topContentLoader
sourceComponent: timerColumnComponent
}
},
State {
name: ScStwRace.INCIDENT
PropertyChanges {
target: control
statusText: app.landscape() ? "Technical\nincident!":"Technical incident!"
2020-10-01 14:19:47 +02:00
}
PropertyChanges {
target: topContentLoader
sourceComponent: raceStatusLabelComponent
}
}
]
}