Warning, /education/gcompris/src/activities/grammar_analysis/GrammarToken.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - GrammarToken.qml 0002 * 0003 * Copyright (C) 2022-2023 Bruno ANSELME <be.root@free.fr> 0004 * 0005 * Authors: 0006 * Bruno ANSELME <be.root@free.fr> (Qt Quick native) 0007 * Timothée Giet <animtim@gmail.com> (Graphics and layout refactoring) 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 import QtQuick 2.12 0012 0013 import GCompris 1.0 0014 import "../../core" 0015 import "grammar_analysis.js" as Activity 0016 0017 // A GrammarToken item display a symbolic image for grammatical classes and the full class name below 0018 Rectangle { 0019 id: token 0020 property string classCode: "" // Grammatical class code (nou, vrb etc...) 0021 property string className: "" // Grammatical class full name (Noun, Verb etc...) 0022 property string svgName: "" // Grammatical class svg image 0023 property alias imgSvg: imgSvg 0024 width: 1 0025 height: 1 0026 radius: background.baseRadius 0027 color: (items.selectedClass === index) ? background.selectionColor : "transparent" 0028 0029 Image { // Display class image 0030 id: imgSvg 0031 width: height 0032 height: parent.height - txtClass.height - 2 * ApplicationInfo.ratio 0033 sourceSize.width: height 0034 sourceSize.height: height 0035 x: (parent.width - width) / 2 // x, y are not anchored to be moved by transition 0036 y: ApplicationInfo.ratio 0037 source: (svgName == "") ? "" : svgName 0038 states: [ 0039 State { 0040 name: "moveto" 0041 PropertyChanges { 0042 target: imgSvg 0043 x: { 0044 var pos = items.boxIndexes[items.selectedBox].split('-') 0045 return mapFromItem(items.wordsFlow.children[pos[0]].rowWords.children[pos[1]].imgSvg, 0, 0).x 0046 } 0047 y: { 0048 var pos = items.boxIndexes[items.selectedBox].split('-') 0049 return mapFromItem(items.wordsFlow.children[pos[0]].rowWords.children[pos[1]].imgSvg, 0, 0).y 0050 } 0051 } 0052 } 0053 ] 0054 0055 transitions: [ 0056 Transition { 0057 to: "moveto" 0058 reversible: false 0059 SequentialAnimation { 0060 alwaysRunToEnd: true 0061 NumberAnimation { properties: "x,y"; duration: 250 } 0062 ScriptAction { script: { imgSvg.state = "" } } 0063 } 0064 } 0065 ] 0066 } 0067 GCText { // Display class name 0068 id: txtClass 0069 width: parent.width 0070 height: parent.height * 0.3 0071 fontSize: smallSize 0072 minimumPointSize: tinySize * ApplicationInfo.fontRatio 0073 fontSizeMode: Text.Fit 0074 text: className 0075 horizontalAlignment: Text.AlignHCenter 0076 verticalAlignment: Text.AlignVCenter 0077 anchors.bottom: parent.bottom 0078 anchors.horizontalCenter: parent.horizontalCenter 0079 wrapMode: Text.Wrap 0080 } 0081 0082 SwingAnimation { 0083 running: (items.keysOnTokens) && (items.selectedClass === index) 0084 amplitude: 4 0085 loops: 1 0086 target: token 0087 } 0088 0089 MouseArea { 0090 anchors.fill: parent 0091 onClicked: { 0092 if (Activity.animRunning) return // No click or key during animation 0093 items.selectedClass = index 0094 items.keysOnTokens = true 0095 } 0096 } 0097 0098 }