Warning, /education/gcompris/src/activities/babymatch/ListWidget.qml is written in an unsupported language. File is not indexed.
0001 /* gcompris - ListWidget.qml
0002 *
0003 * SPDX-FileCopyrightText: 2015 Pulkit Gupta <pulkitgenius@gmail.com>
0004 *
0005 * Authors:
0006 * Pulkit Gupta <pulkitgenius@gmail.com>
0007 *
0008 * SPDX-License-Identifier: GPL-3.0-or-later
0009 */
0010 import QtQuick 2.12
0011 import GCompris 1.0
0012 import "../../core"
0013 import "babymatch.js" as Activity
0014
0015 Item {
0016 id: listWidget
0017 anchors.fill: parent
0018 anchors.topMargin: 5 * ApplicationInfo.ratio
0019 anchors.leftMargin: 5 * ApplicationInfo.ratio
0020 z: 10
0021
0022 property alias model: mymodel
0023 property alias view: view
0024 property alias showOk: showOk
0025 property alias hideOk: hideOk
0026 property alias repeater: repeater
0027
0028 ListModel {
0029 id: mymodel
0030 }
0031
0032 PropertyAnimation {
0033 id: showOk
0034 target: ok
0035 properties: "height"
0036 from: 0
0037 to: view.iconSize * 0.9
0038 duration: 300
0039 onStopped: {
0040 view.okShowed = true;
0041 }
0042 }
0043 PropertyAnimation {
0044 id: hideOk
0045 target: ok
0046 properties: "height"
0047 from: view.iconSize * 0.9
0048 to: 0
0049 duration: 200
0050 onStopped: view.checkDisplayedGroup();
0051 }
0052
0053 Image {
0054 id: ok
0055 source:"qrc:/gcompris/src/core/resource/bar_ok.svg"
0056 sourceSize.width: view.iconSize
0057 fillMode: Image.PreserveAspectFit
0058 anchors.horizontalCenter: parent.horizontalCenter
0059
0060 MouseArea {
0061 anchors.fill: parent
0062 enabled: !items.inputLocked
0063 onClicked: view.checkAnswer();
0064 }
0065 }
0066
0067 Grid {
0068 id: view
0069 width: leftWidget.width
0070 height: background.verticalBar ? background.height - bar.height * 2 : bar.height
0071 spacing: 10
0072 z: 20
0073 columns: background.verticalBar ? 1 : nbItemsByGroup + 1
0074
0075 property int currentDisplayedGroup: 0
0076 property int setCurrentDisplayedGroup
0077 property int nbItemsByGroup:
0078 background.verticalBar ?
0079 view.height / iconSize - 1 :
0080 view.width / iconSize - 2
0081
0082 property int nbDisplayedGroup: nbItemsByGroup > 0 ? Math.ceil(model.count / nbItemsByGroup) : 0
0083 property int iconSize: 80 * ApplicationInfo.ratio
0084 property int previousNavigation: 1
0085 property int nextNavigation: 1
0086 property bool okShowed: false
0087 property bool showGlow: false
0088 property var displayedGroup: []
0089 property alias ok: ok
0090
0091 onNbDisplayedGroupChanged: correctDisplayedGroup();
0092
0093 // For correcting values of Displayed Groups when height or width is changed
0094 function correctDisplayedGroup() {
0095 if(nbDisplayedGroup > 0) {
0096 for(var i = 0 ; i < nbDisplayedGroup ; i++) {
0097 var groupEmpty = true;
0098 for(var j = 0 ; j < nbItemsByGroup && i*nbItemsByGroup + j < model.count ; j++) {
0099 if(repeater.itemAt(i*nbItemsByGroup + j).dropStatus < 0) {
0100 groupEmpty = false;
0101 break;
0102 }
0103 }
0104 if(groupEmpty)
0105 displayedGroup[i] = false;
0106 else
0107 displayedGroup[i] = true;
0108 }
0109 view.refreshLeftWidget();
0110 view.checkDisplayedGroup();
0111 }
0112 }
0113
0114 //For setting navigation buttons
0115 function setNextNavigation() {
0116 nextNavigation = 0;
0117 for(var i = currentDisplayedGroup + 1 ; i < nbDisplayedGroup ; i++) {
0118 if(displayedGroup[i]) {
0119 nextNavigation = i - currentDisplayedGroup;
0120 break;
0121 }
0122 }
0123 }
0124
0125 function setPreviousNavigation() {
0126 previousNavigation = 0;
0127 for(var i = currentDisplayedGroup - 1 ; i >= 0 ; i--) {
0128 if(displayedGroup[i]) {
0129 previousNavigation = currentDisplayedGroup - i;
0130 break;
0131 }
0132 }
0133 }
0134
0135 function checkDisplayedGroup() {
0136 var i = currentDisplayedGroup * nbItemsByGroup;
0137 var groupEmpty = true;
0138 while(i < model.count && i < (currentDisplayedGroup + 1) * nbItemsByGroup) {
0139 if(repeater.itemAt(i).dropStatus < 0) {
0140 groupEmpty = false;
0141 break;
0142 }
0143 i++;
0144 }
0145
0146 if(groupEmpty) {
0147 displayedGroup[currentDisplayedGroup] = false;
0148 previousNavigation = 0;
0149 nextNavigation = 0;
0150 for(var i = 0 ; i < nbDisplayedGroup ; ++i) {
0151 if(displayedGroup[i]) {
0152 view.setCurrentDisplayedGroup = i;
0153 view.refreshLeftWidget();
0154 break;
0155 }
0156 }
0157 }
0158 }
0159
0160 function refreshLeftWidget() {
0161 availablePieces.view.currentDisplayedGroup = availablePieces.view.setCurrentDisplayedGroup;
0162 availablePieces.view.setNextNavigation();
0163 availablePieces.view.setPreviousNavigation();
0164 }
0165
0166 function areAllPlaced() {
0167 for(var i = 0 ; i < model.count ; ++i) {
0168 if(repeater.itemAt(i).dropStatus < 0) {
0169 return false;
0170 }
0171 }
0172 return true;
0173 }
0174
0175 function checkAnswer() {
0176 view.showGlow = true;
0177 for(var i = 0 ; i < model.count ; ++i) {
0178 if(repeater.itemAt(i).dropStatus !== 1) {
0179 return;
0180 }
0181 }
0182 items.inputLocked = true;
0183 Activity.win();
0184 }
0185
0186 Repeater {
0187 id: repeater
0188 property int currentIndex
0189 onCurrentIndexChanged: {
0190 for(var i = 0; i < mymodel.count; i++) {
0191 if(currentIndex != i)
0192 repeater.itemAt(i).selected = false;
0193 else
0194 repeater.itemAt(i).selected = true;
0195 }
0196 if(currentIndex == -1)
0197 toolTip.opacity = 0;
0198 }
0199 DragListItem {
0200 id: contactsDelegate
0201 z: 1
0202 tileSize: view.iconSize
0203 visible: view.currentDisplayedGroup * view.nbItemsByGroup <= index &&
0204 index <= (view.currentDisplayedGroup+1) * view.nbItemsByGroup-1
0205
0206 onPressed: repeater.currentIndex = index;
0207 }
0208
0209 clip: true
0210 model: mymodel
0211
0212 onModelChanged: repeater.currentIndex = -1;
0213 }
0214
0215 Row {
0216 spacing: view.iconSize * 0.20
0217
0218 Image {
0219 id: previous
0220 opacity: (model.count > view.nbItemsByGroup &&
0221 view.previousNavigation != 0 && view.currentDisplayedGroup != 0) ? 1 : 0
0222 source:"qrc:/gcompris/src/core/resource/bar_previous.svg"
0223 sourceSize.width: view.iconSize * 0.35
0224 fillMode: Image.PreserveAspectFit
0225 MouseArea {
0226 anchors.fill: parent
0227 enabled: !items.inputLocked && parent.opacity > 0
0228 onClicked: {
0229 repeater.currentIndex = -1;
0230 if(previous.opacity == 1) {
0231 view.setCurrentDisplayedGroup = view.currentDisplayedGroup - view.previousNavigation;
0232 view.refreshLeftWidget();
0233 }
0234 }
0235 }
0236 }
0237
0238 Image {
0239 id: next
0240 opacity: (model.count > view.nbItemsByGroup && view.nextNavigation != 0
0241 && view.currentDisplayedGroup < view.nbDisplayedGroup - 1) ? 1 : 0
0242 source:"qrc:/gcompris/src/core/resource/bar_next.svg"
0243 sourceSize.width: view.iconSize * 0.35
0244 fillMode: Image.PreserveAspectFit
0245 MouseArea {
0246 anchors.fill: parent
0247 enabled: !items.inputLocked && parent.opacity > 0
0248 onClicked: {
0249 repeater.currentIndex = -1;
0250 view.setCurrentDisplayedGroup = view.currentDisplayedGroup + view.nextNavigation;
0251 view.refreshLeftWidget();
0252 }
0253 }
0254 }
0255 }
0256 }
0257 }