-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeTimer.qml
More file actions
210 lines (182 loc) · 6.59 KB
/
TimeTimer.qml
File metadata and controls
210 lines (182 loc) · 6.59 KB
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
import QtQuick 2.15
import QtQuick.Window 2.15
import QtQuick.Controls 2.15
import QtQuick.Layouts 1.15
Window {
id:windows
objectName:"windows"
property int windowWidth : 300;
property int windowHeight : 420;
property double dOpacity: 1
property bool bAlwaysOnTop : false
opacity: dOpacity
width: windowWidth
height: windowHeight
minimumWidth: windowWidth
maximumWidth: windowWidth
minimumHeight: windowHeight
maximumHeight: windowHeight
visible: true
signal emit_Start();
signal emit_Pause();
signal emit_Stop();
Item {
anchors.fill: parent
ColumnLayout {
spacing : 10
anchors.centerIn : parent
Button {
Layout.preferredWidth: 40
Layout.preferredHeight:30
Layout.alignment: Qt.AlignRight
icon.name: "setting"
icon.source: "qrc:/icon/setting.png"
onClicked: {
timerMgr.showDialog()
}
}
Rectangle {
border.width: 1
Layout.preferredWidth: 280
Layout.preferredHeight:280
Canvas {
id:backgroundCanvas
anchors.fill: parent
property int centerX: parent.width / 2
property int centerY: parent.height / 2
property int radius : parent.width / 2 - 39
property color backColor : "white"
onPaint: {
var ctx = backgroundCanvas.getContext("2d");
ctx.beginPath()
ctx.fillStyle = backColor
ctx.arc(centerX, centerY, radius, 0, 2*Math.PI)
ctx.fill()
ctx.closePath()
}
}
Canvas {
id:timerCanvas
objectName:"timeCanvas"
anchors.fill: parent
property int centerX: parent.width / 2
property int centerY: parent.height / 2
property int radius : parent.width / 2 - 41
property int setMinute: 60
property int setSecond: setMinute*60
property color timeColor : "red"
onPaint: {
var time = setSecond;
var end = (45-(time/60))*6;
var ctx = timerCanvas.getContext("2d");
ctx.reset()
ctx.beginPath()
ctx.fillStyle = timeColor
ctx.moveTo(centerX,centerY);
ctx.arc(centerX, centerY, radius, (Math.PI/180)*end, (Math.PI/180)*270);
ctx.fill()
ctx.closePath()
}
function rePaint() {
timerCanvas.requestPaint()
}
}
Canvas {
id:clockNumber
anchors.fill: parent
property int centerX: parent.width / 2
property int centerY: parent.height / 2
onPaint: {
var ctx = clockNumber.getContext("2d");
ctx.font = "20px sans-serif";
ctx.textAlign = "center";
ctx.textBaseline = "middle";
ctx.fillStyle = "black";
ctx.beginPath()
ctx.translate(centerX,centerY);
for ( var number = 1; number <= 12; number++ ){
var angle = (Math.PI / 180) * 30;
ctx.rotate( angle );
ctx.fillText( number, 0, -120);
}
ctx.closePath()
}
}
Rectangle {
anchors.centerIn: parent
opacity: 0.5
width : 70
height : 40
Label {
id:remainTime
anchors.fill: parent
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
font.pixelSize: 15
text : (parseInt(timerCanvas.setSecond / 60)).toString().padStart(2,'0')
+ ":" + (parseInt(timerCanvas.setSecond % 60)).toString().padStart(2,'0')
}
}
}
SpinBox {
id:spinBox
Layout.alignment: Qt.AlignHCenter
Layout.preferredHeight:35
from: 0
value: 60
to: 60
stepSize: 1
editable: true
onValueChanged: {
timerCanvas.setMinute = value
timerCanvas.requestPaint()
}
Keys.onPressed: {
if ( event.key === Qt.Key_Enter || event.key === Qt.Key_Return ) {
focus = false
}
}
}
RowLayout {
spacing : 10
Layout.alignment: Qt.AlignHCenter
Button {
Layout.preferredWidth: 40
Layout.preferredHeight:30
icon.name: "start"
icon.source: "qrc:/icon/start.png"
onClicked: {
windows.emit_Start()
}
}
Button {
Layout.preferredWidth: 40
Layout.preferredHeight:30
icon.name: "pause"
icon.source: "qrc:/icon/pause.png"
onClicked: {
windows.emit_Pause()
}
}
Button {
Layout.preferredWidth: 40
Layout.preferredHeight:30
icon.name: "reset"
icon.source: "qrc:/icon/reset.png"
onClicked: {
windows.emit_Stop()
}
}
}
}
}
SettingDialog {
id : dlg
Component.onCompleted: {
dlg.emit_changeOpcaity.connect(test)
}
}
function test(value) {
console.log(value)
}
}