Warning, /education/gcompris/src/activities/gnumch-equality/Warning.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - Warning.qml
0002 *
0003 * SPDX-FileCopyrightText: 2014 Manuel Tondeur <manueltondeur@gmail.com>
0004 *
0005 * Authors:
0006 *   Joe Neeman (spuzzzzzzz@gmail.com) (GTK+ version)
0007 *   Manuel Tondeur <manueltondeur@gmail.com> (Qt Quick port)
0008 *
0009 *   SPDX-License-Identifier: GPL-3.0-or-later
0010 */
0011 import QtQuick 2.12
0012 import GCompris 1.0
0013 
0014 import "../../core"
0015 import "gnumch-equality.js" as Activity
0016 
0017 Rectangle {
0018     function hideWarning() {
0019         if (opacity > 0) {
0020             opacity = 0;
0021             monsters.destroyAll();
0022             if(topPanel.life.opacity == 1) {
0023                 topPanel.life.opacity = 0
0024                 if(background.withMonsters) {
0025                     spawningMonsters.restart()
0026                 }
0027             }
0028             else
0029                 background.initLevel()
0030         }
0031     }
0032 
0033     property string warningText: warning.text
0034     property string fault
0035     property var mArea: area
0036 
0037     function setFault(index) {
0038         if (index === -1) {
0039             fault = qsTr("You were eaten by a Troggle.") + "<br>"
0040             return
0041         }
0042 
0043         fault = qsTr("You ate a wrong number.") +"<br>"
0044         var num1 = modelCells.get(index).number1
0045         var num2 = modelCells.get(index).number2
0046         if (activity.type == "equality" || activity.type == "inequality") {
0047             if (Activity.operator == " + ") {
0048                 fault +=  num1 + " + " + num2 + " = " + (num1 + num2)
0049             } else if (Activity.operator == " - ") {
0050                 fault +=  num1 + " - " + num2 + " = " + (num1 - num2)
0051             } else if (Activity.operator == " * ") {
0052                 fault +=  num1 + " * " + num2 + " = " + (num1 * num2)
0053             } else if (Activity.operator == " / ") {
0054                 fault +=  num1 + " / " + num2 + " = " + (num1 / num2)
0055             }
0056             fault += "<br>"
0057 
0058         } else if (activity.type == "primes") {
0059             if (num1 === 1) {
0060                 fault += qsTr("1 is not a prime number.") + "<br>"
0061                 return
0062             }
0063 
0064             var divisors = []
0065             for (var div = 2; div < num1; ++div) {
0066                 if ((num1 / div) % 1 == 0)
0067                     divisors.push(div)
0068             }
0069             var divisorString = "<ul>"
0070             for (var div = 0; div < divisors.length; ++div) {
0071                 divisorString += "<li>" + divisors[div] + "</li>"
0072             }
0073             divisorString += "</ul>"
0074             //: the first argument corresponds to a number and the second argument corresponds to its divisors formatted as an unordered html format (<ul><li>number 1</li>...</ul>)
0075             fault += qsTr("%1 is a non-prime number, its divisors are: %2").arg(num1).arg(divisorString)
0076 
0077         } else if (activity.type == "factors") {
0078             //: %1 is the number to find, %2 and %3 are two multiples of the number, %4 is a wrong number and %5 is the number to find.
0079             fault += qsTr("Multiples of %1 include %2 or %3 but %4 is not a multiple of %5.").arg(num1).arg(num1*2).arg(num1*3).arg(Activity.getGoal()).arg(num1) + "<br>"
0080 
0081         } else if (activity.type == "multiples") {
0082             // First we find divisors of the wrong number.
0083             var divisors = []
0084             for (var div = 1; div < Activity.getGoal() * 6; ++div) {
0085                 if ((num1 / div) % 1 == 0)
0086                     divisors.push(div)
0087             }
0088             var divisorString = "<ul>"
0089             for (var div = 0; div < divisors.length; ++div) {
0090                 divisorString += "<li>" + divisors[div] + "</li>"
0091             }
0092             divisorString += "</ul>"
0093             //: the first argument corresponds to a number and the second argument corresponds to its divisors formatted as an unordered html format (<ul><li>number 1</li>...</ul>
0094             fault += qsTr("Divisors of %1 are: %2").arg(num1).arg(divisorString)
0095 
0096         }
0097     }
0098 
0099     width: warning.paintedWidth + 10 * ApplicationInfo.ratio
0100     height: warning.paintedHeight + 10 * ApplicationInfo.ratio
0101     anchors.horizontalCenter: parent.horizontalCenter
0102     anchors.verticalCenter: parent.verticalCenter
0103     z: 3
0104     border.width: 2
0105     radius: 5
0106     opacity: 0
0107     color: "#82E599"
0108 
0109     onOpacityChanged: {
0110         if (opacity == 0) {
0111             muncher.opacity = 1
0112             area.enabled = false
0113         } else {
0114             area.enabled = true
0115         }
0116 
0117     }
0118 
0119     GCText {
0120         id: warning
0121         anchors.centerIn: parent
0122         horizontalAlignment: Text.AlignHCenter
0123         verticalAlignment: Text.AlignVCenter
0124         text: fault + qsTr("Press \"Return\" or click on me to continue.")
0125 
0126         textFormat: Text.RichText
0127         width: Math.min(400 * ApplicationInfo.ratio, background.width * 0.7)
0128         height: background.height * 0.8
0129         fontSize: smallSize
0130         wrapMode: Text.WordWrap
0131     }
0132 
0133     Behavior on opacity {
0134         NumberAnimation {
0135             duration: 200
0136         }
0137     }
0138 
0139     MouseArea {
0140         id: area
0141         anchors.fill: parent
0142 
0143         enabled: false
0144     }
0145 }