-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmlb.qml
213 lines (184 loc) · 6.01 KB
/
mlb.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
import QtQuick 2.8
import QtQuick.Controls 2.15
import org.kde.plasma.components 2.0
import org.kde.plasma.extras 2.0
import org.kde.plasma.core 2.0
import QtQuick.Layouts 1.1
// mlb scores espn api
Item {
id:root
width:600
//height:400
//implicitHeight:listViewHeight
Layout.fillHeight: true
Layout.preferredWidth:600
Layout.preferredHeight:listViewHeight
Layout.alignment: Qt.AlignHCenter
Timer {
interval:400
running:false
repeat:false
onTriggered: root.height=listViewHeight//root.height=640//Object.keys(scores.events).length*9.35
}
property var url1:"http://site.api.espn.com/apis/site/v2/sports/baseball/mlb/scoreboard"
property var scores:{}
property var listViewHeight:Object.keys(scores.events).length * 60
property real fixedHeight: {
if (showText) {
if (textUnderIcon)
return columnLabels.height + 2 * margins
else
return 2 * margins
}
else
return 2 * margins
}
/// Object.keys(index.events).length // array size
Rectangle {
width:root.width
height:root.height
color:"white"
opacity:.75
anchors.horizontalCenter:root.horizontalCenter;
}
function getData(url){ // get data json api scores
var xhr = new XMLHttpRequest;
xhr.open("GET", url); // set Method and File true=asynchronous
xhr.onreadystatechange = function () {
if(xhr.readyState === XMLHttpRequest.DONE){ // if request_status == DONE
var response = xhr.responseText;
scores=JSON.parse(response)
}
}
xhr.send(); // begin the request
}
Component.onCompleted: {
getData(url1)
listViewHeight=Object.keys(scores.events).length * 60
}
Timer {
interval:400
running:true
repeat:false
onTriggered: listViewHeight=Object.keys(scores.events).length * 60//root.height=640//Object.keys(scores.events).length*9.35
}
Image {
id:logo
source:"espn.jpg"
width:96
height:24
smooth:true
anchors.top:root.top
anchors.left:root.left
anchors.bottomMargin:10
anchors.topMargin:5
}
Image {
id:logo2
source:"mlb.png"
width:96
height:64
smooth:true
anchors.top:root.top
anchors.right:root.right
anchors.topMargin:-10
anchors.bottomMargin:10
}
Component {
id: games
Column {
id:col1
spacing:10
topPadding:10
anchors.horizontalCenter:root.horizontalCenter;
Row {
id:gm
spacing:10
leftPadding:10
Rectangle {
width:root.width*.98
height:40
color:"transparent"
border.color:"lightgray"
border.width:2
radius:6
MouseArea {
id: mouseArea
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
hoverEnabled:true
onEntered:parent.border.color="steelblue"
onExited:parent.border.color="lightgray"
onClicked: {
Qt.openUrlExternally(scores.events[index].links[0].href)
}
}
}
Item {
id:scr
height:20
anchors.centerIn:rect1
Row {
spacing:20
topPadding:5
leftPadding:10
Image {
source:scores.events[index].competitions[0].competitors[1].team.logo
width:28
height:28
smooth:true
}
Text {
text:scores.events[index].competitions[0].competitors[1].team.displayName
color:"black"
font.pointSize:14
width:200
Layout.fillWidth:true
}
Text {
text:scores.events[index].competitions[0].competitors[1].score
color:"black"
font.pointSize:14
}
Image {
source:scores.events[index].competitions[0].competitors[0].team.logo
width:28
height:28
smooth:true
}
Text {
text:scores.events[index].competitions[0].competitors[0].team.displayName
color:"black"
font.pointSize:14
width:200
Layout.fillWidth:true
}
Text {
text:scores.events[index].competitions[0].competitors[0].score
color:"black"
font.pointSize:14
}
}
}
}
}
}
Item {
id:game
anchors.top:logo.bottom
anchors.topMargin:25
width:root.width
// height:root.height
implicitHeight:root.implicitHeight
anchors.fill:parent
//anchors.horizontalCenter:root.horizontalCenter;
ListView {
anchors.fill: parent
//anchors.horizontalCenter:root.horizontalCenter;
model: Object.keys(scores.events).length
// highlight:
delegate: games
spacing: 5
}
}
}