Changeset View
Changeset View
Standalone View
Standalone View
a/src/activities/simplepaint/Simplepaint.qml
Context not available. | |||||
39 | signal start | 39 | signal start | ||
---|---|---|---|---|---|
40 | signal stop | 40 | signal stop | ||
41 | focus: true | 41 | focus: true | ||
42 | property bool isColorTab: false | ||||
43 | | ||||
44 | Keys.onUpPressed: { | ||||
45 | if(isColorTab) { | ||||
46 | if (--items.current_color<0) { | ||||
47 | items.current_color = items.colors.length-1 | ||||
48 | } | ||||
49 | items.colorSelector = items.colors[items.current_color] | ||||
50 | moveColorSelector() | ||||
51 | }else { | ||||
52 | if(cursor.iy>0) { | ||||
53 | cursor.iy-- | ||||
54 | } | ||||
55 | } | ||||
56 | } | ||||
57 | | ||||
58 | Keys.onDownPressed: { | ||||
59 | if(isColorTab) { | ||||
60 | if (++items.current_color>items.colors.length-1){ | ||||
61 | items.current_color = 0 | ||||
62 | } | ||||
63 | items.colorSelector = items.colors[items.current_color] | ||||
64 | moveColorSelector() | ||||
65 | }else { | ||||
66 | if(cursor.iy<(Activity.nby-1)) { | ||||
67 | cursor.iy++ | ||||
68 | } | ||||
69 | } | ||||
70 | } | ||||
71 | | ||||
72 | Keys.onRightPressed: { | ||||
73 | if(!isColorTab) { | ||||
74 | if(cursor.ix<(Activity.nbx-1)) { | ||||
75 | cursor.ix++ | ||||
76 | } | ||||
77 | } | ||||
78 | } | ||||
79 | | ||||
80 | Keys.onLeftPressed: { | ||||
81 | if(!isColorTab) { | ||||
82 | if(cursor.ix>0) { | ||||
83 | cursor.ix-- | ||||
84 | } | ||||
85 | } | ||||
86 | } | ||||
87 | | ||||
88 | Keys.onSpacePressed: spawnBlock() | ||||
89 | | ||||
90 | Keys.onReturnPressed: spawnBlock() | ||||
91 | | ||||
92 | Keys.onEnterPressed: spawnBlock() | ||||
93 | | ||||
94 | Keys.onTabPressed:changeTab() | ||||
95 | | ||||
96 | function changeTab() { | ||||
97 | isColorTab = !isColorTab | ||||
98 | if(isColorTab) { | ||||
99 | colorSelector.cellWidth = 60 * ApplicationInfo.ratio+20 | ||||
100 | }else { | ||||
101 | colorSelector.cellWidth = 60 * ApplicationInfo.ratio | ||||
102 | } | ||||
103 | } | ||||
104 | | ||||
105 | function spawnBlock() { | ||||
106 | if(!isColorTab) { | ||||
107 | var block = rootItem.childAt(cursor.x, cursor.y) | ||||
108 | if(block) | ||||
109 | block.touched() | ||||
110 | }else { | ||||
111 | changeTab() | ||||
112 | } | ||||
113 | } | ||||
114 | | ||||
115 | function refreshCursor() { | ||||
116 | cursor.nbx= Activity.nbx | ||||
117 | cursor.nby=Activity.nby | ||||
118 | } | ||||
119 | | ||||
120 | function moveColorSelector() { | ||||
121 | moveColorSelectorAnim.running = false | ||||
122 | moveColorSelectorAnim.from = colorSelector.contentY | ||||
123 | if(items.current_color != (items.colors.length-1)) { | ||||
124 | colorSelector.positionViewAtIndex(items.current_color >= 1 ? items.current_color-2 : items.current_color, colorSelector.Contain) | ||||
125 | }else { | ||||
126 | colorSelector.positionViewAtEnd() | ||||
127 | colorSelector.positionViewAtEnd() | ||||
128 | } | ||||
129 | moveColorSelectorAnim.to = colorSelector.contentY | ||||
130 | moveColorSelectorAnim.running = true | ||||
131 | } | ||||
42 | 132 | | |||
43 | Component.onCompleted: { | 133 | Component.onCompleted: { | ||
44 | activity.start.connect(start) | 134 | activity.start.connect(start) | ||
45 | activity.stop.connect(stop) | 135 | activity.stop.connect(stop) | ||
46 | } | 136 | } | ||
137 | | ||||
138 | //Cursor to navigate in cells | ||||
139 | PaintCursor { | ||||
140 | id:cursor; | ||||
141 | initialX: colorSelector.width + 20 * ApplicationInfo.ratio | ||||
142 | z:1 | ||||
143 | ix: 0 | ||||
144 | iy: 0 | ||||
145 | nbx: 20 | ||||
146 | nby: 10 | ||||
147 | color: items.colors[0] | ||||
148 | } | ||||
149 | | ||||
150 | | ||||
47 | QtObject { | 151 | QtObject { | ||
48 | id: items | 152 | id: items | ||
49 | property alias background: background | 153 | property alias background: background | ||
50 | property alias bar: bar | 154 | property alias bar: bar | ||
51 | property alias paintModel: paintModel | 155 | property alias paintModel: paintModel | ||
52 | property var colors: bar.level < 10 ? Activity.colorsSimple : Activity.colorsAdvanced | 156 | property var colors: bar.level < 10 ? Activity.colorsSimple : Activity.colorsAdvanced | ||
53 | property string colorSelector: colors[0] | 157 | property int current_color:0 | ||
158 | property string colorSelector: colors[current_color] | ||||
54 | property string backgroundImg: Activity.backgrounds[bar.level - 1] | 159 | property string backgroundImg: Activity.backgrounds[bar.level - 1] | ||
55 | } | 160 | } | ||
56 | 161 | | |||
57 | onStart: Activity.start(main, items) | 162 | onStart: Activity.start(main, items, background) | ||
58 | onStop: Activity.stop() | 163 | onStop: Activity.stop() | ||
59 | 164 | | |||
60 | MultiPointTouchArea { | 165 | MultiPointTouchArea { | ||
Context not available. | |||||
68 | var touch = touchPoints[i] | 173 | var touch = touchPoints[i] | ||
69 | var block = rootItem.childAt(touch.x, touch.y) | 174 | var block = rootItem.childAt(touch.x, touch.y) | ||
70 | if(block) | 175 | if(block) | ||
176 | cursor.ix = block.ix | ||||
177 | cursor.iy = block.iy | ||||
71 | block.touched() | 178 | block.touched() | ||
72 | } | 179 | } | ||
73 | } | 180 | } | ||
Context not available. | |||||
100 | model: items.colors | 207 | model: items.colors | ||
101 | cellWidth: 60 * ApplicationInfo.ratio | 208 | cellWidth: 60 * ApplicationInfo.ratio | ||
102 | cellHeight: cellWidth | 209 | cellHeight: cellWidth | ||
210 | | ||||
211 | NumberAnimation { | ||||
212 | id: moveColorSelectorAnim | ||||
213 | target: colorSelector | ||||
214 | property: "contentY" | ||||
215 | duration: 150 | ||||
216 | } | ||||
217 | | ||||
103 | delegate: Item { | 218 | delegate: Item { | ||
104 | width: colorSelector.cellWidth | 219 | width: colorSelector.cellWidth | ||
105 | height: width | 220 | height: width | ||
Context not available. | |||||
197 | onClicked: { | 312 | onClicked: { | ||
198 | activity.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav') | 313 | activity.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav') | ||
199 | items.colorSelector = modelData | 314 | items.colorSelector = modelData | ||
315 | items.current_color=items.colors.indexOf(modelData) | ||||
316 | items.colorSelector=items.colors[items.current_color] | ||||
200 | } | 317 | } | ||
201 | } | 318 | } | ||
202 | } | 319 | } | ||
Context not available. |