From 6b2c7688b3f344f350125f8b9713a6a77b82c3dd Mon Sep 17 00:00:00 2001 From: Wolfgang Beck Date: Fri, 2 Sep 2011 13:29:38 +1000 Subject: MTMW-98 QML API Version 2 Change-Id: I10c610ae22974d291fad663088c5a11449a86b05 Reviewed-on: http://codereview.qt-project.org/4107 Reviewed-by: Wolfgang Beck --- examples/sensors/qmlqtsensors5/Button.qml | 34 +++ examples/sensors/qmlqtsensors5/SelectionButton.qml | 37 +++ examples/sensors/qmlqtsensors5/checked.gif | Bin 0 -> 246 bytes examples/sensors/qmlqtsensors5/icon.png | Bin 0 -> 2030 bytes examples/sensors/qmlqtsensors5/info.json | 14 + examples/sensors/qmlqtsensors5/main.qml | 290 +++++++++++++++++++++ .../sensors/qmlqtsensors5/qmlqtsensors5.qmlproject | 20 ++ examples/sensors/qmlqtsensors5/unchecked.gif | Bin 0 -> 170 bytes 8 files changed, 395 insertions(+) create mode 100644 examples/sensors/qmlqtsensors5/Button.qml create mode 100644 examples/sensors/qmlqtsensors5/SelectionButton.qml create mode 100644 examples/sensors/qmlqtsensors5/checked.gif create mode 100755 examples/sensors/qmlqtsensors5/icon.png create mode 100644 examples/sensors/qmlqtsensors5/info.json create mode 100644 examples/sensors/qmlqtsensors5/main.qml create mode 100644 examples/sensors/qmlqtsensors5/qmlqtsensors5.qmlproject create mode 100644 examples/sensors/qmlqtsensors5/unchecked.gif (limited to 'examples') diff --git a/examples/sensors/qmlqtsensors5/Button.qml b/examples/sensors/qmlqtsensors5/Button.qml new file mode 100644 index 0000000..4e9c74c --- /dev/null +++ b/examples/sensors/qmlqtsensors5/Button.qml @@ -0,0 +1,34 @@ +import QtQuick 2.0 + +Rectangle { + id: button + width: 100 + height: 20 + property alias text: t.text + property bool checked + signal clicked + property color checkColor; + property color unCheckColor; + border.width: 1 + radius: 2 + + Text{ + x: 0 + id: t + anchors.fill: button + } + + MouseArea{ + anchors.fill: button + onClicked: { + setCheck(!button.checked); + button.clicked(); + } + } + + function setCheck(val) + { + checked = val; + button.color = (button.checked == true ? checkColor : unCheckColor); + } +} diff --git a/examples/sensors/qmlqtsensors5/SelectionButton.qml b/examples/sensors/qmlqtsensors5/SelectionButton.qml new file mode 100644 index 0000000..e258d5e --- /dev/null +++ b/examples/sensors/qmlqtsensors5/SelectionButton.qml @@ -0,0 +1,37 @@ +import QtQuick 2.0 + +Rectangle { + id: button + width: 100 + height: 25 + property alias text: t.text + property bool checked + signal clicked + + Image{ + id: image + x: 0 + width: 15 + height: 15 + source: (button.checked == true ? "checked.gif" : "unchecked.gif") + } + + Text{ + x: image.x + image.width + 10 + id: t + } + + MouseArea{ + anchors.fill: button + onClicked: { + setCheck(true); + button.clicked(); + } + } + + function setCheck(val) + { + checked = val; + image.source = (button.checked == true ? "checked.gif" : "unchecked.gif"); + } +} diff --git a/examples/sensors/qmlqtsensors5/checked.gif b/examples/sensors/qmlqtsensors5/checked.gif new file mode 100644 index 0000000..a4216f2 Binary files /dev/null and b/examples/sensors/qmlqtsensors5/checked.gif differ diff --git a/examples/sensors/qmlqtsensors5/icon.png b/examples/sensors/qmlqtsensors5/icon.png new file mode 100755 index 0000000..2765712 Binary files /dev/null and b/examples/sensors/qmlqtsensors5/icon.png differ diff --git a/examples/sensors/qmlqtsensors5/info.json b/examples/sensors/qmlqtsensors5/info.json new file mode 100644 index 0000000..70eef76 --- /dev/null +++ b/examples/sensors/qmlqtsensors5/info.json @@ -0,0 +1,14 @@ +{ + "info-version": "1.0", + "dict": { + "Category": "application", + "Runtime": "qml", + "DisplayName": "Sensors2", + "Subcategory": "utility", + "MainQML": "main.qml", + "Version": "1.0", + "Identifier": "com.noklab.nrcc.qmlsensors2.demo", + "Summary": "QML Sensors2 demo", + "Author": "Qt" + } +} diff --git a/examples/sensors/qmlqtsensors5/main.qml b/examples/sensors/qmlqtsensors5/main.qml new file mode 100644 index 0000000..113c10b --- /dev/null +++ b/examples/sensors/qmlqtsensors5/main.qml @@ -0,0 +1,290 @@ +//Import the declarative plugins +import QtQuick 2.0 +import Qt.QtSensors 5.0 + +/* Layout + tiltrect + / +------------------------------/ +| @ Facing Up <-------------------- selButtonFacingUp +| O Left Up <-------------------- selButtonLeftUp +| O Top Down <-------------------- selButtonTopDown +| O Face Down <-------------------- selButtonFaceDown +| O Right Up <-------------------- selButtonRightUp +| O Top Up <-------------------- selButtonTopUp +| --------- +| |degree | <-------------------- useRadian +| --------- +| X Rotation: 0 <------------------ xrottext +| Y Rotation: 0 <------------------ yrottext +| --------- +| |start | <-------------------- tiltStart +| --------- ablrect +------------------------------ / +------------------------------/ +| Ambient light: - <--------------- abltext +| --------- +| |start | <-------------------- ablStart +| --------- proxirect +------------------------------ / +------------------------------/ +| Proximity: false <--------------- proxitext +| --------- +| |start | <-------------------- proxiStart +| --------- +------------------------------ + +*/ + +Rectangle { + width: 320 + height: 480 + + Rectangle { + id: tiltrect + x: 2 + y: 22 + width: 315 + height: 270 + border.width: 1 + + TiltSensor { + id: tilt + radian: false + measureFrom: TiltSensor.FaceUp + running: false + } + + SelectionButton{ + id: selButtonFacingUp + x: 5 + y: 20 + checked: true + text: "Facing Up" + onClicked:{ + selButtonLeftUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonRightUp.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.FaceUp; + } + } + SelectionButton{ + id: selButtonLeftUp + x: 5 + y: 45 + checked: false + text: "Left Up" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonRightUp.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.LeftUp; + } + } + SelectionButton{ + id: selButtonTopDown + x: 5 + y: 70 + checked: false + text: "Top Down" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonLeftUp.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonRightUp.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.TopDown; + } + } + SelectionButton{ + id: selButtonFaceDown + x: 5 + y: 95 + checked: false + text: "Face Down" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonLeftUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonRightUp.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.FaceDown; + } + } + SelectionButton{ + id: selButtonRightUp + x: 5 + y: 120 + checked: false + text: "Right Up" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonLeftUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonTopUp.setCheck(false); + tilt.measureFrom=TiltSensor.RightUp; + } + } + SelectionButton{ + id: selButtonTopUp + x: 5 + y: 145 + checked: false + text: "Top Up" + onClicked:{ + selButtonFacingUp.setCheck(false); + selButtonLeftUp.setCheck(false); + selButtonTopDown.setCheck(false); + selButtonFaceDown.setCheck(false); + selButtonRightUp.setCheck(false); + tilt.measureFrom=TiltSensor.TopUp; + } + } + + Button{ + id: useRadian + x: 5 + y: 170 + text: "degree" + checkColor: "lightblue" + unCheckColor: "lightyellow" + checked: tilt.radian + color: "lightyellow" + + onClicked:{ + tilt.radian = useRadian.checked; + if (useRadian.checked) + useRadian.text = "radian"; + else + useRadian.text = "degree"; + } + } + + Text { + id: xrottext + x:5 + y:195 + text: "X Rotation: " + tilt.xRotation + } + Text { + id: yrottext + x:5 + y:220 + text: "Y Rotation: " + tilt.yRotation + } + Button{ + id: tiltStart + x: 5 + y: 245 + text: "start" + checkColor: "lightblue" + unCheckColor: "lightyellow" + checked: tilt.running + color: "lightyellow" + + onClicked:{ + tilt.running = tiltStart.checked; + if (tiltStart.checked) + tiltStart.text = "running"; + else + tiltStart.text = "stopped"; + } + } + } + + Rectangle { + id: ablrect + x: 2 + y: tiltrect.y + tiltrect.height + 10 + width: 315 + height: 70 + border.width: 1 + + AmbientLightSensor { + id: abl + running: false + onLightLevelChanged:{ + if (abl.lightLevel == AmbientLightSensor.Undefined) + abltext.text = "Ambient light: Undefined"; + else if (abl.lightLevel == AmbientLightSensor.Dark) + abltext.text = "Ambient light: Dark"; + else if (abl.lightLevel == AmbientLightSensor.Twilight) + abltext.text = "Ambient light: Twilight"; + else if (abl.lightLevel == AmbientLightSensor.Light) + abltext.text = "Ambient light: Light"; + else if (abl.lightLevel == AmbientLightSensor.Bright) + abltext.text = "Ambient light: Bright"; + else if (abl.lightLevel == AmbientLightSensor.Sunny) + abltext.text = "Ambient light: Sunny"; + } + } + Text { + id: abltext + x: 5 + y: 10 + text: "Ambient light: -" + } + Button{ + id: ablStart + x: 5 + y: 35 + text: "start" + checkColor: "lightblue" + unCheckColor: "lightyellow" + checked: abl.running + color: "lightyellow" + + onClicked:{ + abl.running = ablStart.checked; + if (ablStart.checked) + ablStart.text = "running"; + else + ablStart.text = "stopped"; + } + } + } + + Rectangle { + id: proxirect + x: 2 + y: ablrect.y + ablrect.height + 10 + width: 315 + height: 70 + border.width: 1 + + ProximitySensor { + id: proxi + running: true + } + Text { + id: proxitext + x: 5 + y: 10 + text: "Proximity: " + proxi.close + } + Button{ + id: proxiStart + x: 5 + y: 35 + text: "start" + checkColor: "lightblue" + unCheckColor: "lightyellow" + checked: proxi.running + color: "lightyellow" + + onClicked:{ + proxi.running = proxiStart.checked; + if (proxiStart.checked) + proxiStart.text = "running"; + else + proxiStart.text = "stopped"; + } + } + } +} + diff --git a/examples/sensors/qmlqtsensors5/qmlqtsensors5.qmlproject b/examples/sensors/qmlqtsensors5/qmlqtsensors5.qmlproject new file mode 100644 index 0000000..2218c43 --- /dev/null +++ b/examples/sensors/qmlqtsensors5/qmlqtsensors5.qmlproject @@ -0,0 +1,20 @@ +/* File generated by Qt Creator, version 2.2.0 */ + +import QmlProject 1.1 + +Project { + mainFile: "main.qml" + + /* Include .qml, .js, and image files from current directory and subdirectories */ + QmlFiles { + directory: "." + } + JavaScriptFiles { + directory: "." + } + ImageFiles { + directory: "." + } + /* List of plugin directories passed to QML runtime */ + // importPaths: [ "../exampleplugin" ] +} diff --git a/examples/sensors/qmlqtsensors5/unchecked.gif b/examples/sensors/qmlqtsensors5/unchecked.gif new file mode 100644 index 0000000..ffb651d Binary files /dev/null and b/examples/sensors/qmlqtsensors5/unchecked.gif differ -- cgit v1.2.1