This repository has been archived on 2024-06-03. You can view files and clone it, but cannot push or open issues or pull requests.
app/resources/qml/ProfilesDialog.qml

425 lines
13 KiB
QML
Raw Permalink Normal View History

2018-08-12 20:51:57 +02:00
/*
Speed Climbing Stopwatch - Simple Stopwatch for Climbers
Copyright (C) 2018 Itsblue Development - Dorian Zeder
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2018-08-02 12:50:55 +02:00
import QtQuick 2.9
import QtMultimedia 5.8
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
import com.itsblue.speedclimbingstopwatch 1.0
Popup {
id: root
x: startButt.x
y: startButt.y
width: startButt.width
height: startButt.height
modal: true
dim: false
enter: Transition {
NumberAnimation { properties: "scale"; from: 0; to: 1; duration: 300; easing.type: Easing.Linear }
}
exit: Transition {
NumberAnimation { properties: "scale"; from: 1; to: 0; duration: 300; easing.type: Easing.Linear }
}
background: Rectangle {
radius: width * 0.5
color: "white"
border.color: "grey"
border.width: 1
Label {
id: head_text
2018-08-03 15:18:23 +02:00
text: profiles_stack.currentItem.title
2018-08-02 12:50:55 +02:00
font.pixelSize: headlineUnderline.width * 0.1
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: headlineUnderline.anchors.topMargin / 2 - height / 2
}
}
Rectangle {
id: headlineUnderline
height: 1
width: parent.width
color: "grey"
anchors {
top: parent.top
left: parent.left
right: parent.right
topMargin: parent.height * 0.15
rightMargin: parent.radius - Math.sqrt(Math.pow(parent.radius,2)-Math.pow(parent.radius-anchors.topMargin,2))
leftMargin: parent.radius - Math.sqrt(Math.pow(parent.radius,2)-Math.pow(parent.radius-anchors.topMargin,2))
}
}
ProgressCircle {
id: prog
property string text: "connecting.."
anchors.fill: parent
opacity: 0
lineWidth: 5
arcBegin: 0
arcEnd: 0
Timer {
id: prog_refresh
running: false
interval: 1
repeat: true
onTriggered: {
prog.arcEnd = 360 * ( _cppBuzzerConn.get("connection_progress") / 100 )
}
}
Label {
id: content
text: parent.text
anchors.centerIn: parent
font.pixelSize: parent.width * 0.1
}
}
Button {
id: head_back
anchors {
left: parent.left
leftMargin: parent.width * 0.17
top:parent.top
2018-08-03 15:18:23 +02:00
topMargin: parent.height * 0.01
2018-08-02 12:50:55 +02:00
}
2018-08-03 15:18:23 +02:00
height: parent.height * 0.13
2018-08-02 12:50:55 +02:00
width:height
background: Rectangle {
radius: width * 0.5
2018-08-03 15:18:23 +02:00
color: head_back.pressed ? "lightgrey":"white"
2018-08-02 12:50:55 +02:00
border.color: "grey"
border.width: 1
Image {
anchors.fill: parent
anchors.margins: parent.width * 0.2
source: "qrc:/graphics/icons/back_black.png"
2018-08-03 15:18:23 +02:00
}
}
2018-08-02 12:50:55 +02:00
2018-08-03 15:18:23 +02:00
onClicked: profiles_stack.depth > 1 ? profiles_stack.pop():root.close()
Behavior on opacity {
NumberAnimation {
duration: 100
2018-08-02 12:50:55 +02:00
}
}
2018-08-03 15:18:23 +02:00
}
2018-08-02 12:50:55 +02:00
2018-08-03 15:18:23 +02:00
Button {
id: head_add
anchors {
right: parent.right
rightMargin: parent.width * 0.17
top:parent.top
topMargin: parent.height * 0.01
2018-08-02 12:50:55 +02:00
}
2018-08-03 15:18:23 +02:00
height: parent.height * 0.13
width:height
2018-08-02 12:50:55 +02:00
2018-08-03 15:18:23 +02:00
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
2018-08-02 12:50:55 +02:00
}
2018-08-03 15:18:23 +02:00
}
onClicked: {
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()
}
2018-08-02 12:50:55 +02:00
}
2018-08-03 15:18:23 +02:00
2018-08-02 12:50:55 +02:00
}
2018-08-03 15:18:23 +02:00
2018-08-02 12:50:55 +02:00
Behavior on opacity {
NumberAnimation {
duration: 100
}
}
}
}
ListView {
2018-08-03 15:18:23 +02:00
id: profileModel
model: SqlProfileModel{}
}
StackView {
id: profiles_stack
property int text_pixelSize: headlineUnderline.width * 0.08
initialItem: profileListComp
width: headlineUnderline.width
2018-08-02 12:50:55 +02:00
anchors {
top: parent.top
left: parent.left
leftMargin: ( parent.width - headlineUnderline.width ) / 2
2018-08-03 15:18:23 +02:00
topMargin: headlineUnderline.anchors.topMargin * 1.2
2018-08-02 12:50:55 +02:00
bottom: parent.bottom
2018-08-03 15:18:23 +02:00
bottomMargin: headlineUnderline.anchors.topMargin
2018-08-02 12:50:55 +02:00
}
2018-08-03 15:18:23 +02:00
Behavior on opacity {
NumberAnimation {duration: 200}
}
2018-08-02 12:50:55 +02:00
2018-08-03 15:18:23 +02:00
/*-----List of all profiles-----*/
Component {
id: profileListComp
2018-08-11 23:54:34 +02:00
Tumbler {
id: control
property string title: "profiles"
property string secondButt: "add"
model: SqlProfileModel{}
delegate: Text {
text: model.name
color: control.visualFocus ? control.palette.highlight : control.palette.text
font: control.font
opacity: 1.0 - Math.abs(Tumbler.displacement) / (control.visibleItemCount / 2)
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
}
}
/*
2018-08-03 15:18:23 +02:00
ListView {
id: profileList
model: profileModel.model
property string title: "profiles"
property string secondButt: "add"
2018-08-11 23:54:34 +02:00
2018-08-03 15:18:23 +02:00
Label {
2018-08-11 23:54:34 +02:00
opacity: profileList.count <= 0 ? 1:0
2018-08-03 15:18:23 +02:00
text: "add a profile by clicking +"
anchors.centerIn: parent
font.pixelSize: parent.width*0.06
2018-08-11 23:54:34 +02:00
Behavior on opacity {
NumberAnimation {
duration: 200
easing.type: Easing.InOutQuad
}
}
2018-08-03 15:18:23 +02:00
}
2018-08-02 12:50:55 +02:00
2018-08-03 15:18:23 +02:00
delegate: SwipeDelegate {
id: swipeDelegate
text: model.name
width: profileList.width
2018-08-11 23:54:34 +02:00
font.pixelSize: profiles_stack.text_pixelSize
function remove() {
removeAnim.start()
}
background: Rectangle {
color: pressed ? Qt.darker("white", 1.1):"white"
}
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)
}
2018-08-03 15:18:23 +02:00
Component {
id: component
2018-08-02 12:50:55 +02:00
2018-08-03 15:18:23 +02:00
Rectangle {
2018-08-11 23:54:34 +02:00
color: mouseAr.pressed ? "#333" : "#444"
2018-08-03 15:18:23 +02:00
width: parent.width
height: parent.height
clip: true
2018-08-02 12:50:55 +02:00
2018-08-03 15:18:23 +02:00
Label {
text: qsTr("Press me!")
color: "#21be2b"
anchors.centerIn: parent
}
MouseArea {
id: mouseAr
anchors.fill: parent
onClicked: {
2018-08-11 23:54:34 +02:00
swipeDelegate.remove()
2018-08-03 15:18:23 +02:00
}
}
2018-08-02 12:50:55 +02:00
}
}
2018-08-03 15:18:23 +02:00
2018-08-11 23:54:34 +02:00
swipe.transition: Transition {
SmoothedAnimation { velocity: 3; easing.type: Easing.InOutCubic }
}
swipe.left: Row {
anchors.left: parent.left
height: parent.height
Label {
id: moveLabel
text: qsTr("Move")
color: "white"
verticalAlignment: Label.AlignVCenter
padding: 12
height: parent.height
SwipeDelegate.onClicked: console.log("Moving...")
background: Rectangle {
color: moveLabel.SwipeDelegate.pressed ? Qt.darker("#ffbf47", 1.1) : "#ffbf47"
}
}
Label {
id: deleteLabel
text: qsTr("Delete")
color: "white"
verticalAlignment: Label.AlignVCenter
padding: 12
height: parent.height
SwipeDelegate.onClicked: console.log("Deleting...")
background: Rectangle {
color: deleteLabel.SwipeDelegate.pressed ? Qt.darker("tomato", 1.1) : "tomato"
}
}
}
2018-08-02 12:50:55 +02:00
}
2018-08-03 15:18:23 +02:00
ScrollIndicator.vertical: ScrollIndicator { }
2018-08-02 12:50:55 +02:00
}
2018-08-11 23:54:34 +02:00
*/
2018-08-03 15:18:23 +02:00
}
2018-08-02 12:50:55 +02:00
2018-08-03 15:18:23 +02:00
/*-----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
}
2018-08-11 23:54:34 +02:00
Keys.onReturnPressed: {
if(profileModel.model.append(text)){
profiles_stack.pop()
}
}
2018-08-03 15:18:23 +02:00
}
}
}
/*-----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
}
2018-08-02 12:50:55 +02:00
}
}
}