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

0001 /* GCompris - OperationRow.qml
0002  *
0003  * SPDX-FileCopyrightText: 2016 RAHUL YADAV <rahulyadav170923@gmail.com>
0004  *
0005  * Authors:
0006  *   Pascal Georges <pascal.georges1@free.fr> (GTK+ version)
0007  *   RAHUL YADAV <rahulyadav170923@gmail.com> (Qt Quick port)
0008  *
0009  *   SPDX-License-Identifier: GPL-3.0-or-later
0010  */
0011 
0012 import QtQuick 2.12
0013 import "../../core"
0014 import "guesscount.js" as Activity
0015 
0016 Row {
0017     id: operandRow
0018     spacing: 20
0019     property alias endResult: endResult
0020     property int rowResult
0021     property int noOfRows
0022     property int rowNo
0023     property int guesscount
0024     property bool complete
0025     property bool prevComplete
0026     property bool reparent
0027     property var prevText: ""
0028     property string text: endResult.text
0029     Component {
0030         id: component1
0031         DropTile {
0032             id: operand1
0033             type: "operands"
0034             width: operandRow.width*0.1
0035             height: operandRow.height
0036             droppedItem: operand1.children[count]
0037             property int count: 0
0038             onChildrenChanged: {
0039                 Activity.childrenChange(operand1, operandRow)
0040                 if(operand1.count == 1 && operator.count == 1 && operand2.count == 1) {
0041                     Activity.calculate(operand1.droppedItem.datavalue, operator.droppedItem.datavalue, operand2.droppedItem.datavalue, operandRow)
0042                     if(!items.solved && operandRow.rowNo == operandRow.noOfRows-1 && operandRow.rowResult == operandRow.guesscount) {
0043                         items.solved = true
0044                         Activity.goodAnswer()
0045                     }
0046                 }
0047 
0048             }
0049         }
0050     }
0051     Component {
0052         id:component2
0053         Rectangle {
0054             id: prevResult
0055             width: operandRow.width*0.1
0056             height: operandRow.height
0057             color: "orange"   //orange
0058             radius: 10
0059             Rectangle {
0060                 width: parent.width - anchors.margins
0061                 height: parent.height - anchors.margins
0062                 anchors.verticalCenter: parent.verticalCenter
0063                 anchors.horizontalCenter: parent.horizontalCenter
0064                 anchors.margins: parent.height/4
0065                 radius: 10
0066                 color: "#E8E8E8" //paper white
0067             }
0068             property alias droppedItem: tile
0069             property int count: operandRow.prevComplete ? 1 : 0
0070             GCText {
0071                 id: tile
0072                 property int datavalue: Number(tile.text)
0073                 anchors.horizontalCenter: parent.horizontalCenter
0074                 anchors.verticalCenter: parent.verticalCenter
0075                 fontSize: mediumSize
0076                 text: prevText
0077             }
0078         }
0079     }
0080 
0081     Loader {
0082         id: loader
0083         sourceComponent: rowNo ? component2 : component1
0084     }
0085 
0086     DropTile {
0087         id: operator
0088         type : "operators"
0089         width: operandRow.width*0.1
0090         height: operandRow.height
0091         property int count: 0
0092         droppedItem: operator.children[count]
0093         onChildrenChanged: {
0094             Activity.childrenChange(operator, operandRow)
0095             if(loader.children[0].count == 1 && operator.count == 1 && operand2.count == 1) {
0096                 Activity.calculate(loader.children[0].droppedItem.datavalue, operator.droppedItem.datavalue, operand2.droppedItem.datavalue, operandRow)
0097                 if(!items.solved && operandRow.rowNo == operandRow.noOfRows-1 && operandRow.rowResult == operandRow.guesscount) {
0098                     items.solved = true
0099                     Activity.goodAnswer()
0100                 }
0101             }
0102         }
0103     }
0104     DropTile {
0105         id: operand2
0106         type: "operands"
0107         width: operandRow.width*0.1
0108         height: operandRow.height
0109         property int count: 0
0110         droppedItem: operand2.children[count]
0111         onChildrenChanged: {
0112             Activity.childrenChange(operand2, operandRow)
0113             if(loader.children[0].count == 1 && operator.count == 1 && operand2.count == 1) {
0114                 Activity.calculate(loader.children[0].droppedItem.datavalue, operator.droppedItem.datavalue, operand2.droppedItem.datavalue, operandRow)
0115                 operandRow.complete = true
0116                 if(!items.solved && operandRow.rowNo == operandRow.noOfRows-1 && operandRow.rowResult == operandRow.guesscount) {
0117                     items.solved = true
0118                     Activity.goodAnswer()
0119                 }
0120             }
0121         }
0122     }
0123 
0124     Rectangle {
0125         width: operandRow.width*0.1
0126         height: operandRow.height
0127         color: "transparent"
0128         radius: 10
0129         Rectangle {
0130         width: parent.width * 0.8
0131         height: parent.height * 0.8
0132         anchors.verticalCenter: parent.verticalCenter
0133         anchors.horizontalCenter: parent.horizontalCenter
0134         radius: 10
0135         color: "#1B8BD2"  //blue
0136             Rectangle {
0137                 width: parent.width - anchors.margins
0138                 height: parent.height - anchors.margins
0139                 anchors.verticalCenter: parent.verticalCenter
0140                 anchors.horizontalCenter: parent.horizontalCenter
0141                 anchors.margins: parent.height/4
0142                 radius: 10
0143                 color: "#E8E8E8" //paper white
0144             }
0145         }
0146         GCText {
0147             anchors.horizontalCenter: parent.horizontalCenter
0148             anchors.verticalCenter: parent.verticalCenter
0149             text: "="
0150             fontSize: mediumSize
0151         }
0152     }
0153 
0154     Rectangle {
0155         width: operandRow.width*0.1
0156         height: operandRow.height
0157         color: "orange"   //orange
0158         radius: 10
0159         Rectangle {
0160             width: parent.width - anchors.margins
0161             height: parent.height - anchors.margins
0162             anchors.verticalCenter: parent.verticalCenter
0163             anchors.horizontalCenter: parent.horizontalCenter
0164             anchors.margins: parent.height/4
0165             radius: 10
0166             color: "#E8E8E8" //paper white
0167         }
0168         GCText {
0169             id: endResult
0170             anchors.horizontalCenter: parent.horizontalCenter
0171             anchors.verticalCenter: parent.verticalCenter
0172             fontSize: mediumSize
0173             text: ""
0174         }
0175     }
0176 
0177     onPrevTextChanged: {
0178         if(items.solved) {
0179             return
0180         }
0181         if(!prevComplete) {
0182             endResult.text = ""
0183             operandRow.complete = false
0184         }
0185         else {
0186             if(operator.count == 1 && operand2.count == 1) {
0187                 Activity.calculate(parseInt(prevText), operator.droppedItem.datavalue, operand2.droppedItem.datavalue, operandRow)
0188                 operandRow.complete = true
0189                 if(operandRow.rowNo == operandRow.noOfRows-1 && operandRow.rowResult == operandRow.guesscount) {
0190                     items.solved = true
0191                     Activity.goodAnswer()
0192                 }
0193             }
0194         }
0195     }
0196     onReparentChanged: {
0197         if(operandRow.reparent) {
0198             if(loader.children[0]) {
0199                 if(loader.children[0].count != 0 && rowNo == 0) {
0200                     loader.children[0].droppedItem.parent = loader.children[0].droppedItem.reparent
0201                 }
0202             }
0203             if(operator.count != 0) {
0204                 operator.droppedItem.destroy()
0205             }
0206             if(operand2.count != 0) {
0207                 operand2.droppedItem.parent = operand2.droppedItem.reparent
0208             }
0209         }
0210     }
0211 }