Warning, /education/gcompris/src/activities/lightsoff/Lightsoff.qml is written in an unsupported language. File is not indexed.
0001 /* GCompris - lightsoff.qml 0002 * 0003 * SPDX-FileCopyrightText: 2014 Stephane Mankowski <stephane@mankowski.fr> 0004 * 0005 * Authors: 0006 * Bruno Coudoin <bruno.coudoin@gcompris.net> (GTK+ version) 0007 * Stephane Mankowski <stephane@mankowski.fr> (Qt Quick port) 0008 * Timothée Giet <animtim@gmail.com> (Layout and visual refactoring) 0009 * 0010 * SPDX-License-Identifier: GPL-3.0-or-later 0011 */ 0012 import QtQuick 2.12 0013 import GCompris 1.0 0014 0015 import "../../core" 0016 import "lightsoff.js" as Activity 0017 0018 ActivityBase { 0019 id: activity 0020 0021 onStart: focus = true 0022 onStop: { 0023 0024 } 0025 0026 pageComponent: Image { 0027 id: background 0028 source: "qrc:/gcompris/src/activities/family/resource/background.svg" 0029 anchors.fill: parent 0030 sourceSize.width: width 0031 sourceSize.height: height 0032 fillMode: Image.PreserveAspectCrop 0033 0034 signal start 0035 signal stop 0036 0037 property bool keyNavigationVisible: false 0038 0039 Component.onCompleted: { 0040 dialogActivityConfig.initialize() 0041 activity.start.connect(start) 0042 activity.stop.connect(stop) 0043 } 0044 0045 // Add here the QML items you need to access in javascript 0046 QtObject { 0047 id: items 0048 property Item main: activity.main 0049 property alias background: background 0050 property int currentLevel: activity.currentLevel 0051 property alias bonus: bonus 0052 property bool isPortrait: (background.height >= background.width - tux.width) 0053 property alias nightSky: nightSky.opacity 0054 property alias modelTable: modelTable 0055 readonly property var levels: activity.datasetLoader.data 0056 property bool blockClicks: false 0057 property int nbCell: 5 0058 property int cellSize: isPortrait ? Math.min((parent.height - bar.height * 2.5) / items.nbCell, 0059 (parent.width - 40) / items.nbCell) : 0060 (parent.height - bar.height * 1.5) / items.nbCell 0061 property int nbCelToWin: 0 0062 property var lightRatio: items.nbCelToWin / (items.nbCell * items.nbCell) 0063 } 0064 0065 onStart: { 0066 Activity.start(items) 0067 } 0068 onStop: { 0069 Activity.stop() 0070 } 0071 0072 Keys.enabled: !items.blockClicks 0073 Keys.onPressed: { 0074 background.keyNavigationVisible = true 0075 if (event.key === Qt.Key_Left) 0076 grid.moveCurrentIndexLeft() 0077 if (event.key === Qt.Key_Right) 0078 grid.moveCurrentIndexRight() 0079 if (event.key === Qt.Key_Down) 0080 grid.moveCurrentIndexDown() 0081 if (event.key === Qt.Key_Up) 0082 grid.moveCurrentIndexUp() 0083 if (event.key === Qt.Key_Space || event.key === Qt.Key_Enter || event.key === Qt.Key_Return) 0084 Activity.windowPressed(grid.currentIndex) 0085 } 0086 0087 states: [ 0088 State { 0089 id: verticalState 0090 when: items.isPortrait 0091 AnchorChanges { 0092 target: building 0093 anchors.bottom: tux.verticalCenter 0094 } 0095 }, 0096 State { 0097 id: horizontalState 0098 when: !items.isPortrait 0099 AnchorChanges { 0100 target: building 0101 anchors.bottom: tux.bottom 0102 } 0103 } 0104 ] 0105 0106 Rectangle { 0107 id: nightSky 0108 color: "#052e3c" 0109 opacity: items.lightRatio 0110 anchors.fill: background 0111 } 0112 0113 Image { 0114 id: sun 0115 source: "qrc:/gcompris/src/activities/menu/resource/all.svg" 0116 sourceSize.height: items.cellSize * 2 * items.nbCell / 5 0117 anchors { 0118 left: parent.left 0119 top: parent.top 0120 topMargin: (parent.height - land.height) * items.lightRatio 0121 } 0122 Behavior on anchors.topMargin { 0123 PropertyAnimation { 0124 duration: 1000 0125 } 0126 } 0127 } 0128 0129 Image { 0130 id: land 0131 source: Activity.url + "back.svg" 0132 anchors.bottom: parent.bottom 0133 anchors.top: tux.top 0134 anchors.left: parent.left 0135 anchors.right: parent.right 0136 fillMode: Image.PreserveAspectCrop 0137 sourceSize.height: height 0138 } 0139 Rectangle { 0140 id: buildingBorders 0141 color: "#808080" 0142 width: building.width + 5 * ApplicationInfo.ratio 0143 height: building.height + 2.5 * ApplicationInfo.ratio 0144 anchors.horizontalCenter: building.horizontalCenter 0145 anchors.bottom: building.bottom 0146 } 0147 Rectangle { 0148 id: building 0149 color: "#c8c8c8" 0150 width: gridarea.width 0151 anchors.top: grid.top 0152 anchors.bottom: tux.bottom 0153 anchors.horizontalCenter: parent.horizontalCenter 0154 anchors.topMargin: items.cellSize * -0.5 0155 } 0156 0157 Rectangle { 0158 id: gridarea 0159 visible: false 0160 width: items.cellSize * items.nbCell 0161 anchors.top: parent.top 0162 anchors.bottom: tux.bottom 0163 anchors.horizontalCenter: parent.horizontalCenter 0164 } 0165 0166 GridView { 0167 id: grid 0168 anchors.verticalCenter: gridarea.verticalCenter 0169 anchors.horizontalCenter: parent.horizontalCenter 0170 width: items.nbCell * items.cellSize 0171 height: width 0172 cellWidth: items.cellSize 0173 cellHeight: items.cellSize 0174 0175 ListModel { 0176 id: modelTable 0177 } 0178 0179 model: modelTable 0180 0181 delegate: Rectangle { 0182 color: soluce === 1 ? "#20df543d" : "transparent" 0183 height: items.cellSize 0184 width: items.cellSize 0185 border { 0186 color: soluce === 1 ? "#df543d" : "transparent" 0187 width: items.cellSize * 0.025 0188 } 0189 radius: items.cellSize * 0.1 0190 0191 BarButton { 0192 anchors.fill: parent 0193 fillMode: Image.PreserveAspectFit 0194 source: lighton === 1 ? Activity.url + "on.svg" : Activity.url + "off.svg" 0195 sourceSize.height: items.cellSize 0196 mouseArea.hoverEnabled: !items.blockClicks 0197 mouseArea.enabled: !items.blockClicks 0198 onClicked: Activity.windowPressed(index) 0199 visible: true 0200 } 0201 } 0202 0203 interactive: false 0204 keyNavigationWraps: true 0205 highlightFollowsCurrentItem: true 0206 highlight: Rectangle { 0207 width: items.cellSize 0208 height: items.cellSize 0209 color: "#EEEEEE" 0210 radius: items.cellSize * 0.1 0211 visible: background.keyNavigationVisible 0212 Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } } 0213 Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } } 0214 } 0215 } 0216 0217 Image { 0218 source: Activity.url + "grass.svg" 0219 anchors.verticalCenter: building.bottom 0220 anchors.horizontalCenter: building.horizontalCenter 0221 width: buildingBorders.width 0222 sourceSize.height: height 0223 fillMode: Image.TileHorizontally 0224 } 0225 0226 BarButton { 0227 id: tux 0228 fillMode: Image.PreserveAspectFit 0229 source: "qrc:/gcompris/src/activities/ballcatch/resource/tux.svg" 0230 height: bar.height 0231 sourceSize.height: height 0232 visible: true 0233 anchors { 0234 right: parent.right 0235 rightMargin: 20 0236 bottom: bar.top 0237 bottomMargin: 20 0238 } 0239 onClicked: Activity.solve() 0240 } 0241 0242 DialogHelp { 0243 id: dialogHelp 0244 onClose: home() 0245 } 0246 0247 DialogChooseLevel { 0248 id: dialogActivityConfig 0249 currentActivity: activity.activityInfo 0250 0251 onSaveData: { 0252 levelFolder = dialogActivityConfig.chosenLevels 0253 currentActivity.currentLevels = dialogActivityConfig.chosenLevels 0254 ApplicationSettings.setCurrentLevels(currentActivity.name, dialogActivityConfig.chosenLevels) 0255 } 0256 onClose: { 0257 home() 0258 } 0259 onStartActivity: { 0260 background.stop() 0261 background.start() 0262 } 0263 } 0264 0265 Bar { 0266 id: bar 0267 level: items.currentLevel + 1 0268 content: BarEnumContent { 0269 value: help | home | level | reload | activityConfig 0270 } 0271 onHelpClicked: { 0272 displayDialog(dialogHelp) 0273 } 0274 onPreviousLevelClicked: Activity.previousLevel() 0275 onNextLevelClicked: Activity.nextLevel() 0276 onHomeClicked: activity.home() 0277 onReloadClicked: Activity.initLevel() 0278 onActivityConfigClicked: { 0279 displayDialog(dialogActivityConfig) 0280 } 0281 } 0282 0283 Bonus { 0284 id: bonus 0285 onStop: items.blockClicks = false 0286 Component.onCompleted: win.connect(Activity.nextLevel) 0287 } 0288 } 0289 }