Warning, /education/gcompris/src/activities/explore_farm_animals/AnimalDescriptionLevels.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - AnimalDescriptionLevels.qml 0002 * 0003 * SPDX-FileCopyrightText: 2015 Ayush Agrawal <ayushagrawal288@gmail.com> 0004 * 0005 * Authors: 0006 * Beth Hadley <bethmhadley@gmail.com> (GTK+ version) 0007 * Ayush Agrawal <ayushagrawal288@gmail.com> (Qt Quick port) 0008 * Djalil MESLI <djalilmesli@gmail.com> (Qt Quick port) 0009 * Johnny Jazeix <jazeix@gmail.com> (Qt Quick port) 0010 * 0011 * SPDX-License-Identifier: GPL-3.0-or-later 0012 */ 0013 0014 import QtQuick 2.12 0015 import GCompris 1.0 0016 0017 import "../../core" 0018 import "explore-level.js" as Activity 0019 0020 Rectangle { 0021 id: rectangleDesc 0022 radius: 30 0023 border.width: 5 0024 border.color: "black" 0025 0026 MouseArea { 0027 anchors.fill: parent 0028 onPressed: parent.closeDescriptionPanel() 0029 } 0030 0031 property alias title: heading.text 0032 property alias description: descriptionText.text 0033 property alias imageSource: animalImage.source 0034 0035 property bool horizontalLayout: background.width >= background.height 0036 0037 signal showDescriptionPanel 0038 signal closeDescriptionPanel 0039 0040 onShowDescriptionPanel: { 0041 descriptionPanelCloseAnimation.stop() 0042 descriptionPanelAppearAnimation.start() 0043 } 0044 0045 onCloseDescriptionPanel: { 0046 descriptionPanelAppearAnimation.stop() 0047 close() 0048 } 0049 0050 // animation for appearance of the description panel 0051 NumberAnimation { 0052 id: descriptionPanelAppearAnimation 0053 target: descriptionPanel 0054 property: "x" 0055 from: -width 0056 to: 0 0057 duration: 1200 0058 easing.type: Easing.OutBack 0059 } 0060 0061 GCText { 0062 id: heading 0063 fontSize: largeSize 0064 horizontalAlignment: Text.AlignHCenter 0065 font.weight: Font.DemiBold 0066 anchors.top: parent.top 0067 color: "#2a2a2a" 0068 width: parent.width - cancelButton.width 0069 wrapMode: Text.WordWrap 0070 } 0071 0072 Image { 0073 id: animalImage 0074 width: rectangleDesc.horizontalLayout ? parent.width / 2 : parent.width * 0.9 0075 height: rectangleDesc.horizontalLayout ? 0076 parent.height * 0.8 : 0077 (parent.height - heading.height - descriptionText.height) * 0.9 0078 fillMode: Image.PreserveAspectFit 0079 anchors { 0080 top: rectangleDesc.horizontalLayout ? heading.bottom : descriptionText.bottom 0081 horizontalCenter: rectangleDesc.horizontalLayout ? undefined : parent.horizontalCenter 0082 left: rectangleDesc.horizontalLayout ? parent.left : undefined 0083 leftMargin: rectangleDesc.horizontalLayout ? 30 * ApplicationInfo.ratio : 0 0084 } 0085 0086 MouseArea { 0087 anchors.fill: parent 0088 onClicked: parent.switchImageWithTextOrAlone() 0089 } 0090 0091 state: "zoomedOut" 0092 0093 // Relative width and height of the image is changed on zooming-in and zooming-out keeping original binding intact 0094 states: [ 0095 State { 0096 name: "zoomedIn" 0097 PropertyChanges { 0098 target: animalImage 0099 width: rectangleDesc.width / 1.2 0100 height: rectangleDesc.height / 1.2 0101 } 0102 0103 PropertyChanges { 0104 target: descriptionText 0105 visible: false 0106 } 0107 0108 AnchorChanges { 0109 target: animalImage 0110 anchors.top: heading.bottom 0111 } 0112 }, 0113 State { 0114 name: "zoomedOut" 0115 PropertyChanges { 0116 target: animalImage 0117 width: rectangleDesc.horizontalLayout ? parent.width / 2 : parent.width * 0.9 0118 height: rectangleDesc.horizontalLayout ? 0119 parent.height * 0.8 : 0120 (parent.height - heading.height - descriptionText.height) * 0.9 0121 } 0122 0123 PropertyChanges { 0124 target: descriptionText 0125 visible: true 0126 } 0127 0128 AnchorChanges { 0129 target: animalImage 0130 anchors.top: rectangleDesc.horizontalLayout ? heading.bottom : descriptionText.bottom 0131 } 0132 } 0133 ] 0134 0135 // Transition to animate zoom-in and zoom-out 0136 transitions: [ 0137 Transition { 0138 from: "zoomedOut" 0139 to: "zoomedIn" 0140 0141 NumberAnimation { 0142 target: animalImage 0143 properties: "width, height" 0144 easing.type: Easing.OutBack 0145 duration: 500 0146 } 0147 0148 AnchorAnimation { duration: 250 } 0149 }, 0150 Transition { 0151 from: "zoomedIn" 0152 to: "zoomedOut" 0153 0154 NumberAnimation { 0155 target: animalImage 0156 properties: "width, height" 0157 duration: 250 0158 } 0159 0160 PropertyAnimation { 0161 target: descriptionText 0162 property: "visible" 0163 } 0164 0165 AnchorAnimation { duration: 250 } 0166 } 0167 ] 0168 0169 // Changes the state of the image 0170 function switchImageWithTextOrAlone() { 0171 if(state === "zoomedOut") { 0172 state = "zoomedIn"; 0173 } 0174 else { 0175 state = "zoomedOut"; 0176 } 0177 } 0178 } 0179 0180 GCText { 0181 id: descriptionText 0182 font.weight: Font.DemiBold 0183 fontSizeMode: Text.Fit 0184 horizontalAlignment: Text.AlignJustify 0185 anchors { 0186 top: (heading.height > cancelButton.height) ? heading.bottom : cancelButton.bottom 0187 right: parent.right 0188 rightMargin: 30 * ApplicationInfo.ratio 0189 left: rectangleDesc.horizontalLayout ? animalImage.right : parent.left 0190 leftMargin: 30 * ApplicationInfo.ratio 0191 } 0192 color: "#2a2a2a" 0193 width: rectangleDesc.horizontalLayout ? parent.width * 0.45 : parent.width 0194 height: rectangleDesc.horizontalLayout ? parent.height * 0.5 : parent.height * 0.3 0195 wrapMode: Text.WordWrap 0196 } 0197 0198 // The close panel button 0199 GCButtonCancel { 0200 id: cancelButton 0201 onClose: parent.closeDescriptionPanel() 0202 } 0203 0204 function close() { 0205 if(animalImage.state === "zoomedIn") { 0206 animalImage.state = "zoomedOut"; 0207 } 0208 descriptionPanelCloseAnimation.start(); 0209 if (Activity.isComplete() && !items.descriptionBonusDone) { 0210 items.descriptionBonusDone = true; 0211 items.buttonsBlocked = true; 0212 items.bonus.good("flower"); 0213 } 0214 } 0215 0216 SequentialAnimation { 0217 id: descriptionPanelCloseAnimation 0218 0219 NumberAnimation { 0220 id: slideBackDescriptionPanel 0221 target: descriptionPanel 0222 property: "x" 0223 to: -width 0224 duration: 1200 0225 easing.type: Easing.InSine 0226 } 0227 0228 PropertyAnimation { 0229 id: switchDescriptionPanelInvisible 0230 target: descriptionPanel 0231 property: "visible" 0232 to: false 0233 } 0234 } 0235 0236 }