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/qml/SettingsDialog.qml

516 lines
16 KiB
QML
Raw 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/>.
*/
import QtQuick 2.9
import QtMultimedia 5.8
import QtQuick.Window 2.2
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
2019-03-08 15:36:32 +01:00
import QtGraphicalEffects 1.0
import "./components"
Popup {
id: root
x: startButt.x
y: startButt.y
width: startButt.width
height: startButt.height
2018-07-26 22:13:43 +02:00
modal: true
dim: false
2019-03-08 15:36:32 +01:00
opacity: 0
property var connections
signal connectRequested(var type)
onConnectionsChanged: {
//loop trough all connections
for (var key in connections) {
if(!connections[key])continue; //skip if empty to avoid errors
//check if any connection is in the state "connecting"
if(connections[key]["status"] === "connecting"){
root.closePolicy = Popup.NoAutoClose //make the dalog non-closable
return
}
}
//if no connection is in "conecting" state make popup closable
root.closePolicy = Popup.CloseOnPressOutside
}
function connect(type) {
connectRequested(type)
}
enter: Transition {
2019-03-08 15:36:32 +01:00
NumberAnimation { properties: "opacity"; to: 1; duration: 300; easing.type: Easing.InOutQuad }
}
exit: Transition {
2019-03-08 15:36:32 +01:00
NumberAnimation { properties: "opacity"; to: 0; duration: 300; easing.type: Easing.InOutQuad }
}
background: Rectangle {
radius: width * 0.5
2019-03-08 18:03:27 +01:00
color: appTheme.style.viewColor
border.color: appTheme.style.lineColor
2019-03-08 15:36:32 +01:00
border.width: 0
Behavior on color {
ColorAnimation {
duration: 200
}
}
2019-03-08 15:36:32 +01:00
RectangularGlow {
id: effect_2
glowRadius: 7
spread: 0.02
color: "black"
opacity: 0.18
anchors.fill: headlineUnderline
scale: 1
}
Canvas {
id: headerBackground
anchors {
left: parent.left
right: parent.right
top: parent.top
bottom: headlineUnderline.bottom
}
height: header.height
width: header.width
2019-03-08 18:03:27 +01:00
property color color: appTheme.style.viewColor
2019-03-08 15:36:32 +01:00
Behavior on color {
ColorAnimation {
duration: 200
}
}
2019-03-08 15:36:32 +01:00
onColorChanged: {
requestPaint()
}
onPaint: {
var ctx = getContext("2d");
ctx.reset();
var centreX = root.width / 2;
var centreY = root.height / 2;
ctx.beginPath();
ctx.fillStyle = headerBackground.color
ctx.moveTo(centreX, centreY);
ctx.arc(centreX, centreY, root.width / 2, 1 * Math.PI, 2*Math.PI, false);
//ctx.lineTo(centreX, centreY);
ctx.fill();
}
}
Item {
id: header
anchors {
2019-03-08 15:36:32 +01:00
left: parent.left
right: parent.right
top: parent.top
2019-03-08 15:36:32 +01:00
bottom: headlineUnderline.bottom
}
Label {
id: head_text
text: options_stack.currentItem.title
font.pixelSize: headlineUnderline.width * 0.05
2019-03-08 18:03:27 +01:00
color: enabled ? appTheme.style.textColor:appTheme.style.disabledTextColor
2019-03-08 15:36:32 +01:00
anchors {
horizontalCenter: parent.horizontalCenter
top: parent.top
topMargin: headlineUnderline.anchors.topMargin / 2 - height / 2
}
}
}
Rectangle {
id: headlineUnderline
height: 1
width: parent.width
2019-03-08 18:03:27 +01:00
color: appTheme.style.lineColor
2019-03-08 15:36:32 +01:00
visible: false
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))
}
}
2019-03-08 15:36:32 +01:00
FancyButton {
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-03 15:18:23 +02:00
height: parent.height * 0.13
width: height
2019-03-08 15:36:32 +01:00
//opacity: root.closePolicy === Popup.NoAutoClose ? 0:1
enabled: opacity > 0
2019-03-08 15:36:32 +01:00
glowOpacity: Math.pow( root.opacity, 100 )
2019-03-08 18:03:27 +01:00
backgroundColor: appTheme.style.buttonColor
image: appTheme.style.backIcon
onClicked: {
options_stack.depth > 1 ? options_stack.pop():root.close()
}
Behavior on opacity {
NumberAnimation {
duration: 200
}
}
}
}
StackView {
id: options_stack
2018-08-11 23:54:34 +02:00
property int text_pixelSize: root.height * 0.06
2019-01-01 15:23:15 +01:00
property int rowSpacing: root.height * 0.01
initialItem: settings
width: headlineUnderline.width
enabled: opacity !== 0 //disable when not visible
anchors {
top: parent.top
left: parent.left
leftMargin: ( parent.width - headlineUnderline.width ) / 2
2018-08-11 23:54:34 +02:00
topMargin: headlineUnderline.anchors.topMargin * 0.8
bottom: parent.bottom
}
Behavior on opacity {
NumberAnimation {duration: 200}
}
/*-----start page of the settings-----*/
Component {
id: settings
Column {
property string title: qsTr("Options")
id: settings_col
2019-01-01 15:23:15 +01:00
spacing: options_stack.rowSpacing
/*----Connect to external devices----*/
NextPageDelegate {
id: connect_del
text: qsTr("Base Station")
onClicked: {
options_stack.push(connect)
}
}
/*----Automated Start----*/
NextPageDelegate {
id: autostart_del
text: qsTr("start sequence")
onClicked: {
options_stack.push(autostart)
}
}
/*----Style Settings----*/
ItemDelegate {
id: style_del
text: qsTr("change style")
width: parent.width
contentItem: Text {
text: parent.text
2019-03-08 18:03:27 +01:00
color: appTheme.style.textColor
font.pixelSize: options_stack.text_pixelSize
}
onClicked: {
2019-03-08 18:03:27 +01:00
appTheme.changeTheme()
}
}
2019-01-01 15:23:15 +01:00
/*----Error Dialog----*/
ItemDelegate {
id: error_del
text: qsTr("open error popup")
width: parent.width
contentItem: Text {
text: parent.text
2019-03-08 18:03:27 +01:00
color: appTheme.style.textColor
2019-01-01 15:23:15 +01:00
font.pixelSize: options_stack.text_pixelSize
}
onClicked: {
errorDialog.open()
}
}
}
}
2018-09-09 20:18:00 +02:00
/*-----Page to connect to extenstions like a startpad or buzzer-----*/
Component {
id: connect
Column {
id: connect_col
property string title: qsTr("Base Station")
property int delegateHeight: height*0.18
ConnectionDelegate {
id: connect_base_del
text: "connect"
status: { "status": speedBackend.baseStationState }
connect: speedBackend.connectBaseStation
type: "baseStation"
width: parent.width
font.pixelSize: options_stack.text_pixelSize
}
NextPageDelegate {
id: baseStationConnections_del
text: qsTr("connected extentions")
onClicked: {
options_stack.push(baseStationConnections)
}
}
}
}
/*-----Page to setup automatc start sequence-----*/
Component {
id: autostart
Column {
id: autostart_col
property string title: "Autostart"
2018-08-11 23:54:34 +02:00
property int delegateHeight: height*0.18
function updateSetting(key, val, del){
del.enabled = false
speedBackend.writeSetting(key, val)
del.enabled = true
}
function loadSetting(key, del){
del.enabled = false
var val
val = speedBackend.readSetting(key)
del.enabled = true
return val
}
SwitchDelegate {
id: ready_del
text: qsTr("say 'ready'")
contentItem: Text {
text: parent.text
2019-03-08 18:03:27 +01:00
color: appTheme.style.textColor
font.pixelSize: options_stack.text_pixelSize
}
checked: parent.loadSetting("ready_en", ready_del) === "true"
width: parent.width
2018-08-11 23:54:34 +02:00
height: parent.delegateHeight
font.pixelSize: options_stack.text_pixelSize
onCheckedChanged: {
parent.updateSetting("ready_en",checked, ready_del)
}
2018-08-11 23:54:34 +02:00
indicator: SimpleIndicator{}
}
ItemDelegate {
id: ready_delay_del
text: qsTr("delay (ms)")
contentItem: Text {
text: parent.text
2019-03-08 18:03:27 +01:00
color: appTheme.style.textColor
font.pixelSize: options_stack.text_pixelSize
}
enabled: ready_del.checked
width: parent.width
font.pixelSize: options_stack.text_pixelSize
2018-08-11 23:54:34 +02:00
height: parent.delegateHeight
TextField {
focus: true
placeholderText: qsTr("time")
width: parent.width * 0.3
2018-08-11 23:54:34 +02:00
height: parent.height
anchors.right: parent.right
2018-08-11 23:54:34 +02:00
anchors.verticalCenter: parent.verticalCenter
inputMethodHints: Qt.ImhFormattedNumbersOnly
text: autostart_col.loadSetting("ready_delay", ready_del)
onTextChanged: {
autostart_col.updateSetting("ready_delay", text, ready_delay_del)
}
}
}
SwitchDelegate {
id: at_marks_del
text: qsTr("say\n'at your marks'")
contentItem: Text {
text: parent.text
2019-03-08 18:03:27 +01:00
color: appTheme.style.textColor
font.pixelSize: options_stack.text_pixelSize
}
checked: autostart_col.loadSetting("at_marks_en", ready_del) === "true"
width: parent.width
2018-08-11 23:54:34 +02:00
//height: parent.delegateHeight * 1.5
font.pixelSize: options_stack.text_pixelSize
onCheckedChanged: {
parent.updateSetting("at_marks_en",at_marks_del.checked, at_marks_del)
}
2018-08-11 23:54:34 +02:00
indicator: SimpleIndicator{}
}
ItemDelegate {
id: at_marks_delay_del
text: qsTr("delay (ms)")
contentItem: Text {
text: parent.text
2019-03-08 18:03:27 +01:00
color: appTheme.style.textColor
font.pixelSize: options_stack.text_pixelSize
}
enabled: at_marks_del.checked
width: parent.width
2018-08-11 23:54:34 +02:00
height: parent.delegateHeight
font.pixelSize: options_stack.text_pixelSize
TextField {
focus: true
placeholderText: qsTr("time")
width: parent.width * 0.3
2018-08-11 23:54:34 +02:00
height: parent.height
anchors.right: parent.right
2018-08-11 23:54:34 +02:00
anchors.verticalCenter: parent.verticalCenter
inputMethodHints: Qt.ImhFormattedNumbersOnly
text: autostart_col.loadSetting("at_marks_delay", ready_del)
onTextChanged: {
autostart_col.updateSetting("at_marks_delay",text, at_marks_delay_del)
}
}
}
}
}
/*-----Page to view devices that core connected to the pase startion-----*/
Component{
id: baseStationConnections
ListView {
id: baseStationConnections_list
property string title: qsTr("connections")
property int delegateHeight: height*0.18
model: speedBackend.baseStationConnections.length
delegate: ConnectionDelegate {
enabled: false
font.pixelSize: options_stack.text_pixelSize
width: parent.width
height: baseStationConnections_list.delegateHeight
text: speedBackend.baseStationConnections[index]["name"]
status: {'status': speedBackend.baseStationConnections[index]["state"], 'progress': speedBackend.baseStationConnections[index]["progress"]}
}
}
}
/*-----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
}
}
}
}