Warning, /education/gcompris/src/activities/louis-braille/ReorderList.qml is written in an unsupported language. File is not indexed.

0001 /* GCompris - ReorderList.qml
0002  *
0003  * SPDX-FileCopyrightText: 2014 Arkit Vora <arkitvora123@gmail.com>
0004  *
0005  * Authors:
0006  *   <Srishti Sethi> (GTK+ version)
0007  *   Arkit Vora <arkitvora123@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 "louis-braille.js" as Activity
0016 
0017 Rectangle {
0018     id: wholeBody
0019     width: parent.width
0020     height: parent.height
0021     color: "#85D8F6"
0022 
0023     property int selectedIndex: -1
0024     property alias containerModel: list.model
0025     property bool bonusRunning: false
0026 
0027     signal up
0028     signal down
0029     signal space
0030 
0031     onUp: list.decrementCurrentIndex()
0032     onDown: list.incrementCurrentIndex()
0033     onSpace: selectItem()
0034 
0035     function selectItem() {
0036         if(list.currentIndex == selectedIndex) {
0037             selectedIndex = -1
0038         } else if(selectedIndex != -1) {
0039             containerModel.move(selectedIndex, list.currentIndex, 1)
0040             selectedIndex = -1
0041         } else {
0042             selectedIndex = list.currentIndex
0043         }
0044     }
0045 
0046     function checkWin() {
0047         var win = true
0048         // The shifted numbering comes from the header in the List
0049         for(var i = 0; i < list.count; i++) {
0050             if(list.contentItem.children[i].placed === false) {
0051                 win = false
0052                 return
0053             }
0054         }
0055         if(win) {
0056             bonusRunning = true
0057             bonus.good("tux")
0058             list.currentIndex = -1
0059         }
0060     }
0061 
0062     function stopTimer() {
0063         timer.stop();
0064     }
0065 
0066     Component {
0067         id: listElement
0068 
0069         Rectangle {
0070             id: listRect
0071             color: wholeBody.selectedIndex == index ? "#b5b9ff" : (placed ? "#c1ffb4" : "#F0F0F0")
0072             border.width: list.currentIndex == index ? 0 : ApplicationInfo.ratio
0073             border.color: "#373737"
0074             radius: 3
0075             width: list.width
0076             height: textinfo.height + background.baseMargins
0077 
0078             property bool placed: model.sequence === index
0079             property string text: model.text
0080 
0081             SequentialAnimation {
0082                 id: borderAnim
0083                 running: list.currentIndex == index
0084                 loops: Animation.Infinite
0085                 NumberAnimation {
0086                     target: listRect
0087                     property: "border.width"
0088                     to: 2 * ApplicationInfo.ratio; duration: 500
0089                     easing.type: Easing.InOutQuad
0090                 }
0091                 NumberAnimation {
0092                     target: listRect
0093                     property: "border.width"
0094                     to: 0; duration: 500
0095                     easing.type: Easing.InOutQuad
0096                 }
0097             }
0098 
0099             GCText {
0100                 id: textinfo
0101                 text: listRect.text
0102                 anchors.centerIn: parent
0103                 horizontalAlignment: Text.AlignHCenter
0104                 width: parent.width - background.baseMargins
0105                 wrapMode: Text.WordWrap
0106                 fontSize: smallSize
0107                 color: "#373737"
0108             }
0109 
0110             MouseArea {
0111                 id: dragArea
0112                 anchors.fill: parent
0113                 onClicked: {
0114                     list.currentIndex = index
0115                     wholeBody.selectItem()
0116                 }
0117             }
0118 
0119             Behavior on color {
0120                 ColorAnimation {
0121                     duration: 200
0122                 }
0123             }
0124 
0125         }
0126     }
0127 
0128     ListModel {
0129         id: containerModel
0130     }
0131 
0132     ListView {
0133         id: list
0134         anchors {
0135             top: parent.top
0136             left: parent.left
0137             right: scrollItem.left
0138             bottom: parent.bottom
0139             topMargin: background.baseMargins
0140             leftMargin: background.baseMargins
0141             rightMargin: background.baseMargins
0142             bottomMargin: bar.height * 1.5
0143         }
0144         model: containerModel
0145         spacing: 5 * ApplicationInfo.ratio
0146         delegate: listElement
0147         interactive: true
0148         // setting huge cacheBuffer is needed to make sure hidden children are not discarded...
0149         cacheBuffer: 100000
0150         clip: true
0151 
0152         header: Item {
0153             width: parent.width
0154             height: heading.height + background.baseMargins * 2
0155             Rectangle {
0156                 width: parent.width
0157                 height: heading.height + background.baseMargins
0158                 radius: background.baseMargins * 0.5
0159                 anchors.top: parent.top
0160                 color: "#80FFFFFF"
0161                 GCText {
0162                     id: heading
0163                     text: qsTr("Arrange the events in the order in which they happened. " +
0164                     "Select the line to move, then select its target position.")
0165                     width: parent.width - background.baseMargins * 2
0166                     wrapMode: Text.WordWrap
0167                     horizontalAlignment: Text.AlignHCenter
0168                     anchors.centerIn: parent
0169                     color: "#373737"
0170                     fontSize: smallSize
0171                 }
0172             }
0173         }
0174         onCurrentIndexChanged: {
0175             if(!wholeBody.bonusRunning) {
0176                 timer.restart();
0177             }
0178         }
0179         displaced: Transition {
0180             NumberAnimation { properties: "y"; duration: 500 }
0181         }
0182         move: Transition {
0183             NumberAnimation { properties: "y"; duration: 500 }
0184         }
0185         Component.onCompleted: currentIndex = -1
0186     }
0187 
0188     GCButtonScroll {
0189         id: scrollItem
0190         anchors.right: parent.right
0191         anchors.rightMargin: background.baseMargins
0192         anchors.top: parent.top
0193         anchors.topMargin: background.baseMargins
0194         anchors.bottom: parent.bottom
0195         anchors.bottomMargin: bar.height * 1.5
0196         onUp: list.flick(0, 1000)
0197         onDown: list.flick(0, -1000)
0198         upVisible: list.atYBeginning ? false : true
0199         downVisible: list.atYEnd ? false : true
0200     }
0201 
0202     Timer {
0203         id: timer
0204         interval: 1000
0205         running: false
0206         repeat: false
0207         onTriggered: wholeBody.checkWin()
0208     }
0209 }