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

0001 /* GCompris - RectangleChart.qml
0002  *
0003  * SPDX-FileCopyrightText: 2022 Johnny Jazeix <jazeix@gmail.com>
0004  * SPDX-FileCopyrightText: 2022 Timothée Giet <animtim@gmail.com>
0005  * SPDX-License-Identifier: GPL-3.0-or-later
0006  */
0007 import QtQuick 2.12
0008 import QtQml.Models 2.12
0009 
0010 import GCompris 1.0
0011 
0012 Item {
0013     id: chart
0014 
0015     Item {
0016         id: chartContainer
0017         // reduce the margin only in case it's vertical and there's more than one rectangle
0018         height: !chart.parent.horizontalLayout && chart.parent.numberOfCharts > 1 ?
0019             parent.height - 20 * ApplicationInfo.ratio :
0020             parent.height - 60 * ApplicationInfo.ratio
0021         width: height
0022         anchors.centerIn: parent
0023 
0024         GridView {
0025             id: chartGrid
0026             anchors.fill: parent
0027             model: ListModel {
0028                 id: listModel
0029             }
0030             cellWidth: Math.floor(parent.width / model.count)
0031             cellHeight: cellWidth * model.count
0032             interactive: false
0033             anchors.verticalCenter: parent.verticalCenter
0034             anchors.horizontalCenter: parent.horizontalCenter
0035 
0036             delegate: Rectangle {
0037                 border.width: 5
0038                 border.color: "white"
0039                 color: selected ? gridContainer.selectedColor : gridContainer.unselectedColor
0040                 // add border.width as an offset to avoid double-sized separation lines
0041                 width: chartGrid.cellWidth + border.width
0042                 // also add border.width to height to keep it square
0043                 height: chartGrid.cellHeight + border.width
0044 
0045                 MouseArea {
0046                     anchors.fill: parent
0047                     onClicked: {
0048                         if(items.buttonsBlocked || activity.mode === "findFraction") {
0049                             return;
0050                         }
0051                         if(selected) {
0052                             numeratorText.value --;
0053                         }
0054                         else {
0055                             numeratorText.value ++;
0056                         }
0057                         selected = !selected;
0058                     }
0059                 }
0060             }
0061         }
0062     }
0063     function initLevel(pieIndex) {
0064         chartGrid.model.clear();
0065         for(var pieSliceIndex = 0 ; pieSliceIndex < items.denominatorToFind ; ++ pieSliceIndex) {
0066             // Select the good number of slices at the beginning
0067             var selectPie = (activity.mode === "findFraction" && (pieSliceIndex+pieIndex*items.denominatorToFind < items.numeratorToFind));
0068 
0069             chartGrid.model.append({
0070                 "selected": selectPie
0071             });
0072         }
0073 
0074     }
0075 
0076     function countSelectedParts() {
0077         var selected = 0;
0078         for(var i = 0 ; i < listModel.count ; ++ i) {
0079             if(listModel.get(i).selected) {
0080                 selected ++;
0081             }
0082         }
0083         return selected;
0084     }
0085 }