• Skip to content
  • Skip to link menu
KDE API Documentation - Menu.qml Source File (GCompris-qt)
  • KDE Home
  • Contact Us
 

GCompris-qt

  • src
  • activities
  • menu
Menu.qml
1 /* GCompris - Menu.qml
2  *
3  * Copyright (C) 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
4  *
5  * Authors:
6  * Bruno Coudoin <bruno.coudoin@gcompris.net> (Qt Quick port)
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, see <http://www.gnu.org/licenses/>.
20  */
21 import QtQuick 2.2
22 import "../../core"
23 import GCompris 1.0
24 import "qrc:/gcompris/src/core/core.js" as Core
25 import QtGraphicalEffects 1.0
26 
44 ActivityBase {
45  id: menuActivity
46  focus: true
47  activityInfo: ActivityInfoTree.rootMenu
48 
49  onHome: {
50  if(pageView.depth === 1) {
51  Core.quit(main);
52  }
53  else {
54  pageView.pop();
55  // Restore focus that has been taken by the loaded activity
56  if(pageView.currentItem == menuActivity)
57  focus = true;
58  }
59  }
60 
61  onDisplayDialog: pageView.push(dialog)
62 
63  // @cond INTERNAL_DOCS
64  property string url: "qrc:/gcompris/src/activities/menu/resource/"
65  property variant sections: [
66  {
67  icon: menuActivity.url + "all.svg",
68  tag: "favorite"
69  },
70  {
71  icon: menuActivity.url + "computer.svg",
72  tag: "computer"
73  },
74  {
75  icon: menuActivity.url + "discovery.svg",
76  tag: "discovery"
77  },
78  {
79  icon: menuActivity.url + "experience.svg",
80  tag: "experiment"
81  },
82  {
83  icon: menuActivity.url + "fun.svg",
84  tag: "fun"
85  },
86  {
87  icon: menuActivity.url + "math.svg",
88  tag: "math"
89  },
90  {
91  icon: menuActivity.url + "puzzle.svg",
92  tag: "puzzle"
93  },
94  {
95  icon: menuActivity.url + "reading.svg",
96  tag: "reading"
97  },
98  {
99  icon: menuActivity.url + "strategy.svg",
100  tag: "strategy"
101  },
102  ]
103  property string currentTag: sections[0].tag
105 
106  pageComponent: Image {
107  id: background
108  source: menuActivity.url + "background.svg"
109  sourceSize.width: parent.width
110  fillMode: Image.PreserveAspectCrop
111 
112  function loadActivity() {
113  pageView.push(activityLoader.item)
114  }
115 
116  Loader {
117  id: activityLoader
118  asynchronous: true
119  onStatusChanged: if (status == Loader.Ready) loadActivity()
120  }
121 
122  // Filters
123  property bool horizontal: main.width > main.height
124  property int sectionIconWidth:
125  horizontal ?
126  Math.min(100 * ApplicationInfo.ratio, main.width / (sections.length + 1)) :
127  Math.min(100 * ApplicationInfo.ratio, (main.height - bar.height) / (sections.length + 1))
128  property int sectionIconHeight: sectionIconWidth
129  property int sectionCellWidth: sectionIconWidth * 1.1
130  property int sectionCellHeight: sectionIconHeight * 1.1
131 
132  property var currentActiveGrid: activitiesGrid
133  property bool keyboardMode: false
134  Keys.onPressed: {
135  if (event.modifiers === Qt.ControlModifier &&
136  event.key === Qt.Key_S) {
137  // Ctrl+S toggle show / hide section
138  ApplicationSettings.sectionVisible = !ApplicationSettings.sectionVisible
139  } else if(event.key === Qt.Key_Space) {
140  currentActiveGrid.currentItem.selectCurrentItem()
141  }
142  }
143  Keys.onReleased: {
144  keyboardMode = true
145  event.accepted = false
146  }
147  Keys.onTabPressed: currentActiveGrid = ((currentActiveGrid == activitiesGrid) ?
148  section : activitiesGrid);
149  Keys.onEnterPressed: currentActiveGrid.currentItem.selectCurrentItem();
150  Keys.onReturnPressed: currentActiveGrid.currentItem.selectCurrentItem();
151  Keys.onRightPressed: currentActiveGrid.moveCurrentIndexRight();
152  Keys.onLeftPressed: currentActiveGrid.moveCurrentIndexLeft();
153  Keys.onDownPressed: currentActiveGrid.moveCurrentIndexDown();
154  Keys.onUpPressed: currentActiveGrid.moveCurrentIndexUp();
155 
156  GridView {
157  id: section
158  model: sections
159  width: horizontal ? main.width : sectionCellWidth
160  height: horizontal ? sectionCellHeight : main.height - bar.height
161  x: ApplicationSettings.sectionVisible ? section.initialX : -sectionCellWidth
162  y: ApplicationSettings.sectionVisible ? section.initialY : -sectionCellHeight
163  cellWidth: sectionCellWidth
164  cellHeight: sectionCellHeight
165  interactive: false
166  keyNavigationWraps: true
167 
168  property int initialX: 4
169  property int initialY: 4
170 
171  Component {
172  id: sectionDelegate
173  Item {
174  id: backgroundSection
175  width: sectionCellWidth
176  height: sectionCellHeight
177 
178  Image {
179  source: modelData.icon
180  sourceSize.height: sectionIconHeight
181  anchors.margins: 5
182  anchors.horizontalCenter: parent.horizontalCenter
183  }
184 
185  ParticleSystemStarLoader {
186  id: particles
187  anchors.fill: backgroundSection
188  clip: false
189  }
190  MouseArea {
191  anchors.fill: backgroundSection
192  onClicked: {
193  selectCurrentItem()
194  }
195  }
196 
197  function selectCurrentItem() {
198  particles.burst(10)
199  ActivityInfoTree.filterByTag(modelData.tag)
200  ActivityInfoTree.filterLockedActivities()
201  ActivityInfoTree.filterEnabledActivities()
202  menuActivity.currentTag = modelData.tag
203  section.currentIndex = index
204  }
205  }
206  }
207  delegate: sectionDelegate
208  highlight: Item {
209  width: sectionCellWidth
210  height: sectionCellHeight
211 
212  Rectangle {
213  anchors.fill: parent
214  color: "#99FFFFFF"
215  }
216  Image {
217  source: "qrc:/gcompris/src/core/resource/button.svg"
218  anchors.fill: parent
219  }
220  Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } }
221  Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } }
222  }
223  }
224 
225  // Activities
226  property int iconWidth: 190 * ApplicationInfo.ratio
227  property int iconHeight: 190 * ApplicationInfo.ratio
228  property int activityCellWidth:
229  horizontal ? background.width / Math.floor(background.width / iconWidth) :
230  (background.width - section.width) / Math.floor((background.width - section.width) / iconWidth)
231  property int activityCellHeight: iconHeight * 1.5
232 
233  Loader {
234  id: warningOverlay
235  anchors {
236  top: horizontal ? section.bottom : parent.top
237  bottom: parent.bottom
238  left: horizontal ? parent.left : section.right
239  right: parent.right
240  margins: 4
241  }
242  active: (ActivityInfoTree.menuTree.length === 0) && (currentTag === "favorite")
243  sourceComponent: Item {
244  anchors.fill: parent
245  GCText {
246  id: instructionTxt
247  fontSize: smallSize
248  y: height * 0.2
249  x: (parent.width - width) / 2
250  z: 2
251  width: parent.width * 0.6
252  horizontalAlignment: Text.AlignHCenter
253  wrapMode: Text.WordWrap
254  font.weight: Font.DemiBold
255  color: 'white'
256  text: qsTr("Put your favorite activities here by selecting the " +
257  "sun on each activity top right.")
258  }
259  Rectangle {
260  anchors.fill: instructionTxt
261  anchors.margins: -6
262  z: 1
263  opacity: 0.5
264  radius: 10
265  border.width: 2
266  border.color: "black"
267  gradient: Gradient {
268  GradientStop { position: 0.0; color: "#000" }
269  GradientStop { position: 0.9; color: "#666" }
270  GradientStop { position: 1.0; color: "#AAA" }
271  }
272  }
273  }
274  }
275 
276  GridView {
277  id: activitiesGrid
278  layer.enabled: true
279  anchors {
280  top: horizontal ? section.bottom : parent.top
281  bottom: bar.top
282  left: horizontal ? parent.left : section.right
283  margins: 4
284  }
285  width: background.width
286  cellWidth: activityCellWidth
287  cellHeight: activityCellHeight
288  clip: true
289  model: ActivityInfoTree.menuTree
290  keyNavigationWraps: true
291  property int spacing: 10
292 
293  delegate: Item {
294  id: delegateItem
295  width: activityCellWidth - activitiesGrid.spacing
296  height: activityCellHeight - activitiesGrid.spacing
297  Rectangle {
298  id: activityBackground
299  width: activityCellWidth - activitiesGrid.spacing
300  height: activityCellHeight - activitiesGrid.spacing
301  anchors.horizontalCenter: parent.horizontalCenter
302  color: "white"
303  opacity: 0.5
304  }
305  Image {
306  source: "qrc:/gcompris/src/activities/" + icon;
307  anchors.top: activityBackground.top
308  anchors.horizontalCenter: parent.horizontalCenter
309  sourceSize.height: iconHeight
310  anchors.margins: 5
311  Image {
312  source: "qrc:/gcompris/src/core/resource/difficulty" +
313  ActivityInfoTree.menuTree[index].difficulty + ".svg";
314  anchors.top: parent.top
315  sourceSize.width: iconWidth * 0.15
316  x: 5
317  }
318  Image {
319  anchors {
320  horizontalCenter: parent.horizontalCenter
321  top: parent.top
322  rightMargin: 4
323  }
324  source: demo || !ApplicationSettings.isDemoMode
325  ? "" :
326  menuActivity.url + "lock.svg"
327  sourceSize.width: 30 * ApplicationInfo.ratio
328  }
329  GCText {
330  id: title
331  anchors.top: parent.bottom
332  anchors.horizontalCenter: parent.horizontalCenter
333  horizontalAlignment: Text.AlignHCenter
334  width: activityBackground.width
335  fontSizeMode: Text.Fit
336  minimumPointSize: 7
337  fontSize: regularSize
338  elide: Text.ElideRight
339  maximumLineCount: 2
340  wrapMode: Text.WordWrap
341  text: ActivityInfoTree.menuTree[index].title
342  }
343  // If we have enough room at the bottom display the description
344  GCText {
345  id: description
346  visible: delegateItem.height - (title.y + title.height) > description.height ? 1 : 0
347  anchors.top: title.bottom
348  anchors.horizontalCenter: parent.horizontalCenter
349  horizontalAlignment: Text.AlignHCenter
350  width: activityBackground.width
351  fontSizeMode: Text.Fit
352  minimumPointSize: 7
353  fontSize: regularSize
354  elide: Text.ElideRight
355  maximumLineCount: 3
356  wrapMode: Text.WordWrap
357  text: ActivityInfoTree.menuTree[index].description
358  }
359  }
360  ParticleSystemStarLoader {
361  id: particles
362  anchors.fill: activityBackground
363  }
364  MouseArea {
365  anchors.fill: activityBackground
366  onClicked: selectCurrentItem()
367  }
368  Image {
369  source: menuActivity.url + (favorite ? "all.svg" : "all_disabled.svg");
370  anchors {
371  top: parent.top
372  right: parent.right
373  rightMargin: 4 * ApplicationInfo.ratio
374  }
375  sourceSize.width: iconWidth * 0.25
376  visible: ApplicationSettings.sectionVisible
377  MouseArea {
378  anchors.fill: parent
379  onClicked: favorite = !favorite
380  }
381  }
382 
383  function selectCurrentItem() {
384  if(pageView.busy)
385  return
386  particles.burst(50)
387  ActivityInfoTree.currentActivity = ActivityInfoTree.menuTree[index]
388  activityLoader.setSource("qrc:/gcompris/src/activities/" + ActivityInfoTree.menuTree[index].name,
389  {
390  'audioVoices': audioVoices,
391  'audioEffects': audioEffects,
392  'menu': menuActivity,
393  'activityInfo': ActivityInfoTree.currentActivity
394  })
395  if (activityLoader.status == Loader.Ready) loadActivity()
396  }
397  }
398  highlight: Rectangle {
399  width: activityCellWidth - activitiesGrid.spacing
400  height: activityCellHeight - activitiesGrid.spacing
401  color: "#AAFFFFFF"
402  border.width: 3
403  border.color: "black"
404  visible: background.keyboardMode
405  Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } }
406  Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } }
407  }
408 
409  Rectangle{
410  id: activitiesMask
411  visible: false
412  anchors.fill: activitiesGrid
413  gradient: Gradient {
414  GradientStop { position: 0.0; color: "#FFFFFFFF" }
415  GradientStop { position: 0.92; color: "#FFFFFFFF" }
416  GradientStop { position: 0.96; color: "#00FFFFFF"}
417  }
418  }
419 
420  layer.effect: OpacityMask {
421  id: activitiesOpacity
422  source: activitiesGrid
423  maskSource: activitiesMask
424  anchors.fill: activitiesGrid
425  }
426 
427  }
428 
429  Bar {
430  id: bar
431  content: BarEnumContent { value: help | exit | config | about }
432  onAboutClicked: {
433  displayDialog(dialogAbout)
434  }
435 
436  onHelpClicked: {
437  displayDialog(dialogHelp)
438  }
439 
440  onConfigClicked: {
441  dialogActivityConfig.active = true
442  dialogActivityConfig.loader.item.loadFromConfig()
443  displayDialog(dialogActivityConfig)
444  }
445  }
446  }
447 
448  DialogAbout {
449  id: dialogAbout
450  onClose: home()
451  }
452  DialogHelp {
453  id: dialogHelp
454  onClose: home()
455  activityInfo: ActivityInfoTree.rootMenu
456  }
457 
458  DialogActivityConfig {
459  id: dialogActivityConfig
460  currentActivity: menuActivity
461 
462  content: Component {
463  ConfigurationItem {
464  id: configItem
465  width: dialogActivityConfig.width - 50 * ApplicationInfo.ratio
466  }
467  }
468 
469  onSaveData: {
470  dialogActivityConfig.configItem.save();
471  }
472  onClose: {
473  ActivityInfoTree.filterByTag(menuActivity.currentTag)
474  ActivityInfoTree.filterLockedActivities()
475  ActivityInfoTree.filterEnabledActivities()
476  home()
477  }
478  }
479 }
DialogAbout
GCompris' full screen about dialog.
Definition: DialogAbout.qml:28
BarEnumContent
QML container for defining all visible child elements of a Bar.
Definition: BarEnumContent.qml:31
DialogActivityConfig
A QML component for a full screen configuration dialog.
Definition: DialogActivityConfig.qml:43
GCText
A QML component unifying text presentation in GCompris.
Definition: GCText.qml:47
QtQuick
Bar
A QML component for GCompris' navigation bar.
Definition: Bar.qml:43
DialogHelp
GCompris' full screen help dialog.
Definition: DialogHelp.qml:36
ApplicationSettings::isDemoMode
bool isDemoMode
Whether in demo mode.
Definition: ApplicationSettings.h:144
GCompris
ApplicationSettings::sectionVisible
bool sectionVisible
Whether the section selection row is visible in the menu view.
Definition: ApplicationSettings.h:154
ApplicationSettings
Singleton that contains GCompris' persistent settings.
Definition: ApplicationSettings.h:63
main
GCompris' main QML file defining the top level window.
Definition: main.qml:41
ParticleSystemStarLoader
A QML loader that wraps ParticleSystemStar.
Definition: ParticleSystemStarLoader.qml:34
QtGraphicalEffects
ApplicationInfo
A general purpose singleton that exposes miscellaneous native functions to the QML layer...
Definition: ApplicationInfo.h:43
ParticleSystemStarLoader::burst
void burst(val)
Emits count particles from the particle emitter immediately.
ApplicationInfo::ratio
qreal ratio
Ratio factor used for scaling of sizes on high-dpi devices.
Definition: ApplicationInfo.h:91
This file is part of the KDE documentation.
Documentation copyright © 1996-2015 The KDE developers.
Generated on Tue Jun 2 2015 21:47:47 by doxygen 1.8.9.1 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

GCompris-qt

Skip menu "GCompris-qt"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • File List
  • Modules

Class Picker

Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal