blob: a8e3e13d2dbe0c57c6a742323be11e25b4e91e7f (
plain)
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
209
210
211
212
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Controls
import QtQuick.Controls.Material
import QtQuick.Shapes
import qtgrpc.examples.magic8ball
ApplicationWindow {
id: root
width: 665
height: width
minimumWidth: width
minimumHeight: height
visible: true
title: qsTr("Magic-8-ball Qt GRPC Example")
Material.theme: Material.Light
property string textAnswer: ""
property string textError: ""
MagicText {
anchors.top: parent.top
anchors.topMargin: 20
anchors.horizontalCenter: parent.horizontalCenter
width: parent.width * 0.9
height: parent.height/3
color: "black"
text: qsTr("For fortune-telling and seeking advice ask the ball"
+ " a yes-no question and press the button.")
}
Rectangle {
id: magic8ball
anchors.centerIn: parent
width: 433
height: width
color: "#000000"
radius: 300
gradient: Gradient {
orientation: Gradient.Horizontal
GradientStop { position: 0.0; color: "#4b4b4b" }
GradientStop { position: 0.33; color: "#212121" }
GradientStop { position: 1.0; color: "#000000" }
}
}
Rectangle {
width: 244
height: width
anchors.verticalCenter: parent.verticalCenter
anchors.horizontalCenter: parent.horizontalCenter
anchors.horizontalCenterOffset: 6
radius: 300
color: "#bababa"
}
Rectangle {
id: magic8ballCenter
anchors.centerIn: parent
width: 244
height: width
color: "black"
border.width: 1.5
border.color: "#bababa"
radius: 300
Shape {
anchors.centerIn: parent
width: 200
height: 200
ShapePath {
strokeWidth: 4
strokeColor: "#213f94"
capStyle: ShapePath.RoundCap
fillGradient: RadialGradient {
centerX: 100
centerY: 100
focalX: centerX
focalY: centerY
centerRadius: 50
focalRadius: 0
GradientStop { position: 0; color: "#1C2F60" }
GradientStop { position: 0.5; color: "#000547" }
GradientStop { position: 1; color: "#000324" }
}
startX: 10
startY: 40
PathLine { x: 100.5; y: 190 }
PathLine { x: 188; y: 40 }
PathLine { x: 10; y: 40 }
}
}
}
WaitingAnimation {
id: waitingAnimation
anchors.centerIn: parent
visible: false
}
AnimatedAnswer {
id: answer
anchors.centerIn: parent
visible: false
}
Connections {
target: ClientService
function onMessageRecieved(value) {
root.textAnswer = value
}
function onErrorRecieved(value) {
root.textError = value
}
}
Rectangle {
id: button
anchors.bottom: parent.bottom
anchors.bottomMargin: 30
anchors.horizontalCenter: parent.horizontalCenter
width: 200
height: 50
radius: 10
color: handler.pressed ? "#a5a5a5" : "#bebebe"
MagicText {
id: btnText
anchors.centerIn: parent
text: qsTr("Ask question")
color: "black"
}
TapHandler {
id: handler
onTapped: animationTimeout.start()
}
}
Connections {
target: answer.closingAnimation
function onStopped() {
answer.animationText = ""
answer.visible = false
waitingAnimation.visible = true
waitingAnimation.runAnimation = true
}
}
Connections {
target: waitingAnimation
function onRunAnimationChanged() {
if (!waitingAnimation.runAnimation) {
answer.visible = true
answer.openingAnimation.start()
}
}
}
Timer {
id: animationTimeout
interval: 3000
repeat: false
running: false
onTriggered: ClientService.setMessage()
onRunningChanged: {
if (running) {
answer.closingAnimation.start()
ClientService.sendRequest()
} else {
waitingAnimation.runAnimation = false
waitingAnimation.visible = false
answer.animationText = root.textError === "" ? root.textAnswer : root.textError
}
}
}
footer: MagicText {
text: root.textError === "" ? "" : "Please, start server: ../magic8ball/SimpleGrpcServer"
}
}
|