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 0000000..f24dbf6 Binary files /dev/null and b/graphics/icons/ok_black.png differ diff --git a/headers/sqlprofilemodel.h b/headers/sqlprofilemodel.h index 80a96d4..ee3d84f 100644 --- a/headers/sqlprofilemodel.h +++ b/headers/sqlprofilemodel.h @@ -17,6 +17,8 @@ public: QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE; QHash 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); +}