-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgolfScores.qml
222 lines (196 loc) · 6.56 KB
/
golfScores.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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
import QtQuick 2.9
import org.kde.plasma.core 2.1
import QtQuick.Layouts 1.5
Rectangle {
id:golfMain
width:640
height:800
color:"black"
property var url1:"https://site.api.espn.com/apis/site/v2/sports/golf/pga/scoreboard"
//property var url1: "/home/Data/projects/QML/sports/golf.json"
property var scores:{}
property var scorebard:[];
property int key:0
property int gameInterval:20*60*1000
Component.onCompleted: {
getData(url1);
//init.start();
}
function getOrdinal(n) { // assigns superfix to date
var s=["th","st","nd","rd"],
v=n%100;
return (s[(v-20)%10]||s[v]||s[0]);
}
function getData(url){ // get json data sources
var xhr = new XMLHttpRequest;
//var scores={};
xhr.open("GET", url); // set Method and File true=asynchronous
xhr.onreadystatechange = function () {
if(xhr.readyState == 4){ // if request_status == DONE
if (xhr.status == 200) {
var response = xhr.responseText;
scores=JSON.parse(response);
//response=null;
//xhr=null;
}
}
}
xhr.send(); // begin the request
}
function refreshGameData () {
getData(url1);
return null;
}
Component {
id:golfers
Column {
spacing:2
leftPadding:50
Row {
spacing:10
Image {
source:scores.events[0].competitions[0].competitors[index].athlete.flag.href
width:20
height:20
smooth:true
cache:true
}
Text {
text:scores.events[0].competitions[0].competitors[index].athlete.fullName
//text:scores1[0].name
font.pointSize:12
color:"white"
width:165
Layout.fillWidth:true
horizontalAlignment: Text.AlignRight
}
Text {
text:scores.events[0].competitions[0].competitors[index].score
color:"white"
font.pointSize:12
width:28
Layout.fillWidth:true
horizontalAlignment: Text.AlignRight
}
Text {
text:(typeof(scores.events[0].competitions[0].competitors[index].linescores[0].value) != "undefined") ? scores.events[0].competitions[0].competitors[index].linescores[0].value : "Na"
color:"white"
font.pointSize:12
width:28
Layout.fillWidth:true
horizontalAlignment: Text.AlignRight
}
Text {
text:(typeof(scores.events[0].competitions[0].competitors[index].linescores[1].value) != "undefined") ? scores.events[0].competitions[0].competitors[index].linescores[1].value : "Na"
color:"white"
font.pointSize:12
width:28
Layout.fillWidth:true
horizontalAlignment: Text.AlignRight
}
Text {
text:(typeof(scores.events[0].competitions[0].competitors[index].linescores[2].value) != "undefined") ? scores.events[0].competitions[0].competitors[index].linescores[2].value : "Na"
color:"white"
font.pointSize:12
width:28
Layout.fillWidth:true
horizontalAlignment: Text.AlignRight
}
Text {
text:(typeof(scores.events[0].competitions[0].competitors[index].linescores[3].value) != "undefined") ? scores.events[0].competitions[0].competitors[index].linescores[3].value : "Na"
color:"white"
font.pointSize:12
width:28
Layout.fillWidth:true
horizontalAlignment: Text.AlignRight
}
}
}
}
Column {
id:titles
height:90
width:240
spacing:3
//anchors.left:golfMain.left
anchors.top:golfMain.top
anchors.horizontalCenter:golfMain.horizontalCenter;
Text {
id:eventTitle
text:scores.events[0].name
color:"white"
anchors.horizontalCenter:parent.horizontalCenter;
font.pointSize:12
MouseArea {
id: mouseArea1a
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled:true
acceptedButtons: Qt.LeftButton | Qt.MiddleButton
onEntered:parent.color=Theme.viewHoverColor
onExited:parent.color="white"
onClicked:Qt.openUrlExternally(scores.events[0].links[0].href)
}
}
Text {
id:eventDate
text:Qt.formatDate(scores.events[0].date)
color:"white"
anchors.horizontalCenter:eventTitle.horizontalCenter;
font.pointSize:12
}
Text {
id:eventDetail
text:scores.events[0].competitions[0].status.type.detail
color:"white"
anchors.horizontalCenter:eventTitle.horizontalCenter;
font.pointSize:12
}
Rectangle {
width:360
height:1
color:"gray"
anchors.horizontalCenter:eventTitle.horizontalCenter;
}
Text {
text:"RD1 RD2 RD3 RD4"
color:"white"
font.pointSize:11
width:236
Layout.fillWidth:true
topPadding:5
horizontalAlignment: Text.AlignRight
}
}
property var gameTimer: Timer {
interval: 20*60*1000
running:(scores.events[0].status.type.id==2)
//id: 2 = in play, 7 = suspended
repeat:true
triggeredOnStart:false
onTriggered:getData(url1)
}
Item {
id:golfEvent
width:golfMain.width
height:golfMain.height
anchors.top:titles.bottom
anchors.left:golfMain.left
anchors.topMargin:15
anchors.bottomMargin:10
//anchors.horizontalCenter:golfMain.horizontalCenter;
//anchors.topMargin:10
ListView { // how to sort by scores ?? /// show which hole current playing, which round?
id:golfView
anchors.fill: parent
//anchors.centerIn:parent
//anchors.horizontalCenter:golfMain.horizontalCenter;
model:Object.keys(scores.events[0].competitions[0].competitors).length
delegate: golfers
header : eventHeader
//highlight: highlightBar
//highlightFollowsCurrentItem: false
spacing: 5
}
}
}