-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.qml
187 lines (156 loc) · 4.45 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
import QtQuick 2.3
import QtQuick.Window 2.2
import "Currency.js" as Currency
Window {
id: window
visible: true
width: 1024
height: 768
title: "COSCUP 拍賣會"
FontLoader { source: "fonts/Oswald-Regular.ttf" }
FontLoader { source: "fonts/Oswald-Bold.ttf" }
Image {
anchors.fill: parent
source: "coscup.png"
}
Item {
id: displayArea
width: parent.width
height: parent.height * .618
Text {
id: priceLabel
anchors {
fill: parent
margins: 16
}
font {
family: "Oswald, Source Han Sans TC, LiHei Pro, sans-serif"
pointSize: 256
weight: Font.Bold
}
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
fontSizeMode: Text.Fit
renderType: Text.NativeRendering
text: "..."
}
}
Row {
id: currencyArea
anchors {
bottom: parent.bottom
left: parent.left
}
height: parent.height * .382
width: parent.width * 0.67
CurrencyItem {
id: currencyUSD
currency: "USD 美金"
color: "#3F51B5"
}
CurrencyItem {
id: currencyHKD
currency: "HKD 港幣"
color: "#FFC107"
}
CurrencyItem {
id: currencyRMB
currency: "RMB 人民幣"
color: "#F44336"
}
}
TextInput {
id: input
anchors {
bottom: parent.bottom
left: parent.left
right: parent.right
bottomMargin: 4
leftMargin: 12
rightMargin: 12
}
font {
family: "Menlo"
pointSize: 12
}
color: "#555"
selectionColor: color
selectedTextColor: "#fff"
focus: true
property int blankCount: 0
Keys.onReturnPressed: {
if (text.length) {
priceLabel.text = text
blankCount = 0
var price = Number(text)
if (text == "refresh" || text == "r") {
priceLabel.text = "..."
Currency.load()
} else if (text == "exit" || text == "quit" || text == "q") {
Qt.quit()
} else if (isNaN(price)) {
window.clear()
} else {
window.update(text)
}
} else {
blankCount += 1
if (blankCount >= 2) {
var sentences = ["感謝", "銘謝惠顧", "無任感禱", "多謝", "承蒙您",
"安仔細", "Thanks", "感恩開源", "讚嘆開源", "We ♥︎ Open"]
priceLabel.text = sentences[Math.floor(Math.random() * sentences.length)]
} else {
priceLabel.text = "0"
}
window.clear()
}
text = ""
tickAnimation.start()
}
Text {
id: inputPrompt
anchors {
right: parent.left
baseline: parent.baseline
}
font: parent.font
color: parent.color
text: ":"
}
}
ParallelAnimation {
id: tickAnimation
NumberAnimation {
target: priceLabel
property: "opacity"
from: 0.5; to: 1
duration: 500
easing.type: Easing.OutBack
}
NumberAnimation {
target: displayArea
property: "y"
from: priceLabel.height * .15
to: 0
duration: 500
easing.type: Easing.OutBack
}
function play() {
if (running) stop()
start()
}
}
function clear() {
currencyUSD.price = Currency.get("美金 (USD)", 1)
currencyHKD.price = Currency.get("港幣 (HKD)", 1)
currencyRMB.price = Currency.get("人民幣 (CNY)", 1)
}
function update(price) {
currencyUSD.price = Currency.get("美金 (USD)", price)
currencyHKD.price = Currency.get("港幣 (HKD)", price)
currencyRMB.price = Currency.get("人民幣 (CNY)", price)
}
Component.onCompleted: {
Currency.load()
}
}