From 1f29eb8ff16883dc5d0b5107e6903dee0e8ea681 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 27 Jul 2021 18:40:46 +0200 Subject: [PATCH] lots of improvements and launch screen --- devicehandler.h | 2 +- qml/Livedata.qml | 34 ------- qml/RemoteControl.qml | 203 ++++++++++++++++++++++++------------------ qml/SplashScreen.qml | 10 +++ qml/main.qml | 2 +- 5 files changed, 128 insertions(+), 123 deletions(-) diff --git a/devicehandler.h b/devicehandler.h index 40b7e08..8f7ae8e 100644 --- a/devicehandler.h +++ b/devicehandler.h @@ -146,7 +146,7 @@ private: float m_frontLeftSpeed{}; float m_frontRightSpeed{}; float m_backLeftSpeed{}; - float m_backRightSpeed; + float m_backRightSpeed{}; float m_frontLeftDcLink{}; float m_frontRightDcLink{}; float m_backLeftDcLink{}; diff --git a/qml/Livedata.qml b/qml/Livedata.qml index 93353f9..ab48667 100644 --- a/qml/Livedata.qml +++ b/qml/Livedata.qml @@ -124,26 +124,6 @@ GamePage { font.pixelSize: GameSettings.mediumFontSize } - Image { - id: bobbycar - //anchors.horizontalCenter: flickable.horizontalCenter - //anchors.verticalCenter: flickable.bottom - width: parent.width * 0.2 - height: width - source: "images/logo.png" - smooth: true - antialiasing: true - - SequentialAnimation{ - id: bobbycarAnim - running: deviceHandler.alive - loops: Animation.Infinite - alwaysRunToEnd: true - PropertyAnimation { target: bobbycar; property: "scale"; to: 1.2; duration: 500; easing.type: Easing.InQuad } - PropertyAnimation { target: bobbycar; property: "scale"; to: 1.0; duration: 500; easing.type: Easing.OutQuad } - } - } - Row { Label { text: 'iMotMax:' @@ -169,20 +149,6 @@ GamePage { value: 50 } } - - Repeater { - model: 20 - Text { - horizontalAlignment: Text.AlignHCenter - verticalAlignment: Text.AlignVCenter - wrapMode: Text.WordWrap - text: "Placeholder" - //visible: deviceHandler.alive - color: GameSettings.textColor - minimumPixelSize: 10 - font.pixelSize: GameSettings.mediumFontSize - } - } } } } diff --git a/qml/RemoteControl.qml b/qml/RemoteControl.qml index 5a2132f..3cf764f 100644 --- a/qml/RemoteControl.qml +++ b/qml/RemoteControl.qml @@ -4,117 +4,146 @@ import QtQuick.Controls 2.15 GamePage { id: remoteControlPage - Text { - anchors.horizontalCenter: parent.horizontalCenter - anchors.bottom: container.top - anchors.bottomMargin: GameSettings.fieldMargin + errorMessage: deviceHandler.error + infoMessage: deviceHandler.info - font.pixelSize: GameSettings.hugeFontSize - color: GameSettings.textColor - text: qsTr("REMOTE CONTROL") - } + property real avgSpeed: (deviceHandler.frontLeftSpeed + deviceHandler.frontRightSpeed + deviceHandler.backLeftSpeed + deviceHandler.backRightSpeed) / 4 + property real avgVoltage: (deviceHandler.frontVoltage + deviceHandler.backVoltage) / 2 + property real totalCurrent: deviceHandler.frontLeftDcLink + deviceHandler.frontRightDcLink + deviceHandler.backLeftDcLink + deviceHandler.backRightDcLink + property real totalPower: totalCurrent * avgVoltage - Rectangle { - id: container + Column { anchors.centerIn: parent anchors.horizontalCenter: parent.horizontalCenter width: Math.min(remoteControlPage.width, remoteControlPage.height-GameSettings.fieldHeight*4) - 2*GameSettings.fieldMargin - height: width - radius: GameSettings.buttonRadius - color: GameSettings.viewColor - property real remoteControlFrontLeft: (handler.relativeX * frontLeftRightSpinbox.value) + (handler.relativeY * frontUpDownSpinbox.value) - property real remoteControlFrontRight: (-handler.relativeX * frontLeftRightSpinbox.value) + (handler.relativeY * frontUpDownSpinbox.value) - property real remoteControlBackLeft: (handler.relativeX * backLeftRightSpinbox.value) + (handler.relativeY * backUpDownSpinbox.value) - property real remoteControlBackRight: (-handler.relativeX * backLeftRightSpinbox.value) + (handler.relativeY * backUpDownSpinbox.value) + Column { + width: parent.width - onRemoteControlFrontLeftChanged: deviceHandler.remoteControlFrontLeft = remoteControlFrontLeft - onRemoteControlFrontRightChanged: deviceHandler.remoteControlFrontRight = remoteControlFrontRight - onRemoteControlBackLeftChanged: deviceHandler.remoteControlBackLeft = remoteControlBackLeft - onRemoteControlBackRightChanged: deviceHandler.remoteControlBackRight = remoteControlBackRight + Text { + font.pixelSize: GameSettings.hugeFontSize + color: GameSettings.textColor + text: Number(avgSpeed).toLocaleString(Qt.locale()) + 'km/h' + } - Rectangle { - parent: container - color: "white" - anchors.centerIn: parent - anchors.horizontalCenter: parent.horizontalCenter - anchors.verticalCenter: parent.verticalCenter - width: 20 - height: width - radius: width / 2 - } + Text { + font.pixelSize: GameSettings.hugeFontSize + color: GameSettings.textColor + text: Number(totalCurrent).toLocaleString(Qt.locale()) + 'A' + } - Text { - anchors.top: parent.top - minimumPixelSize: 10 - font.pixelSize: GameSettings.mediumFontSize - color: GameSettings.textColor - text: { - return "x:" + handler.relativeX.toFixed(1) + " y:" + handler.relativeY.toFixed(1) + "\n" + - "fl:" + Math.round(container.remoteControlFrontLeft) + " fr:" + Math.round(container.remoteControlFrontRight) + "\n" + - "bl:" + Math.round(container.remoteControlBackLeft) + " br:" + Math.round(container.remoteControlBackRight); + Text { + font.pixelSize: GameSettings.hugeFontSize + color: GameSettings.textColor + text: Number(totalPower>1000?(totalPower/1000):totalPower).toLocaleString(Qt.locale()) + (totalPower > 1000 ? "kW" : "W") + } + + Text { + font.pixelSize: GameSettings.hugeFontSize + color: GameSettings.textColor + text: Number(avgVoltage).toLocaleString(Qt.locale()) + 'V' } } - PointHandler { - id: handler - //acceptedDevices: PointerDevice.TouchScreen - property real clampedX: handler.active ? Math.min(Math.max(handler.point.position.x, 0), container.width) : (container.width / 2) - property real clampedY: handler.active ? Math.min(Math.max(handler.point.position.y, 0), container.height) : (container.height / 2) - property real relativeX: ((clampedX / container.width) - 0.5) * 2 - property real relativeY: ((clampedY / container.height) - 0.5) * -2 + Rectangle { + id: container + width: parent.width + height: width + radius: GameSettings.buttonRadius + color: GameSettings.viewColor - target: Rectangle { + property real remoteControlFrontLeft: (handler.relativeX * frontLeftRightSpinbox.value) + (handler.relativeY * frontUpDownSpinbox.value) + property real remoteControlFrontRight: (-handler.relativeX * frontLeftRightSpinbox.value) + (handler.relativeY * frontUpDownSpinbox.value) + property real remoteControlBackLeft: (handler.relativeX * backLeftRightSpinbox.value) + (handler.relativeY * backUpDownSpinbox.value) + property real remoteControlBackRight: (-handler.relativeX * backLeftRightSpinbox.value) + (handler.relativeY * backUpDownSpinbox.value) + + onRemoteControlFrontLeftChanged: deviceHandler.remoteControlFrontLeft = remoteControlFrontLeft + onRemoteControlFrontRightChanged: deviceHandler.remoteControlFrontRight = remoteControlFrontRight + onRemoteControlBackLeftChanged: deviceHandler.remoteControlBackLeft = remoteControlBackLeft + onRemoteControlBackRightChanged: deviceHandler.remoteControlBackRight = remoteControlBackRight + + Rectangle { parent: container - color: "red" - visible: handler.active - x: handler.clampedX - width / 2 - y: handler.clampedY - height / 2 - width: 50 + color: "white" + anchors.centerIn: parent + anchors.horizontalCenter: parent.horizontalCenter + anchors.verticalCenter: parent.verticalCenter + width: 20 height: width radius: width / 2 } - onActiveChanged: deviceHandler.remoteControlActive = handler.active - } - } + Text { + anchors.top: parent.top + minimumPixelSize: 10 + font.pixelSize: GameSettings.mediumFontSize + color: GameSettings.textColor + text: { + return "x:" + handler.relativeX.toFixed(1) + " y:" + handler.relativeY.toFixed(1) + "\n" + + "fl:" + Math.round(container.remoteControlFrontLeft) + " fr:" + Math.round(container.remoteControlFrontRight) + "\n" + + "bl:" + Math.round(container.remoteControlBackLeft) + " br:" + Math.round(container.remoteControlBackRight); + } + } - Grid { - anchors.top: container.bottom - anchors.left: container.left - anchors.right: container.right - columns: 2 + PointHandler { + id: handler + //acceptedDevices: PointerDevice.TouchScreen + property real clampedX: handler.active ? Math.min(Math.max(handler.point.position.x, 0), container.width) : (container.width / 2) + property real clampedY: handler.active ? Math.min(Math.max(handler.point.position.y, 0), container.height) : (container.height / 2) + property real relativeX: ((clampedX / container.width) - 0.5) * 2 + property real relativeY: ((clampedY / container.height) - 0.5) * -2 - SpinBox { - id: frontLeftRightSpinbox - value: 100 - editable: true - from: 0 - to: 1000 + target: Rectangle { + parent: container + color: "red" + visible: handler.active + x: handler.clampedX - width / 2 + y: handler.clampedY - height / 2 + width: 50 + height: width + radius: width / 2 + } + + onActiveChanged: deviceHandler.remoteControlActive = handler.active + } } - SpinBox { - id: frontUpDownSpinbox - value: 100 - editable: true - from: 0 - to: 1000 - } + Grid { + width: parent.width + columns: 2 + horizontalItemAlignment: Grid.AlignHCenter - SpinBox { - id: backLeftRightSpinbox - value: 100 - editable: true - from: 0 - to: 1000 - } + SpinBox { + id: frontLeftRightSpinbox + value: 100 + editable: true + from: -1000 + to: 1000 + } - SpinBox { - id: backUpDownSpinbox - value: 100 - editable: true - from: 0 - to: 1000 + SpinBox { + id: frontUpDownSpinbox + value: 75 + editable: true + from: -1000 + to: 1000 + } + + SpinBox { + id: backLeftRightSpinbox + value: 0 + editable: true + from: -1000 + to: 1000 + } + + SpinBox { + id: backUpDownSpinbox + value: 100 + editable: true + from: -1000 + to: 1000 + } } } } diff --git a/qml/SplashScreen.qml b/qml/SplashScreen.qml index 26f6808..b301767 100644 --- a/qml/SplashScreen.qml +++ b/qml/SplashScreen.qml @@ -24,10 +24,20 @@ Item { } Image { + id: bobbycar anchors.centerIn: parent width: Math.min(parent.height, parent.width)*0.6 height: GameSettings.heightForWidth(width, sourceSize) source: "images/logo.png" + + SequentialAnimation{ + id: bobbycarAnim + running: true + loops: Animation.Infinite + alwaysRunToEnd: true + PropertyAnimation { target: bobbycar; property: "scale"; to: 1.2; duration: 500; easing.type: Easing.InQuad } + PropertyAnimation { target: bobbycar; property: "scale"; to: 1.0; duration: 500; easing.type: Easing.OutQuad } + } } Timer { diff --git a/qml/main.qml b/qml/main.qml index 8d8e8f3..e85077f 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -31,7 +31,7 @@ Window { Connections { target: splashLoader.item - onReadyToGo: { + function onReadyToGo() { appLoader.visible = true appLoader.item.init() splashLoader.visible = false