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

0001 /* GCompris - tangram.qml
0002  *
0003  * SPDX-FileCopyrightText: 2016 Bruno Coudoin <bruno.coudoin@gcompris.net>
0004  *
0005  * Authors:
0006  *   Yves Combe / Philippe Banwarth (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 import GCompris 1.0
0014 
0015 import "../../core"
0016 import "tangram.js" as Activity
0017 
0018 MouseArea {
0019     id: rotateArea
0020     anchors.fill: parent
0021     enabled: items.selectedItem && items.selectedItem.selected && items.selectedItem.rotable
0022     property double prevRotation: 0
0023     onPositionChanged: {
0024         var backPoint = background.mapFromItem(parent, mouseX, mouseY)
0025         // Calc the angle touch / object center
0026         var rotation = Activity.getAngleOfLineBetweenTwoPoints(
0027                     items.selectedItem.x + items.selectedItem.width / 2, items.selectedItem.y +
0028                     items.selectedItem.height / 2,
0029                     backPoint.x, backPoint.y) * (180 / Math.PI)
0030         if(prevRotation) {
0031             items.selectedItem.rotation += rotation - prevRotation
0032         }
0033         prevRotation = rotation
0034     }
0035     onReleased: {
0036         prevRotation = 0
0037         // Force a modulo 45 rotation
0038         items.selectedItem.rotation = Math.floor((items.selectedItem.rotation + 45 / 2) / 45) * 45
0039         items.selectedItem.selected = false
0040         background.checkWin()
0041     }
0042 }