forked from rschiang/ntuosc-qml-intro-clock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.qml
122 lines (105 loc) · 2.99 KB
/
main.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
import QtQuick 2.0
import QtQuick.Window 2.0
import QtGraphicalEffects 1.0
Window {
id: root
color: "#689881"
width: 800
height: 600
visible: true
AnimatedImage {
id: wheel
width: radius * 2
height: radius * 2
source: "slippy.gif"
fillMode: Image.PreserveAspectCrop
visible: false
property int radius: 64
}
Rectangle {
id: mask
width: wheel.width
height: wheel.height
radius: wheel.radius
color: "#000"
visible: false
}
Rectangle {
id: clock
color: "orange"
width: (parent.width >= parent.height) ? parent.height : parent.width
height: width
radius: width / 2
anchors.centerIn: parent
opacity: 1
property int hour: 9
property int minute: 41
property int second: 0
OpacityMask {
id: secondCircle
width: wheel.width
height: wheel.height
source: wheel
maskSource: mask
visible: (x != 0 || y != 0)
x: clock.radius + (clock.radius - wheel.radius) * Math.cos((6.0 * clock.second - 90.0) / 360.0 * 2 * Math.PI) - wheel.radius
y: clock.radius + (clock.radius - wheel.radius) * Math.sin((6.0 * clock.second - 90.0) / 360.0 * 2 * Math.PI) - wheel.radius
z: 1
Behavior on x {
NumberAnimation {
easing.type: Easing.OutBack
duration: 200
}
}
Behavior on y {
NumberAnimation {
easing.type: Easing.OutBack
duration: 200
}
}
}
}
Text {
id: label
anchors.centerIn: clock
text: (clock.hour > 12 ? clock.hour - 12 : clock.hour) + ":" + (clock.minute < 10 ? "0" + clock.minute : clock.minute)
font.family: "Roboto"
font.pointSize: 84
font.weight: Font.Bold
color: "#fff"
}
Text {
id: creditLabel
anchors {
top: label.bottom
horizontalCenter: label.horizontalCenter
}
text: "臺灣大學開源社"
font.family: "Source Han Sans TC"
font.pointSize: 24
color: "#fff"
}
NumberAnimation {
id: minuteAnimation
target: label
property: "opacity"
from: 0.7; to: 1
duration: 1000
easing.type: Easing.OutExpo
}
Timer {
id: timer
interval: 1000
running: true
repeat: true
onTriggered: {
var date = new Date()
clock.hour = date.getHours()
clock.minute = date.getMinutes()
clock.second = date.getSeconds()
if (clock.second == 0)
minuteAnimation.start()
}
}
// (C) NTUOSC 2014. Released under MIT License.
}