Warning, /education/gcompris/src/activities/fifteen/Fifteen.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - fifteen.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version)
0007  *   Bruno Coudoin <bruno.coudoin@gcompris.net> (Qt Quick port)
0008  *
0009  *   SPDX-License-Identifier: GPL-3.0-or-later
0010  */
0011 import QtQuick 2.12
0012 import QtGraphicalEffects 1.0
0013 
0014 import "../../core"
0015 import "fifteen.js" as Activity
0016 
0017 ActivityBase {
0018     id: activity
0019 
0020     onStart: focus = true
0021     onStop: {}
0022 
0023     pageComponent: Image {
0024         id: background
0025         anchors.fill: parent
0026         source: Activity.url + "background.svg"
0027         sourceSize.width: width
0028         sourceSize.height: height
0029         fillMode: Image.PreserveAspectCrop
0030 
0031         signal start
0032         signal stop
0033 
0034         Keys.onPressed: Activity.processPressedKey(event)
0035 
0036         Component.onCompleted: {
0037             activity.start.connect(start)
0038             activity.stop.connect(stop)
0039         }
0040 
0041         // Add here the QML items you need to access in javascript
0042         QtObject {
0043             id: items
0044             property Item main: activity.main
0045             property GCSfx audioEffects: activity.audioEffects
0046             property alias background: background
0047             property int currentLevel: activity.currentLevel
0048             property alias bonus: bonus
0049             property alias model: fifteenModel
0050             property string scene: bar.level < 5 ? Activity.url + "Fishing_Boat_Scene.svg" :
0051                                                    Activity.url + "Coastal_Path.svg"
0052         }
0053 
0054         onStart: { Activity.start(items) }
0055         onStop: { Activity.stop() }
0056         
0057         property int pieceSize: Math.round(blueFrame.width * 0.222)
0058 
0059         Image {
0060             id: blueFrame
0061             source: Activity.url + "blueframe.svg"
0062             sourceSize.width: Math.min(background.width,
0063                                        background.height - bar.height) * 0.95
0064             anchors.horizontalCenter: parent.horizontalCenter
0065             anchors.verticalCenter: parent.verticalCenter
0066             anchors.verticalCenterOffset: -bar.height * 0.55
0067         }
0068 
0069         Grid {
0070             id: puzzleArea
0071             anchors.horizontalCenter: blueFrame.horizontalCenter
0072             anchors.verticalCenter: blueFrame.verticalCenter
0073             columns: 4
0074             spacing: 0
0075 
0076             property alias trans: trans
0077 
0078             ListModel {
0079                 id: fifteenModel
0080             }
0081 
0082 
0083             move: Transition {
0084                 id: trans
0085                 NumberAnimation {
0086                     properties: "x, y"
0087                     easing.type: Easing.InOutQuad
0088                 }
0089             }
0090 
0091             Repeater {
0092                 id: repeater
0093                 model: fifteenModel
0094                 delegate: Item {
0095                     width: pieceSize
0096                     height: pieceSize
0097                     clip: true
0098                     property int val: value
0099 
0100                     Image {
0101                         id: image
0102                         source: value ? items.scene : ""
0103                         sourceSize.width: pieceSize * 4
0104                         fillMode: Image.Pad
0105                         transform: Translate {
0106                             x: - pieceSize * ((value - 1) % 4)
0107                             y: - pieceSize * Math.floor((value - 1) / 4)
0108                         }
0109                     }
0110 
0111                     GCText {
0112                         id: text
0113                         anchors.horizontalCenter: parent.horizontalCenter
0114                         anchors.verticalCenter: parent.verticalCenter
0115                         text: value && bar.level % 2 == 1 ? value : ""
0116                         fontSize: mediumSize
0117                         color: "#ffe9f0fb"
0118                         style: Text.Outline
0119                         styleColor: "#ff1c4788"
0120                     }
0121 
0122                     DropShadow {
0123                         anchors.fill: text
0124                         cached: false
0125                         horizontalOffset: 3
0126                         verticalOffset: 3
0127                         radius: 1
0128                         samples: 16
0129                         color: "#ff1c4788"
0130                         source: text
0131                     }
0132                 }
0133             }
0134         }
0135 
0136         MultiPointTouchArea {
0137             x: puzzleArea.x
0138             y: puzzleArea.y
0139             width: puzzleArea.width
0140             height: puzzleArea.height
0141             onPressed: checkTouchPoint(touchPoints)
0142 
0143             function checkTouchPoint(touchPoints) {
0144                 for(var i in touchPoints) {
0145                     var touch = touchPoints[i]
0146                     var block = puzzleArea.childAt(touch.x, touch.y)
0147                     if(block.val === 0)
0148                         return
0149                     else if(!puzzleArea.trans.running && block) {
0150                         Activity.onClick(block.val)
0151                         if(Activity.checkAnswer())
0152                             bonus.good('flower')
0153                         else
0154                             activity.audioEffects.play("qrc:/gcompris/src/core/resource/sounds/flip.wav")
0155                     }
0156                 }
0157             }
0158         }
0159 
0160         DialogHelp {
0161             id: dialogHelp
0162             onClose: home()
0163         }
0164 
0165         Bar {
0166             id: bar
0167             level: items.currentLevel + 1
0168             content: BarEnumContent { value: help | home | level }
0169             onHelpClicked: {
0170                 displayDialog(dialogHelp)
0171             }
0172             onPreviousLevelClicked: Activity.previousLevel()
0173             onNextLevelClicked: Activity.nextLevel()
0174             onHomeClicked: activity.home()
0175         }
0176 
0177         Bonus {
0178             id: bonus
0179             Component.onCompleted: win.connect(Activity.nextLevel)
0180         }
0181     }
0182 
0183 }