diff --git a/src/activities/babymatch/DragListItem.qml b/src/activities/babymatch/DragListItem.qml index ee794e1fa..6e5119101 100644 --- a/src/activities/babymatch/DragListItem.qml +++ b/src/activities/babymatch/DragListItem.qml @@ -1,271 +1,270 @@ /* gcompris - DragListItem.qml Copyright (C) 2003, 2014: Bruno Coudoin: initial version 2015: Pulkit Gupta: Qt port This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, see . */ import QtQuick 2.1 -import QtQuick.Controls 1.1 import QtGraphicalEffects 1.0 import GCompris 1.0 import "babymatch.js" as Activity Item { id: item width: tile.width height: tile.height property double heightInColumn property double widthInColumn property double tileWidth property double tileHeight property string imageName: imgName property alias tileImageGlow: tileImageGlow property QtObject answer: tileImage.parent property bool isInList: tileImage.parent == tile ParallelAnimation { id: tileImageAnimation NumberAnimation { target: tileImage easing.type: Easing.OutQuad property: "x" to: tileImage.moveImageX duration: 430 } NumberAnimation { target: tileImage easing.type: Easing.OutQuad property: "y" to: tileImage.moveImageY duration: 430 } onStarted: { tileImage.anchors.centerIn = undefined if(view.showGlow) view.showGlow = false } onStopped: { tileImage.parent = tileImage.tileImageParent tileImage.anchors.centerIn = tileImage.parent view.itemsDropped = view.itemsDropped + tileImage.dropNo if(view.itemsDropped == mymodel.count) { showOk.start() view.okShowed = true } else if(view.okShowed) { hideOk.start() view.okShowed = false } if(!view.okShowed && tileImage.dropNo == 1) view.checkDisplayedGroup() if(!view.okShowed && tileImage.dropNo == -1) { view.displayedGroup[parseInt(index/view.nbItemsByGroup)] = true view.setPreviousNavigation() view.setNextNavigation() } } } Rectangle { id: tile width: tileWidth height: tileHeight color: "transparent" border.color: "transparent" border.width: 2 radius: 2 property double xCenter: tile.x + tile.width/2 property double yCenter: tile.y + tile.height/2 property bool colorChange: true Image { id: tileImage anchors.centerIn: parent height: Activity.glowEnabled ? heightInColumn * 1.1 : heightInColumn width: Activity.glowEnabled ? widthInColumn * 1.1 : widthInColumn fillMode: Image.PreserveAspectFit source: Activity.url + imgName property QtObject dragTarget property QtObject tileImageParent property double moveImageX property double moveImageY property int dropNo property bool dropping: false function imageRemove() { if(backgroundImage.source == "") leftContainer.z = 1 tileImage.state = "INITIAL" var coord = tileImage.parent.mapFromItem(tile, tile.xCenter - tileImage.width/2, tile.yCenter - tileImage.height/2) tileImage.moveImageX = coord.x tileImage.moveImageY = coord.y tileImage.tileImageParent = tile tileImage.dragTarget = null tile.colorChange = true if(tileImage.parent != tile) tileImage.dropNo = -1 else tileImage.dropNo = 0 tileImageAnimation.start() } MouseArea { id: mouseArea width: parent.width; height: parent.height anchors.fill: parent drag.target: parent hoverEnabled: true onEntered: { if(tile.colorChange) { tile.color = "#FF294D" tile.border.color = "white" } if(toolTipText != "") { toolTip.text = toolTipText toolTip.visible = true } } onExited: { if(!pressed) { tile.color = "transparent" tile.border.color = "transparent" toolTip.visible = false } } onPressed: { if(tileImage.parent == tile) leftContainer.z = 3 else leftContainer.z = 1 //activity.audioEffects.stop() //activity.audioEffects.play(pressSound) tileImage.anchors.centerIn = undefined if (tileImage.dragTarget != null) { tileImage.dragTarget.parent.dropCircleColor = "pink" tileImage.dragTarget.dragSource = null } } onReleased: { tile.color = "transparent" tile.border.color = "transparent" //activity.audioEffects.stop() //activity.audioEffects.play("qrc:/gcompris/src/activities/babymatch/resource/sound/drop.wav") if(tileImage.Drag.target === null) tileImage.imageRemove() else { tileImage.dragTarget = tileImage.Drag.target tileImage.state = "DROPPED" tile.colorChange = false tileImage.dropping = true var coord = tileImage.parent.mapFromItem(backgroundImage, tileImage.Drag.target.xCenter - tileImage.width/2, tileImage.Drag.target.yCenter - tileImage.height/2) tileImage.moveImageX = coord.x tileImage.moveImageY = coord.y tileImage.Drag.target.dropped(tileImage.Drag) // Emit signal manually if(tileImage.parent == tile) tileImage.dropNo = 1 else tileImage.dropNo = 0 tileImage.tileImageParent = tileImage.Drag.target tileImageAnimation.start() } } } Drag.active: mouseArea.drag.active Drag.hotSpot.x: tileImage.width/2 Drag.hotSpot.y: tileImage.height/2 states: [ State { name: "INITIAL" PropertyChanges { target: tileImage height: Activity.glowEnabled ? heightInColumn * 1.1 : heightInColumn width: Activity.glowEnabled ? widthInColumn * 1.1 : widthInColumn } }, State { name: "DROPPED" PropertyChanges { target: tileImage height: imgHeight ? imgHeight * backgroundImage.height : (backgroundImage.source == "" ? backgroundImage.height * tileImage.sourceSize.height/backgroundImage.height : backgroundImage.height * tileImage.sourceSize.height/backgroundImage.sourceSize.height) width: imgWidth ? imgWidth * backgroundImage.width : (backgroundImage.source == "" ? backgroundImage.width * tileImage.sourceSize.width/backgroundImage.width : backgroundImage.width * tileImage.sourceSize.width/backgroundImage.sourceSize.width) } } ] Image { id: wrongAnswer anchors.centerIn: parent height: heightInColumn * 0.3 width: widthInColumn * 0.3 fillMode: Image.PreserveAspectFit source:"qrc:/gcompris/src/activities/babymatch/resource/error.svg" visible: view.showGlow && tileImageGlow.setColor == "red" } } Glow { id: tileImageBorder parent: tileImage.parent anchors.fill: tileImage radius: 0.7 samples: 2 color: view.showGlow && Activity.glowEnabled ? "black" : "transparent" source: tileImage spread: 1.0 } Glow { id: tileImageGlow property string setColor: "transparent" parent: tileImage.parent anchors.fill: tileImage radius: view.showGlow && Activity.glowEnabled ? 9 : 0 samples: 18 color: view.showGlow && Activity.glowEnabled ? setColor : "transparent" source: tileImage spread: 0.95 } } } diff --git a/src/activities/gletters/Gletters.qml b/src/activities/gletters/Gletters.qml index c861991cb..0f0961666 100644 --- a/src/activities/gletters/Gletters.qml +++ b/src/activities/gletters/Gletters.qml @@ -1,273 +1,272 @@ /* GCompris - gletters.qml * * Copyright (C) 2014 Holger Kaelberer * * Authors: * Bruno Coudoin (GTK+ version) * Holger Kaelberer (Qt Quick port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.1 -import QtQuick.Controls 1.0 import GCompris 1.0 import "../../core" import "gletters.js" as Activity ActivityBase { id: activity // Overload this in your activity to change it // Put you default-.json files in it property string dataSetUrl: "qrc:/gcompris/src/activities/gletters/resource/" property bool uppercaseOnly: false; // FIXME: this should go in activity settings /* mode of the activity, "letter" (gletters) or "word" (wordsgame):*/ property string mode: "letter" // Override if you want to replace texts by your image function getImage(key) { return "" } // Override if you want to replace texts by the domino function getDominoValues(key) { return [] } onStart: focus = true onStop: {} // When going on configuration, it steals the focus and re set it to the activity. // We need to set it back to the textinput item in order to have key events. onFocusChanged: { if(focus) { Activity.focusTextInput() } } pageComponent: Image { id: background source: activity.dataSetUrl + "background.svg" fillMode: Image.PreserveAspectCrop sourceSize.width: parent.width signal start signal stop // system locale by default property string locale: "system" Component.onCompleted: { dialogActivityConfig.getInitialConfiguration() activity.start.connect(start) activity.stop.connect(stop) } QtObject { id: items property Item main: activity.main property Item ourActivity: activity property GCAudio audioVoices: activity.audioVoices property alias background: background property alias bar: bar property alias bonus: bonus property alias wordlist: wordlist property alias score: score property alias keyboard: keyboard property alias wordDropTimer: wordDropTimer property GCAudio audioEffects: activity.audioEffects property alias locale: background.locale property alias textinput: textinput } onStart: { Activity.start(items, uppercaseOnly, mode); Activity.focusTextInput() } onStop: { Activity.stop() } TextInput { // Helper element to capture composed key events like french รด which // are not available via Keys.onPressed() on linux. Must be // disabled on mobile! id: textinput anchors.centerIn: background enabled: !ApplicationInfo.isMobile focus: true visible: false onTextChanged: { if (text != "") { Activity.processKeyPress(text); text = ""; } } } DialogActivityConfig { id: dialogActivityConfig currentActivity: activity content: Component { Item { property alias localeBox: localeBox height: column.height property alias availableLangs: langs.languages LanguageList { id: langs } Column { id: column spacing: 10 width: parent.width Flow { spacing: 5 width: dialogActivityConfig.width GCComboBox { id: localeBox model: langs.languages background: dialogActivityConfig width: 250 * ApplicationInfo.ratio label: qsTr("Select your locale") } } /* TODO handle this: GCDialogCheckBox { id: uppercaseBox width: 250 * ApplicationInfo.ratio text: qsTr("Uppercase only mode") checked: true onCheckedChanged: { print("uppercase changed") } } */ } } } onClose: home() onLoadData: { if(dataToSave && dataToSave["locale"]) { background.locale = dataToSave["locale"]; } } onSaveData: { var oldLocale = background.locale; var newLocale = dialogActivityConfig.configItem.availableLangs[dialogActivityConfig.loader.item.localeBox.currentIndex].locale; // Remove .UTF-8 if(newLocale.indexOf('.') != -1) { newLocale = newLocale.substring(0, newLocale.indexOf('.')) } dataToSave = {"locale": newLocale} background.locale = newLocale; // Restart the activity with new information if(oldLocale !== newLocale) { background.stop(); background.start(); } } function setDefaultValues() { var localeUtf8 = background.locale; if(background.locale != "system") { localeUtf8 += ".UTF-8"; } for(var i = 0 ; i < dialogActivityConfig.configItem.availableLangs.length ; i ++) { if(dialogActivityConfig.configItem.availableLangs[i].locale === localeUtf8) { dialogActivityConfig.loader.item.localeBox.currentIndex = i; break; } } } } DialogHelp { id: dialogHelp onClose: home() } Bar { id: bar anchors.bottom: keyboard.top content: BarEnumContent { value: help | home | level | config } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onConfigClicked: { dialogActivityConfig.active = true dialogActivityConfig.setDefaultValues() displayDialog(dialogActivityConfig) } } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextLevel) } Score { id: score anchors.top: undefined anchors.topMargin: 10 * ApplicationInfo.ratio anchors.right: parent.right anchors.rightMargin: 10 * ApplicationInfo.ratio anchors.bottom: keyboard.top } VirtualKeyboard { id: keyboard anchors.bottom: parent.bottom anchors.horizontalCenter: parent.horizontalCenter width: parent.width onKeypress: Activity.processKeyPress(text) onError: console.log("VirtualKeyboard error: " + msg); } Wordlist { id: wordlist defaultFilename: activity.dataSetUrl + "default-en.json" // To switch between locales: xx_XX stored in configuration and // possibly correct xx if available (ie fr_FR for french but dataset is fr.) useDefault: false filename: "" onError: console.log("Gletters: Wordlist error: " + msg); } Timer { id: wordDropTimer repeat: false onTriggered: Activity.dropWord(); } } } diff --git a/src/activities/traffic/Traffic.qml b/src/activities/traffic/Traffic.qml index 6b11b8b62..bb8004247 100644 --- a/src/activities/traffic/Traffic.qml +++ b/src/activities/traffic/Traffic.qml @@ -1,195 +1,194 @@ /* GCompris - Traffic.qml * * Copyright (C) 2014 Holger Kaelberer * * Authors: * Bruno Coudoin (GTK+ version) * Holger Kaelberer (Qt Quick port) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, see . */ import QtQuick 2.1 -import QtQuick.Controls 1.0 import GCompris 1.0 import "../../core" import "traffic.js" as Activity ActivityBase { id: activity onStart: focus = true onStop: {} pageComponent: Image { id: background source: "qrc:/gcompris/src/activities/traffic/resource/traffic_bg.svg" sourceSize.width: parent.width fillMode: Image.PreserveAspectCrop signal start signal stop property string mode: "IMAGE" // allow to choose between "COLOR" and "IMAGE" // mode, candidate for a config dialog Component.onCompleted: { dialogActivityConfig.getInitialConfiguration() activity.start.connect(start) activity.stop.connect(stop) } QtObject { id: items property Item main: activity.main property GCAudio audioEffects: activity.audioEffects property alias background: background property alias bar: bar property alias bonus: bonus property alias score: score property alias jamBox: jamBox property alias jamGrid: jamGrid } onStart: { Activity.start(items, mode) } onStop: { Activity.stop() } Image { id: jamBox source: "qrc:/gcompris/src/activities/traffic/resource/traffic_box.svg" anchors.centerIn: parent sourceSize.width: Math.max(400, background.width * 0.4175 * ApplicationInfo.ratio) //334 sourceSize.height: Math.max(400, background.height * 0.636538462 * ApplicationInfo.ratio) //331 fillMode: Image.PreserveAspectFit property double scaleFactor: Math.min(background.width / background.sourceSize.width, background.height / background.sourceSize.height) Grid { id: jamGrid anchors.centerIn: parent width: parent.width - 86 * jamBox.scaleFactor * ApplicationInfo.ratio height: parent.height - 86 * jamBox.scaleFactor * ApplicationInfo.ratio columns: 6 rows: 6 spacing: 0 // Add an alias to mode so it can be used on Car items property alias mode: background.mode Repeater { id: gridRepeater model: jamGrid.columns * jamGrid.rows delegate: Rectangle { id: gridDelegate height: jamGrid.height/ jamGrid.rows width: height border.width: 1 border.color: "white" color: "#444444" } } } } DialogHelp { id: dialogHelp onClose: home() } DialogActivityConfig { id: dialogActivityConfig currentActivity: activity content: Component { Item { property alias modeBox: modeBox property var availableModes: [ { "text": qsTr("Colors"), "value": "COLOR" }, { "text": qsTr("Images"), "value": "IMAGE" } ] Flow { id: flow spacing: 5 width: dialogActivityConfig.width GCComboBox { id: modeBox model: availableModes width: 250 * ApplicationInfo.ratio background: dialogActivityConfig label: qsTr("Select your mode") } } } } onClose: home() onLoadData: { if(dataToSave && dataToSave["mode"]) { mode = dataToSave["mode"]; Activity.mode = dataToSave["mode"]; } } onSaveData: { mode = dialogActivityConfig.configItem.availableModes[dialogActivityConfig.configItem.modeBox.currentIndex].value; dataToSave = {"mode": mode} Activity.mode = mode; } function setDefaultValues() { for(var i = 0 ; i < dialogActivityConfig.configItem.availableModes.length ; i ++) { if(dialogActivityConfig.configItem.availableModes[i].value === mode) { dialogActivityConfig.configItem.modeBox.currentIndex = i; break; } } } } Bar { id: bar content: BarEnumContent { value: help | home | level | reload | config } onHelpClicked: { displayDialog(dialogHelp) } onPreviousLevelClicked: Activity.previousLevel() onNextLevelClicked: Activity.nextLevel() onHomeClicked: activity.home() onReloadClicked: Activity.initLevel() onConfigClicked: { dialogActivityConfig.active = true // Set default values dialogActivityConfig.setDefaultValues(); displayDialog(dialogActivityConfig) } } Bonus { id: bonus Component.onCompleted: win.connect(Activity.nextSubLevel) } Score { id: score anchors.top: parent.top anchors.topMargin: 10 * ApplicationInfo.ratio anchors.right: parent.right anchors.rightMargin: 10 * ApplicationInfo.ratio anchors.bottom: undefined } } }