-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
189 lines (157 loc) · 3.64 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
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
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
Window {
id: root
visible: true
width: 640
height: 480
title: qsTr("Keyboard monitor")
/*
* As mensioned in main.cpp file, you can simply acess the monitor
* like standard item thanks to setting context before. Just use keyboardMonitor keyword.
*/
Page {
id: mainPage
anchors.fill: parent
Text {
id: apsLabel
anchors {
top: parent.top
left: parent.left
leftMargin: 100
topMargin: 40
}
font.pointSize: 20
text: qsTr("APS")
}
Text {
id: apsValue
anchors {
top: apsLabel.bottom
topMargin: 10
horizontalCenter: apsLabel.horizontalCenter
}
font.pointSize: 40
/* By using Q_PROPERTY makro in class declaration
* you are able to use property binding like with
* standard object properties.
*/
text: keyboardMonitor.aps
}
Text {
id: apmLabel
anchors {
top: parent.top
right: parent.right
rightMargin: 100
topMargin: 40
}
font.pointSize: 20
text: qsTr("APM")
}
Text {
id: apmValue
anchors {
top: apmLabel.bottom
topMargin: 10
horizontalCenter: apmLabel.horizontalCenter
}
visible: false
font.pointSize: 40
text: keyboardMonitor.apm
}
Text {
id: avarageLabel
anchors {
top: apmValue.bottom
topMargin: 10
horizontalCenter: parent.horizontalCenter
}
font.pointSize: 20
text: qsTr("Avarage APS")
}
Text {
id: avarageValue
anchors {
top: avarageLabel.bottom
topMargin: 10
horizontalCenter: parent.horizontalCenter
}
visible: false
font.pointSize: 30
text: keyboardMonitor.avarageAps.toFixed(3)
}
Text {
id: historyLabel
anchors {
top: avarageValue.bottom
topMargin: 10
horizontalCenter: parent.horizontalCenter
}
font.pointSize: 20
text: qsTr("APM History")
}
Rectangle {
id: historyWrapper
width: mainPage.width * 0.8
height: hisoryValue.height
color: "#EBEBEB"
radius: 10
anchors {
top: historyLabel.bottom
topMargin: 10
horizontalCenter: parent.horizontalCenter
}
border {
color: "#404040"
width: 1
}
Text {
id: hisoryValue
width: parent.width * 0.95
anchors.centerIn: parent
font.pointSize: 15
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideLeft
text: qsTr("Empty")
}
}
/*
* The monitor can also be manually stopped or started
*/
Button {
id: runningButton
anchors {
top: historyWrapper.bottom
topMargin: 10
horizontalCenter: parent.horizontalCenter
}
text: keyboardMonitor.isRunning? qsTr("STOP"): qsTr("START")
onClicked: {
keyboardMonitor.setIsRunning(!keyboardMonitor.isRunning)
}
}
/*
* All main monitor properties also have corresponding
* signals. They can be connected with Connections object
* like shown below.
*/
Connections {
target: keyboardMonitor
onApmChanged: {
if(!apmValue.visible) {
apmValue.visible = true
}
}
onAvarageApsChanged: {
if(!avarageValue.visible) {
avarageValue.visible = true
}
}
onApmHistoryChanged: {
hisoryValue.text = keyboardMonitor.apmHisoryStringify()
}
}
}
}