diff --git a/headers/baseconn.h b/headers/baseconn.h index cd24233..e3ead24 100644 --- a/headers/baseconn.h +++ b/headers/baseconn.h @@ -51,6 +51,8 @@ private: QTcpSocket *socket; //socket for communication with the extention + QString readBuffer; + QSemaphore remoteSessions; int nextConnectionId; diff --git a/qml/ProfilesDialog.qml b/qml/ProfilesDialog.qml index 4345c18..fc675be 100644 --- a/qml/ProfilesDialog.qml +++ b/qml/ProfilesDialog.qml @@ -87,6 +87,10 @@ Popup { Connections { target: root onOpened: { + if(profiles_stack.depth > 0){ + profiles_stack.clear() + } + profiles_stack.openAthletes() } } @@ -109,143 +113,188 @@ Popup { Component { id: profileListComp - RemoteDataListView { - id: profileList + RemoteDataListView { + id: profileList - property string title: "profiles" - property string secondButt: "add" + property int currentAthlete: -1 + property string title: "profiles" + property string secondButt: "add" - signal opened() + signal opened() - onOpened: { - loadData() - } - - loadData: function () { - status = 905 - listData = {} - listData = speedBackend.getAthletes() - status = listData.lenght !== false ? 200:0 - } - - delegate: SwipeDelegate { - id: swipeDelegate - - property bool active: profileList.listData[index]["active"] - - text: profileList.listData[index]["fullName"] - width: profileList.width - (swipeDelegate.x) - - - - font.pixelSize: profiles_stack.text_pixelSize - - function remove() { - removeAnim.start() + onOpened: { + profileList.loadData() } - onClicked: { - profiles_stack.openResults(profileList.listData[index]["userName"]) - } + anchors.fill: parent + anchors.topMargin: topContainerItm.height * 0.1 - background: Rectangle { - color: Qt.darker( pressed ? Qt.darker("white", 1.1):"white", swipeDelegate.active ? 1.1:0 ) - } + loadData: function () { + status = 905 + listData = {} + var retData = speedBackend.getAthletes() - CheckBox { - id: control - - anchors { - verticalCenter: parent.verticalCenter - right: parent.right + if(retData === undefined){ + status = 500 + return } - height: parent.height * 0.6 + listData = retData["allAthletes"] + currentAthlete = retData["activeAthlete"] + status = listData.lenght !== false ? 200:0 + } - checked: swipeDelegate.active + delegate: SwipeDelegate { + id: swipeDelegate - onCheckedChanged: { - if(checked && !swipeDelegate.active && speedBackend.selectAthlete(profileList.listData[index]["userName"])){ - profileList.loadData() - } + property bool active: profileList.currentAthlete === profileList.listData[index]["id"] + + text: profileList.listData[index]["fullName"] + width: profileList.width - (swipeDelegate.x) + + + + font.pixelSize: profiles_stack.text_pixelSize + + function remove() { + removeAnim.start() } - indicator: Rectangle { - implicitWidth: 26 - implicitHeight: 26 - - height: parent.height - width: height - - x: control.leftPadding - y: parent.height / 2 - height / 2 - - radius: width * 0.2 - border.color: control.down ? "#17a81a" : "#21be2b" - - Rectangle { - width: parent.width * 0.65 - height: width - anchors.centerIn: parent - radius: width * 0.2 - color: control.down ? "#17a81a" : "#21be2b" - visible: control.checked - } + onClicked: { + profiles_stack.openResults(profileList.listData[index]["userName"]) } - } - Rectangle { - color: "grey" - height: 1 - width: parent.width * 0.9 - visible: index > 0 - anchors { - horizontalCenter: parent.horizontalCenter - top: parent.top - } - } + background: Rectangle { + color: Qt.darker( pressed ? Qt.darker("white", 1.1):"white", swipeDelegate.active ? 1.1:0 ) - NumberAnimation { - id: removeAnim - target: swipeDelegate - property: "height" - to: 0 - easing.type: Easing.InOutQuad - onStopped: profileModel.model.remove(index) - } + Behavior on color { - swipe.transition: Transition { - SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } - } - - swipe.left: Row { - anchors.left: parent.left - height: parent.height - - Label { - id: deleteLabel - text: qsTr("Delete") - color: "white" - verticalAlignment: Label.AlignVCenter - padding: 12 - height: parent.height - - SwipeDelegate.onClicked: { - profileList.status = 905 - if(speedBackend.deleteAthlete(profileList.listData[index]["userName"])){ - profileList.loadData() - return + ColorAnimation { + duration: 200 } - profileList.status = 200 + } + } + + CheckBox { + id: control + + anchors { + verticalCenter: parent.verticalCenter + right: parent.right } - background: Rectangle { - color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato" + height: parent.height * 0.6 + + checked: swipeDelegate.active + + onCheckedChanged: { + if(checked && !swipeDelegate.active && speedBackend.selectAthlete(profileList.listData[index]["userName"])){ + profileList.loadData() + } + } + + indicator: Rectangle { + implicitWidth: 26 + implicitHeight: 26 + + height: parent.height + width: height + + x: control.leftPadding + y: parent.height / 2 - height / 2 + + radius: width * 0.2 + border.color: control.down ? "#17a81a" : "#21be2b" + + Rectangle { + width: parent.width * 0.65 + height: width + anchors.centerIn: parent + radius: control.checked ? width * 0.2:0 + color: control.down ? "#17a81a" : "#21be2b" + opacity: control.checked ? 1:0 + scale: control.checked ? 0.9:0 + + Behavior on color { + ColorAnimation { + duration: 200 + } + } + + Behavior on radius { + NumberAnimation { + duration: 200 + } + } + + Behavior on opacity { + NumberAnimation { + duration: 200 + } + } + + Behavior on scale { + NumberAnimation { + duration: 200 + } + } + } + } + } + + Rectangle { + color: "grey" + height: 1 + width: parent.width * 0.9 + visible: index > 0 + anchors { + horizontalCenter: parent.horizontalCenter + top: parent.top + } + } + + NumberAnimation { + id: removeAnim + target: swipeDelegate + property: "height" + to: 0 + easing.type: Easing.InOutQuad + onStopped: profileModel.model.remove(index) + } + + swipe.transition: Transition { + SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic } + } + + swipe.left: Row { + anchors.left: parent.left + height: parent.height + + Label { + id: deleteLabel + text: qsTr("Delete") + color: "white" + verticalAlignment: Label.AlignVCenter + padding: 12 + height: parent.height + + SwipeDelegate.onClicked: { + profileList.status = 905 + if(speedBackend.deleteAthlete(profileList.listData[index]["userName"])){ + profileList.loadData() + return + } + profileList.status = 200 + } + + background: Rectangle { + color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato" + } } } } } - } + } /*-----Option to add a profile-----*/ @@ -263,7 +312,7 @@ Popup { onClicked: { if(speedBackend.createAthlete(userNameTf.text, fullNameTf.text)){ - profiles_stack.get(profiles_stack.depth - 2 ).loadData() + profiles_stack.get(profiles_stack.depth - 2 ).opened() profiles_stack.pop() } } @@ -545,9 +594,9 @@ Popup { height: parent.height * 0.1 width:height - opacity: profiles_stack.currentItem.secondButt !== "none" ? 1:0 + opacity: root.opacity < 1 ? root.opacity : profiles_stack.currentItem.secondButt !== "none" ? 1:0 - glowOpacity: Math.pow( root.opacity, 100 ) + //glowOpacity: Math.pow( root.opacity, 100 ) backgroundColor: appTheme.style.buttonColor diff --git a/qml/components/FadeAnimation.qml b/qml/components/FadeAnimation.qml index bb05356..40343b7 100644 --- a/qml/components/FadeAnimation.qml +++ b/qml/components/FadeAnimation.qml @@ -29,21 +29,42 @@ SequentialAnimation { property alias outEasingType: outAnimation.easing.type property alias inEasingType: inAnimation.easing.type property string easingType: "Quad" + ParallelAnimation { NumberAnimation { // in the default case, fade scale to 0 id: outAnimation target: root.target - property: root.fadeProperty + property: "scale" + duration: root.fadeDuration_in + to: 0.9 + easing.type: Easing["In"+root.easingType] + } + NumberAnimation { // in the default case, fade scale to 0 + id: outAnimation2 + target: root.target + property: "opacity" duration: root.fadeDuration_in to: 0 easing.type: Easing["In"+root.easingType] } - PropertyAction { } // actually change the property targeted by the Behavior between the 2 other animations - NumberAnimation { // in the default case, fade scale back to 1 - id: inAnimation - target: root.target - property: root.fadeProperty - duration: root.fadeDuration_out - to: 1 - easing.type: Easing["Out"+root.easingType] } + PropertyAction { } // actually change the property targeted by the Behavior between the 2 other animations + ParallelAnimation { + NumberAnimation { // in the default case, fade scale back to 1 + id: inAnimation + target: root.target + property: root.fadeProperty + duration: root.fadeDuration_out + to: 1 + easing.type: Easing["Out"+root.easingType] + } + NumberAnimation { // in the default case, fade scale to 0 + id: inAnimation2 + target: root.target + property: "opacity" + duration: root.fadeDuration_in + to: 1 + easing.type: Easing["In"+root.easingType] + } + } + } diff --git a/qml/components/FancyButton.qml b/qml/components/FancyButton.qml index 81f9bcc..c5f5f7b 100644 --- a/qml/components/FancyButton.qml +++ b/qml/components/FancyButton.qml @@ -12,7 +12,7 @@ Button { property double glowSpread: 0.2 property bool glowVisible: true property double glowScale: 0.75 - property double glowOpacity: 1 + property double glowOpacity: Math.pow( control.opacity, 100 ) diff --git a/qml/components/RemoteDataListView.qml b/qml/components/RemoteDataListView.qml index d9c8ccc..e8bc730 100644 --- a/qml/components/RemoteDataListView.qml +++ b/qml/components/RemoteDataListView.qml @@ -23,10 +23,10 @@ Item { anchors.fill: parent + //enabled: status === 200 || status === 902 + //opacity: enabled ? 1:0 - enabled: status === 200 || status === 902 - opacity: enabled ? 1:0 - + boundsBehavior: ListView.StopAtBounds ScrollBar.vertical: ScrollBar { parent: listView.parent @@ -62,16 +62,16 @@ Item { } } - Behavior on contentY { - NumberAnimation { - duration: 200 - } - } - } FancyBusyIndicator { anchors.centerIn: parent - opacity: listView.opacity === 1 ? 0:1 + opacity: !(status === 200 || status === 902) ? 1:0 + + Behavior on opacity { + NumberAnimation { + duration: 200 + } + } } } diff --git a/qml/main.qml b/qml/main.qml index 86cf030..4b85415 100644 --- a/qml/main.qml +++ b/qml/main.qml @@ -689,7 +689,10 @@ Window { anchors.rightMargin: root.landscape() ? parent.width * 0.05:parent.width * 0.5 - startButt.width * 0.5 //put the button more to the right to hide the menu (only in landscape mode) anchors.bottomMargin: root.landscape() ? parent.height * 0.5 - startButt.height * 0.5:parent.height * 0.1 //put the button lower to hide the menu (only in portrait mode) } - + PropertyChanges { + target: topLa + text: "" + } }, State { @@ -707,6 +710,10 @@ Window { anchors.rightMargin: root.landscape() ? 0-startButt.width/2:undefined anchors.bottomMargin: root.landscape() ? undefined:0-startButt.height/2 } + PropertyChanges { + target: topLa + text: "" + } } ] diff --git a/sources/baseconn.cpp b/sources/baseconn.cpp index 2120dc2..effe924 100644 --- a/sources/baseconn.cpp +++ b/sources/baseconn.cpp @@ -186,12 +186,30 @@ QVariantMap BaseConn::sendCommand(int header, QJsonValue data){ void BaseConn::readyRead() { + //qDebug() << "ready to ready " << socket->bytesAvailable() << " bytes" ; QString reply = socket->readAll(); + + if(!reply.endsWith("")){ + this->readBuffer += reply; + return; + } + else { + if(!this->readBuffer.isEmpty()){ + reply = readBuffer + reply; + readBuffer.clear(); + } + } + + reply.replace("", ""); + reply.replace("", ""); + int id = 0; QJsonDocument jsonReply = QJsonDocument::fromJson(reply.toUtf8()); QJsonObject replyObj = jsonReply.object(); + //qDebug() << "got: " << reply; + if(!replyObj.isEmpty()){ id = replyObj.value("id").toInt(); @@ -206,6 +224,7 @@ void BaseConn::readyRead() { latestReadReply = reply; emit gotUnexpectedReply(reply); + } int BaseConn::writeRemoteSetting(QString key, QString value) { diff --git a/sources/climbingrace.cpp b/sources/climbingrace.cpp index 6e42c0f..f827496 100644 --- a/sources/climbingrace.cpp +++ b/sources/climbingrace.cpp @@ -457,9 +457,9 @@ QVariant ClimbingRace::getAthletes() { return false; } - QVariantList tmpAthletes = reply["data"].toList(); + QVariantMap tmpAthletes = reply["data"].toMap(); - //qDebug() << tmpAthletes; + qDebug() << tmpAthletes; return tmpAthletes; }