Warning, /education/gcompris/src/activities/hexagon/HexagonItem.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - Hexagon.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net> 0004 * 0005 * Authors: 0006 * Christof Petig and Ingo Konrad (GTK+ version) 0007 * Bruno Coudoin <bruno.coudoin@gcompris.net> (Qt Quick port) 0008 * Timothée Giet <animtim@gmail.com> (add mode without OpenGL) 0009 * 0010 * SPDX-License-Identifier: GPL-3.0-or-later 0011 */ 0012 import QtQuick 2.12 0013 import QtGraphicalEffects 1.0 0014 import "hexagon.js" as Activity 0015 import "../../core" 0016 import GCompris 1.0 0017 0018 Item { 0019 id: hexagon 0020 property GCSfx audioEffects 0021 property ParticleSystemStar particles 0022 property alias color: softCanvas.color 0023 property bool hasStrawberry: false 0024 property double ix 0025 property double iy 0026 property int nbx 0027 property int nby 0028 // Warning testing parent here, just to avoid an error at deletion time 0029 property double r: parent ? Math.min(parent.width / nbx / 2, (parent.height - 10) / nby / 2) : 0 0030 property double offsetX: parent ? (parent.width % (width * nbx)) / 2 : 0 0031 property double offsetY: parent ? (parent.height % (height * nby)) / 2 : 0 0032 x: (iy % 2 ? width * ix + width / 2 : width * ix) + offsetX 0033 y: height * iy - (Math.sin((Math.PI * 2) / 12) * r * 2 * iy) / 2 + offsetY 0034 width: Math.cos((Math.PI * 2) / 12) * r * 2 0035 height: r * 2 0036 0037 Image { 0038 id: strawberry 0039 anchors.fill: parent 0040 opacity: 0 0041 onSourceChanged: opacity = 1 0042 Behavior on opacity { PropertyAnimation { duration: 2000; easing.type: Easing.OutQuad } } 0043 } 0044 0045 Image { 0046 id: border 0047 anchors.fill: parent 0048 source: Activity.url + "hexagon_border.svg" 0049 Behavior on opacity { PropertyAnimation { duration: 500 } } 0050 } 0051 0052 Image { 0053 id: canvas 0054 anchors.fill: parent 0055 source: Activity.url + "hexagon.svg" 0056 visible: false 0057 } 0058 0059 Rectangle { 0060 id:softCanvas 0061 width: parent.width * 0.8 0062 height: width 0063 radius: width * 0.5 0064 anchors.centerIn: parent 0065 opacity: strawberry.opacity == 0 ? 0.65 : 0 0066 visible: ApplicationInfo.useOpenGL ? false : true 0067 } 0068 0069 ColorOverlay { 0070 id: colorOverlay 0071 anchors.fill: canvas 0072 source: canvas 0073 onOpacityChanged: if(opacity == 0) Activity.strawberryFound() 0074 color: softCanvas.color 0075 opacity: 0.65 0076 Behavior on opacity { PropertyAnimation { duration: 500 } } 0077 } 0078 0079 // Create a particle only for the strawberry 0080 Loader { 0081 id: particleLoader 0082 anchors.fill: parent 0083 active: hasStrawberry 0084 sourceComponent: particle 0085 } 0086 0087 Component { 0088 id: particle 0089 ParticleSystemStarLoader 0090 { 0091 id: particles 0092 clip: false 0093 } 0094 } 0095 0096 property bool isTouched: false 0097 function touched() { 0098 if(hasStrawberry && !isTouched) { 0099 colorOverlay.opacity = 0 0100 border.opacity = 0 0101 isTouched = true 0102 strawberry.source = Activity.url + "strawberry.svg" 0103 audioEffects.play("qrc:/gcompris/src/core/resource/sounds/win.wav") 0104 Activity.strawberryFound() 0105 particleLoader.item.burst(40) 0106 } else { 0107 hexagon.color = 0108 Activity.getColor(Activity.getDistance(hexagon.ix, hexagon.iy)) 0109 } 0110 } 0111 }