From 270a7625d7296d45cf41416e33e33c8ea620e9f6 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Fri, 3 Aug 2018 15:18:23 +0200 Subject: [PATCH] added "add profile" dialog --- CHANGELOG | 2 + graphics/icons/ok_black.png | Bin 0 -> 383 bytes headers/sqlprofilemodel.h | 2 + qml/ProfilesDialog.qml | 221 +++++++++++++++++++++++++++++------- qml/SettingsDialog.qml | 4 +- shared.qrc | 1 + sources/sqlprofilemodel.cpp | 16 +++ 7 files changed, 200 insertions(+), 46 deletions(-) create mode 100644 graphics/icons/ok_black.png diff --git a/CHANGELOG b/CHANGELOG index 002ede0..570ebbe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - start seqnece continues in a buggy way when cancel is being pressed while 'at your marks' or 'ready' - bug that made the start sequence freeze if a delay of zero or lower or a non valid number was set as delay +### Changed +- increased the size f the back buttons in settings / profiles dialog ## [0.03 - BETA] - 2018-07-29 ### Added diff --git a/graphics/icons/ok_black.png b/graphics/icons/ok_black.png new file mode 100644 index 0000000000000000000000000000000000000000..f24dbf6cd8ed5980df3857ab9b20567a619a603d GIT binary patch literal 383 zcmV-_0f7FAP)E3jDBoO!Dfwn1%*j_DVTpXT5iIg|05VV`8OY$L;Iv{z&l6=Ud4iqW>t=CIM${+Cj7u7rOQ?xuc^@@-}-YY^X zd9Kq&`=pfLDne@cwGoPx2cEBsZpPuP5sH;3NBBi3UY>YFNFz_SjF3*AbXXrDtvp#1 zA-z2LB*L%p_+sUWCBk*|nO>eOi7=La7a@&2nTzmB_SN_4 roleNames() const Q_DECL_OVERRIDE; + + Q_INVOKABLE bool append(QString name); signals: public slots: diff --git a/qml/ProfilesDialog.qml b/qml/ProfilesDialog.qml index 9774245..4209a3d 100644 --- a/qml/ProfilesDialog.qml +++ b/qml/ProfilesDialog.qml @@ -31,7 +31,7 @@ Popup { Label { id: head_text - text: options_stack.currentItem.title + text: profiles_stack.currentItem.title font.pixelSize: headlineUnderline.width * 0.1 anchors { horizontalCenter: parent.horizontalCenter @@ -91,36 +91,82 @@ Popup { left: parent.left leftMargin: parent.width * 0.17 top:parent.top - topMargin: parent.height * 0.025 + topMargin: parent.height * 0.01 } - height: parent.height * 0.1 + height: parent.height * 0.13 width:height background: Rectangle { radius: width * 0.5 - color: "white" + color: head_back.pressed ? "lightgrey":"white" border.color: "grey" border.width: 1 Image { anchors.fill: parent anchors.margins: parent.width * 0.2 source: "qrc:/graphics/icons/back_black.png" + } + } + onClicked: profiles_stack.depth > 1 ? profiles_stack.pop():root.close() + + Behavior on opacity { + NumberAnimation { + duration: 100 + } + } + } + + Button { + id: head_add + + anchors { + right: parent.right + rightMargin: parent.width * 0.17 + top:parent.top + topMargin: parent.height * 0.01 + } + height: parent.height * 0.13 + width:height + + background: Rectangle { + radius: width * 0.5 + color: parent.pressed ? "lightgrey":"white" + border.color: "grey" + border.width: 1 + Label { + anchors { + top: parent.top + topMargin: parent.height/2 - height*0.55 + left: parent.left + leftMargin: parent.width/2 - width/2 + } + opacity: profiles_stack.currentItem.secondButt === "add" ? 1:0 + text: "+" + font.pixelSize: parent.height + } + + Image { + anchors.fill: parent + anchors.margins: parent.width * 0.2 + source: "qrc:/graphics/icons/ok_black.png" + opacity: profiles_stack.currentItem.secondButt === "ok" ? 1:0 } } onClicked: { - options_stack.depth > 1 ? options_stack.pop():root.close() + switch(profiles_stack.currentItem.secondButt){ + case "add": + profiles_stack.push(addProfileComp) + break + case "ok": + if(profileModel.model.append(profiles_stack.currentItem.newProfileName)){ + profiles_stack.pop() + } + } + } - onPressedChanged: { - if(pressed){ - background.color = "lightgrey" - } - else { - background.color = "white" - } - } Behavior on opacity { NumberAnimation { duration: 100 @@ -129,54 +175,141 @@ Popup { } } - ListView { - id: profileList + ListView{ + id: profileModel + model: SqlProfileModel{} + } + + StackView { + id: profiles_stack + property int text_pixelSize: headlineUnderline.width * 0.08 + initialItem: profileListComp + width: headlineUnderline.width + + + anchors { top: parent.top left: parent.left leftMargin: ( parent.width - headlineUnderline.width ) / 2 - right: parent.right - rightMargin: headlineUnderline.anchors.rightMargin - topMargin: headlineUnderline.anchors.topMargin + topMargin: headlineUnderline.anchors.topMargin * 1.2 bottom: parent.bottom + bottomMargin: headlineUnderline.anchors.topMargin } - model:SqlProfileModel{} - delegate: SwipeDelegate { - id: swipeDelegate - text: model.name + Behavior on opacity { + NumberAnimation {duration: 200} + } - width: profileList.width - Component { - id: component + /*-----List of all profiles-----*/ + Component { + id: profileListComp + ListView { + id: profileList + model: profileModel.model + property string title: "profiles" + property string secondButt: "add" + Label { + visible: profileList.count <= 0 + text: "add a profile by clicking +" + anchors.centerIn: parent + font.pixelSize: parent.width*0.06 + } - Rectangle { - color: mouse.pressed ? "#333" : "#444" - width: parent.width - height: parent.height - clip: true + delegate: SwipeDelegate { + id: swipeDelegate + text: model.name + + width: profileList.width + Component { + id: component + + Rectangle { + color: mouse.pressed ? "#333" : "#444" + width: parent.width + height: parent.height + clip: true - Label { - text: qsTr("Press me!") - color: "#21be2b" - anchors.centerIn: parent + Label { + text: qsTr("Press me!") + color: "#21be2b" + anchors.centerIn: parent + } + + MouseArea { + id: mouseAr + anchors.fill: parent + onClicked: { + model.remove(index) + } + } + } } - MouseArea { - id: mouseAr - anchors.fill: parent - onClicked: { - model.remove(index) - } + swipe.left: component + swipe.right: component + } + ScrollIndicator.vertical: ScrollIndicator { } + } + } + + /*-----Option to add a profile-----*/ + Component { + id: addProfileComp + Column { + property string title: "add profile" + property string secondButt: "ok" + property string newProfileName: "" + TextField { + width: parent.width + placeholderText: "name" + onTextChanged: { + parent.newProfileName = text } } } - - swipe.left: component - swipe.right: component } - ScrollIndicator.vertical: ScrollIndicator { } + + /*-----Custom animations-----*/ + + pushEnter: Transition { + NumberAnimation { + property: "opacity" + from: 0 + to: 1 + duration: 200 + easing.type: Easing.InOutQuad + } + } + pushExit: Transition { + NumberAnimation { + property: "opacity" + from: 1 + to: 0 + duration: 200 + easing.type: Easing.InOutQuad + } + } + + popExit: Transition { + NumberAnimation { + property: "opacity" + from: 1 + to: 0 + duration: 200 + easing.type: Easing.InOutQuad + } + } + popEnter: Transition { + NumberAnimation { + property: "opacity" + from: 0 + to: 1 + duration: 200 + easing.type: Easing.InOutQuad + } + } } } diff --git a/qml/SettingsDialog.qml b/qml/SettingsDialog.qml index bbbe391..f4ca44d 100644 --- a/qml/SettingsDialog.qml +++ b/qml/SettingsDialog.qml @@ -89,9 +89,9 @@ Popup { left: parent.left leftMargin: parent.width * 0.17 top:parent.top - topMargin: parent.height * 0.025 + topMargin: parent.height * 0.01 } - height: parent.height * 0.1 + height: parent.height * 0.13 width:height background: Rectangle { diff --git a/shared.qrc b/shared.qrc index ff1b551..27896f1 100644 --- a/shared.qrc +++ b/shared.qrc @@ -14,5 +14,6 @@ sounds/ready_2.wav sounds/at_marks_2.wav graphics/icons/buzzer_black.png + graphics/icons/ok_black.png diff --git a/sources/sqlprofilemodel.cpp b/sources/sqlprofilemodel.cpp index 46c8287..e36de05 100644 --- a/sources/sqlprofilemodel.cpp +++ b/sources/sqlprofilemodel.cpp @@ -35,6 +35,7 @@ SqlProfileModel::SqlProfileModel(QObject *parent) : QSqlTableModel(parent) qDebug("ProfileModel constructor"); createTable(); setTable("profiles"); + setEditStrategy(QSqlTableModel::OnManualSubmit); select(); } @@ -55,3 +56,18 @@ QHash SqlProfileModel::roleNames() const return names; } + +bool SqlProfileModel::append(QString name) +{ + qDebug() << name; + QSqlRecord newRecord = record(); + newRecord.setValue("name", name); + + if (!insertRecord(rowCount(), newRecord)) { + qWarning() << "Failed to add profile:" << lastError().text(); + return(false); + } + + submitAll(); + return(true); +}