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-07-17 19:17:25 +02:00
import QtQuick 2.9
import QtMultimedia 5.8
2020-10-01 01:54:38 +02:00
import QtQuick . Window 2.0
import QtQuick . Controls 2.12
2019-03-08 15:36:32 +01:00
import QtGraphicalEffects 1.0
2020-10-01 01:54:38 +02:00
import QtQuick . Layouts 1.0
2018-08-28 23:03:35 +02:00
import "."
import "./components"
2019-06-08 11:14:18 +02:00
import "./ProfilesDialog"
2019-10-18 16:10:41 +02:00
import "./SettingsDialog"
2020-10-01 01:54:38 +02:00
import "./components/layout"
import "./MainPage"
2018-07-22 21:08:11 +02:00
//import QtQuick.Layouts 1.11
2018-07-22 16:47:55 +02:00
2020-05-26 17:57:54 +02:00
import de . itsblue . ScStw 2.0
import de . itsblue . ScStw . Styling 2.0
import de . itsblue . ScStw . Styling . Components 1.0
import de . itsblue . ScStwApp 2.0
2018-07-17 19:17:25 +02:00
Window {
visible: true
2020-10-01 02:27:00 +02:00
//width: 540
//height: 960
width: XscreenWidth
height: XscreenHeight
2020-07-10 15:20:41 +02:00
title: "ScStwApp"
2018-07-17 19:17:25 +02:00
Page {
2020-10-01 01:54:38 +02:00
id: app
2018-07-17 19:17:25 +02:00
anchors.fill: parent
2018-08-14 17:07:42 +02:00
//set default state to IDLE
2020-10-01 01:54:38 +02:00
state: ScStwRace . IDLE
2018-07-22 16:47:55 +02:00
2018-08-28 23:03:35 +02:00
Rectangle {
id: backgroundRect
anchors.fill: parent
2020-05-19 12:43:32 +02:00
color: appTheme . theme . colors . background
2019-03-24 21:31:59 +01:00
Behavior on color {
ColorAnimation {
duration: 200
}
}
2018-07-25 00:32:20 +02:00
}
2020-04-17 19:57:33 +02:00
ScStw {
id: scStw
}
2019-03-07 17:18:24 +01:00
SpeedBackend {
id: speedBackend
2020-04-15 21:47:55 +02:00
}
2019-03-07 17:18:24 +01:00
2020-04-15 21:47:55 +02:00
Connections {
target: speedBackend . race
2019-03-07 17:18:24 +01:00
onStateChanged: {
var stateString
2020-04-19 13:09:46 +02:00
console . log ( "race state changed to: " + speedBackend . race . state )
2020-10-01 01:54:38 +02:00
if ( speedBackend . race . state != ScStwRace . IDLE ) {
//settingsDialog.close()
2019-03-07 17:18:24 +01:00
}
2020-10-01 01:54:38 +02:00
app . state = speedBackend . race . state
2018-10-04 18:35:29 +02:00
}
2018-08-28 23:03:35 +02:00
}
2020-05-19 12:43:32 +02:00
ScStwAppThemeManager {
2019-03-08 18:03:27 +01:00
id: appTheme
2020-07-11 20:30:50 +02:00
property ScStwSetting setting: speedBackend . settings . getSetting ( ScStwAppSettings . AppThemeSetting , ScStwAppSettings . KeyLevel )
2020-08-09 12:20:04 +02:00
themeName: setting . value
2019-03-08 18:03:27 +01:00
}
2020-10-01 01:54:38 +02:00
// ---------------
// - Main layout -
// ---------------
2019-04-15 13:33:31 +02:00
2020-10-01 01:54:38 +02:00
GridLayout {
id: mainLayout
2019-10-13 16:42:38 +02:00
2020-10-01 01:54:38 +02:00
anchors.fill: parent
2019-04-15 13:33:31 +02:00
2020-10-01 01:54:38 +02:00
columns: app . landscape ( ) ? 3 : 1
rows: app . landscape ( ) ? 1 : 3
2019-04-15 13:33:31 +02:00
2020-10-01 01:54:38 +02:00
TopToolBar {
id: topToolBar
2018-10-14 18:39:39 +02:00
2020-10-01 01:54:38 +02:00
state: app . state
2018-10-04 18:35:29 +02:00
2020-10-01 01:54:38 +02:00
sizeMode: "large"
2018-07-17 19:17:25 +02:00
}
2018-08-29 18:33:39 +02:00
2019-09-08 00:50:03 +02:00
2020-10-01 01:54:38 +02:00
CenterContent {
id: centerContent
2019-04-15 13:33:31 +02:00
2020-10-01 01:54:38 +02:00
state: app . state
2019-04-15 13:33:31 +02:00
2020-10-01 01:54:38 +02:00
Layout.fillWidth: true
Layout.fillHeight: true
2019-04-15 13:33:31 +02:00
}
2020-10-01 01:54:38 +02:00
BottomToolBar {
id: bottomToolBar
2019-03-24 21:16:16 +01:00
2020-10-01 01:54:38 +02:00
sizeMode: "tiny"
2019-03-24 21:16:16 +01:00
}
2020-10-01 01:54:38 +02:00
}
2020-09-22 15:44:57 +02:00
2020-10-01 01:54:38 +02:00
states: [
State {
name: ScStwRace . IDLE
2020-09-22 15:44:57 +02:00
2020-10-01 01:54:38 +02:00
PropertyChanges {
target: topToolBar
sizeMode: "small"
2019-03-24 21:16:16 +01:00
}
2020-06-13 17:11:26 +02:00
2020-10-01 01:54:38 +02:00
PropertyChanges {
target: bottomToolBar
sizeMode: "small"
2020-06-13 17:11:26 +02:00
}
2020-10-01 01:54:38 +02:00
} ,
2018-07-17 19:17:25 +02:00
2020-10-01 01:54:38 +02:00
State {
name: ScStwRace . PREPAIRING
2018-07-22 16:47:55 +02:00
2020-10-01 01:54:38 +02:00
PropertyChanges {
target: topToolBar
sizeMode: "medium"
2018-08-14 17:07:42 +02:00
}
2020-10-01 01:54:38 +02:00
PropertyChanges {
target: bottomToolBar
sizeMode: "tiny"
2018-07-22 16:47:55 +02:00
}
2020-10-01 01:54:38 +02:00
} ,
2019-10-02 19:12:06 +02:00
2020-10-01 01:54:38 +02:00
State {
name: ScStwRace . WAITING
2019-10-02 19:12:06 +02:00
2020-10-01 01:54:38 +02:00
PropertyChanges {
target: topToolBar
sizeMode: "medium"
2019-10-02 19:12:06 +02:00
}
2020-10-01 01:54:38 +02:00
PropertyChanges {
target: bottomToolBar
sizeMode: "tiny"
2019-10-02 19:12:06 +02:00
}
2020-10-01 01:54:38 +02:00
} ,
2018-07-28 21:17:41 +02:00
2020-10-01 01:54:38 +02:00
State {
name: ScStwRace . STARTING
2018-07-28 21:17:41 +02:00
2020-10-01 01:54:38 +02:00
PropertyChanges {
target: topToolBar
sizeMode: "medium"
2018-07-28 21:17:41 +02:00
}
2019-03-07 17:18:24 +01:00
2020-10-01 01:54:38 +02:00
PropertyChanges {
target: bottomToolBar
sizeMode: "tiny"
2018-07-22 16:47:55 +02:00
}
}
2020-10-01 01:54:38 +02:00
]
2019-03-08 15:36:32 +01:00
2018-07-25 00:32:20 +02:00
/ * - - - - - -
Popups
2020-10-01 01:54:38 +02:00
-- -- --
2018-07-25 00:32:20 +02:00
SettingsDialog {
2018-08-02 12:50:55 +02:00
id: settingsDialog
2019-08-19 15:14:11 +02:00
x: startButt . x
y: startButt . y
width: startButt . width
height: startButt . height
2018-07-22 16:47:55 +02:00
}
2019-04-30 23:44:04 +02:00
ProfilesDialog {
id: profilesDialog
2019-09-08 15:08:50 +02:00
property int margin: app . landscape ( ) ? app . height * 0.05 : app . width * 0.05
2019-04-30 23:44:04 +02:00
2019-09-08 15:08:50 +02:00
x: app . landscape ( ) ? topContainerItm . width + margin: topContainerItm . x + margin
y: ! app . landscape ( ) ? topContainerItm . height + margin: topContainerItm . x + margin
width: app . landscape ( ) ? app . width - topContainerItm . width - menu_container . width - margin * 2 : app . width - margin * 2
height: ! app . landscape ( ) ? app . height - topContainerItm . height - menu_container . height - margin * 2 : app . height - margin * 2
2019-04-30 23:44:04 +02:00
}
2018-07-25 00:32:20 +02:00
2018-07-17 19:17:25 +02:00
states: [
2018-07-22 16:47:55 +02:00
State {
name: "IDLE"
//state for the start page
PropertyChanges {
2019-04-15 13:33:31 +02:00
target: topContainerItm ;
2019-09-08 15:08:50 +02:00
anchors.bottomMargin: app . landscape ( ) ? undefined: parent . height * 0.1 ;
anchors.rightMargin: app . landscape ( ) ? parent . height * 0.05 : 0
2018-07-22 16:47:55 +02:00
}
PropertyChanges {
target: startButt ;
2020-10-01 01:54:38 +02:00
enabled: true ;
text: "start" ;
2019-09-08 15:08:50 +02:00
size: app . landscape ( ) ? parent . width * 0.5 : parent . height * 0.5
2018-07-22 16:47:55 +02:00
anchors.bottomMargin: parent . height * 0.5 - startButt . height * 0.5
anchors.rightMargin: parent . width * 0.5 - startButt . width * 0.5
}
2019-04-15 13:33:31 +02:00
PropertyChanges {
target: topLa
2020-10-01 01:54:38 +02:00
text: "click start to start"
2019-04-15 13:33:31 +02:00
}
2018-07-22 16:47:55 +02:00
} ,
2020-10-01 01:54:38 +02:00
State {
name: "PREPAIRING"
//state for the start sequence
PropertyChanges { target: startButt ; enabled: false ; text: "starting..." ;
anchors.rightMargin: app . 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: app . 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: cancelButt ; scale: 1 }
PropertyChanges { target: menu_container ; }
PropertyChanges {
target: topLa
text: "At your marks"
}
} ,
2019-04-15 13:33:31 +02:00
State {
name: "WAITING"
PropertyChanges {
2019-09-08 15:08:50 +02:00
target: startButt ; enabled: false ; text: "waiting..." ;
anchors.rightMargin: app . 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: app . 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)
2019-04-15 13:33:31 +02:00
}
PropertyChanges { target: cancelButt ; scale: 0 ; enabled: false }
PropertyChanges { target: menu_container ; }
PropertyChanges {
target: topLa
2020-10-01 01:54:38 +02:00
implicitText: "Ready"
2019-04-15 13:33:31 +02:00
}
} ,
2018-07-22 16:47:55 +02:00
State {
name: "STARTING"
//state for the start sequence
2019-09-08 15:08:50 +02:00
PropertyChanges { target: startButt ; enabled: false ; text: "starting..." ;
anchors.rightMargin: app . 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: app . 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)
2018-07-22 16:47:55 +02:00
}
PropertyChanges { target: cancelButt ; scale: 1 }
PropertyChanges { target: menu_container ; }
2019-04-15 13:33:31 +02:00
PropertyChanges {
target: topLa
2020-10-01 01:54:38 +02:00
implicitText: "Starting"
2019-04-15 13:33:31 +02:00
}
2018-07-22 16:47:55 +02:00
} ,
State {
name: "RUNNING"
//state when the timer is running
PropertyChanges { target: startButt ; enabled: true ;
2020-06-13 17:11:26 +02:00
text: speedBackend . scStwClient . state === ScStwClient . CONNECTED ? "cancel" : "stop"
2019-09-08 15:08:50 +02:00
anchors.rightMargin: app . 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: app . 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)
2018-07-22 16:47:55 +02:00
}
2019-05-19 14:06:05 +02:00
PropertyChanges {
target: topLa
2019-10-13 16:42:38 +02:00
implicitText: ""
2019-05-19 14:06:05 +02:00
}
2018-07-22 16:47:55 +02:00
} ,
State {
name: "STOPPED"
//state when the meassuring is over
PropertyChanges {
target: startButt ;
2019-09-08 15:08:50 +02:00
enabled: true ; text: "reset" ;
size: app . landscape ( ) ? parent . height * 0.35 : parent . height * 0.2 ;
anchors.bottomMargin: app . landscape ( ) ? parent . height * 0.5 - startButt . height * 0.5 : parent . height * 0.2 - startButt . height * 0.5
anchors.rightMargin: app . landscape ( ) ? parent . height * 0.2 - startButt . height * 0.5 : parent . width * 0.5 - startButt . width * 0.5
2018-07-22 16:47:55 +02:00
}
PropertyChanges {
2019-04-15 13:33:31 +02:00
target: topContainerItm ;
2019-09-08 15:08:50 +02:00
anchors.rightMargin: app . landscape ( ) ? 0 - startButt . width / 2 : undefined
anchors.bottomMargin: app . landscape ( ) ? undefined: 0 - startButt . height / 2
2018-07-22 16:47:55 +02:00
}
2019-05-19 14:06:05 +02:00
PropertyChanges {
target: topLa
text: ""
}
2020-10-01 01:54:38 +02:00
} ,
State {
name: "INCIDENT"
//state when the meassuring is over
PropertyChanges {
target: startButt ;
enabled: true ; text: "reset" ;
size: app . landscape ( ) ? parent . height * 0.35 : parent . height * 0.2 ;
anchors.bottomMargin: app . landscape ( ) ? parent . height * 0.5 - startButt . height * 0.5 : parent . height * 0.2 - startButt . height * 0.5
anchors.rightMargin: app . landscape ( ) ? parent . height * 0.2 - startButt . height * 0.5 : parent . width * 0.5 - startButt . width * 0.5
}
PropertyChanges {
target: topContainerItm ;
anchors.rightMargin: app . landscape ( ) ? 0 - startButt . width / 2 : undefined
anchors.bottomMargin: app . landscape ( ) ? undefined: 0 - startButt . height / 2
}
PropertyChanges {
target: topLa
text: ""
}
2018-07-22 16:47:55 +02:00
}
]
/ * - - - - - - - - - - - - - - - - - - - - - -
Timer animations
-- -- -- -- -- -- -- -- -- -- -- * /
2020-10-01 01:54:38 +02:00
/ * t r a n s i t i o n s : [
2018-07-17 19:17:25 +02:00
Transition {
2018-10-04 18:35:29 +02:00
NumberAnimation { properties: "size,rightMargin,height,width,bottomMargin,font.pixelSize,pixelSize" ; easing.type: Easing . InOutQuad ; duration: 700 }
2018-07-17 19:17:25 +02:00
} ,
Transition {
2018-07-18 14:06:04 +02:00
to: "STOPPED"
2018-10-04 18:35:29 +02:00
NumberAnimation { properties: "size,rightMargin,height,width,bottomMargin,font.pixelSize,pixelSize" ; easing.type: Easing . InOutQuad ; duration: 700 }
2018-07-18 14:06:04 +02:00
} ,
Transition {
to: "IDLE"
2018-10-04 18:35:29 +02:00
NumberAnimation { properties: "size,rightMargin,height,width,bottomMargin,font.pixelSize,pixelSize" ; easing.type: Easing . InOutQuad ; duration: 700 }
2018-07-18 14:06:04 +02:00
} ,
Transition {
2019-03-09 15:06:48 +01:00
from: "STARTING"
2018-07-18 14:06:04 +02:00
to: "RUNNING"
//disable transitions for the RUNNING state
2019-05-02 22:39:22 +02:00
} ,
Transition {
from: "RUNNING"
to: "WAITING"
//disable transitions for the RUNNING state
2018-07-17 19:17:25 +02:00
}
2020-10-01 01:54:38 +02:00
] * /
2018-07-22 16:47:55 +02:00
/ * - - - - - - - - - - - - - - - - - - - - - -
Timer functions
-- -- -- -- -- -- -- -- -- -- -- * /
function landscape ( ) {
2019-09-08 15:08:50 +02:00
return ( app . height < app . width )
2018-07-22 16:47:55 +02:00
}
2018-08-14 17:07:42 +02:00
/*----Functions to control the stopwatch----*/
function start ( ) {
2020-04-15 21:47:55 +02:00
var ret = speedBackend . race . start ( )
2020-04-17 19:57:33 +02:00
if ( ret !== 200 ) {
console . log ( "+ --- error starting race: " + ret )
2019-03-07 17:18:24 +01:00
}
2018-08-14 17:07:42 +02:00
}
2020-04-17 19:57:33 +02:00
function cancel ( ) {
2020-05-26 17:57:54 +02:00
var ret = speedBackend . race . cancel ( )
2020-04-17 19:57:33 +02:00
if ( ret !== 200 ) {
console . log ( "+ --- error canellingr race: " + ret )
}
}
2019-03-07 17:18:24 +01:00
2020-04-17 19:57:33 +02:00
function stop ( ) {
2019-03-07 17:18:24 +01:00
2020-04-17 19:57:33 +02:00
var ret = speedBackend . race . stop ( )
if ( ret !== 200 ) {
console . log ( "+ --- error stopping race: " + ret )
2019-03-07 17:18:24 +01:00
}
2018-08-14 17:07:42 +02:00
}
function reset ( ) {
2019-03-07 17:18:24 +01:00
2020-04-17 19:57:33 +02:00
var ret = speedBackend . race . reset ( )
2019-03-07 17:18:24 +01:00
if ( ret !== 200 ) {
2020-04-17 19:57:33 +02:00
console . log ( "+ --- error resetting race: " + ret )
2019-03-07 17:18:24 +01:00
}
2018-08-14 17:07:42 +02:00
}
2018-07-17 19:17:25 +02:00
}
}