-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathdecimal-time.qml
179 lines (163 loc) · 5.98 KB
/
decimal-time.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/*
* Copyright (C) 2021-2024 - Ed Beroset <github.com/beroset>
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import QtQuick 2.1
Item {
// these three constants describe metric time
readonly property int metricHoursPerStandardDay: 10
readonly property int metricMinutesPerMetricHour: 100
readonly property int metricSecondsPerMetricMinute: 100
// this constant adjusts the minutes ticks on the watchface
readonly property int majorMinuteTicksEvery: 5
// this adjusts the number of revolutions per day
// (e.g. 2 twelve-hour revolutions for a standard 24 hour day)
readonly property int revolutionsPerDay: 1
// these are derived constants
readonly property int metricSecondsPerStandardDay: metricHoursPerStandardDay * metricMinutesPerMetricHour * metricSecondsPerMetricMinute
readonly property double metricSecondsScaleFactor: metricSecondsPerStandardDay / 86400
function getMetricMilliseconds(t) {
return (t.getHours() * 3600000
+ t.getMinutes() * 60000
+ t.getSeconds() * 1000
+ t.getMilliseconds()) * metricSecondsScaleFactor
}
function getMetricHours(metricMilli){
return getMetricMilliseconds(wallClock.time) / metricMinutesPerMetricHour / metricSecondsPerMetricMinute / 1000
}
component Tick: Rectangle {
id: thisTick
property bool outsideRing: true
property real angle: 0
property real radius: 0.72
antialiasing : true
transform: [
Rotation {
origin.x: thisTick.width/2
origin.y: outsideRing
? thisTick.height + parent.width * radius / 2
: parent.width * radius / 2
angle: thisTick.angle
},
Translate {
x: (parent.width - thisTick.width)/2
y: outsideRing
? parent.height/2 - parent.width * radius / 2 - thisTick.height
: parent.height/2 - parent.width * radius / 2
}
]
}
Repeater{
id: minuteTicks
model: metricMinutesPerMetricHour / revolutionsPerDay
Tick {
angle: (index)*360/minuteTicks.count
color: "lightgreen"
opacity: 0.6
visible: !displayAmbient
width: parent.width*0.005
height: parent.width*(index % majorMinuteTicksEvery == 0 ? 0.030 : 0.015)
}
}
Repeater{
id: hourTicks
model: metricHoursPerStandardDay / revolutionsPerDay
Tick {
angle: (index)*360/hourTicks.count
color: "lightgreen"
opacity: displayAmbient ? 0.3 : 0.6
width: parent.width*0.01
height: parent.width*0.03
}
}
Repeater{
id: hourLabels
model: metricHoursPerStandardDay / revolutionsPerDay
Text {
font {
pixelSize: parent.height*0.08
family: "CPMono_v07"
styleName: "Plain"
}
color: "lightblue"
id: hourLabel
antialiasing : true
opacity: displayAmbient ? 0.3 : 0.6
text: index ? index : hourLabels.count
transform: [
Rotation {
origin.x: hourLabel.width/2
origin.y: hourLabel.height + parent.width * 0.40
angle: (index)*360/ (metricHoursPerStandardDay / revolutionsPerDay)
},
Translate {
x: (parent.width - hourLabel.width)/2
y: parent.height/2 - parent.width * 0.40 - hourLabel.height
}
]
}
}
Image {
id: logoAsteroid
antialiasing: true
opacity: displayAmbient ? 0.6 : 1.0
source: "../watchfaces-img/asteroid-logo.svg"
width: parent.width/12
height: width
transform : [
Rotation {
origin.x : logoAsteroid.width/2
origin.y : logoAsteroid.height + parent.width * 0.275
angle: getMetricHours(wallClock.time) * 360 * revolutionsPerDay / metricHoursPerStandardDay
},
Translate {
x: (parent.width - logoAsteroid.width)/2
y: parent.height/2 - logoAsteroid.height - parent.width * 0.275
}
]
}
component PlainText : Text {
font {
pixelSize: parent.height*0.06
family: "CPMono_v07"
styleName: "Plain"
}
color: "white"
visible: !displayAmbient
horizontalAlignment: Text.AlignHCenter
anchors.centerIn: parent
}
PlainText {
id: conventionalTime
anchors.verticalCenterOffset: +parent.width*0.18
text: if (use12H.value)
wallClock.time.toLocaleString(Qt.locale(), "hh:mm:ss ap")
else
wallClock.time.toLocaleString(Qt.locale(), "HH:mm:ss")
}
PlainText {
id: conventionalDate
anchors.verticalCenterOffset: -parent.width*0.18
text: wallClock.time.toLocaleDateString(Qt.locale(), Locale.ShortFormat)
}
PlainText {
id: decimalHours
font.pixelSize: parent.width*0.15
anchors.verticalCenterOffset: parent.width*0.016
textFormat: Text.RichText
text: getMetricHours(wallClock.time).toPrecision(5)
}
}