-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailsView.qml
309 lines (267 loc) · 8.03 KB
/
DetailsView.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import QtQuick 2.8 // note the version: Text padding is used below and that was added in 2.7 as per docs
import QtQuick.Layouts 1.11
import QtGraphicalEffects 1.12
import "utils.js" as Utils // some helper functions
// The details "view". Consists of some images, a bunch of textual info and a game list.
FocusScope {
id: root
property var currentCollection
property alias currentGameIndex: grid.currentIndex
readonly property var currentGame: currentCollection.games.get(currentGameIndex)
width: parent.width
height: parent.height
enabled: focus
visible: y + height >= 0
signal cancel
signal nextCollection
signal prevCollection
signal launchGame
// Key handling. In addition, pressing left/right also moves to the prev/next collection.
// Keys.onLeftPressed: prevCollection()
// Keys.onRightPressed: nextCollection()
Keys.onPressed: {
if (event.isAutoRepeat)
return;
if (api.keys.isAccept(event)) {
event.accepted = true;
launchGame();
return;
}
if (api.keys.isCancel(event)) {
event.accepted = true;
cancel();
return;
}
if (api.keys.isNextPage(event)) {
event.accepted = true;
nextCollection();
return;
}
if (api.keys.isPrevPage(event)) {
event.accepted = true;
prevCollection();
return;
}
}
BackgroundImage {
id: backgroundimage
gameData: currentGame
collectionView: collectionsView.focus
detailView: detailsView.focus
anchors {
left: parent.left; right: parent.right
top: parent.top; bottom: parent.bottom
}
opacity: 0.555
}
// ColorOverlay {
// id: backgroundimageOverlay
// anchors.fill: backgroundimage
// source: backgroundimage
// color: Utils.systemColor(currentCollection.shortName)
// }
// GridView start!
Rectangle {
id: content
anchors {
top: parent.top
left: screenshotBox.right
right: parent.right
bottom: parent.bottom
}
// TODO: use loader to make loading grid/list views based on system type.
// https://doc.qt.io/qt-5/qml-qtquick-loader.html
// https://stackoverflow.com/questions/27695717/conditionally-include-component-based-on-property-value
// NOTE: may require considerable re-work
color: "transparent"
clip: true
GridView {
id: grid
width: root.width / 2.22
height: parent.height
preferredHighlightBegin: vpx(120)
preferredHighlightEnd: root.height - vpx(220)
anchors {
rightMargin: vpx(48)
top: parent.top;
right: parent.right;
}
property bool firstImageLoaded: false
property real cellHeightRatio: 0.5
function cells_need_recalc() {
firstImageLoaded = false;
cellHeightRatio = 0.5;
}
focus: true
snapMode: GridView.SnapToRow
highlightFollowsCurrentItem: true
highlightRangeMode: GridView.StrictlyEnforceRange
model: currentCollection.games
onModelChanged: cells_need_recalc()
onCountChanged: cells_need_recalc()
property real columnCount: {
if (cellHeightRatio > 1.2) return 5;
if (cellHeightRatio > 0.6) return 4;
return 3;
}
function calcHeightRatio(imageW, imageH) {
cellHeightRatio = 0.5;
if (imageW > 0 && imageH > 0)
cellHeightRatio = imageH / imageW;
}
cellWidth: width / columnCount
cellHeight: cellWidth * cellHeightRatio;
displayMarginBeginning: anchors.topMargin
transform: Rotation { origin.x: grid.height/2; origin.y: grid.width/2; axis { x: 0; y: 1; z: 0 } angle: -8 }
delegate: GameGridItem {
width: GridView.view.cellWidth
height: GridView.view.cellHeight
selected: GridView.isCurrentItem
systemColor: Utils.systemColor(currentCollection.shortName)
game: modelData
imageHeightRatio: {
if (grid.firstImageLoaded) return grid.cellHeightRatio;
return 0.5;
}
onImageLoaded: {
// NOTE: because images are loaded asynchronously,
// firstImageLoaded may appear false multiple times!
if (!grid.firstImageLoaded) {
grid.firstImageLoaded = true;
grid.calcHeightRatio(imageWidth, imageHeight);
}
}
}
}
}
// Subtle gradient over the bottom of the grid.
LinearGradient {
width: parent.width
height: parent.height
anchors {
top: parent.top
right: parent.right
bottom: parent.bottom
}
start: Qt.point(0, 0)
end: Qt.point(0, height)
gradient: Gradient {
GradientStop { position: 0.0; color: "#00000000" }
GradientStop { position: 0.7; color: "#00000000" }
GradientStop { position: 0.999; color: "#000000" }
}
}
// Header/Meta Start
Rectangle {
id: headerGameTitle
readonly property int paddingH: vpx(20)
readonly property int paddingV: vpx(20)
width: vpx(1260)
height: vpx(64)
color: "transparent"
anchors {
bottom: root.bottom; bottomMargin: paddingH
left: root.left; leftMargin: paddingV
rightMargin: paddingV
}
HeaderText {
titletext: currentGame.title;
game: currentGame
anchors {
}
}
}
Item {
id: metaBar
width: parent.width
height: vpx(106)
anchors {
bottom: headerGameTitle.top
left: headerGameTitle.left
right: parent.right
}
Rectangle {
id: metaBarBg
width: vpx(620)
height: parent.height
color: "#00f3f3f3"
visible: true
}
Text {
id: collectionName
anchors {
left: parent.left
top: metaBarBg.top
topMargin: vpx(4)
}
text: "≡ %1".arg(currentCollection.name) || "Not Found"
color: "#f3f3f3"
font.pixelSize: vpx(18)
font.family: subheaderFont.name
font.capitalization: Font.AllUppercase
Behavior on text {
FadeAnimation {
target: collectionName
}
}
}
GameMetaInfo {
id: gameDetails1
game: currentGame
color: "transparent"
width: parent.width / 2.06
anchors {
top: collectionName.bottom; topMargin: vpx(4)
left: parent.left;
bottomMargin: vpx(4)
}
}
}
GameDetails {
id: gameDetails
game: currentGame
color: "#00f3f3f3"
height: vpx(80)
width: parent.width / 2.06
anchors {
top: screenshotBox.bottom
bottom: metaBar.top
left: headerGameTitle.left
}
}
Rectangle {
id: screenshotBox
height: vpx(400)
width: parent.width / 2.06
color: "transparent"
clip: false
anchors {
top: root.top; topMargin: vpx(40)
left: parent.left; leftMargin: vpx(20)
}
Rectangle {
// TODO: make width/height adhere to platform specific ratios so screenshots
// and videos "fit nicely". Currently forced to 4/3.
// 16:9 :: 608 x 342 (PSVita)
// 3:2 :: 612:408 (GBA/GB)
// 8:7 :: 608:532 (NES)
id: screenshot
width: vpx(504)
height: vpx(378)
color: "#00f3f3f3"
transform: Rotation { origin.x: screenshotBox.height/2; origin.y: screenshotBox.width/2; axis { x: 0; y: 1; z: 0 } angle: 8 }
anchors {
horizontalCenter: parent.horizontalCenter
verticalCenter: parent.verticalCenter
}
GameVideoItem {
id: screenshotImage
anchors { fill: parent }
game: currentGame
collectionView: collectionsView.focus
detailView: detailsView.focus
collectionShortName: currentCollection.shortName
}
}
}
}