From ab7154cfd0a88c066ce15455f950003a9022d6b4 Mon Sep 17 00:00:00 2001 From: dorian Date: Mon, 8 Apr 2019 18:03:23 +0200 Subject: [PATCH] - fixed a bug in baseconn - added volume regulation for base station --- headers/climbingrace.h | 1 + qml/SettingsDialog.qml | 59 ++++++++++++++++++--- qml/components/InputDelegate.qml | 10 +++- qml/components/SmoothSliderDelegate.qml | 68 ++++++++++++++++++++++++- qml/main.qml | 7 +++ qml/qml.qrc | 1 + sources/baseconn.cpp | 9 ++-- sources/climbingrace.cpp | 12 +++-- sources/speedtimer.cpp | 7 ++- 9 files changed, 152 insertions(+), 22 deletions(-) diff --git a/headers/climbingrace.h b/headers/climbingrace.h index 8b88acb..b0c9469 100644 --- a/headers/climbingrace.h +++ b/headers/climbingrace.h @@ -53,6 +53,7 @@ private: // helper vars QVariantList qmlTimers; const QStringList remoteSettings = {"ready_en", "ready_delay", "at_marks_en", "at_marks_delay"}; + const QStringList remoteOnlySettings = {"soundVolume"}; private slots: // helper functions diff --git a/qml/SettingsDialog.qml b/qml/SettingsDialog.qml index 00bd862..901049c 100644 --- a/qml/SettingsDialog.qml +++ b/qml/SettingsDialog.qml @@ -330,7 +330,7 @@ Popup { inputText: autostart_col.loadSetting("ready_delay", ready_del) - onInputTextChanged: { + onInputFinished: { autostart_col.updateSetting("ready_delay", inputText, ready_delay_del) } } @@ -364,7 +364,7 @@ Popup { inputText: autostart_col.loadSetting("at_marks_delay", at_marks_delay_del) - onInputTextChanged: { + onInputFinished: { autostart_col.updateSetting("at_marks_delay", inputText, at_marks_delay_del) } } @@ -380,8 +380,19 @@ Popup { spacing: options_stack.rowSpacing - function baseConnected(){ - return speedBackend.baseStationState === "connected" + property bool baseConnected: false + + Connections { + target: speedBackend + + onBaseStationStateChanged: { + if(speedBackend.baseStationState === "connected"){ + connectCol.baseConnected = true + } + else { + connectCol.baseConnected = false + } + } } ConnectionDelegate { @@ -414,7 +425,7 @@ Popup { } width: parent.width - height: !connectCol.baseConnected() ? options_stack.delegateHeight:0 + height: !connectCol.baseConnected ? options_stack.delegateHeight:0 visible: height > 5 @@ -426,12 +437,48 @@ Popup { } } + SmoothSliderDelegate { + id: baseStationVolumeDel + text: qsTr("volume") + + property bool active: connectCol.baseConnected + + width: parent.width + height: active ? options_stack.delegateHeight:0 + + visible: height > 5 + + sliderValue: 0 + + onSliderFinished: { + speedBackend.writeSetting("soundVolume", sliderValue) + } + + onActiveChanged: { + + if(active){ + var val = speedBackend.readSetting("soundVolume") + console.log(val) + if(val !== "false"){ + sliderValue = parseFloat(val) + } + } + } + + Behavior on height { + NumberAnimation { + duration: 400 + easing.type: Easing.Linear + } + } + } + NextPageDelegate { id: baseStationConnectionsDel text: qsTr("connected extensions") width: parent.width - height: connectCol.baseConnected() ? options_stack.delegateHeight:0 + height: connectCol.baseConnected ? options_stack.delegateHeight:0 visible: height > 5 diff --git a/qml/components/InputDelegate.qml b/qml/components/InputDelegate.qml index 915efca..306321b 100644 --- a/qml/components/InputDelegate.qml +++ b/qml/components/InputDelegate.qml @@ -7,6 +7,8 @@ SmoothItemDelegate { property string inputText: "" property string inputHint: "" + signal inputFinished() + property int inputMethodHints: Qt.ImhNone property int inputTextFieldWidth: control.width * 0.3 @@ -15,8 +17,6 @@ SmoothItemDelegate { textField.text = inputText } - text: qsTr("delay (ms)") - width: parent.width rightPadding: textField.width + width * 0.02 height: parent.delegateHeight @@ -44,6 +44,12 @@ SmoothItemDelegate { control.inputTextChanged() } + onActiveFocusChanged: { + if(!activeFocus){ + control.inputFinished() + } + } + background: Rectangle { implicitWidth: 200 implicitHeight: 40 diff --git a/qml/components/SmoothSliderDelegate.qml b/qml/components/SmoothSliderDelegate.qml index 9c36e13..b4815da 100644 --- a/qml/components/SmoothSliderDelegate.qml +++ b/qml/components/SmoothSliderDelegate.qml @@ -1,5 +1,71 @@ import QtQuick 2.0 +import QtQuick.Controls 2.4 -Item { +SmoothItemDelegate { + id: control + + property double sliderValue: 0.5 + signal sliderFinished() + + onSliderValueChanged: { + slider.value = control.sliderValue + } + + rightPadding: slider.width + width * 0.02 + + Slider { + id: slider + + anchors { + right: parent.right + rightMargin: parent.width * 0.01 + verticalCenter: parent.verticalCenter + } + + height: control.height * 0.4 + width: parent.width * 0.6 + + onValueChanged: { + control.sliderValue = value + } + + onPressedChanged: { + if(!pressed){ + control.sliderFinished() + } + } + + background: Rectangle { + x: slider.leftPadding + y: slider.topPadding + slider.availableHeight / 2 - height / 2 + implicitWidth: 200 + implicitHeight: 4 + width: slider.availableWidth + height: slider.height * 0.2 + radius: height * 0.5 + color: "#bdbebf" + + Rectangle { + width: slider.visualPosition * parent.width + height: parent.height + color: "#21be2b" + radius: height * 0.5 + } + } + + handle: Rectangle { + x: slider.leftPadding + slider.visualPosition * (slider.availableWidth - width) + y: slider.topPadding + slider.availableHeight / 2 - height / 2 + implicitWidth: 26 + implicitHeight: 26 + + width: slider.height + height: width + + radius: height * 0.5 + color: slider.pressed ? "#f0f0f0" : "#f6f6f6" + border.color: "#bdbebf" + } + } } diff --git a/qml/main.qml b/qml/main.qml index 10917af..17a9362 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -212,6 +212,7 @@ Window { scale: 0 height: !root.landscape()? parent.height*0.17:parent.width*0.17 + width: status === "disconnected" ? 0:height Component.onCompleted: { scale = 1 @@ -222,6 +223,12 @@ Window { duration: 200 } } + + Behavior on width { + NumberAnimation { + duration: 200 + } + } } } } diff --git a/qml/qml.qrc b/qml/qml.qrc index ecb48d7..6a1ba34 100644 --- a/qml/qml.qrc +++ b/qml/qml.qrc @@ -13,5 +13,6 @@ components/SmoothItemDelegate.qml components/SmoothSwitchDelegate.qml components/InputDelegate.qml + components/SmoothSliderDelegate.qml diff --git a/sources/baseconn.cpp b/sources/baseconn.cpp index c14225d..e176f24 100644 --- a/sources/baseconn.cpp +++ b/sources/baseconn.cpp @@ -42,7 +42,6 @@ bool BaseConn::connectToHost() { if(timer.remainingTime() == -1){ //the time has been triggered -> timeout this->socket->abort(); - setState("disconnected"); return(false); } @@ -50,7 +49,9 @@ bool BaseConn::connectToHost() { timer.stop(); connect(this->socket, &QTcpSocket::readyRead, this, &BaseConn::readyRead); this->connection_progress = 100; - setState("connected"); + + this->setState("connected"); + return(true); } @@ -113,6 +114,7 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){ // generate id and witing requests entry int thisId = nextConnectionId; + //qDebug() << "sending command: " << header << " with data: " << data << " and id: " << thisId; nextConnectionId ++; QEventLoop loop; @@ -163,7 +165,6 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){ timer.deleteLater(); - //remoteSessions.release(1); return {{"status", reply.value("header").toInt()}, {"data", reply.value("data").toVariant()}}; } @@ -227,7 +228,7 @@ void BaseConn::socketStateChanged(QAbstractSocket::SocketState socketState) { } case QAbstractSocket::ConnectedState: { - this->setState("connected"); + //this->setState("connected"); break; } default: diff --git a/sources/climbingrace.cpp b/sources/climbingrace.cpp index 7a4c109..cdd24b5 100644 --- a/sources/climbingrace.cpp +++ b/sources/climbingrace.cpp @@ -470,28 +470,30 @@ double ClimbingRace::getNextStartActionDelayProgress() { void ClimbingRace::writeSetting(QString key, QVariant value) { this->refreshMode(); - if(this->mode == REMOTE && this->remoteSettings.contains(key)){ + if(this->mode == REMOTE && ( this->remoteSettings.contains(key) || this->remoteOnlySettings.contains(key) ) ){ this->baseConn->writeRemoteSetting(key, value.toString()); } - else { + else if(!this->remoteOnlySettings.contains(key)){ this->appSettings->writeSetting(key, value); } - } QString ClimbingRace::readSetting(QString key) { this->refreshMode(); - if(this->mode == REMOTE && this->remoteSettings.contains(key)){ + if(this->mode == REMOTE && ( this->remoteSettings.contains(key) || this->remoteOnlySettings.contains(key) )){ QVariantMap reply = this->baseConn->sendCommand(3001, key); if(reply["status"] != 200){ return "false"; } return reply["data"].toString(); } - else { + else if(!this->remoteOnlySettings.contains(key)){ return this->appSettings->loadSetting(key); } + else { + return "false"; + } } bool ClimbingRace::connectBaseStation() { diff --git a/sources/speedtimer.cpp b/sources/speedtimer.cpp index bfeba68..5350e8a 100644 --- a/sources/speedtimer.cpp +++ b/sources/speedtimer.cpp @@ -27,7 +27,6 @@ bool SpeedTimer::start(bool force) { this->setState(RUNNING); return true; - //this->startPad->appendCommand("SET_LED_RUNNING"); } bool SpeedTimer::stop(int type, bool force) { @@ -128,7 +127,7 @@ QString SpeedTimer::getText() { QString newText; switch (this->state) { case SpeedTimer::IDLE: - newText = "Click Start to start"; + newText = tr("Click Start to start"); break; case SpeedTimer::STARTING: newText = "0.000 sec"; @@ -140,10 +139,10 @@ QString SpeedTimer::getText() { newText = QString::number( this->stoppedTime / 1000.0, 'f', 3 ) + " sec"; break; case SpeedTimer::FAILED: - newText = "False Start"; + newText = tr("False Start"); break; case SpeedTimer::CANCELLED: - newText = "Cancelled"; + newText = tr("Cancelled"); break; }