Warning, /education/gcompris/src/activities/photo_hunter/PhotoHunter.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - PhotoHunter.qml 0002 * 0003 * SPDX-FileCopyrightText: 2016 Stefan Toncu <stefan.toncu29@gmail.com> 0004 * 0005 * Authors: 0006 * <Marc Le Douarain> (GTK+ version) 0007 * Stefan Toncu <stefan.toncu29@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 import QtQuick.Controls 2.12 0014 0015 import "../../core" 0016 import "photo_hunter.js" as Activity 0017 0018 ActivityBase { 0019 id: activity 0020 0021 onStart: focus = true 0022 onStop: {} 0023 0024 pageComponent: Image { 0025 id: background 0026 anchors.fill: parent 0027 source: "qrc:/gcompris/src/activities/fifteen/resource/background.svg" 0028 sourceSize.width: width 0029 sourceSize.height: height 0030 fillMode: Image.PreserveAspectCrop 0031 signal start 0032 signal stop 0033 0034 Component.onCompleted: { 0035 activity.start.connect(start) 0036 activity.stop.connect(stop) 0037 } 0038 0039 // Add here the QML items you need to access in javascript 0040 QtObject { 0041 id: items 0042 property Item main: activity.main 0043 property alias background: background 0044 property int currentLevel: activity.currentLevel 0045 property alias bonus: bonus 0046 property var model 0047 property alias img1: img1 0048 property alias img2: img2 0049 property int total 0050 property int totalFound: img1.good + img2.good 0051 property alias frame: frame 0052 } 0053 0054 onStart: { Activity.start(items) } 0055 onStop: { Activity.stop() } 0056 0057 property bool vert: frame.width <= frame.height 0058 property double barHeight: ApplicationSettings.isBarHidden ? bar.height / 2 : bar.height 0059 property bool startedHelp: false 0060 0061 function checkAnswer() { 0062 if (items.totalFound === items.model.length) { 0063 bonus.good("flower") 0064 0065 // after completing a level, mark the problem as shown 0066 if (!problem.hideProblem) { 0067 problem.hideProblem = true 0068 } 0069 } 0070 } 0071 0072 Rectangle { 0073 id: problem 0074 width: parent.width - score.width - 20 * ApplicationInfo.ratio 0075 height: hideProblem ? 0 : problemText.height 0076 anchors.top: parent.top 0077 anchors.topMargin: hideProblem ? 0 : 10 * ApplicationInfo.ratio 0078 anchors.left: parent.left 0079 color: "#C0373737" 0080 z: hideProblem ? -5 : 5 0081 0082 property bool hideProblem: false 0083 0084 GCText { 0085 id: problemText 0086 anchors.centerIn: parent 0087 width: parent.width * 0.9 0088 fontSize: mediumSize 0089 wrapMode: Text.WordWrap 0090 horizontalAlignment: Text.AlignHCenter 0091 verticalAlignment: Text.AlignVCenter 0092 text: background.startedHelp ? qsTr("Drag the slider to show the differences.") : 0093 qsTr("Click on the differences between the two images.") 0094 color: "white" 0095 } 0096 0097 MouseArea { 0098 anchors.fill: parent 0099 onClicked: problem.hideProblem = true 0100 } 0101 } 0102 0103 states: [ 0104 State { 0105 name: "anchorProblem" 0106 when: problem.height >= score.height 0107 AnchorChanges { 0108 target: frame 0109 anchors.top: problem.bottom 0110 } 0111 PropertyChanges { 0112 target: frame 0113 height: background.height - problem.height - bar.height * 1.5 - 10 * ApplicationInfo.ratio 0114 } 0115 }, 0116 State { 0117 name: "anchorScore" 0118 when: score.height > problem.height 0119 AnchorChanges { 0120 target: frame 0121 anchors.top: score.bottom 0122 } 0123 PropertyChanges { 0124 target: frame 0125 height: background.height - score.height - bar.height * 1.5 - 10 * ApplicationInfo.ratio 0126 } 0127 } 0128 ] 0129 0130 Item { 0131 id: frame 0132 height: background.height - problem.height - bar.height * 1.5 - 10 * ApplicationInfo.ratio 0133 anchors.top: problem.bottom 0134 anchors.left: background.left 0135 anchors.right: background.right 0136 0137 //left/top image 0138 Observe { 0139 id: img1 0140 show: true 0141 anchors.horizontalCenter: parent.horizontalCenter 0142 anchors.verticalCenter: parent.verticalCenter 0143 } 0144 0145 //right/bottom image 0146 Observe { 0147 id: img2 0148 opacity: background.startedHelp ? 1 - slider.value : 1 0149 show: false 0150 anchors.horizontalCenter: parent.horizontalCenter 0151 anchors.verticalCenter: parent.verticalCenter 0152 } 0153 states: [ 0154 State { 0155 name: "horizontalImages" 0156 when: !background.vert && !background.startedHelp 0157 PropertyChanges { 0158 target: img1 0159 anchors.horizontalCenterOffset: -img1.width * 0.5 - 5 * ApplicationInfo.ratio 0160 anchors.verticalCenterOffset: 0 0161 } 0162 PropertyChanges { 0163 target: img2 0164 anchors.horizontalCenterOffset: img1.width * 0.5 + 5 * ApplicationInfo.ratio 0165 anchors.verticalCenterOffset: 0 0166 } 0167 }, 0168 State { 0169 name: "horizontalHelp" 0170 when: !background.vert && background.startedHelp 0171 PropertyChanges { 0172 target: img1 0173 anchors.horizontalCenterOffset: 0 0174 anchors.verticalCenterOffset: 0 0175 } 0176 PropertyChanges { 0177 target: img2 0178 anchors.horizontalCenterOffset: 0 0179 anchors.verticalCenterOffset: 0 0180 } 0181 }, 0182 State { 0183 name: "verticalImages" 0184 when: background.vert && !background.startedHelp 0185 PropertyChanges { 0186 target: img1 0187 anchors.verticalCenterOffset: -img1.height * 0.5 - 5 * ApplicationInfo.ratio 0188 } 0189 PropertyChanges { 0190 target: img2 0191 anchors.verticalCenterOffset: img1.height * 0.5 + 5 * ApplicationInfo.ratio 0192 } 0193 }, 0194 State { 0195 name: "verticallHelp" 0196 when: background.vert && background.startedHelp 0197 PropertyChanges { 0198 target: img1 0199 anchors.verticalCenterOffset: 0 0200 } 0201 PropertyChanges { 0202 target: img2 0203 anchors.verticalCenterOffset: 0 0204 } 0205 } 0206 ] 0207 0208 GCSlider { 0209 id: slider 0210 value: 0 0211 height: background.startedHelp ? 50 : 0 0212 width: img1.width * 0.9 0213 z: background.startedHelp ? 5 : -5 0214 opacity: background.startedHelp ? 1 : 0 0215 enabled: background.startedHelp 0216 snapMode: Slider.NoSnap 0217 stepSize: 0 0218 0219 anchors { 0220 top: img1.bottom 0221 topMargin: 20 0222 horizontalCenter: img1.horizontalCenter 0223 } 0224 } 0225 } 0226 0227 DialogHelp { 0228 id: dialogHelp 0229 onClose: home() 0230 } 0231 0232 Bar { 0233 id: bar 0234 level: items.currentLevel + 1 0235 content: BarEnumContent { value: help | home | level | hint } 0236 onHelpClicked: { 0237 displayDialog(dialogHelp) 0238 } 0239 onPreviousLevelClicked: Activity.previousLevel() 0240 onNextLevelClicked: Activity.nextLevel() 0241 onHomeClicked: activity.home() 0242 onHintClicked: { 0243 background.startedHelp = !background.startedHelp 0244 slider.value = 0 0245 } 0246 } 0247 0248 Bonus { 0249 id: bonus 0250 Component.onCompleted: win.connect(Activity.nextLevel) 0251 } 0252 0253 Score { 0254 id: score 0255 anchors { 0256 bottom: undefined 0257 left: undefined 0258 top: background.top 0259 topMargin: 10 * ApplicationInfo.ratio 0260 right: parent.right 0261 rightMargin: 10 * ApplicationInfo.ratio 0262 } 0263 numberOfSubLevels: items.total 0264 currentSubLevel: items.totalFound 0265 } 0266 } 0267 }