Changeset View
Changeset View
Standalone View
Standalone View
src/activities/question_and_answer/MenuScreen.qml
- This file was added.
1 | /* GCompris - MenuScreen.qml | ||||
---|---|---|---|---|---|
2 | * | ||||
3 | * Copyright (C) Amit Sagtani <asagtani06@gmail.com> | ||||
4 | * | ||||
5 | * Authors: | ||||
6 | * Pascal Georges (pascal.georges1@free.fr) (GTK+ version) | ||||
7 | * Holger Kaelberer <holger.k@elberer.de> (Qt Quick port of imageid) | ||||
8 | * Siddhesh suthar <siddhesh.it@gmail.com> (Qt Quick port) | ||||
9 | * Bruno Coudoin <bruno.coudoin@gcompris.net> (Integration Lang dataset) | ||||
10 | * | ||||
11 | * This program is free software; you can redistribute it and/or modify | ||||
12 | * it under the terms of the GNU General Public License as published by | ||||
13 | * the Free Software Foundation; either version 3 of the License, or | ||||
14 | * (at your option) any later version. | ||||
15 | * | ||||
16 | * This program is distributed in the hope that it will be useful, | ||||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
19 | * GNU General Public License for more details. | ||||
20 | * | ||||
21 | * You should have received a copy of the GNU General Public License | ||||
22 | * along with this program; if not, see <http://www.gnu.org/licenses/>. | ||||
23 | */ | ||||
24 | import QtQuick 2.6 | ||||
25 | import GCompris 1.0 | ||||
26 | import QtGraphicalEffects 1.0 | ||||
27 | import QtQuick.Controls 1.5 | ||||
28 | | ||||
29 | import "../../core" | ||||
30 | import "question_and_answer.js" as Activity | ||||
31 | | ||||
32 | Image { | ||||
33 | id: menuScreen | ||||
34 | anchors.fill: parent | ||||
35 | fillMode: Image.Tile | ||||
36 | source: "qrc:/gcompris/src/activities/digital_electricity/resource/texture02.png" | ||||
37 | sourceSize.width: Math.max(parent.width, parent.height) | ||||
38 | opacity: 0 | ||||
39 | | ||||
40 | property alias menuModel: menuModel | ||||
41 | property bool keyboardMode: false | ||||
42 | property bool started: opacity == 1 | ||||
43 | | ||||
44 | Behavior on opacity { PropertyAnimation { duration: 200 } } | ||||
45 | | ||||
46 | visible: opacity != 0 | ||||
47 | | ||||
48 | function start() { | ||||
49 | focus = true | ||||
50 | forceActiveFocus() | ||||
51 | menuGrid.currentIndex = 0 | ||||
52 | opacity = 1 | ||||
53 | } | ||||
54 | | ||||
55 | function stop() { | ||||
56 | focus = false | ||||
57 | opacity = 0 | ||||
58 | } | ||||
59 | | ||||
60 | Keys.onEscapePressed: { | ||||
61 | home() | ||||
62 | } | ||||
63 | | ||||
64 | //Keys.enabled : (items.mode == "expert") ? false : true | ||||
65 | Keys.onPressed: { | ||||
66 | if(event.key === Qt.Key_Space) { | ||||
67 | menuGrid.currentItem.selectCurrentItem() | ||||
68 | event.accepted = true | ||||
69 | } | ||||
70 | if(event.key === Qt.Key_Enter) { | ||||
71 | menuGrid.currentItem.selectCurrentItem() | ||||
72 | event.accepted = true | ||||
73 | } | ||||
74 | if(event.key === Qt.Key_Return) { | ||||
75 | menuGrid.currentItem.selectCurrentItem() | ||||
76 | event.accepted = true | ||||
77 | } | ||||
78 | if(event.key === Qt.Key_Left) { | ||||
79 | menuGrid.moveCurrentIndexLeft() | ||||
80 | event.accepted = true | ||||
81 | } | ||||
82 | if(event.key === Qt.Key_Right) { | ||||
83 | menuGrid.moveCurrentIndexRight() | ||||
84 | event.accepted = true | ||||
85 | } | ||||
86 | if(event.key === Qt.Key_Up) { | ||||
87 | menuGrid.moveCurrentIndexUp() | ||||
88 | event.accepted = true | ||||
89 | } | ||||
90 | if(event.key === Qt.Key_Down) { | ||||
91 | menuGrid.moveCurrentIndexDown() | ||||
92 | event.accepted = true | ||||
93 | } | ||||
94 | } | ||||
95 | | ||||
96 | Keys.onReleased: { | ||||
97 | keyboardMode = true | ||||
98 | event.accepted = false | ||||
99 | } | ||||
100 | | ||||
101 | // sections | ||||
102 | property int iconWidth: 180 * ApplicationInfo.ratio | ||||
103 | property int iconHeight: 180 * ApplicationInfo.ratio | ||||
104 | | ||||
105 | property int levelCellWidth: background.width / Math.floor(background.width / iconWidth ) | ||||
106 | property int levelCellHeight: iconHeight * 1.2 | ||||
107 | | ||||
108 | ListModel { | ||||
109 | id: menuModel | ||||
110 | } | ||||
111 | | ||||
112 | GridView { | ||||
113 | id: menuGrid | ||||
114 | anchors { | ||||
115 | fill: parent | ||||
116 | bottomMargin: bar.height | ||||
117 | } | ||||
118 | cellWidth: levelCellWidth | ||||
119 | cellHeight: levelCellHeight | ||||
120 | clip: true | ||||
121 | model: menuModel | ||||
122 | keyNavigationWraps: true | ||||
123 | property int spacing: 10 | ||||
124 | | ||||
125 | delegate: Item { | ||||
126 | id: delegateItem | ||||
127 | width: levelCellWidth - menuGrid.spacing | ||||
128 | height: levelCellHeight - menuGrid.spacing | ||||
129 | property string sectionName: name | ||||
130 | opacity: 1 | ||||
131 | | ||||
132 | Rectangle { | ||||
133 | id: activityBackground | ||||
134 | width: levelCellWidth - menuGrid.spacing | ||||
135 | height: levelCellHeight - menuGrid.spacing | ||||
136 | anchors.horizontalCenter: parent.horizontalCenter | ||||
137 | color: "white" | ||||
138 | opacity: 0.5 | ||||
139 | } | ||||
140 | | ||||
141 | Image { | ||||
142 | id: containerImage | ||||
143 | source: image | ||||
144 | anchors.top: activityBackground.top | ||||
145 | anchors.horizontalCenter: parent.horizontalCenter | ||||
146 | height: activityBackground.height*0.8 - 6 | ||||
147 | width: height | ||||
148 | anchors.margins: 5 | ||||
149 | sourceSize.height: height | ||||
150 | fillMode: Image.PreserveAspectCrop | ||||
151 | clip: true | ||||
152 | } | ||||
153 | | ||||
154 | GCText { | ||||
155 | id: categoryName | ||||
156 | anchors.top: containerImage.bottom | ||||
157 | horizontalAlignment: Text.AlignHCenter | ||||
158 | verticalAlignment: Text.AlignVCenter | ||||
159 | width: activityBackground.width | ||||
160 | height: activityBackground.height*0.2 - 6 | ||||
161 | fontSizeMode: Text.Fit | ||||
162 | elide: Text.ElideRight | ||||
163 | maximumLineCount: 2 | ||||
164 | wrapMode: Text.WordWrap | ||||
165 | text: name | ||||
166 | opacity: 1 | ||||
167 | } | ||||
168 | | ||||
169 | ParticleSystemStarLoader { | ||||
170 | id: particles | ||||
171 | anchors.fill: activityBackground | ||||
172 | } | ||||
173 | MouseArea { | ||||
174 | anchors.fill: activityBackground | ||||
175 | enabled: menuScreen.started | ||||
176 | onClicked: selectCurrentItem() | ||||
177 | } | ||||
178 | | ||||
179 | function selectCurrentItem() { | ||||
180 | particles.burst(50) | ||||
181 | console.log(name) | ||||
182 | Activity.initializeSubActivity(index) | ||||
183 | menuScreen.stop() | ||||
184 | } | ||||
185 | | ||||
186 | } //delegate close | ||||
187 | | ||||
188 | highlight: Rectangle { | ||||
189 | width: levelCellWidth - menuGrid.spacing | ||||
190 | height: levelCellHeight - menuGrid.spacing | ||||
191 | color: "#AA41AAC4" | ||||
192 | border.width: 3 | ||||
193 | border.color: "black" | ||||
194 | visible: true | ||||
195 | Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } } | ||||
196 | Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } } | ||||
197 | } | ||||
198 | | ||||
199 | Rectangle { | ||||
200 | id: menusMask | ||||
201 | visible: false | ||||
202 | anchors.fill: menuGrid | ||||
203 | gradient: Gradient { | ||||
204 | GradientStop { position: 0.0; color: "#FFFFFFFF" } | ||||
205 | GradientStop { position: 0.92; color: "#FFFFFFFF" } | ||||
206 | GradientStop { position: 0.96; color: "#00FFFFFF" } | ||||
207 | } | ||||
208 | } | ||||
209 | | ||||
210 | layer.enabled: ApplicationInfo.useOpenGL | ||||
211 | layer.effect: OpacityMask { | ||||
212 | id: activitiesOpacity | ||||
213 | source: menuGrid | ||||
214 | maskSource: menusMask | ||||
215 | anchors.fill: menuGrid | ||||
216 | } | ||||
217 | } // grid view close | ||||
218 | } |