summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorThomas Hartmann <Thomas.Hartmann@theqtcompany.com>2016-08-23 14:00:03 +0200
committerThomas Hartmann <Thomas.Hartmann@theqtcompany.com>2016-09-02 08:10:23 +0000
commit4013583a50336d97f71c7a40ea6e0c56ec8b4bbb (patch)
treedd1c6f1d4a689fe4e4cf2aafac0859ccd2dc91fb /examples
parenta327d55aec8feec5ea6bc147f08d71c0dc1341cb (diff)
Examples: Use .ui file for trafficlight
This decouples the logic/implementation from the declarative ui definition. Change-Id: I039b754df2b9ca86279fe8e9fb9bba23e9c49bf6 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/scxml/trafficlight-common/Lights.ui.qml100
-rw-r--r--examples/scxml/trafficlight-common/TrafficLight.qml50
-rw-r--r--examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc1
-rw-r--r--examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc1
4 files changed, 112 insertions, 40 deletions
diff --git a/examples/scxml/trafficlight-common/Lights.ui.qml b/examples/scxml/trafficlight-common/Lights.ui.qml
new file mode 100644
index 0000000..31f1e3e
--- /dev/null
+++ b/examples/scxml/trafficlight-common/Lights.ui.qml
@@ -0,0 +1,100 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the QtScxml module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+import QtQuick 2.5
+import QtQuick.Window 2.2
+
+Image {
+ id: lights
+
+ property alias mouseArea: mouseArea
+ property alias button: button
+ property alias redLight: redLight
+ property alias yellowLight: yellowLight
+ property alias greenLight: greenLight
+
+ source: "background.png"
+
+ MouseArea {
+ id: mouseArea
+ anchors.fill: parent
+ }
+
+ Column {
+ y: 40
+ spacing: 27
+ anchors.horizontalCenter: parent.horizontalCenter
+
+ Image {
+ id: redLight
+ source: "red.png"
+ }
+
+ Image {
+ id: yellowLight
+ source: "yellow.png"
+ }
+
+ Image {
+ id: greenLight
+ source: "green.png"
+ }
+ }
+
+ Button {
+ id: button
+
+ anchors.right: parent.right
+ anchors.bottom: parent.bottom
+ anchors.margins: 20
+ source: "pause.png"
+ }
+}
diff --git a/examples/scxml/trafficlight-common/TrafficLight.qml b/examples/scxml/trafficlight-common/TrafficLight.qml
index ff4325a..6d7c45c 100644
--- a/examples/scxml/trafficlight-common/TrafficLight.qml
+++ b/examples/scxml/trafficlight-common/TrafficLight.qml
@@ -60,55 +60,25 @@ Window {
width: lights.width
height: lights.height
- Image {
+ Lights {
id: lights
- source: "background.png"
- MouseArea {
- anchors.fill: parent
- onClicked: {
- Qt.quit();
- }
+ mouseArea.onClicked: {
+ Qt.quit();
}
- Column {
- y: 40
- spacing: 27
- anchors.horizontalCenter: parent.horizontalCenter
+ button.onClicked: {
- Image {
- id: redLight
- source: "red.png"
- opacity: stateMachine.red || stateMachine.redGoingGreen ? 1 : 0.2
- }
-
- Image {
- id: yellowLight
- source: "yellow.png"
- opacity: stateMachine.yellow || stateMachine.blinking ? 1 : 0.2
- }
-
- Image {
- id: greenLight
- source: "green.png"
- opacity: stateMachine.green ? 1 : 0.2
- }
- }
- }
-
- Button {
- id: button
- anchors.right: parent.right
- anchors.bottom: parent.bottom
- anchors.margins: 20
-
- source: stateMachine.working ? "pause.png" : "play.png"
-
- onClicked: {
if (stateMachine.working)
stateMachine.submitEvent("smash")
else
stateMachine.submitEvent("repair")
}
+
+ button.source: stateMachine.working ? "pause.png" : "play.png"
+
+ redLight.opacity: stateMachine.red || stateMachine.redGoingGreen ? 1 : 0.2
+ yellowLight.opacity: stateMachine.yellow || stateMachine.blinking ? 1 : 0.2
+ greenLight.opacity: stateMachine.green ? 1 : 0.2
}
}
diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc
index 475a7be..547935b 100644
--- a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc
+++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc
@@ -2,6 +2,7 @@
<qresource prefix="/">
<file alias="TrafficLight.qml">../trafficlight-common/TrafficLight.qml</file>
<file alias="Button.qml">../trafficlight-common/Button.qml</file>
+ <file alias="Lights.ui.qml">../trafficlight-common/Lights.ui.qml</file>
<file>trafficlight-qml-dynamic.qml</file>
<file alias="statemachine.scxml">../trafficlight-common/statemachine.scxml</file>
<file alias="green.png">../trafficlight-common/green.png</file>
diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc
index 46c408f..890b4a7 100644
--- a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc
+++ b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc
@@ -3,6 +3,7 @@
<file>trafficlight-qml-static.qml</file>
<file alias="TrafficLight.qml">../trafficlight-common/TrafficLight.qml</file>
<file alias="Button.qml">../trafficlight-common/Button.qml</file>
+ <file alias="Lights.ui.qml">../trafficlight-common/Lights.ui.qml</file>
<file alias="green.png">../trafficlight-common/green.png</file>
<file alias="yellow.png">../trafficlight-common/yellow.png</file>
<file alias="red.png">../trafficlight-common/red.png</file>