forked from PlayingKarrde/clearOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameGrid.qml
132 lines (116 loc) · 3.78 KB
/
GameGrid.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
import QtQuick 2.12
import QtGraphicalEffects 1.0
import QtQml.Models 2.10
import QtMultimedia 5.9
import "Lists"
import "utils.js" as Utils
FocusScope {
id: root
property var currentState
property alias menu: gamegrid
// Pull in our custom lists and define
ListAllGames { id: listNone; max: 0 }
ListAllGames { id: listAllGames; }
ListFavorites { id: listFavorites; }
ListLastPlayed { id: listLastPlayed; }
ListTopGames { id: listTopGames; }
property var currentList: {
switch (currentState) {
case "allgames":
return listAllGames;
break;
case "topgames":
return listTopGames;
break;
default:
return listAllGames;
}
}
Component {
id: gridHeader
Item {
height: vpx(90)
Text {
id: collectionName
property string collectionTitle: currentCollection != -1 ? " - " + api.collections.get(currentCollection).name : ""
property string pageTitle: currentState == "topgames" ? "Top games" : "All games"
text: pageTitle + collectionTitle
font.family: titleFont.name
font.pixelSize: vpx(26)
font.bold: true
color: theme.text
anchors { bottom: parent.bottom; bottomMargin: vpx(20)}
}//*/
}
}
GridView {
id: gamegrid
focus: true
cellWidth: width / 4
cellHeight: vpx(235)
anchors { left: parent.left; leftMargin: vpx(25) }
anchors {
top: parent.top;
bottom: parent.bottom;
left: parent.left; right: parent.right
}
preferredHighlightBegin: vpx(15)
preferredHighlightEnd: parent.height
header: gridHeader
model: currentList.games
delegate: boxartDelegate
// We need to set to -1 so there are no selections in the grid
currentIndex: focus ? currentGameIndex : -1
onCurrentIndexChanged: {
// Ensure that the game index is never set to -1
if (currentIndex != -1)
currentGameIndex = currentIndex;
}
Component {
id: boxartDelegate
GridItem {
id: delegatecontainer
selected: GridView.isCurrentItem && root.focus
gameData: modelData
width: GridView.view.cellWidth
height: GridView.view.cellHeight
// List specific input
Keys.onPressed: {
// Back
if (api.keys.isCancel(event) && !event.isAutoRepeat) {
event.accepted = true;
sfxBack.play();
navigationMenu();
}
// Favorites
if (api.keys.isDetails(event) && !event.isAutoRepeat) {
event.accepted = true;
sfxToggle.play();
modelData.favorite = !modelData.favorite;
}
}
}
}
property int col: currentIndex % 4;
Keys.onLeftPressed: {
sfxNav.play();
if (col == 0)
navigationMenu();
else
moveCurrentIndexLeft();
}
Keys.onRightPressed: {
sfxNav.play();
if (col != 3)
moveCurrentIndexRight();
}
Keys.onUpPressed: {
sfxNav.play();
moveCurrentIndexUp();
}
Keys.onDownPressed: {
sfxNav.play();
moveCurrentIndexDown();
}
}
}