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

GCompris-qt

  • src
  • core
DominoNumber.qml
1 /* GCompris - DominoNumber.qml
2  *
3  * Copyright (C) 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
4  *
5  * Authors:
6  * Bruno Coudoin <bruno.coudoin@gcompris.net>
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 GCompris 1.0
23 
24 Item {
25  id: item
26  property int value
27  property int valueMax
28  property color color
29  property color borderColor
30  property int borderWidth
31  property int radius
32  property bool isClickable: true // Default value
33  property GCAudio audioEffects
34 
35  function isVisible(index) {
36  var value = item.value
37  var visible = false
38  switch(index) {
39  case 0:
40  if(value >= 2) visible = true
41  break
42  case 1:
43  if(value >= 6) visible = true
44  break
45  case 2:
46  if(value >= 4) visible = true
47  break
48  case 3:
49  if(value >= 8) visible = true
50  break
51  case 4:
52  if(value == 1 || value == 3 || value == 5 ||
53  value == 7 || value == 9) visible = true
54  break
55  case 5:
56  if(value >= 8) visible = true
57  break
58  case 6:
59  if(value >= 4) visible = true
60  break
61  case 7:
62  if(value >= 6) visible = true
63  break
64  case 8:
65  if(value >= 2) visible = true
66  break
67  }
68  return visible
69  }
70 
71  Grid {
72  columns: 3
73  spacing: 3
74  anchors.horizontalCenter: parent.horizontalCenter
75  anchors.verticalCenter: parent.verticalCenter
76  horizontalItemAlignment: Grid.AlignHCenter
77  verticalItemAlignment: Grid.AlignVCenter
78 
79  Repeater {
80  model: 9
81  Rectangle {
82  width: radius
83  height: radius
84  border.width: item.borderWidth
85  color: item.color
86  border.color: item.borderColor
87  radius: item.radius
88  opacity: isVisible(index)
89 
90  Behavior on opacity { PropertyAnimation { duration: 200 } }
91  }
92  }
93  }
94 
95  function up() {
96  audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav')
97  if(item.value == item.valueMax)
98  item.value = 0
99  else
100  item.value++
101  }
102 
103  function down() {
104  audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav')
105  if(item.value == 0)
106  item.value = item.valueMax
107  else
108  item.value--
109  }
110 
111  MouseArea {
112  enabled: !ApplicationInfo.isMobile && item.isClickable
113  anchors.fill: parent
114  acceptedButtons: Qt.LeftButton | Qt.RightButton
115  onClicked: {
116  if (mouse.button == Qt.LeftButton)
117  up()
118  else
119  down()
120  }
121  }
122 
123  property bool goUp
124  Timer {
125  id: timer
126  interval: 500
127  repeat: true
128  onTriggered: goUp ? up() : down()
129  }
130 
131  MultiPointTouchArea
132  {
133  enabled: ApplicationInfo.isMobile && item.isClickable
134  anchors.fill: parent
135  maximumTouchPoints: 1
136  onPressed: {
137  goUp = true
138  up()
139  timer.start()
140  }
141  onTouchUpdated: {
142  if(touchPoints.length) {
143  var touch = touchPoints[0]
144  if(touch.y < parent.y + parent.height)
145  goUp = true
146  else
147  goUp = false
148  }
149  }
150  onReleased: timer.stop()
151  }
152 
153 }
QtQuick
GCAudio
A QML component for audio playback.
Definition: GCAudio.qml:44
GCAudio::play
void play(string file)
When mute is changed we set the volume to 0 to mute a potential playing sound.
GCompris
ApplicationInfo::isMobile
bool isMobile
Whether the application is currently running on a mobile platform.
Definition: ApplicationInfo.h:65
ApplicationInfo
A general purpose singleton that exposes miscellaneous native functions to the QML layer...
Definition: ApplicationInfo.h:43
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