Warning, /education/gcompris/src/activities/share/CandyWidget.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - CandyWidget.qml
0002 *
0003 * SPDX-FileCopyrightText: 2016 Stefan Toncu <stefan.toncu29@gmail.com>
0004 *
0005 * SPDX-License-Identifier: GPL-3.0-or-later
0006 */
0007
0008 import QtQuick 2.12
0009 import GCompris 1.0
0010
0011 WidgetOption {
0012 id: widget
0013
0014 src: "resource/images/candy.svg"
0015 name: "candy"
0016 availableItems: (background.easyMode) ? widget.total - widget.current : ""
0017
0018 property int placedInChild
0019
0020 releaseElement: function() {
0021 var newCoordinate = widget.mapToItem(background, element.x, element.y)
0022 // Easy mode
0023 if (background.easyMode) {
0024 if (background.currentCandies < items.totalCandies) {
0025 items.acceptCandy = true
0026
0027 for (var i = 0; i < listModel.count; i++) {
0028 var currentChild = repeaterDropAreas.itemAt(i)
0029 var childCoordinate = dropAreas.mapToItem(background, currentChild.x, currentChild.y)
0030 //coordinates of "boy/girl rectangle" in background coordinates
0031
0032 var currentElement = element.parent.mapToItem(background, element.x, element.y)
0033
0034 if (currentElement.x > childCoordinate.x && currentElement.x < childCoordinate.x + currentChild.area.width &&
0035 currentElement.y > childCoordinate.y + currentChild.childImage.height &&
0036 currentElement.y < childCoordinate.y + currentChild.childImage.height + currentChild.area.height) {
0037 if ((listModel.get(i).countS + 1) > items.maxNumberOfCandiesPerWidget) {
0038 background.wrongMove.visible = true
0039 continue
0040 }
0041 repeaterDropAreas.itemAt(i).candyCount.text = listModel.get(i).countS + 1
0042 listModel.setProperty(i, "countS", listModel.get(i).countS + 1)
0043 background.currentCandies ++
0044 }
0045
0046 if (background.currentCandies == items.totalCandies) {
0047 widget.canDrag = false
0048 background.resetCandy()
0049 candyWidget.element.opacity = 0.6
0050 }
0051 }
0052 }
0053 else {
0054 widget.canDrag = false
0055 background.resetCandy()
0056 element.opacity = 0.6
0057 }
0058 }
0059 else {
0060 // Hard mode
0061 if (background.currentCandies < widget.total) {
0062 items.acceptCandy = true
0063
0064 for (i = 0; i < listModel.count; i++) {
0065 currentChild = repeaterDropAreas.itemAt(i)
0066 childCoordinate = dropAreas.mapToItem(background, currentChild.x, currentChild.y)
0067 //coordinates of "boy/girl rectangle" in background coordinates
0068 currentElement = element.parent.mapToItem(background, element.x, element.y)
0069
0070 if (currentElement.x > childCoordinate.x && currentElement.x < childCoordinate.x + currentChild.area.width &&
0071 currentElement.y > childCoordinate.y + currentChild.childImage.height &&
0072 currentElement.y < childCoordinate.y + currentChild.childImage.height + currentChild.area.height) {
0073
0074 if ((listModel.get(i).countS + 1) > items.maxNumberOfCandiesPerWidget) {
0075 background.wrongMove.visible = true
0076 continue
0077 }
0078
0079 repeaterDropAreas.itemAt(i).candyCount.text = listModel.get(i).countS + 1
0080 listModel.setProperty(i, "countS", listModel.get(i).countS + 1)
0081 background.currentCandies ++
0082 }
0083
0084 if (background.currentCandies === items.totalCandies) {
0085 widget.canDrag = false
0086 background.resetCandy()
0087 candyWidget.element.opacity = 0.6
0088 }
0089 }
0090 }
0091 else {
0092 widget.canDrag = false
0093 background.resetCandy()
0094 candyWidget.element.opacity = 0.6
0095 }
0096 }
0097 }
0098
0099 //swing animation for candies
0100 SequentialAnimation {
0101 id: anim
0102 running: items.acceptCandy ? true : false
0103 loops: Animation.Infinite
0104 NumberAnimation {
0105 target: candyWidget.element
0106 property: "rotation"
0107 from: -10; to: 10
0108 duration: 700
0109 easing.type: Easing.InOutQuad
0110 }
0111 NumberAnimation {
0112 target: candyWidget.element
0113 property: "rotation"
0114 from: 10; to: -10
0115 duration: 700
0116 easing.type: Easing.InOutQuad
0117 }
0118 }
0119
0120 }