Warning, /education/gcompris/src/activities/calcudoku/CalcudokuListWidget.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - CalcudokuListWidget.qml
0002 *
0003 * SPDX-FileCopyrightText: 2023 Johnny Jazeix <jazeix@gmail.com>
0004 * SPDX-License-Identifier: GPL-3.0-or-later
0005 */
0006 import QtQuick 2.12
0007 import GCompris 1.0
0008 import "calcudoku.js" as Activity
0009 import "../../core"
0010
0011 Item {
0012 id: listWidget
0013 width: view.width
0014 height: view.height
0015 anchors {
0016 left: parent.left
0017 leftMargin: background.baseMargins
0018 top: parent.top
0019 topMargin: background.baseMargins
0020 }
0021
0022
0023 property alias model: mymodel;
0024 property alias view: view;
0025 property GCSfx audioEffects
0026 property bool inputBlocked: false
0027
0028 ListModel {
0029 id: mymodel
0030 }
0031
0032 ListView {
0033 id: view
0034 interactive: false
0035 spacing: 5 * ApplicationInfo.ratio
0036 model: mymodel
0037 delegate: listItemComponent
0038
0039 property int iconSize
0040
0041 states: [
0042 State {
0043 name: "horizontalLayout"
0044 when: background.isHorizontalLayout
0045 PropertyChanges {
0046 target: view
0047 width: iconSize
0048 height: background.height - 2 * bar.height
0049 orientation: ListView.Vertical
0050 iconSize: Math.min((height - (mymodel.count - 1) * spacing) / mymodel.count,
0051 100 * ApplicationInfo.ratio)
0052 }
0053 },
0054 State {
0055 name: "verticalLayout"
0056 when: !background.isHorizontalLayout
0057 PropertyChanges {
0058 target: view
0059 width: background.width - background.baseMargins * 2
0060 height: iconSize
0061 orientation: ListView.Horizontal
0062 iconSize: Math.min((width - (model.count - 1) * spacing) / mymodel.count,
0063 100 * ApplicationInfo.ratio)
0064 }
0065 }
0066 ]
0067
0068 Component {
0069 id: listItemComponent
0070
0071 Rectangle {
0072 id: iconBg
0073 width: view.iconSize
0074 height: view.iconSize
0075 color: "#AAFFFFFF"
0076 radius: height * 0.1
0077
0078 Image {
0079 id: icon
0080 anchors.centerIn: parent
0081 sourceSize.height: view.iconSize
0082 source: model.imgName === undefined ? "" :
0083 Activity.url + model.imgName
0084 z: iAmSelected ? 10 : 1
0085
0086 property bool iAmSelected: view.currentIndex == index
0087
0088 states: [
0089 State {
0090 name: "notclicked"
0091 when: !icon.iAmSelected && !mouseArea.containsMouse
0092 PropertyChanges {
0093 target: icon
0094 scale: 0.8
0095 }
0096 },
0097 State {
0098 name: "clicked"
0099 when: mouseArea.pressed
0100 PropertyChanges {
0101 target: icon
0102 scale: 0.7
0103 }
0104 },
0105 State {
0106 name: "hover"
0107 when: mouseArea.containsMouse && !icon.iAmSelected
0108 PropertyChanges {
0109 target: icon
0110 scale: 1
0111 }
0112 },
0113 State {
0114 name: "selected"
0115 when: icon.iAmSelected
0116 PropertyChanges {
0117 target: icon
0118 scale: 0.9
0119 }
0120 }
0121 ]
0122
0123 SequentialAnimation {
0124 id: anim
0125 running: icon.iAmSelected
0126 loops: Animation.Infinite
0127 alwaysRunToEnd: true
0128 NumberAnimation {
0129 target: iconBg
0130 property: "rotation"
0131 from: 0; to: 5
0132 duration: 200
0133 easing.type: Easing.OutQuad
0134 }
0135 NumberAnimation {
0136 target: iconBg
0137 property: "rotation"
0138 from: 5; to: -5
0139 duration: 400
0140 easing.type: Easing.InOutQuad
0141 }
0142 NumberAnimation {
0143 target: iconBg
0144 property: "rotation"
0145 from: -5; to: 0
0146 duration: 200
0147 easing.type: Easing.InQuad
0148 }
0149 }
0150
0151 Behavior on scale { NumberAnimation { duration: 70 } }
0152
0153 MouseArea {
0154 id: mouseArea
0155 anchors.fill: icon
0156 hoverEnabled: true
0157 enabled: !listWidget.inputBlocked
0158 onClicked: {
0159 listWidget.audioEffects.play('qrc:/gcompris/src/core/resource/sounds/scroll.wav')
0160 view.currentIndex = index
0161 }
0162 }
0163 }
0164 }
0165 }
0166 }
0167 }
0168