Warning, /education/gcompris/src/activities/tens_complement_swap/CardContainer.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - CardContainer.qml
0002 *
0003 * SPDX-FileCopyrightText: 2022 Samarth Raj <mailforsamarth@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 "../../core"
0009
0010 Item {
0011 readonly property string correctAnswerImage: "qrc:/gcompris/src/core/resource/apply.svg"
0012 readonly property string wrongAnswerImage: "qrc:/gcompris/src/core/resource/cancel.svg"
0013
0014 Rectangle {
0015 id: cardContainer
0016 color: "#EBEBEB"
0017 height: items.isHorizontal ? parent.height - background.layoutMargins :
0018 (parent.height - background.layoutMargins) * 0.67
0019 width: parent.width
0020 anchors.centerIn: parent
0021 radius: 15
0022
0023 property int cardWidth: cardContainer.width / numberOfItemsInModel()
0024
0025 // add 1 for numberCard or resultCard, else add 0.5
0026 function numberOfItemsInModel() {
0027 var numberOfItems = 0;
0028 if(listmodel) {
0029 for (var i = 0; i < listmodel.count; i++) {
0030 if (listmodel.get(i).type == "symbolCard") {
0031 numberOfItems += 0.5;
0032 } else {
0033 numberOfItems += 1;
0034 }
0035 }
0036 return numberOfItems;
0037 } else {
0038 return 1;
0039 }
0040 }
0041
0042 ListView {
0043 height: parent.height
0044 width: parent.width
0045 interactive: false
0046 orientation: ListView.Horizontal
0047 model: listmodel
0048 delegate: Card {
0049 height: cardContainer.height
0050 width: type == "symbolCard" ? cardContainer.cardWidth * 0.5 : cardContainer.cardWidth
0051 }
0052 }
0053 }
0054
0055 Image {
0056 id: validationImage
0057 visible: isValidationImageVisible
0058 height: cardContainer.height
0059 width: height
0060 sourceSize.height: height
0061 source: isGood === true ? correctAnswerImage : wrongAnswerImage
0062 states: [
0063 State {
0064 name: "horizontalLayout"
0065 when: items.isHorizontal
0066 PropertyChanges {
0067 target: validationImage
0068 height: cardContainer.height
0069 anchors.margins: background.layoutMargins * 0.5
0070 }
0071 AnchorChanges {
0072 target: validationImage
0073 anchors {
0074 left: cardContainer.right
0075 verticalCenter: cardContainer.verticalCenter
0076 right: undefined
0077 top: undefined
0078 }
0079 }
0080 },
0081 State {
0082 name: "verticaleLayout"
0083 when: !items.isHorizontal
0084 PropertyChanges {
0085 target: validationImage
0086 height: cardContainer.height * 0.5
0087 anchors.margins: -background.layoutMargins * 0.5
0088 }
0089 AnchorChanges {
0090 target: validationImage
0091 anchors {
0092 left: undefined
0093 verticalCenter: undefined
0094 right: cardContainer.right
0095 top: cardContainer.bottom
0096 }
0097 }
0098 }
0099 ]
0100 }
0101 }