Warning, /education/gcompris/src/activities/learn_decimals/MultipleBars.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - MultipleBars.qml 0002 * 0003 * SPDX-FileCopyrightText: 2021 Mariam Fahmy <mariamfahmy66@gmail.com> 0004 * 0005 * Authors: 0006 * Mariam Fahmy <mariamfahmy66@gmail.com> 0007 * Timothée Giet <animtim@gmail.com> 0008 * 0009 * SPDX-License-Identifier: GPL-3.0-or-later 0010 */ 0011 import QtQuick 2.12 0012 import GCompris 1.0 0013 import "../../core" 0014 import "learn_decimals.js" as Activity 0015 0016 GridView { 0017 id: multipleBars 0018 anchors.centerIn: parent 0019 property int cellSize: 10 0020 interactive: false 0021 model: largestNumberRepresentation 0022 0023 delegate: delegateUnit 0024 0025 states: [ 0026 State { 0027 when: background.horizontalLayout 0028 PropertyChanges { 0029 target: multipleBars 0030 cellSize: Math.min(mainRectangle.height / 6, mainRectangle.width / 11) 0031 cellHeight: cellSize * 1.14 0032 cellWidth: cellSize 0033 width: cellSize * 10 0034 height: cellSize * 5.86 0035 anchors.verticalCenterOffset: cellSize * 0.14 0036 anchors.horizontalCenterOffset: 0 0037 flow: GridView.FlowTopToBottom 0038 } 0039 }, 0040 State { 0041 when: !background.horizontalLayout 0042 PropertyChanges { 0043 target: multipleBars 0044 cellSize: Math.min(mainRectangle.width / 6, mainRectangle.height / 11) 0045 cellHeight: cellSize 0046 cellWidth: cellSize * 1.14 0047 width: cellSize * 5.86 0048 height: cellSize * 10 0049 anchors.verticalCenterOffset: 0 0050 anchors.horizontalCenterOffset: cellSize * 0.14 0051 flow: GridView.FlowLeftToRight 0052 } 0053 } 0054 ] 0055 0056 Component { 0057 id: delegateUnit 0058 Item { 0059 id: singleBar 0060 0061 Grid { 0062 id: gridLayout 0063 0064 signal barClicked 0065 onBarClicked: { 0066 multipleBars.currentIndex = index 0067 } 0068 0069 anchors.fill: parent 0070 0071 states: [ 0072 State { 0073 when: background.horizontalLayout 0074 PropertyChanges { 0075 target: gridLayout 0076 rows: 1 0077 columns: 0 0078 } 0079 }, 0080 State { 0081 when: !background.horizontalLayout 0082 PropertyChanges { 0083 target: gridLayout 0084 rows: 0 0085 columns: 1 0086 } 0087 } 0088 ] 0089 0090 Repeater { 0091 id: squareRepeater 0092 0093 property int gridIndex: index 0094 0095 model: Activity.squaresNumber 0096 0097 Image { 0098 id: squareDark 0099 source: "qrc:/gcompris/src/activities/learn_decimals/resource/rectDark.svg" 0100 width: multipleBars.cellSize 0101 height: width 0102 sourceSize.width: width 0103 0104 Image { 0105 id: squareWhite 0106 source: "qrc:/gcompris/src/activities/learn_decimals/resource/rectWhite.svg" 0107 anchors.centerIn: parent 0108 width: parent.width - 6 0109 height: width 0110 sourceSize.width: width 0111 } 0112 0113 Image { 0114 id: crossImage 0115 source: "qrc:/gcompris/src/activities/learn_decimals/resource/cross.svg" 0116 anchors.centerIn: parent 0117 width: squareWhite.width 0118 sourceSize.width: width 0119 visible: squareRepeater.gridIndex < largestNumberRepresentation.count - 1 || 0120 index < Activity.lastBarSquareUnits 0121 } 0122 0123 Image { 0124 id: squareFill 0125 source: "qrc:/gcompris/src/activities/learn_decimals/resource/rectFill.svg" 0126 anchors.centerIn: parent 0127 width: squareWhite.width 0128 height: width 0129 sourceSize.width: width 0130 visible: crossImage.visible && index < selectedSquareNumbers 0131 } 0132 0133 MouseArea { 0134 id: mouseArea 0135 anchors.fill: parent 0136 enabled: !items.buttonsBlocked 0137 onPressed: { 0138 if(items.typeResult) return; 0139 gridLayout.barClicked(); 0140 0141 //All bars before the clicked bar are totally full 0142 var i; 0143 for(i = 0; i < multipleBars.currentIndex ; i++) { 0144 Activity.changeMultiBarVisibility(i, Activity.squaresNumber); 0145 } 0146 0147 //Adjusting the visibility of square units of the clicked bar. 0148 Activity.changeMultiBarVisibility(i, index); 0149 i = i + 1; 0150 0151 //All bars after the clicked bar are totally transparent. 0152 for(; i < largestNumberRepresentation.count; i++) { 0153 Activity.changeMultiBarVisibility(i, 0); 0154 } 0155 } 0156 } 0157 } 0158 } 0159 } 0160 } 0161 } 0162 }