Warning, /education/gcompris/src/core/Score.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - Score.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Bruno Coudoin <bruno.coudoin@gcompris.net>
0004  *
0005  * Authors:
0006  *   Bruno Coudoin <bruno.coudoin@gcompris.net>
0007  *
0008  *   SPDX-License-Identifier: GPL-3.0-or-later
0009  */
0010 import QtQuick 2.12
0011 import GCompris 1.0
0012 
0013 /**
0014  * A QML component to visualize sub-level progress.
0015  * @ingroup components
0016  *
0017  * Score usually consists of current-level (@ref currentSubLevel)
0018  * and the max number of levels (@ref numberOfSubLevels).
0019  *
0020  * It is mainly used as a score counter, starting at 0 and increasing
0021  * directly after a good answer.
0022  *
0023  * It can in some cases be used as a sub-level counter, starting at 1.
0024  * But it should be used as sub-level counter only if the sub-level increases
0025  * regardless of if the answer is good or bad, or if there is no answer to give
0026  * to reach next sub-level. In this case, don't forget to set the variable
0027  * "isScoreCounter" to false, so it will look a bit different visually.
0028  *
0029  * For other cases an activity can also directly define the whole message
0030  * it wants to be shown (@ref message).
0031  *
0032  * @inherit QtQuick.Rectangle
0033  */
0034 Rectangle {
0035     id: score
0036 
0037     /**
0038      * type:int
0039      * Size of the font used in pt.
0040      *
0041      * @sa GCFont.fontSize.
0042      */
0043     property alias fontSize: subLevelText.fontSize
0044 
0045     /**
0046      * type:string
0047      * Define how text size is determined
0048      *
0049      * @sa GCFont.fontSizeMode.
0050      */
0051     property alias fontSizeMode: subLevelText.fontSizeMode
0052     
0053     /**
0054      * type:real
0055      * Define margins
0056      */
0057     property real margins: 30
0058     
0059     /**
0060      * type:int
0061      * Total number of sub-levels to show.
0062      *
0063      * @sa currentSubLevel
0064      */
0065     property int numberOfSubLevels
0066 
0067     /**
0068      * type:int
0069      * Current sub-level to show.
0070      *
0071      * @sa numberOfSubLevels
0072      */
0073     property int currentSubLevel
0074 
0075     /**
0076      * type:string
0077      * Complete message string to show.
0078      *
0079      * Mutually exclusive with currentSubLevel and numberOfSubLevels
0080      */
0081     property string message
0082 
0083     /**
0084      * type:bool
0085      * Wether the component is used as a score counter (true)
0086      * or something else, like a subLevel counter (false)
0087      */
0088     property bool isScoreCounter: true
0089 
0090     /**
0091      * Alias for external reference of subLevelText.
0092      */
0093     readonly property alias internalTextComponent: subLevelText
0094 
0095     /**
0096      * Emitted when the win animation should be started.
0097      *
0098      * Triggers scale and rotation animation.
0099      */
0100     signal playWinAnimation
0101     /**
0102      * Emitted when manually stopping the animation
0103      *
0104      * Resets scale and rotation.
0105      */
0106     signal stopWinAnimation
0107     /**
0108      * Emitted when the animation is finished
0109      */
0110     signal stop
0111 
0112     Connections {
0113         target: activity
0114         onStop: stopWinAnimation();
0115     }
0116 
0117     color: "#AAFFFFFF"
0118     width: subLevelText.width * 2
0119     height: subLevelText.height * 1.4
0120     radius: 10
0121     anchors.bottom: parent.bottom
0122     anchors.right: parent.right
0123     anchors.margins: margins
0124 
0125     border.color: "white"
0126     border.width: isScoreCounter ? 0 : 3 * ApplicationInfo.ratio
0127 
0128     z: 1000
0129 
0130     onCurrentSubLevelChanged: message = currentSubLevel + "/" + numberOfSubLevels
0131     onNumberOfSubLevelsChanged: message = currentSubLevel + "/" + numberOfSubLevels
0132     onPlayWinAnimation: winAnimation.start()
0133     onStopWinAnimation: {
0134         winAnimation.stop()
0135         score.scale = 1.0
0136         score.rotation = 0
0137     }
0138 
0139     readonly property bool isWinAnimationPlaying: winAnimation.running
0140 
0141     GCText {
0142         id: subLevelText
0143         anchors.centerIn: parent
0144         fontSizeMode: Text.Fit
0145         font.bold: true
0146         color: "#373737"
0147         text: message
0148     }
0149 
0150     SequentialAnimation {
0151         id: winAnimation
0152         ParallelAnimation {
0153             PropertyAnimation {
0154                 target: score
0155                 properties: "scale"
0156                 from: 1.0
0157                 to: 1.4
0158                 duration: 500
0159             }
0160             NumberAnimation {
0161                 target: score
0162                 property: "rotation"
0163                 from: -10; to: 10
0164                 duration: 750
0165                 easing.type: Easing.InOutQuad
0166             }
0167         }
0168         ParallelAnimation {
0169             PropertyAnimation {
0170                 target: score
0171                 properties: "scale"
0172                 from: 1.4
0173                 to: 1.0
0174                 duration: 500
0175             }
0176             NumberAnimation {
0177                 target: score
0178                 property: "rotation"
0179                 from: 10; to: 0
0180                 duration: 750
0181                 easing.type: Easing.InOutQuad
0182             }
0183         }
0184         onFinished: score.stop()
0185     }
0186 }