diff options
Diffstat (limited to 'examples/sensors/maze')
-rw-r--r-- | examples/sensors/maze/Button.qml | 82 | ||||
-rw-r--r-- | examples/sensors/maze/Maze.qml | 180 | ||||
-rw-r--r-- | examples/sensors/maze/images/button_background_disabled.png | bin | 0 -> 579 bytes | |||
-rw-r--r-- | examples/sensors/maze/images/button_background_normal.png | bin | 0 -> 901 bytes | |||
-rw-r--r-- | examples/sensors/maze/images/button_background_pressed.png | bin | 0 -> 334 bytes | |||
-rw-r--r-- | examples/sensors/maze/maze.qdoc | 57 |
6 files changed, 168 insertions, 151 deletions
diff --git a/examples/sensors/maze/Button.qml b/examples/sensors/maze/Button.qml index 96ed2d7d..2ae8f772 100644 --- a/examples/sensors/maze/Button.qml +++ b/examples/sensors/maze/Button.qml @@ -45,85 +45,31 @@ import QtQuick 2.0 Item { id: button width: 30 - height: 30 - property alias buttonText: innerText.text; - property color color: "white" - property color hoverColor: "#aaaaaa" - property color pressColor: "slategray" - property int fontSize: 10 - property int borderWidth: 1 - property int borderRadius: 2 - scale: state === "Pressed" ? 0.96 : 1.0 - onEnabledChanged: state = "" + height: 100 + property alias text: innerText.text signal clicked - //define a scale animation - Behavior on scale { - NumberAnimation { - duration: 100 - easing.type: Easing.InOutQuad - } - } - - //Rectangle to draw the button - Rectangle { - id: rectangleButton + Image { + id: backgroundImage anchors.fill: parent - radius: borderRadius - color: button.enabled ? button.color : "grey" - border.width: borderWidth - border.color: "black" - - Text { - id: innerText - font.pointSize: fontSize - anchors.centerIn: parent - } + source: (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") } - //change the color of the button in differen button states - states: [ - State { - name: "Hovering" - PropertyChanges { - target: rectangleButton - color: hoverColor - } - }, - State { - name: "Pressed" - PropertyChanges { - target: rectangleButton - color: pressColor - } - } - ] - - //define transmission for the states - transitions: [ - Transition { - from: ""; to: "Hovering" - ColorAnimation { duration: 200 } - }, - Transition { - from: "*"; to: "Pressed" - ColorAnimation { duration: 10 } - } - ] + Text { + id: innerText + anchors.centerIn: parent + color: "white" + font.bold: true + } //Mouse area to react on click events MouseArea { - hoverEnabled: true anchors.fill: button - onEntered: { button.state='Hovering'} - onExited: { button.state=''} onClicked: { button.clicked();} - onPressed: { button.state="Pressed" } + onPressed: { + backgroundImage.source = "images/button_background_pressed.png" } onReleased: { - if (containsMouse) - button.state="Hovering"; - else - button.state=""; + backgroundImage.source = (button.enabled ? "images/button_background_normal.png" : "images/button_background_disabled.png") } } } diff --git a/examples/sensors/maze/Maze.qml b/examples/sensors/maze/Maze.qml index c8f3051e..90c22a6f 100644 --- a/examples/sensors/maze/Maze.qml +++ b/examples/sensors/maze/Maze.qml @@ -51,27 +51,29 @@ import "lib.js" as Lib /* Layout mainWnd / -------------------------------/ +------------------------------/ gameRect +| / +|-----------------------------/ +||---------------------------| +||||M| || +||| \ || +||| mouseCtrl || +||| || +||| || +||| Labyrinth || +||| || +||| || +||| cheeseSquare || +||| \ || +||| |C||| +||---------------------------| +|----------------------------- | |----------------------------- -|||M| | -|| \ | -|| mouseCtrl | -|| | -|| | -|| Labyrinth | -|| | -|| | -|| cheeseSquare | -|| \ | -|| |C|| +|| || | |----------------------------- -| -|---------- -------------- -|| | | | -|---------- -------------- -| \ \ -| \ timePlayingLabel +| \ \ +| \ timePlayingLabel | newGameButton ------------------------------ @@ -80,85 +82,95 @@ import "lib.js" as Lib Rectangle { id: mainWnd x: 0 - y: 30 + y: 0 width: 320 - height: 440 - color: "white" + height: 480 + color: "#ececec" property Mouse mouseCtrl; property LabyrinthSquare cheeseSquare; property Congratulation congratulation; - //timer for starting the labyrinth game - Timer { - id: startTimer - interval: 50; running: true; repeat: false - onTriggered: { + Rectangle { + id: gameRect + x: (mainWnd.width - width) / 2 + y: 25 + width: Lib.dimension * Lib.cellDimension + height: Lib.dimension * Lib.cellDimension + color: "transparent" + border.width: 2 - //reset game time - timePlayingLabel.text = "--"; - Lib.sec = 0.0; - Lib.createLabyrinth(); + //timer for starting the labyrinth game + Timer { + id: startTimer + interval: 50; running: true; repeat: false + onTriggered: { - //create labyrinth elements (only at the first time) - var needloadcomponent = false; - if (Lib.objectArray === null){ - needloadcomponent = true; - Lib.objectArray = new Array(Lib.dimension * Lib.dimension); - } - var idx = 0; - for (var y = 0; y < Lib.dimension; y++ ){ - for (var x = 0; x < Lib.dimension; x++ ){ - var component = null; + //reset game time + timePlayingLabel.text = "--"; + Lib.sec = 0.0; + Lib.createLabyrinth(); - //create labyrinth components (only at the first time) - if (needloadcomponent){ - component = Qt.createComponent("LabyrinthSquare.qml"); - if (component.status == Component.Ready) { - var square = component.createObject(parent); - square.x = x * square.width; - square.y = y * square.height; - square.val = Lib.labyrinth[x][y]; - square.updateImage(); - Lib.objectArray[idx] = square; - if (x == (Lib.dimension - 1) && y == (Lib.dimension - 1)){ - cheeseSquare = square; - var component1 = Qt.createComponent("Congratulation.qml"); - if (component1.status == Component.Ready) { - congratulation = component1.createObject(parent); - congratulation.visible = false; + //create labyrinth elements (only at the first time) + var needloadcomponent = false; + if (Lib.objectArray === null){ + needloadcomponent = true; + Lib.objectArray = new Array(Lib.dimension * Lib.dimension); + } + var idx = 0; + for (var y = 0; y < Lib.dimension; y++ ){ + for (var x = 0; x < Lib.dimension; x++ ){ + var component = null; + + //create labyrinth components (only at the first time) + if (needloadcomponent){ + component = Qt.createComponent("LabyrinthSquare.qml"); + if (component.status == Component.Ready) { + var square = component.createObject(parent); + square.x = x * square.width; + square.y = y * square.height; + square.val = Lib.labyrinth[x][y]; + square.updateImage(); + Lib.objectArray[idx] = square; + if (x == (Lib.dimension - 1) && y == (Lib.dimension - 1)){ + cheeseSquare = square; + var component1 = Qt.createComponent("Congratulation.qml"); + if (component1.status == Component.Ready) { + congratulation = component1.createObject(parent); + congratulation.visible = false; + } } } } - } - else{ - Lib.objectArray[idx].val = Lib.labyrinth[x][y]; - Lib.objectArray[idx].updateImage(); - if (x == (Lib.dimension - 1) && y == (Lib.dimension - 1)){ - cheeseSquare = Lib.objectArray[idx]; - congratulation.visible = false; + else{ + Lib.objectArray[idx].val = Lib.labyrinth[x][y]; + Lib.objectArray[idx].updateImage(); + if (x == (Lib.dimension - 1) && y == (Lib.dimension - 1)){ + cheeseSquare = Lib.objectArray[idx]; + congratulation.visible = false; + } } + idx++; } - idx++; } - } - //Lib.printLab(); //this is for debug. Labyrinth will be printed out in the console + //Lib.printLab(); //this is for debug. Labyrinth will be printed out in the console - //Create the mouse control (only at the first time) - if (mouseCtrl === null){ - var component = Qt.createComponent("Mouse.qml"); - if (component.status == Component.Ready) { - mouseCtrl = component.createObject(parent); + //Create the mouse control (only at the first time) + if (mouseCtrl === null){ + var component = Qt.createComponent("Mouse.qml"); + if (component.status == Component.Ready) { + mouseCtrl = component.createObject(parent); + } } - } - mouseCtrl.x = 0; - mouseCtrl.y = 0; - newGameButton.enabled = true; + mouseCtrl.x = 0; + mouseCtrl.y = 0; + newGameButton.enabled = true; - //Start the Tilt reader timer - tiltTimer.running = true; - tiltSensor.calibrate(); + //Start the Tilt reader timer + tiltTimer.running = true; + tiltSensor.calibrate(); + } } } @@ -263,11 +275,12 @@ Rectangle { //Button to start a new Game Button{ id: newGameButton - x: 0 - y: mainWnd.x + (Lib.dimension * Lib.cellDimension) + 10 + anchors.left: gameRect.left + anchors.top: gameRect.bottom + anchors.topMargin: 5 height: 30 width: 100 - buttonText: "new game" + text: "new game" enabled: false; onClicked: { newGameButton.enabled = false; @@ -278,8 +291,9 @@ Rectangle { //Label to print out the game time Text{ id: timePlayingLabel - x: newGameButton.x + newGameButton.width + 20 - y: newGameButton.y + 10 + anchors.right: gameRect.right + anchors.top: gameRect.bottom + anchors.topMargin: 5 } } diff --git a/examples/sensors/maze/images/button_background_disabled.png b/examples/sensors/maze/images/button_background_disabled.png Binary files differnew file mode 100644 index 00000000..62a00b9a --- /dev/null +++ b/examples/sensors/maze/images/button_background_disabled.png diff --git a/examples/sensors/maze/images/button_background_normal.png b/examples/sensors/maze/images/button_background_normal.png Binary files differnew file mode 100644 index 00000000..1fecad5b --- /dev/null +++ b/examples/sensors/maze/images/button_background_normal.png diff --git a/examples/sensors/maze/images/button_background_pressed.png b/examples/sensors/maze/images/button_background_pressed.png Binary files differnew file mode 100644 index 00000000..149529e1 --- /dev/null +++ b/examples/sensors/maze/images/button_background_pressed.png diff --git a/examples/sensors/maze/maze.qdoc b/examples/sensors/maze/maze.qdoc new file mode 100644 index 00000000..f24222ad --- /dev/null +++ b/examples/sensors/maze/maze.qdoc @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** GNU Free Documentation License +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms +** and conditions contained in a signed written agreement between you +** and Nokia. +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example sensors/maze + \title Maze example + \ingroup qtsensors-examples + \brief The Maze example demonstrates the TiltSensor QML element. + \image maze.jpg + +\section1 Overview + To write a QML application that will use the TiltSensor QML sensors element you need to do the following steps: + + Import the QtSensors 5.x declarative plugin: + +\snippet ../examples/sensors/maze/Maze.qml 0 + + Add the Sensor QML elements into your qml file. + + In this example we use the TiltSensor with values based in degrees and an accuracy of 5 degree: + +\snippet ../examples/sensors/maze/Maze.qml 1 + + Starting the sensor can be done by setting the 'enabled' property to true: + +\snippet ../examples/sensors/maze/Maze.qml 2 + + To determine the walk direction of the mouse we use the following if -else statements: + +\snippet ../examples/sensors/maze/Maze.qml 3 + +*/ + |