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

0001 /* GCompris - Domino.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 display a domino.
0015  *
0016  * Domino consists of Flipable sides(front and back)
0017  * and uses DominoNumber to display numbers.
0018  * It is divided into two regions containing DominoNumbers.
0019  *
0020  * @inherit QtQuick.Flipable
0021  */
0022 Flipable {
0023     id: flipable
0024 
0025     /**
0026      * type:int
0027      * Integer displayed in first region.
0028      */
0029     property alias value1: number1.value
0030 
0031     /**
0032      * type:int
0033      * Integer displayed in second region.
0034      */
0035     property alias value2: number2.value
0036 
0037     /**
0038      * type:int
0039      * Highest integer to display.
0040      */
0041     property int valueMax: 9
0042 
0043     // Domino style
0044     property color color: "#f8f8f8"
0045     property color borderColor: "#373737"
0046     property int borderWidth: 2
0047     property int radius: width * 0.05
0048     property color backColor: "#f8f8f8"
0049     property color pointColor: "#373737"
0050 
0051     // Define the mode/representation of domino
0052     property string mode: "dot"
0053 
0054     // menu modes for setting different types for domino
0055     readonly property var menuModes : [
0056         //: "Dots" is for representation of the points in a domino in the form of dots
0057         { "text": qsTr("Dots"), "value": "dot" },
0058         //: "Arabic Numbers" is for representation of the points in a domino in the form of integer numbers
0059         { "text": qsTr("Arabic Numbers"), "value": "number" },
0060         //: "Roman Numbers" is for representation of the points in a domino  in the form of roman numbers
0061         { "text": qsTr("Roman Numbers"), "value": "roman" },
0062         //: "Images" is for representation of the points in a domino in the form of an image (containing a specific count of same elements)
0063         { "text": qsTr("Images"), "value": "image" }
0064     ]
0065 
0066     // Set to true when to display on both sides.
0067     property bool flipEnabled: false
0068 
0069     property bool flipped: true
0070 
0071     // Set to false to prevent user inputs.
0072     property bool isClickable: true
0073     property GCSfx audioEffects
0074 
0075     front: Rectangle {
0076         anchors.fill: parent
0077         smooth: true;
0078         color: flipable.color
0079         border.color: flipable.borderColor
0080         border.width: flipable.borderWidth
0081         radius: flipable.radius
0082 
0083         DominoNumber {
0084             id: number1
0085             mode: flipable.mode
0086             width: parent.width / 2
0087             height: parent.height
0088             color: flipable.pointColor
0089             borderColor: flipable.borderColor
0090             borderWidth: 0
0091             radius: parent.height * 0.25
0092             valueMax: flipable.valueMax
0093             onValueChanged: if(flipEnabled) flipable.flipped = !flipable.flipped
0094             isClickable: flipable.isClickable
0095             audioEffects: flipable.audioEffects
0096         }
0097 
0098         // Separation
0099         Rectangle {
0100             x: front.width / 2
0101             anchors.verticalCenter: front.verticalCenter
0102             width: 2
0103             height: front.height * 0.7
0104             color: flipable.borderColor
0105         }
0106 
0107         DominoNumber {
0108             id: number2
0109             mode: flipable.mode
0110             x: parent.width / 2
0111             width: parent.width / 2
0112             height: parent.height
0113             color: flipable.pointColor
0114             borderColor: flipable.borderColor
0115             borderWidth: 0
0116             radius: parent.height * 0.25
0117             valueMax: flipable.valueMax
0118             onValueChanged: if(flipEnabled) flipable.flipped = !flipable.flipped
0119             isClickable: flipable.isClickable
0120             audioEffects: flipable.audioEffects
0121         }
0122     }
0123 
0124     back: Rectangle {
0125         anchors.fill: parent
0126         smooth: true;
0127         color: flipable.backColor
0128         border.width: flipable.borderWidth
0129         radius: flipable.radius
0130     }
0131 
0132     transform: Rotation {
0133         id: rotation
0134         origin.x: flipable.width/2
0135         origin.y: flipable.height/2
0136         axis.x: 0; axis.y: 1; axis.z: 0     // set axis.y to 1 to rotate around y-axis
0137         angle: 0    // the default angle
0138     }
0139 
0140     states: State {
0141         name: "back"
0142         PropertyChanges { target: rotation; angle: 180 }
0143         when: flipable.flipped
0144         onCompleted: flipable.flipped = false
0145     }
0146 
0147     transitions: Transition {
0148         NumberAnimation { target: rotation; property: "angle"; duration: 250 }
0149     }
0150 }