diff --git a/src/activities/simplepaint/PaintCursor.qml b/src/activities/simplepaint/PaintCursor.qml --- a/src/activities/simplepaint/PaintCursor.qml +++ b/src/activities/simplepaint/PaintCursor.qml @@ -1,4 +1,4 @@ -/* GCompris - PaintItem.qml +/* GCompris - PaintCursor.qml * * Copyright (C) 2014 Bruno Coudoin * diff --git a/src/activities/simplepaint/Simplepaint.qml b/src/activities/simplepaint/Simplepaint.qml --- a/src/activities/simplepaint/Simplepaint.qml +++ b/src/activities/simplepaint/Simplepaint.qml @@ -39,22 +39,112 @@ signal start signal stop focus: true + property bool isColorTab: false + + Keys.onUpPressed: { + if(isColorTab) { + if (--items.current_color<0) { + items.current_color = items.colors.length-1 + } + items.colorSelector = items.colors[items.current_color] + }else { + if(cursor.iy>0) { + cursor.iy-- + } + } + } + + Keys.onDownPressed: { + if(isColorTab) { + if (++items.current_color>items.colors.length-1){ + items.current_color = 0 + } + items.colorSelector = items.colors[items.current_color] + }else { + if(cursor.iy<(Activity.nby-1)) { + cursor.iy++ + } + } + } + + Keys.onRightPressed: { + if(!isColorTab) { + if(cursor.ix<(Activity.nbx-1)) { + cursor.ix++ + } + } + } + + Keys.onLeftPressed: { + if(!isColorTab) { + if(cursor.ix>0) { + cursor.ix-- + } + } + } + + Keys.onSpacePressed: spawnBlock() + + Keys.onReturnPressed: spawnBlock() + + Keys.onEnterPressed: spawnBlock() + + Keys.onTabPressed:changeTab() + + function changeTab() { + isColorTab = !isColorTab + if(isColorTab) { + colorSelector.cellWidth = 60 * ApplicationInfo.ratio+20 + }else { + colorSelector.cellWidth = 60 * ApplicationInfo.ratio + } + } + + function spawnBlock() { + if(!isColorTab) { + var block = rootItem.childAt(cursor.x, cursor.y) + if(block) + block.touched() + }else { + changeTab() + } + } + + function refreshCursor() { + cursor.nbx= Activity.nbx + cursor.nby=Activity.nby + } Component.onCompleted: { activity.start.connect(start) activity.stop.connect(stop) } + + //Cursor to navigate in cells + PaintCursor { + id:cursor; + initialX: colorSelector.width + 20 * ApplicationInfo.ratio + z:1 + ix: 0 + iy: 0 + nbx: 20 + nby: 10 + color: items.colors[0] + } + + QtObject { id: items property alias background: background property alias bar: bar property alias paintModel: paintModel property var colors: bar.level < 10 ? Activity.colorsSimple : Activity.colorsAdvanced - property string colorSelector: colors[0] + property int current_color:0 + property string colorSelector: colors[current_color] property string backgroundImg: Activity.backgrounds[bar.level - 1] } - onStart: Activity.start(main, items) + onStart: Activity.start(main, items, background) onStop: Activity.stop() MultiPointTouchArea { @@ -84,7 +174,6 @@ Column { id: colorSelectorColumn spacing: 2 - anchors { left: background.left top: background.top @@ -197,6 +286,8 @@ onClicked: { activity.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav') items.colorSelector = modelData + items.current_color=items.colors.indexOf(modelData) + items.colorSelector=items.colors[items.current_color] } } } @@ -251,6 +342,7 @@ displayDialog(dialogHelpLeftRight) } onReloadClicked: Activity.initLevel() + onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: home() diff --git a/src/activities/simplepaint/simplepaint.js b/src/activities/simplepaint/simplepaint.js --- a/src/activities/simplepaint/simplepaint.js +++ b/src/activities/simplepaint/simplepaint.js @@ -131,7 +131,10 @@ var currentLevel = 0 var numberOfLevel = backgrounds.length -function start(main_, items_) { +var background + +function start(main_, items_, _background) { + background=_background main = main_ items = items_ currentLevel = 0 @@ -146,6 +149,7 @@ items.paintModel.clear() nbx = 20 + currentLevel nby = Math.floor(nbx * (main.height / main.width)) + background.refreshCursor() var model = [] for(var ix = 0; ix < nbx; ++ix) {