diff options
Diffstat (limited to 'examples/scxml')
84 files changed, 6007 insertions, 0 deletions
diff --git a/examples/scxml/calculator/calculator.pro b/examples/scxml/calculator/calculator.pro new file mode 100644 index 0000000..9c0ef68 --- /dev/null +++ b/examples/scxml/calculator/calculator.pro @@ -0,0 +1,21 @@ +QT += widgets scxml + +CONFIG += c++11 + +STATECHARTS = calculator.scxml + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +HEADERS += \ + mainwindow.h + +FORMS += \ + mainwindow.ui + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/calculator +INSTALLS += target + +load(qscxmlc) diff --git a/examples/scxml/calculator/calculator.scxml b/examples/scxml/calculator/calculator.scxml new file mode 100644 index 0000000..2b1e926 --- /dev/null +++ b/examples/scxml/calculator/calculator.scxml @@ -0,0 +1,164 @@ +<?xml version="1.0" ?> +<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" + initial="wrapper" datamodel="ecmascript" name="Calculator"> + <datamodel> + <data id="long_expr" /> + <data id="short_expr" /> + <data id="res" /> + </datamodel> + <state id="wrapper" initial="on"> + <state id="on" initial="ready"> + <onentry> + <send event="DISPLAY.UPDATE" /> + </onentry> + <state id="ready" initial="begin"> + <state id="begin"> + <transition event="OPER.MINUS" target="negated1" /> + <onentry> + <assign location="long_expr" expr="''" /> + <assign location="short_expr" expr="0" /> + <assign location="res" expr="0" /> + <send event="DISPLAY.UPDATE" /> + </onentry> + </state> + <state id="result"> + </state> + <transition event="OPER" target="opEntered" /> + <transition event="DIGIT.0" target="zero1"> + <assign location="short_expr" expr="''" /> + </transition> + <transition event="DIGIT" target="int1"> + <assign location="short_expr" expr="''" /> + </transition> + <transition event="POINT" target="frac1"> + <assign location="short_expr" expr="''" /> + </transition> + </state> + <state id="negated1"> + <onentry> + <assign location="short_expr" expr="'-'" /> + <send event="DISPLAY.UPDATE" /> + </onentry> + <transition event="DIGIT.0" target="zero1" /> + <transition event="DIGIT" target="int1" /> + <transition event="POINT" target="frac1" /> + </state> + <state id="operand1"> + <state id="zero1"> + <transition event="DIGIT" cond="_event.name != 'DIGIT.0'" target="int1" /> + <transition event="POINT" target="frac1" /> + </state> + <state id="int1"> + <transition event="POINT" target="frac1" /> + <transition event="DIGIT"> + <assign location="short_expr" expr="short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> + <send event="DISPLAY.UPDATE" /> + </transition> + <onentry> + <assign location="short_expr" expr="short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> + <send event="DISPLAY.UPDATE" /> + </onentry> + </state> + <state id="frac1"> + <onentry> + <assign location="short_expr" expr="short_expr+'.'" /> + <send event="DISPLAY.UPDATE" /> + </onentry> + <transition event="DIGIT"> + <assign location="short_expr" expr="short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> + <send event="DISPLAY.UPDATE" /> + </transition> + </state> + <transition event="OPER" target="opEntered" /> + </state> + <state id="opEntered"> + <transition event="OPER.MINUS" target="negated2" /> + <transition event="POINT" target="frac2" /> + <transition event="DIGIT.0" target="zero2" /> + <transition event="DIGIT" target="int2" /> + <onentry> + <raise event="CALC.SUB" /> + <send target="#_internal" event="OP.INSERT"> + <param name="operator" expr="_event.name" /> + </send> + </onentry> + </state> + <state id="negated2"> + <onentry> + <assign location="short_expr" expr="'-'" /> + <send event="DISPLAY.UPDATE" /> + </onentry> + <transition event="DIGIT.0" target="zero2" /> + <transition event="DIGIT" target="int2" /> + <transition event="POINT" target="frac2" /> + </state> + <state id="operand2"> + <state id="zero2"> + <transition event="DIGIT" cond="_event.name != 'DIGIT.0'" target="int2" /> + <transition event="POINT" target="frac2" /> + </state> + <state id="int2"> + <transition event="DIGIT"> + <assign location="short_expr" expr="short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> + <send event="DISPLAY.UPDATE" /> + </transition> + <onentry> + <assign location="short_expr" expr="short_expr+_event.name.substr(_event.name.lastIndexOf('.')+1)" /> + <send event="DISPLAY.UPDATE" /> + </onentry> + <transition event="POINT" target="frac2" /> + </state> + <state id="frac2"> + <onentry> + <assign location="short_expr" expr="short_expr +'.'" /> + <send event="DISPLAY.UPDATE" /> + </onentry> + <transition event="DIGIT"> + <assign location="short_expr" expr="short_expr +_event.name.substr(_event.name.lastIndexOf('.')+1)" /> + <send event="DISPLAY.UPDATE" /> + </transition> + </state> + <transition event="OPER" target="opEntered"> + <raise event="CALC.SUB" /> + <raise event="OP.INSERT" /> + </transition> + <transition event="EQUALS" target="result"> + <raise event="CALC.SUB" /> + <raise event="CALC.DO" /> + </transition> + </state> + <transition event="C" target="on" /> + </state> + <transition event="CALC.DO"> + <assign location="short_expr" expr="''+ res" /> + <assign location="long_expr" expr="''" /> + <assign location="res" expr="0" /> + </transition> + <transition event="CALC.SUB"> + <if cond="short_expr!=''"> + <assign location="long_expr" expr="long_expr+'('+short_expr+')'" /> + </if> + <assign location="res" expr="eval(long_expr)" /> + <assign location="short_expr" expr="''" /> + <send event="DISPLAY.UPDATE" /> + </transition> + <transition event="DISPLAY.UPDATE"> + <log label="'result'" expr="short_expr==''?res:short_expr" /> + <send type="qt:signal" event="updateDisplay"> + <param name="display" expr="short_expr==''?res:short_expr"/> + </send> + </transition> + <transition event="OP.INSERT"> + <log expr="_event.data.operator" /> + <if cond="_event.data.operator == 'OPER.PLUS'"> + <assign location="long_expr" expr="long_expr+'+'" /> + <elseif cond="_event.data.operator=='OPER.MINUS'" /> + <assign location="long_expr" expr="long_expr+'-'" /> + <elseif cond="_event.data.operator=='OPER.STAR'" /> + <assign location="long_expr" expr="long_expr+'*'" /> + <elseif cond="_event.data.operator=='OPER.DIV'" /> + <assign location="long_expr" expr="long_expr+'/'" /> + </if> + </transition> + </state> +</scxml> diff --git a/examples/scxml/calculator/doc/images/calculator.png b/examples/scxml/calculator/doc/images/calculator.png Binary files differnew file mode 100644 index 0000000..443242a --- /dev/null +++ b/examples/scxml/calculator/doc/images/calculator.png diff --git a/examples/scxml/calculator/doc/src/calculator.qdoc b/examples/scxml/calculator/doc/src/calculator.qdoc new file mode 100644 index 0000000..9edb0c3 --- /dev/null +++ b/examples/scxml/calculator/doc/src/calculator.qdoc @@ -0,0 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example calculator + \title Qt SCXML Calculator Example + \ingroup examples-qtscxml + + \image calculator.png + + \brief Implements the Calculator example presented in the SCXML + Specification. + + \e {Calculator} uses Qt SCXML to implement the + \l{SCXML Specification - Calculator Example}{Calculator Example} + presented in the SCXML Specification. + + \include examples-run.qdocinc +*/ diff --git a/examples/scxml/calculator/main.cpp b/examples/scxml/calculator/main.cpp new file mode 100644 index 0000000..2587e2b --- /dev/null +++ b/examples/scxml/calculator/main.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "calculator.h" +#include "mainwindow.h" + +#include <QApplication> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + Calculator machine; + machine.init(); + MainWindow mainWindow(&machine); + + machine.start(); + mainWindow.show(); + return app.exec(); +} diff --git a/examples/scxml/calculator/mainwindow.cpp b/examples/scxml/calculator/mainwindow.cpp new file mode 100644 index 0000000..eacafaa --- /dev/null +++ b/examples/scxml/calculator/mainwindow.cpp @@ -0,0 +1,130 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include <QStringListModel> +#include <QScxmlStateMachine> + +QT_USE_NAMESPACE + +MainWindow::MainWindow(QScxmlStateMachine *machine, QWidget *parent) : + QWidget(parent), + ui(new Ui::MainWindow), + m_machine(machine) +{ + ui->setupUi(this); + + connect(ui->digit0, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.0"); + }); + connect(ui->digit1, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.1"); + }); + connect(ui->digit2, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.2"); + }); + connect(ui->digit3, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.3"); + }); + connect(ui->digit4, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.4"); + }); + connect(ui->digit5, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.5"); + }); + connect(ui->digit6, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.6"); + }); + connect(ui->digit7, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.7"); + }); + connect(ui->digit8, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.8"); + }); + connect(ui->digit9, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("DIGIT.9"); + }); + connect(ui->point, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("POINT"); + }); + connect(ui->operPlus, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("OPER.PLUS"); + }); + connect(ui->operMinus, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("OPER.MINUS"); + }); + connect(ui->operStar, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("OPER.STAR"); + }); + connect(ui->operDiv, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("OPER.DIV"); + }); + connect(ui->equals, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("EQUALS"); + }); + connect(ui->c, &QAbstractButton::clicked, [this] { + m_machine->submitEvent("C"); + }); + + connect(m_machine, &QScxmlStateMachine::eventOccurred, [this](const QScxmlEvent &event) { + if (event.name() == QLatin1String("updateDisplay")) { + const QString display = event.data().toMap().value("display").toString(); + ui->display->setText(display); + } + }); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + diff --git a/examples/scxml/calculator/mainwindow.h b/examples/scxml/calculator/mainwindow.h new file mode 100644 index 0000000..c8d77f3 --- /dev/null +++ b/examples/scxml/calculator/mainwindow.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +class QScxmlStateMachine; +QT_END_NAMESPACE + + +class MainWindow : public QWidget +{ + Q_OBJECT + +public: + explicit MainWindow(QScxmlStateMachine *machine, QWidget *parent = 0); + ~MainWindow(); + +private: + QT_PREPEND_NAMESPACE(Ui::MainWindow) *ui; + QScxmlStateMachine *m_machine; +}; + +#endif // MAINWINDOW_H diff --git a/examples/scxml/calculator/mainwindow.ui b/examples/scxml/calculator/mainwindow.ui new file mode 100644 index 0000000..8001ff1 --- /dev/null +++ b/examples/scxml/calculator/mainwindow.ui @@ -0,0 +1,180 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QWidget" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>364</width> + <height>182</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="display"> + <property name="frameShape"> + <enum>QFrame::StyledPanel</enum> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item row="1" column="0"> + <spacer name="horizontalSpacer"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item row="1" column="1"> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0"> + <widget class="QPushButton" name="digit7"> + <property name="text"> + <string>7</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QPushButton" name="point"> + <property name="text"> + <string>.</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QPushButton" name="digit5"> + <property name="text"> + <string>5</string> + </property> + </widget> + </item> + <item row="0" column="2"> + <widget class="QPushButton" name="digit9"> + <property name="text"> + <string>9</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QPushButton" name="digit8"> + <property name="text"> + <string>8</string> + </property> + </widget> + </item> + <item row="4" column="2"> + <widget class="QPushButton" name="c"> + <property name="text"> + <string>C</string> + </property> + </widget> + </item> + <item row="1" column="0"> + <widget class="QPushButton" name="digit4"> + <property name="text"> + <string>4</string> + </property> + </widget> + </item> + <item row="2" column="3"> + <widget class="QPushButton" name="operStar"> + <property name="text"> + <string>*</string> + </property> + </widget> + </item> + <item row="2" column="2"> + <widget class="QPushButton" name="digit3"> + <property name="text"> + <string>3</string> + </property> + </widget> + </item> + <item row="4" column="3"> + <widget class="QPushButton" name="equals"> + <property name="text"> + <string>=</string> + </property> + </widget> + </item> + <item row="1" column="3"> + <widget class="QPushButton" name="operMinus"> + <property name="text"> + <string>-</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QPushButton" name="digit1"> + <property name="text"> + <string>1</string> + </property> + </widget> + </item> + <item row="3" column="0"> + <widget class="QPushButton" name="digit0"> + <property name="text"> + <string>0</string> + </property> + </widget> + </item> + <item row="3" column="3"> + <widget class="QPushButton" name="operDiv"> + <property name="text"> + <string>/</string> + </property> + </widget> + </item> + <item row="0" column="3"> + <widget class="QPushButton" name="operPlus"> + <property name="text"> + <string>+</string> + </property> + </widget> + </item> + <item row="1" column="2"> + <widget class="QPushButton" name="digit6"> + <property name="text"> + <string>6</string> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QPushButton" name="digit2"> + <property name="text"> + <string>2</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="1"> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>10</height> + </size> + </property> + </spacer> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/scxml/invoke-common/Button.qml b/examples/scxml/invoke-common/Button.qml new file mode 100644 index 0000000..4e92e32 --- /dev/null +++ b/examples/scxml/invoke-common/Button.qml @@ -0,0 +1,82 @@ +/**************************************************************************** +** +** 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 + +Item { + id: button + signal clicked + property string text: "hello" + property bool enabled: true + opacity: enabled ? 1.0 : 0.5 + + Rectangle { + x: 5 + y: 5 + width: parent.width - 10 + height: parent.height - 10 + radius: 5 + color: "lightsteelblue" + + Text { + anchors.fill: parent + color: "white" + text: button.text + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + MouseArea { + id: mouse + anchors.fill: parent + onClicked: if (button.enabled) button.clicked() + } + } +} diff --git a/examples/scxml/invoke-common/MainView.qml b/examples/scxml/invoke-common/MainView.qml new file mode 100644 index 0000000..0f51ae5 --- /dev/null +++ b/examples/scxml/invoke-common/MainView.qml @@ -0,0 +1,97 @@ +/**************************************************************************** +** +** 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 + +Window { + id: window + visible: true + property var stateMachine + + color: "black" + width: 400 + height: 300 + + Item { + width: parent.width / 2 + height: parent.height + + Button { + id: nowhere + text: "Go Nowhere" + width: parent.width + height: parent.height / 2 + onClicked: stateMachine.goNowhere() + enabled: stateMachine.somewhere + } + + Button { + id: somewhere + text: "Go Somewhere" + width: parent.width + height: parent.height / 2 + y: parent.height / 2 + onClicked: stateMachine.goSomewhere() + enabled: stateMachine.nowhere + } + } + + Loader { + source: "SubView.qml" + active: stateMachine.somewhere + + x: parent.width / 2 + width: parent.width / 2 + height: parent.height + property var anywhere: stateMachine.anywhere + } +} + diff --git a/examples/scxml/invoke-common/SubView.qml b/examples/scxml/invoke-common/SubView.qml new file mode 100644 index 0000000..cec32e3 --- /dev/null +++ b/examples/scxml/invoke-common/SubView.qml @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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 + +Item { + Button { + id: here + enabled: anywhere.here + text: "Go There" + width: parent.width / 2 + height: parent.height + onClicked: anywhere.goThere() + } + + Button { + id: there + enabled: anywhere.there + text: "Go Here" + width: parent.width / 2 + height: parent.height + x: width + onClicked: anywhere.goHere() + } +} diff --git a/examples/scxml/invoke-common/statemachine.scxml b/examples/scxml/invoke-common/statemachine.scxml new file mode 100644 index 0000000..b9defeb --- /dev/null +++ b/examples/scxml/invoke-common/statemachine.scxml @@ -0,0 +1,80 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +--> +<!-- enable-qt-mode: yes --> +<scxml + xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + name="Directions" + initial="anyplace" +> + <state id="anyplace"> + <transition event="goNowhere" target="nowhere"/> + <transition event="goSomewhere" target="somewhere"/> + + <state id="nowhere"/> + <state id="somewhere"> + <invoke type="http://www.w3.org/TR/scxml/"> + <content> + <scxml name="anywhere" version="1.0"> + <state id="here"> + <transition event="goThere" target="there"/> + </state> + <state id="there"> + <transition event="goHere" target="here"/> + </state> + </scxml> + </content> + </invoke> + </state> + </state> +</scxml> diff --git a/examples/scxml/invoke-dynamic/doc/src/invoke-dynamic.qdoc b/examples/scxml/invoke-dynamic/doc/src/invoke-dynamic.qdoc new file mode 100644 index 0000000..aff0d9d --- /dev/null +++ b/examples/scxml/invoke-dynamic/doc/src/invoke-dynamic.qdoc @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example invoke-dynamic + \title Qt SCXML: Invoke Example (Dynamic) + \ingroup examples-qtscxml + + \brief Demonstrates the use of <invoke> and the use of the generated/created + nested state-machines, where the SCXML file dynamically loaded. +*/ diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.cpp b/examples/scxml/invoke-dynamic/invoke-dynamic.cpp new file mode 100644 index 0000000..958128d --- /dev/null +++ b/examples/scxml/invoke-dynamic/invoke-dynamic.cpp @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:/invoke-dynamic.qml"))); + + return app.exec(); +} diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.pro b/examples/scxml/invoke-dynamic/invoke-dynamic.pro new file mode 100644 index 0000000..d86caeb --- /dev/null +++ b/examples/scxml/invoke-dynamic/invoke-dynamic.pro @@ -0,0 +1,14 @@ +TEMPLATE = app + +QT += qml scxml +CONFIG += c++11 + +SOURCES += invoke-dynamic.cpp + +RESOURCES += invoke-dynamic.qrc + +load(qscxmlc) + +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/invoke-dynamic +INSTALLS += target + diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.qml b/examples/scxml/invoke-dynamic/invoke-dynamic.qml new file mode 100644 index 0000000..d0cfa4d --- /dev/null +++ b/examples/scxml/invoke-dynamic/invoke-dynamic.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 Scxml 1.0 as Scxml + +MainView { + stateMachine: directions.stateMachine + + Scxml.StateMachineLoader { + id: directions + filename: "qrc:///statemachine.scxml" + } +} diff --git a/examples/scxml/invoke-dynamic/invoke-dynamic.qrc b/examples/scxml/invoke-dynamic/invoke-dynamic.qrc new file mode 100644 index 0000000..ecf8bd1 --- /dev/null +++ b/examples/scxml/invoke-dynamic/invoke-dynamic.qrc @@ -0,0 +1,9 @@ +<RCC> + <qresource prefix="/"> + <file>invoke-dynamic.qml</file> + <file alias="statemachine.scxml">../invoke-common/statemachine.scxml</file> + <file alias="MainView.qml">../invoke-common/MainView.qml</file> + <file alias="SubView.qml">../invoke-common/SubView.qml</file> + <file alias="Button.qml">../invoke-common/Button.qml</file> + </qresource> +</RCC> diff --git a/examples/scxml/invoke-static/doc/src/invoke-static.qdoc b/examples/scxml/invoke-static/doc/src/invoke-static.qdoc new file mode 100644 index 0000000..a7987e3 --- /dev/null +++ b/examples/scxml/invoke-static/doc/src/invoke-static.qdoc @@ -0,0 +1,35 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example invoke-static + \title Qt SCXML: Invoke Example (Static) + \ingroup examples-qtscxml + + \brief Demonstrates the use of <invoke> and the use of the generated/created + nested state-machines, where the SCXML file is compiled to C++ first. +*/ diff --git a/examples/scxml/invoke-static/invoke-static.cpp b/examples/scxml/invoke-static/invoke-static.cpp new file mode 100644 index 0000000..c6d0655 --- /dev/null +++ b/examples/scxml/invoke-static/invoke-static.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> + +#include "statemachine.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + Directions stateMachine; + + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty(QStringLiteral("directions"), &stateMachine); + engine.load(QUrl(QStringLiteral("qrc:/invoke-static.qml"))); + stateMachine.start(); + + return app.exec(); +} diff --git a/examples/scxml/invoke-static/invoke-static.pro b/examples/scxml/invoke-static/invoke-static.pro new file mode 100644 index 0000000..86e0845 --- /dev/null +++ b/examples/scxml/invoke-static/invoke-static.pro @@ -0,0 +1,16 @@ +TEMPLATE = app + +QT += qml scxml +CONFIG += c++11 + +SOURCES += invoke-static.cpp + +RESOURCES += invoke-static.qrc + +STATECHARTS = ../invoke-common/statemachine.scxml + +load(qscxmlc) + +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/invoke-static +INSTALLS += target + diff --git a/examples/scxml/invoke-static/invoke-static.qml b/examples/scxml/invoke-static/invoke-static.qml new file mode 100644 index 0000000..68f0556 --- /dev/null +++ b/examples/scxml/invoke-static/invoke-static.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +MainView { + stateMachine: directions +} diff --git a/examples/scxml/invoke-static/invoke-static.qrc b/examples/scxml/invoke-static/invoke-static.qrc new file mode 100644 index 0000000..cc5bcad --- /dev/null +++ b/examples/scxml/invoke-static/invoke-static.qrc @@ -0,0 +1,8 @@ +<RCC> + <qresource prefix="/"> + <file>invoke-static.qml</file> + <file alias="MainView.qml">../invoke-common/MainView.qml</file> + <file alias="SubView.qml">../invoke-common/SubView.qml</file> + <file alias="Button.qml">../invoke-common/Button.qml</file> + </qresource> +</RCC> diff --git a/examples/scxml/mediaplayer-common/Mediaplayer.qml b/examples/scxml/mediaplayer-common/Mediaplayer.qml new file mode 100644 index 0000000..c3e1b98 --- /dev/null +++ b/examples/scxml/mediaplayer-common/Mediaplayer.qml @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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 +import Scxml 1.0 as Scxml + +Window { + id: root + property QtObject stateMachine: scxmlLoader.stateMachine + property alias filename: scxmlLoader.filename + + visible: true + width: 750 + height: 350 + color: "white" + + ListView { + id: theList + width: parent.width / 2 + height: parent.height + keyNavigationWraps: true + highlightMoveDuration: 0 + focus: true + model: ListModel { + id: theModel + ListElement { media: "Song 1" } + ListElement { media: "Song 2" } + ListElement { media: "Song 3" } + } + highlight: Rectangle { color: "lightsteelblue" } + currentIndex: -1 + delegate: Rectangle { + height: 40 + width: parent.width + color: "transparent" + MouseArea { + anchors.fill: parent; + onClicked: tap(index) + } + Text { + id: txt + anchors.fill: parent + text: media + verticalAlignment: Text.AlignVCenter + } + } + } + + Text { + id: theLog + anchors.left: theList.right + anchors.top: theText.bottom + anchors.right: parent.right + anchors.bottom: parent.bottom + } + + Text { + id: theText + anchors.left: theList.right + anchors.right: parent.right; + anchors.top: parent.top + text: "Stopped" + color: stateMachine.playing ? "green" : "red" + } + + Scxml.StateMachineLoader { + id: scxmlLoader + } + + Connections { + target: stateMachine + onPlaybackStarted: { + var media = data.media + theText.text = "Playing '" + media + "'" + theLog.text = theLog.text + "\nplaybackStarted with data: " + JSON.stringify(data) + } + onPlaybackStopped: { + var media = data.media + theText.text = "Stopped '" + media + "'" + theLog.text = theLog.text + "\nplaybackStopped with data: " + JSON.stringify(data) + } + } + + function tap(idx) { + var media = theModel.get(idx).media + var data = { "media": media } + stateMachine.tap(data) + } +} diff --git a/examples/scxml/mediaplayer-common/mainwindow.cpp b/examples/scxml/mediaplayer-common/mainwindow.cpp new file mode 100644 index 0000000..e9a5767 --- /dev/null +++ b/examples/scxml/mediaplayer-common/mainwindow.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include <QStringListModel> + +QT_USE_NAMESPACE + +MainWindow::MainWindow(QWidget *parent) : + QWidget(parent), + ui(new Ui::MainWindow) +{ + ui->setupUi(this); + + auto model = new QStringListModel(QStringList() << QStringLiteral("song 1") + << QStringLiteral("song 2") + << QStringLiteral("song 3"), this); + ui->mediaListView->setModel(model); + + connect(ui->mediaListView, &QAbstractItemView::clicked, [model,this](const QModelIndex & index){ + QVariantMap data; + data.insert(QStringLiteral("media"), model->data(index, Qt::EditRole).toString()); + emit tap(data); + }); +} + +MainWindow::~MainWindow() +{ + delete ui; +} + +void MainWindow::started(const QVariant &data) +{ + QString media = data.toMap().value("media").toString(); + ui->logText->appendPlainText(QStringLiteral("call on slot started with media '%1'").arg(media)); + ui->statusLabel->setText(QStringLiteral("Playing %1").arg(media)); +} + +void MainWindow::stopped(const QVariant &data) +{ + QString media = data.toMap().value("media").toString(); + ui->logText->appendPlainText(QStringLiteral("call on slot stopped with media '%1'").arg(media)); + ui->statusLabel->setText(QStringLiteral("Stopped")); +} diff --git a/examples/scxml/mediaplayer-common/mainwindow.h b/examples/scxml/mediaplayer-common/mainwindow.h new file mode 100644 index 0000000..e9ed5fe --- /dev/null +++ b/examples/scxml/mediaplayer-common/mainwindow.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class MainWindow : public QWidget +{ + Q_OBJECT + +public: + explicit MainWindow(QWidget *parent = 0); + ~MainWindow(); + +signals: + void tap(const QVariant &data); + +public slots: + void started(const QVariant &data); + void stopped(const QVariant &data); + +private: + QT_PREPEND_NAMESPACE(Ui::MainWindow) *ui; +}; + +#endif // MAINWINDOW_H diff --git a/examples/scxml/mediaplayer-common/mainwindow.ui b/examples/scxml/mediaplayer-common/mainwindow.ui new file mode 100644 index 0000000..79679a8 --- /dev/null +++ b/examples/scxml/mediaplayer-common/mainwindow.ui @@ -0,0 +1,34 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QWidget" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>750</width> + <height>350</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" rowspan="2"> + <widget class="QListView" name="mediaListView"/> + </item> + <item row="0" column="1"> + <widget class="QLabel" name="statusLabel"> + <property name="text"> + <string>Stopped</string> + </property> + </widget> + </item> + <item row="1" column="1"> + <widget class="QPlainTextEdit" name="logText"/> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/scxml/mediaplayer-common/mediaplayer.scxml b/examples/scxml/mediaplayer-common/mediaplayer.scxml new file mode 100644 index 0000000..025245a --- /dev/null +++ b/examples/scxml/mediaplayer-common/mediaplayer.scxml @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +--> +<!-- enable-qt-mode: yes --> +<scxml + xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + name="MediaPlayerStateMachine" + initial="stopped" + datamodel="ecmascript" +> + <datamodel> + <data id="media"/> + </datamodel> + + <script> + function isValidMedia() { + var m = _event.data.media + return (m + "").length > 0 + } + </script> + + <state id="stopped"> + <transition event="tap" cond="isValidMedia()" target="playing"/> + </state> + + <state id="playing"> + <onentry> + <assign location="media" expr="_event.data.media"/> + <send type="qt:signal" event="playbackStarted"> + <param name="media" expr="media"/> + </send> + </onentry> + + <onexit> + <send type="qt:signal" event="playbackStopped"> + <param name="media" expr="media"/> + </send> + </onexit> + + <transition event="tap" cond="!isValidMedia() || media === _event.data.media" target="stopped"/> + <transition event="tap" cond="isValidMedia() && media !== _event.data.media" target="playing"/> + </state> +</scxml> diff --git a/examples/scxml/mediaplayer-qml-cppdatamodel/doc/src/mediaplayer-qml-cppdatamodel.qdoc b/examples/scxml/mediaplayer-qml-cppdatamodel/doc/src/mediaplayer-qml-cppdatamodel.qdoc new file mode 100644 index 0000000..d1b2eaa --- /dev/null +++ b/examples/scxml/mediaplayer-qml-cppdatamodel/doc/src/mediaplayer-qml-cppdatamodel.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example mediaplayer-qml-cppdatamodel + \title Qt SCXML: Media Player QML Example (C++ Data Model) + \ingroup examples-qtscxml + + \brief Demonstrates how to send/receive data to/from a C++ data-model. +*/ diff --git a/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-cppdatamodel.scxml b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-cppdatamodel.scxml new file mode 100644 index 0000000..3683c19 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-cppdatamodel.scxml @@ -0,0 +1,84 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +--> +<!-- enable-qt-mode: yes --> +<scxml + xmlns="http://www.w3.org/2005/07/scxml" + version="1.0" + name="MediaPlayerStateMachine" + initial="stopped" + datamodel="cplusplus:TheDataModel:thedatamodel.h" +> + <state id="stopped"> + <transition event="tap" cond="isValidMedia()" target="playing"/> + </state> + + <state id="playing"> + <onentry> + <script> + media = eventData().value(QStringLiteral("media")).toString(); + </script> + <send type="qt:signal" event="playbackStarted"> + <param name="media" expr="media"/> + </send> + </onentry> + + <onexit> + <send type="qt:signal" event="playbackStopped"> + <param name="media" expr="media"/> + </send> + </onexit> + + <transition event="tap" cond="!isValidMedia() || media == eventData().value(QStringLiteral("media"))" target="stopped"/> + <transition event="tap" cond="isValidMedia() && media != eventData().value(QStringLiteral("media"))" target="playing"/> + </state> +</scxml> diff --git a/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.cpp b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.cpp new file mode 100644 index 0000000..cc087f2 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> + +#include "mediaplayer-cppdatamodel.h" +#include "thedatamodel.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + MediaPlayerStateMachine stateMachine; + TheDataModel dataModel(&stateMachine); + stateMachine.init(); + stateMachine.start(); + + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty(QStringLiteral("mediaPlayerStateMachine"), &stateMachine); + engine.load(QUrl(QStringLiteral("qrc:///mediaplayer-qml-cppdatamodel.qml"))); + + return app.exec(); +} diff --git a/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.pro b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.pro new file mode 100644 index 0000000..fae454d --- /dev/null +++ b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.pro @@ -0,0 +1,19 @@ +TEMPLATE = app + +QT += qml scxml +CONFIG += c++11 + +SOURCES += mediaplayer-qml-cppdatamodel.cpp \ + thedatamodel.cpp + +HEADERS += thedatamodel.h + +RESOURCES += mediaplayer-qml-cppdatamodel.qrc + +STATECHARTS = mediaplayer-cppdatamodel.scxml + +load(qscxmlc) + +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/mediaplayer-qml-cppdatamodel +INSTALLS += target + diff --git a/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.qml b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.qml new file mode 100644 index 0000000..252d69b --- /dev/null +++ b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +Mediaplayer { + stateMachine: mediaPlayerStateMachine +} diff --git a/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.qrc b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.qrc new file mode 100644 index 0000000..0de7eb7 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-cppdatamodel/mediaplayer-qml-cppdatamodel.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file alias="Mediaplayer.qml">../mediaplayer-common/Mediaplayer.qml</file> + <file>mediaplayer-qml-cppdatamodel.qml</file> + </qresource> +</RCC> diff --git a/examples/scxml/mediaplayer-qml-cppdatamodel/thedatamodel.cpp b/examples/scxml/mediaplayer-qml-cppdatamodel/thedatamodel.cpp new file mode 100644 index 0000000..8ac6864 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-cppdatamodel/thedatamodel.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "thedatamodel.h" + +#include <QScxmlEvent> + +TheDataModel::TheDataModel(QScxmlStateMachine *stateMachine) + : QScxmlCppDataModel(stateMachine) +{ +} + +TheDataModel::~TheDataModel() +{} + +bool TheDataModel::isValidMedia() const +{ + QString eventMedia = eventData().value(QStringLiteral("media")).toString(); + return eventMedia.size() > 0; +} + +QVariantMap TheDataModel::eventData() const +{ + return event().data().value<QVariantMap>(); +} diff --git a/examples/scxml/mediaplayer-qml-cppdatamodel/thedatamodel.h b/examples/scxml/mediaplayer-qml-cppdatamodel/thedatamodel.h new file mode 100644 index 0000000..ce4ac67 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-cppdatamodel/thedatamodel.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef THEDATAMODEL_H +#define THEDATAMODEL_H + +#include "qscxmlcppdatamodel.h" + +class TheDataModel: public QScxmlCppDataModel +{ + Q_SCXML_DATAMODEL + +public: + TheDataModel(QScxmlStateMachine *stateMachine); + ~TheDataModel(); + +private: + bool isValidMedia() const; + QVariantMap eventData() const; + + QString media; +}; + +#endif // THEDATAMODEL_H diff --git a/examples/scxml/mediaplayer-qml-dynamic/doc/src/mediaplayer-qml-dynamic.qdoc b/examples/scxml/mediaplayer-qml-dynamic/doc/src/mediaplayer-qml-dynamic.qdoc new file mode 100644 index 0000000..7bdc6e3 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-dynamic/doc/src/mediaplayer-qml-dynamic.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example mediaplayer-qml-dynamic + \title Qt SCXML: Media Player QML Example (Dynamic) + \ingroup examples-qtscxml + + \brief Demonstrates how to send/receive data to/from EcmaScript data-model. +*/ diff --git a/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.cpp b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.cpp new file mode 100644 index 0000000..51f5738 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:///mediaplayer-qml-dynamic.qml"))); + + return app.exec(); +} + diff --git a/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.pro b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.pro new file mode 100644 index 0000000..1af874f --- /dev/null +++ b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.pro @@ -0,0 +1,14 @@ +TEMPLATE = app + +QT += qml scxml +CONFIG += c++11 + +SOURCES += mediaplayer-qml-dynamic.cpp + +RESOURCES += mediaplayer-qml-dynamic.qrc + +load(qscxmlc) + +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/mediaplayer-qml-dynamic +INSTALLS += target + diff --git a/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qml b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qml new file mode 100644 index 0000000..3e936c3 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +Mediaplayer { + filename: "qrc:///mediaplayer.scxml" +} diff --git a/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qrc b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qrc new file mode 100644 index 0000000..0c7c40b --- /dev/null +++ b/examples/scxml/mediaplayer-qml-dynamic/mediaplayer-qml-dynamic.qrc @@ -0,0 +1,7 @@ +<RCC> + <qresource prefix="/"> + <file alias="Mediaplayer.qml">../mediaplayer-common/Mediaplayer.qml</file> + <file>mediaplayer-qml-dynamic.qml</file> + <file alias="mediaplayer.scxml">../mediaplayer-common/mediaplayer.scxml</file> + </qresource> +</RCC> diff --git a/examples/scxml/mediaplayer-qml-static/doc/src/mediaplayer-qml-static.qdoc b/examples/scxml/mediaplayer-qml-static/doc/src/mediaplayer-qml-static.qdoc new file mode 100644 index 0000000..427a100 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-static/doc/src/mediaplayer-qml-static.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example mediaplayer-qml-static + \title Qt SCXML: Media Player QML Example (Static) + \ingroup examples-qtscxml + + \brief Demonstrates how to send/receive data to/from EcmaScript data-model. +*/ diff --git a/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.cpp b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.cpp new file mode 100644 index 0000000..c6d9d3a --- /dev/null +++ b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> + +#include "mediaplayer.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + MediaPlayerStateMachine stateMachine; + stateMachine.init(); + stateMachine.start(); + + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty(QStringLiteral("mediaPlayerStateMachine"), &stateMachine); + engine.load(QUrl(QStringLiteral("qrc:///mediaplayer-qml-static.qml"))); + + return app.exec(); +} + diff --git a/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.pro b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.pro new file mode 100644 index 0000000..b6ca140 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.pro @@ -0,0 +1,16 @@ +TEMPLATE = app + +QT += qml scxml +CONFIG += c++11 + +SOURCES += mediaplayer-qml-static.cpp + +RESOURCES += mediaplayer-qml-static.qrc + +STATECHARTS = ../mediaplayer-common/mediaplayer.scxml + +load(qscxmlc) + +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/mediaplayer-qml-static +INSTALLS += target + diff --git a/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qml b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qml new file mode 100644 index 0000000..252d69b --- /dev/null +++ b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +Mediaplayer { + stateMachine: mediaPlayerStateMachine +} diff --git a/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qrc b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qrc new file mode 100644 index 0000000..e65d449 --- /dev/null +++ b/examples/scxml/mediaplayer-qml-static/mediaplayer-qml-static.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file alias="Mediaplayer.qml">../mediaplayer-common/Mediaplayer.qml</file> + <file>mediaplayer-qml-static.qml</file> + </qresource> +</RCC> diff --git a/examples/scxml/mediaplayer-widgets-dynamic/doc/src/mediaplayer-widgets-dynamic.qdoc b/examples/scxml/mediaplayer-widgets-dynamic/doc/src/mediaplayer-widgets-dynamic.qdoc new file mode 100644 index 0000000..6ef43ea --- /dev/null +++ b/examples/scxml/mediaplayer-widgets-dynamic/doc/src/mediaplayer-widgets-dynamic.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example mediaplayer-widgets-dynamic + \title Qt SCXML: Media Player Example (Dynamic) + \ingroup examples-qtscxml + + \brief Demonstrates how to send/receive data to/from EcmaScript data-model. +*/ diff --git a/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer-widgets-dynamic.cpp b/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer-widgets-dynamic.cpp new file mode 100644 index 0000000..f36a62e --- /dev/null +++ b/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer-widgets-dynamic.cpp @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "../mediaplayer-common/mainwindow.h" + +#include <QScxmlStateMachine> +#include <QApplication> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + auto machine = QScxmlStateMachine::fromFile(QStringLiteral(":mediaplayer.scxml")); + machine->init(); + MainWindow mainWindow; + machine->setParent(&mainWindow); + + QObject::connect(&mainWindow, SIGNAL(tap(const QVariant &)), + machine, SLOT(tap(const QVariant &))); + QObject::connect(machine, SIGNAL(playbackStarted(const QVariant &)), + &mainWindow, SLOT(started(const QVariant &))); + QObject::connect(machine, SIGNAL(playbackStopped(const QVariant &)), + &mainWindow, SLOT(stopped(const QVariant &))); + + machine->start(); + mainWindow.show(); + return app.exec(); +} diff --git a/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer-widgets-dynamic.pro b/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer-widgets-dynamic.pro new file mode 100644 index 0000000..e157f0c --- /dev/null +++ b/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer-widgets-dynamic.pro @@ -0,0 +1,20 @@ +QT += widgets scxml + +CONFIG += c++11 + +SOURCES += \ + mediaplayer-widgets-dynamic.cpp \ + ../mediaplayer-common/mainwindow.cpp + +FORMS += \ + ../mediaplayer-common/mainwindow.ui + +HEADERS += \ + ../mediaplayer-common/mainwindow.h + +RESOURCES += \ + mediaplayer.qrc + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/mediaplayer-widgets +INSTALLS += target diff --git a/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer.qrc b/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer.qrc new file mode 100644 index 0000000..aecd468 --- /dev/null +++ b/examples/scxml/mediaplayer-widgets-dynamic/mediaplayer.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/"> + <file alias="mediaplayer.scxml">../mediaplayer-common/mediaplayer.scxml</file> + </qresource> +</RCC> + diff --git a/examples/scxml/mediaplayer-widgets-static/doc/src/mediaplayer-widgets-static.qdoc b/examples/scxml/mediaplayer-widgets-static/doc/src/mediaplayer-widgets-static.qdoc new file mode 100644 index 0000000..f06db24 --- /dev/null +++ b/examples/scxml/mediaplayer-widgets-static/doc/src/mediaplayer-widgets-static.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example mediaplayer-widgets-static + \title Qt SCXML: Media Player Example (Static) + \ingroup examples-qtscxml + + \brief Demonstrates how to send/receive data to/from EcmaScript data-model. +*/ diff --git a/examples/scxml/mediaplayer-widgets-static/mediaplayer-widgets-static.cpp b/examples/scxml/mediaplayer-widgets-static/mediaplayer-widgets-static.cpp new file mode 100644 index 0000000..dcc6d59 --- /dev/null +++ b/examples/scxml/mediaplayer-widgets-static/mediaplayer-widgets-static.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "mediaplayer.h" +#include "../mediaplayer-common/mainwindow.h" + +#include <QApplication> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + MediaPlayerStateMachine machine; + machine.init(); + MainWindow mainWindow; + + QObject::connect(&mainWindow, &MainWindow::tap, + &machine, &MediaPlayerStateMachine::tap); + QObject::connect(&machine, &MediaPlayerStateMachine::playbackStarted, + &mainWindow, &MainWindow::started); + QObject::connect(&machine, &MediaPlayerStateMachine::playbackStopped, + &mainWindow, &MainWindow::stopped); + + machine.start(); + mainWindow.show(); + return app.exec(); +} diff --git a/examples/scxml/mediaplayer-widgets-static/mediaplayer-widgets-static.pro b/examples/scxml/mediaplayer-widgets-static/mediaplayer-widgets-static.pro new file mode 100644 index 0000000..a108453 --- /dev/null +++ b/examples/scxml/mediaplayer-widgets-static/mediaplayer-widgets-static.pro @@ -0,0 +1,21 @@ +QT += widgets scxml + +CONFIG += c++11 + +STATECHARTS = ../mediaplayer-common/mediaplayer.scxml + +SOURCES += \ + mediaplayer-widgets-static.cpp \ + ../mediaplayer-common/mainwindow.cpp + +FORMS += \ + ../mediaplayer-common/mainwindow.ui + +HEADERS += \ + ../mediaplayer-common/mainwindow.h + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/mediaplayer-widgets +INSTALLS += target + +load(qscxmlc) diff --git a/examples/scxml/pinball/doc/images/pinball.png b/examples/scxml/pinball/doc/images/pinball.png Binary files differnew file mode 100644 index 0000000..bbd390e --- /dev/null +++ b/examples/scxml/pinball/doc/images/pinball.png diff --git a/examples/scxml/pinball/doc/src/pinball.qdoc b/examples/scxml/pinball/doc/src/pinball.qdoc new file mode 100644 index 0000000..f67b66d --- /dev/null +++ b/examples/scxml/pinball/doc/src/pinball.qdoc @@ -0,0 +1,551 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example pinball + \title Qt SCXML: Pinball Example + \ingroup examples-qtscxml + \brief Demonstrates how the internal + logic of the application can be encapsulated in a scxml file. + + This example demonstrates a clear separation + between chosen user interface, which may be easily replaced, + and internal logic encapsulated in the scxml file, + which may stay the same for different user interface. + + \section1 Pinball Features + + \image pinball.png Screenshot of the Pinball example + + \e {Pinball Example} mimics a pinball game. + The targets on the pinball table are substituted here by GUI controls, + mainly by push buttons. Display elements, including current + score, highscore and targets' lights are substituted by labels. + Usually targets' lights state changes very often during game: + they get turned on or off, they blink slowly, fast or + with any intermediate speed indicating a game (or a certain target) + entered some temporary state. The state of each target light + is presented here as an enabled or a disabled label. + There is no real ball here, but one can easily imagine that + pressing a target's button can mimic hitting a real pinball + target with a ball. + + Our pinball contains the following features: + \list + \li Initially and when the game ends the pinball table + goes into \c offState. In that state all lights on the table + blink slowly (with 1s interval). + \li After pressing the \uicontrol START button the pinball table + goes into \c onState. All lights get turned off and the + pinball table is ready to be played. + \li Whenever the table is in \c onState and the inattentive player + presses the \uicontrol {BALL OUT} button, the game ends + and enters into the \c offState. If the player's score is + higher than the current highscore, the highscore is updated. + \li The goal is to collect the \uicontrol JACKPOT. In order to do that, + the player must hit all five \uicontrol CRAZY letters twice. + He has unlimited time for collecting it for the first time. + However, after he has collected all the letters for the first time, + he enters the \c hurryState and he must quickly collect + all the letters again within 5s. If the time passed and + the letters were not collected again, the player must + start collecting the letters from scratch. + \li Scores: + \list + \li 1.000 per letter hit when not in \c hurryState. + \li 10.000 per letter hit when in \c hurryState. + \li 100.000 bonus for all 5 letters when not in \c hurryState. + \li 1.000.000 bonus for all 5 letters when in \c hurryState (\uicontrol JACKPOT) + \endlist + \li When not in \c hurryState, the letters already hit should blink + with intermediate speed (500ms). Letters not hit yet should stay off. + \li When in \c hurryState, the letters already hit should + stay on. Letters not hit yet should blink fast (200ms). + In addition the \uicontrol HURRY light should blink with the same speed. + \li When jackpot gets collected the \uicontrol JACKPOT light should stay on. + \endlist + + \section1 SCXML Part: Internal Logic Description + + The pinball.scxml file describes the internal logic implemented for + pinball game. + + \quotefromfile pinball/pinball.scxml + \skipto scxml + \printuntil guiControl + \dots 12 + \skipto /^\ {8}<\// + \printuntil internalState + \dots 12 + \skipto /^\ {8}<\// + \printuntil scxml + + In this example we've chosen ecmascript data model + ("datamodel" attribute of <scxml> element). + This data model enables declaring variables with + initial values, which can be modified later. + We declare two variables in our model: "highscore" and "score", + with initial values of 0 (two <data> elements inside <datamodel> element). + We also define a root parallel state "global", + with two child states: \c guiControl and \c internalState, + which are also parallel. Since the top \c global state is + parallel, it means that whenever a \c global state is active + all of its direct children are also active. In fact, + the top level \c global is always active, meaning + all of its children are always active, too. + The \c global state in our example doesn't play any other role apart from + collecting its two children and making them both active at a time. + + \quotefromfile pinball/pinball.scxml + \skipto guiControl + \printuntil rLight + \dots 16 + \skipto /^\ {12}<\// + \printuntil aLight + \dots 16 + \skipto /^\ {12}<\// + \printuntil zLight + \dots 16 + \skipto /^\ {12}<\// + \printuntil yLight + \dots 16 + \skipto /^\ {12}<\// + \printuntil hurryLight + \dots 16 + \skipto /^\ {12}<\// + \printuntil jackpotLight + \dots 16 + \skipto /^\ {12}<\// + \printuntil gameOverLight + \dots 16 + \skipto /^\ {12}<\// + \printuntil /^\ {8}<\// + + The \c guiControl part is responsible for maintaining the current + state of every light control, which is visible on the pinball table. + We have eight different lights, five for letters: C, R, A, Z and Y, + and three for whole texts: \uicontrol HURRY!, \uicontrol JACKPOT + and \uicontrol {GAME OVER}. Every light + corresponds to its state, e.g. for light of letter \uicontrol C we have + a \c cLight state and so on. Every light state has two child states + indicating whether the light is on or off, e.g. \c cLight state + contains \c cLightOn and \c cLightOff states. The content + for other light states, which is omitted here, is analogous. + As mentioned before, \c guiControl state is always active, and since + it is of parallel type, all its direct children are always active too. + So, \c cLight state is always active, however, + only one of \c cLightOn or \c cLightOff it active at a time. + The same applies to other children of \c guiControl state. + In addition, we define transitions between on and off substates, e.g. + whenever the active state is \c cLightOn and someone posts \c turnOffC event, + we change the active substate of \c cLight into \c cLightOff, and vice versa: + whenever the active state is \c cLightOff and we receive \c turnOnC event, + we change the active substate of \c cLight into \c cLightOn. + + In case of our application, we use instances of QLabel class in C++ + to pretend real lights on the table. Whenever the light transitions + into "on" or "off" state we enable or disable the particular label + accordingly. The glue connection between the state machine and the GUI + part of the application will be shown in \l {cpp} {cpp code} later on. For now + it is enough to realize that changes to active states inside + the state machine will serve as external interface of the state machine, + so that other parts of the application (e.g. GUI part) can listen to. + + All of the mentioned events which switch the state of every light + will be generated by this state machine inside \c internalState + in reaction to running timers or to external triggers. + + \quotefromfile pinball/pinball.scxml + \skipto internalState + \printuntil logicalState + \dots 16 + \skipto /^\ {12}<\// + \printuntil workflow + \dots 16 + \skipto /^\ {12}<\// + \printuntil /^\ {8}<\// + + The \c internalState consists of two main parts: \c logicalState and \c workflow. + The \c logicalState holds the definitions for modes the game is able + to go into and logical states of collected targets, while \c workflow state + implements generator for light blinking and calculates most of new states + machine should go into depending on incoming events and on currently active states. + As mentioned already, \c internalState is always active, and since + it is of a parallel type, \c logicalState and \c workflow children are always active too. + + \quotefromfile pinball/pinball.scxml + \skipto logicalState + \printuntil letterState + \dots 20 + \skipto /^\ {16}<\// + \printuntil modeState + \dots 20 + \skipto /^\ {16}<\// + \printuntil /^\ {12}<\// + + The \c logicalState consist of two parts: \c letterState and \c modeState. + As previously mentioned, \c logicalState is always active, and since + it is of parallel type, \c letterState and \c modeState children are always active too. + Now let's look at the first part of it, the \c letterState: + + \quotefromfile pinball/pinball.scxml + \skipto letterState + \printuntil lettersState + \printuntil rLetter + \dots 28 + \skipto /^\ {24}<\// + \printuntil aLetter + \dots 28 + \skipto /^\ {24}<\// + \printuntil zLetter + \dots 28 + \skipto /^\ {24}<\// + \printuntil yLetter + \dots 28 + \skipto /^\ {24}<\// + \printuntil /^\ {16}<\// + + It contains one parallel \c lettersState. + The \c lettersState maintains the logical state of + buttons pretending targets which were pressed by the user. + Please notice the difference between lettersStates and lightStates + which were mentioned earlier. E.g. the letter state for \uicontrol C letter + holds the info if the target for \uicontrol C letter was hit or not, + while the light state for \uicontrol C letter holds the info if the + light for the target for \uicontrol C letter should be currently on or off. + In the real pinball game these states are usually orthogonal, + e.g. if you didn't hit any target yet, the target is blinking, + indicating that it's currently worth to hit it. This blinking + means the light state switches between on or off in some short time interval, + while the target state is continouosly off, since it was not hit yet. + The author of a pinball table can decide e.g. that + after hitting the target (so after the target state goes to on) + he turns target's light continouosly off or on or just increase + of decrease the interval of blinking. + + As mentioned before, \c letterState is always active, so it means + that its only child \c lettersState should always be active too. However, + there is an exception here: for a short while the \c lettersState may + end up being \e {not active}. This happens when the transition for + \c lettersState is being performed. This transition is triggered when + the \c resetLetters event will appear and it instructs the state machine + to exit \c lettersState and all its descendant states and reenter + \c lettersState and set up all its descendant states with their initial states. + In short, the \c resetLetters event resets the \c lettersState and all its + descendant states to the default configuration. + + The \c lettersState contains five direct substates which + correspond to five different letters. The content + for other letters states than C, which is omitted here, is analogous. + + The \c cLetter contains two substates reflecting its off and on states: + \c cLetterOff and \c cLetterOn. The "cLetter" state inside its parallel + parent \c lettersState is always active (under condition that + \c lettersState is active, too, what was described before), however, + only one of its child states is active at a time: \c cLetterOff or \c cLetterOn. + The initial substate of \c cLetter state is \c cLetterOff meaning + that whenever \c cLetter state is being activated (what happens + initially and after \c resetLetters event) its active + substate will be set to \c cLetterOff. + + The \c cLetterOff defines a transition, which will be triggered by + the \c {cLetterTriggered} event. This transition activates the \c cLetterOn, + the other child of \c cLetter, only when the machine is in \c onState + (which will be defined later, but in short: when the pinball game is running). + The \c {cLetterTriggered} event is expected to be an event posted into the state machine + from outside of the state machine. This event should be generated when + the ball hits the \uicontrol C letter target. In our example we mimic + it by the pressing \uicontrol C letter button. + + The \c cLetterOn state defines additional action. The action is defined + inside \c onentry element of the state, which means it will be executed + when the state machine enters this state. The action will generate + the event \c letterOn, which is common for all other letter states + defined in \c lettersState. This event will be used in further part + for updating the current score. So, whenever any of letters will switch + its state from off to on (but not vice versa), the \c letterOn + event will be posted. + + The \c cLetterOn state is defined as a final state, which means that + whenever this state is activated the \c {done.state.cLetter} event + will be automatically posted by the state machine. Moreover, + when all \c lettersState children reach their final state, + the state machine will automatically post \c {done.state.lettersState} event. + Later, we will make use of it. + + \quotefromfile pinball/pinball.scxml + \skipto modeState + \printuntil offState + \dots 24 + \skipto /^\ {20}<\// + \printuntil onState + \dots 24 + \skipto /^\ {20}<\// + \printuntil /^\ {16}<\// + + The \c modeState consists of two substates, \c offState and \c onState. + The \c offState describes what should happen when the pinball game + is not yet started or when it is over, + while \c onState represents the logic appropriate for the active game. + + \quotefromfile pinball/pinball.scxml + \skipto offState + \printuntil /^\ {20}<\// + + Whenever the pinball application starts or when the game ends the machine goes into the + \c offState. Entering that state invokes some actions, which are + enclosed inside <onentry> element. First, we update the highScore + variable in case the current highScore value is less than current score value. + This is being checked inside the "cond" attribute of <if> element + (please note that we need to escape the "<" character with "<"). + When being in off state, we still want to show the last reached score, + so we don't clear it here - we will do that when we enter the on state. + Next, we raise two events: \c resetLetters for logical reset of + all letter which were possibly hit during last game and \c update + for immediate generation of light blink and update of all lights. + When the machine is in \c offState it is ready to go into the + \c onState if only the \c startTriggered event occurs, which is described + by <transition> element. This event is expected to be generated externally + after pressing the \uicontrol START button on the pinball table. + + \skipto onState + \printuntil /^\ {20}<\// + + The fist thing which is being done by the state machine after in enters + the \c onState is clearing the current score variable. The \c onState + is of parallel type and consists of two direct child states: + \c hurryState and \c jackpotState, which both are always active as long as + their parent "onState" is active too. Both \c hurryState and \c jackpotState + contain two substates which reflects the off and the on state of each of them. + Only one substate of \c hurryState and one substate of \c jackpotState + can be acitve at a time and initially the off substates are active. + + Whenever we enter \c hurryStateOff or \c hurryStateOn we generate two events: + \c resetLetters and \c update (the same as we generate when entering the \c onState). + In addition when we enter the \c hurryStateOn we send a delayed event + \c goToHurryOff with a delay of 5s, marked with \c hurryId. It means, that after 5s we just + switch the state back to \c hurryStateOff. In this way we implement + the five seconds hurry feature of the pinball table. + We also define transitions: \c hurryStateOff -> \c hurryStateOn + when \c goToHurryOn event occurs and the opposite, + \c hurryStateOn -> \c hurryStateOff when \c goToHurryOff event occurs. + When we exit the \c hurryStateOn we cancel possibly pending delayed + event which was marked with \c hurryId. This is important in case + the 5s time hasn't elapsed yet, but we've collected all the five letters + in the hurry state - we then collect the jackpot and want the pending + timer to finish. + + The substates of \c jackpotState generate the request for update the state + of lights. The \c jackpotStateOff defines the transition to \c jackpotStateOn + when the \c goForJackpot event occurs. The opposite transition isn't + needed, since when the jackpot gets collected the corresponding light + is left lit until the end of game. When the new game starts, the \c jackpotState + is entered again which causes that its initial active substate will be + \c jackpotStateOff. + + In addition, the \c onState defines one transition in reaction to + \c ballOutTriggered event which instructs the machine to go into the \c offState. + The \c ballOutTriggered event is expected to be an event posted into the state machine + from outside of the state machine. This event should be generated when + the ball gets out of playing area of the table. In our example we mimic + it by the pressing \uicontrol {BALL OUT} button. Posting the event from outside of state + machine will be shown in \l {cpp} {cpp code} later on. + + \quotefromfile pinball/pinball.scxml + \skipto workflow + \printuntil letterOn + \dots 20 + \skipto /^\ {16}<\// + \printuntil lettersState + \dots 20 + \skipto /^\ {16}<\// + \printuntil updateLights + \dots 20 + \skipto /^\ {16}<\// + \printuntil /^\ {12}<\// + + The \c workflow state is responsible for generator for light blinking, + which is defined in its \c lightImpulseGenerator substate, and + for reacting for events which were posted so far from other parts + of the state machine. + + The \c lightImpulseGenerator contains two child states: + \c lightImpulseOn and \c lightImpulseOff, with only one active at a time. + Whenever the delayed \c lightImpulse event is being delivered, it immediately + cause the transition from \c lightImpluseOn into \c lightImpulseOff or vice versa, + depending on the state the machine was in. In effect, the \c lightImpulseGenerator + toggles between its on and off state. These transitions are defined inside + \c lightImpulseGenerator, so it means that during this toggling the machine + also exits \c lightImpulseGenerator and reenters it immediately afterwards. + Entering \c lightImpulseGenerator cause generation of the \c update event. + The \c update event triggers the targetless transition and posts two other + events: \c scheduleNewImpulse and \c updateLights. The first one, + \c scheduleNewImpulse returns back to the \c lightImpulseGenerator and + it posts delayed \c lightImpulse event. After the desired delay, + the \c lightImpulse gets delivered to \c lightImpulseGenerator back + and it causes to toggle its substate again. In this way the machine + gets into the cycle. The current delay of the \c lightImpulse + event depends on the state in which the machine was in time of posting that delayed event. + Please also notice, that the next \c scheduleNewImpulse + event may occur on demand, before the next delayed \c lightImpulse + event gets delivered, so for that case we cancel any possible pending event. + + \quotefromfile pinball/pinball.scxml + \skipto workflow + \skipto letterOn + \printuntil /^\ {16}<\// + \printuntil /^\ {16}<\// + + Whenever we receive the \c letterOn event we update the current score. + The transition for the \c letterOn event is targetless, since we just + listen for that event and update the internal data accordingly + without changing any active state. The new score is being + increased by 1.000 or 10.000 points, depending if we currently are + in \c hurryStateOff or \c hurryStateOn. + After the score is updated we generate the \c updateLights event + in order to update immediately letters' lights accordingly. + We don't generate "update" here, since we don't want to toggle + light impulse now, but just update the lights according to + the current impulse state. + + We also intercept the \c {done.state.lettersState} event, + which is being generated when all the letters were hit. + Depending on which state we are currently in, we grant + a small bonus of 100.000 or a big one of 1.000.000 (jackpot). + In addition we toggle \c hurryState substate by + sending \c goToHurryOn or \c goToHurryOff event. + When all letters were collected being in \c hurryStateOn + we also raise the \c goForJackpot event which instructs + the machine to activate the \c jackpotStateOn. + + \skipto updateLights + \printuntil rLetterOn + \dots 32 + \skipto /^\ {28}<\// + \printuntil aLetterOn + \dots 32 + \skipto /^\ {28}<\// + \printuntil zLetterOn + \dots 32 + \skipto /^\ {28}<\// + \printuntil yLetterOn + \dots 32 + \skipto /^\ {28}<\// + \printuntil rLetterOn + \dots 32 + \skipto /^\ {28}<\// + \printuntil aLetterOn + \dots 32 + \skipto /^\ {28}<\// + \printuntil zLetterOn + \dots 32 + \skipto /^\ {28}<\// + \printuntil yLetterOn + \dots 32 + \skipto /^\ {28}<\// + \printuntil /^\ {16}<\// + + When we receive \c updateLights event, we first want to send a + \c updateScore signal outside of the state machine. We pass + to the signal current value of highscore and score variables. + This signal is received by the cpp part. + + Next, depending if we are in \c jackpotStateOn or \c jackpotStateOff + we send the \c turnOnJackpot or the \c turnOffJackpot signal, + which instructs the \c guiControl state to transition to + \c jackpotLightOn or \c jackpotLightOff respectively. + + When the machine is in \e idle state, i.e. in off state + or when the game is on, but no interaction is being performed, + the \c updateLights event is delivered periodically + during the game, each time with \c lightImpulseOn or + \c lightImpulseOff state toggled. Depending on the + current state of light impulse, and depending also + on which of \c offState, \c hurryStateOff or \c hurryStateOn + is active we turn on or off all the lights accordingly + to the description of the pinball table. + + \section1 GUI Part: User Interface Description + + The GUI part of the application consists of a mainwindow.ui + file which describes the static user interface of the game. + + \target cpp + \section1 CPP Part: Glue GUI with SCXML + + The CPP part of the application consists of a + MainWindow class which glues the GUI part with the SCXML part. + The class is declared in mainwindow.h. + + \quotefromfile pinball/mainwindow.h + \skipto Pinball + \printuntil }; + + The MainWindow class holds the pointer to the + \c {Pinball *m_machine} which is the state machine + class automatically generated by Qt out of SCMXL file + and the pointer to the \c {Ui::MainWindow *m_ui} which + describes the GUI part. It also declares two helper methods. + + \quotefromfile pinball/mainwindow.cpp + \skipto #include + \printuntil /}$/ + + The constructor of the MainWindow class + instantiates the GUI part of the application + and stores the pointer to the passed \c Pinball state machine. + It also initializes the GUI part and glues the + GUI part with the state machine by connecting + their communication interfaces together. + + The \c initAndConnect() method connects + the state with the corresponding GUI widget by + binding its activity with the enablement of the widget, + so that whenever the state is active its corresponding + widget is enabled and whenever the state is inactive + the widget is disabled. We do that for all lights, targets + and description lables. + + We also connect to the \c updateScore propagated + by the state machine and update the score displays + with the values passed with the event. + + The info about hitting any GUI target needs to be passed + to the state machine and we do that by connecting + all target buttons' \c clicked signals to the lambda expressions + which submit corresponding event into the state machine. + + \quotefromfile pinball/main.cpp + \skipto #include + \printuntil /}$/ + + Finally, there is main.cpp file with the main() function + inside which we instantiate the + \c app application object, \c Pinball state machine + and \c MainWindow GUI class. We initialize and start the state machine, + show the main window and execute the application. +*/ diff --git a/examples/scxml/pinball/main.cpp b/examples/scxml/pinball/main.cpp new file mode 100644 index 0000000..4b4c06e --- /dev/null +++ b/examples/scxml/pinball/main.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "pinball.h" +#include "mainwindow.h" + +#include <QApplication> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + Pinball machine; + MainWindow mainWindow(&machine); + machine.init(); + + machine.start(); + mainWindow.show(); + return app.exec(); +} diff --git a/examples/scxml/pinball/mainwindow.cpp b/examples/scxml/pinball/mainwindow.cpp new file mode 100644 index 0000000..424a786 --- /dev/null +++ b/examples/scxml/pinball/mainwindow.cpp @@ -0,0 +1,137 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "mainwindow.h" +#include "ui_mainwindow.h" + +#include <QStringListModel> +#include "pinball.h" + +QT_USE_NAMESPACE + +MainWindow::MainWindow(Pinball *machine, QWidget *parent) : + QWidget(parent), + m_ui(new Ui::MainWindow), + m_machine(machine) +{ + m_ui->setupUi(this); + + // lights + initAndConnect(QLatin1String("cLightOn"), m_ui->cLabel); + initAndConnect(QLatin1String("rLightOn"), m_ui->rLabel); + initAndConnect(QLatin1String("aLightOn"), m_ui->aLabel); + initAndConnect(QLatin1String("zLightOn"), m_ui->zLabel); + initAndConnect(QLatin1String("yLightOn"), m_ui->yLabel); + initAndConnect(QLatin1String("hurryLightOn"), m_ui->hurryLabel); + initAndConnect(QLatin1String("jackpotLightOn"), m_ui->jackpotLabel); + initAndConnect(QLatin1String("gameOverLightOn"), m_ui->gameOverLabel); + + // help labels + initAndConnect(QLatin1String("offState"), m_ui->offStateLabel); + initAndConnect(QLatin1String("hurryStateOff"), m_ui->normalStateLabel); + initAndConnect(QLatin1String("hurryStateOn"), m_ui->hurryStateLabel); + initAndConnect(QLatin1String("jackpotStateOn"), m_ui->jackpotStateLabel); + + // context enablement + initAndConnect(QLatin1String("offState"), m_ui->startButton); + initAndConnect(QLatin1String("onState"), m_ui->cButton); + initAndConnect(QLatin1String("onState"), m_ui->rButton); + initAndConnect(QLatin1String("onState"), m_ui->aButton); + initAndConnect(QLatin1String("onState"), m_ui->zButton); + initAndConnect(QLatin1String("onState"), m_ui->yButton); + initAndConnect(QLatin1String("onState"), m_ui->ballOutButton); + + // datamodel update + connect(m_machine, SIGNAL(updateScore(const QVariant &)), + this, SLOT(updateScore(const QVariant &))); + + // gui interaction + connect(m_ui->cButton, &QAbstractButton::clicked, + [this] { m_machine->submitEvent("cLetterTriggered"); + }); + connect(m_ui->rButton, &QAbstractButton::clicked, + [this] { m_machine->submitEvent("rLetterTriggered"); + }); + connect(m_ui->aButton, &QAbstractButton::clicked, + [this] { m_machine->submitEvent("aLetterTriggered"); + }); + connect(m_ui->zButton, &QAbstractButton::clicked, + [this] { m_machine->submitEvent("zLetterTriggered"); + }); + connect(m_ui->yButton, &QAbstractButton::clicked, + [this] { m_machine->submitEvent("yLetterTriggered"); + }); + connect(m_ui->startButton, &QAbstractButton::clicked, + [this] { m_machine->submitEvent("startTriggered"); + }); + connect(m_ui->ballOutButton, &QAbstractButton::clicked, + [this] { m_machine->submitEvent("ballOutTriggered"); + }); +} + +MainWindow::~MainWindow() +{ + delete m_ui; +} + +void MainWindow::initAndConnect(const QString &state, QWidget *widget) +{ + widget->setEnabled(m_machine->isActive(state)); + m_machine->connectToState(state, widget, SLOT(setEnabled(bool))); +} + +void MainWindow::updateScore(const QVariant &data) +{ + const QString highScore = data.toMap().value("highScore").toString(); + m_ui->highScoreLabel->setText(highScore); + const QString score = data.toMap().value("score").toString(); + m_ui->scoreLabel->setText(score); +} + diff --git a/examples/scxml/pinball/mainwindow.h b/examples/scxml/pinball/mainwindow.h new file mode 100644 index 0000000..985f77c --- /dev/null +++ b/examples/scxml/pinball/mainwindow.h @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include <QWidget> + +QT_BEGIN_NAMESPACE +namespace Ui { +class MainWindow; +} +QT_END_NAMESPACE + +class Pinball; + +class MainWindow : public QWidget +{ + Q_OBJECT + +public: + explicit MainWindow(Pinball *machine, QWidget *parent = 0); + ~MainWindow(); + +private slots: + void updateScore(const QVariant &data); + +private: + void initAndConnect(const QString &state, QWidget *widget); + QT_PREPEND_NAMESPACE(Ui::MainWindow) *m_ui; + Pinball *m_machine; +}; + +#endif // MAINWINDOW_H diff --git a/examples/scxml/pinball/mainwindow.ui b/examples/scxml/pinball/mainwindow.ui new file mode 100644 index 0000000..cc25176 --- /dev/null +++ b/examples/scxml/pinball/mainwindow.ui @@ -0,0 +1,666 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>MainWindow</class> + <widget class="QWidget" name="MainWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>476</width> + <height>458</height> + </rect> + </property> + <property name="windowTitle"> + <string>Pinball</string> + </property> + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="5"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QLabel" name="highScoreTextLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>HIGH SCORE:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="highScoreLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>0</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="scoreTextLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>SCORE:</string> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="scoreLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>0</string> + </property> + <property name="alignment"> + <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set> + </property> + </widget> + </item> + </layout> + </item> + <item row="0" column="5" rowspan="7"> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>1</width> + <height>98</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QToolButton" name="startButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Minimum"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>^ +^ +^ + +S +T +A +R +T + +^ +^ +^</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="1" column="0" colspan="5"> + <widget class="QLabel" name="gameOverLabel"> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>0</green> + <blue>4</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>255</red> + <green>0</green> + <blue>4</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>190</red> + <green>190</green> + <blue>190</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="font"> + <font> + <pointsize>20</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>GAME OVER</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="2" column="0" colspan="5"> + <widget class="QLabel" name="jackpotLabel"> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>55</red> + <green>200</green> + <blue>191</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>55</red> + <green>200</green> + <blue>191</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>190</red> + <green>190</green> + <blue>190</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="font"> + <font> + <pointsize>20</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>JACKPOT!</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="3" column="0" colspan="5"> + <widget class="QLabel" name="hurryLabel"> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>67</red> + <green>24</green> + <blue>97</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>67</red> + <green>24</green> + <blue>97</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>190</red> + <green>190</green> + <blue>190</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="font"> + <font> + <pointsize>20</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>HURRY!</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="cLabel"> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>7</red> + <green>0</green> + <blue>222</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>7</red> + <green>0</green> + <blue>222</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>190</red> + <green>190</green> + <blue>190</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="font"> + <font> + <pointsize>20</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>C</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QLabel" name="rLabel"> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>6</red> + <green>208</green> + <blue>36</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>6</red> + <green>208</green> + <blue>36</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>190</red> + <green>190</green> + <blue>190</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="font"> + <font> + <pointsize>20</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>R</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="4" column="2"> + <widget class="QLabel" name="aLabel"> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>238</red> + <green>17</green> + <blue>1</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>238</red> + <green>17</green> + <blue>1</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>190</red> + <green>190</green> + <blue>190</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="font"> + <font> + <pointsize>20</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>A</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="4" column="3"> + <widget class="QLabel" name="zLabel"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>230</red> + <green>10</green> + <blue>230</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>230</red> + <green>10</green> + <blue>230</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>190</red> + <green>190</green> + <blue>190</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="font"> + <font> + <pointsize>20</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Z</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="4" column="4"> + <widget class="QLabel" name="yLabel"> + <property name="palette"> + <palette> + <active> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>239</red> + <green>224</green> + <blue>9</blue> + </color> + </brush> + </colorrole> + </active> + <inactive> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>239</red> + <green>224</green> + <blue>9</blue> + </color> + </brush> + </colorrole> + </inactive> + <disabled> + <colorrole role="WindowText"> + <brush brushstyle="SolidPattern"> + <color alpha="255"> + <red>190</red> + <green>190</green> + <blue>190</blue> + </color> + </brush> + </colorrole> + </disabled> + </palette> + </property> + <property name="font"> + <font> + <pointsize>20</pointsize> + <weight>75</weight> + <bold>true</bold> + </font> + </property> + <property name="text"> + <string>Y</string> + </property> + <property name="alignment"> + <set>Qt::AlignCenter</set> + </property> + </widget> + </item> + <item row="5" column="0"> + <widget class="QPushButton" name="cButton"> + <property name="text"> + <string>C</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QPushButton" name="rButton"> + <property name="text"> + <string>R</string> + </property> + </widget> + </item> + <item row="5" column="2"> + <widget class="QPushButton" name="aButton"> + <property name="text"> + <string>A</string> + </property> + </widget> + </item> + <item row="5" column="3"> + <widget class="QPushButton" name="zButton"> + <property name="text"> + <string>Z</string> + </property> + </widget> + </item> + <item row="5" column="4"> + <widget class="QPushButton" name="yButton"> + <property name="text"> + <string>Y</string> + </property> + </widget> + </item> + <item row="6" column="0" colspan="5"> + <widget class="QPushButton" name="ballOutButton"> + <property name="text"> + <string>BALL OUT</string> + </property> + </widget> + </item> + <item row="7" column="0" colspan="6"> + <widget class="QLabel" name="offStateLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Press START to release the ball.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="8" column="0" colspan="6"> + <widget class="QLabel" name="normalStateLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Try to hit all CRAZY letters. Watch out for ball and avoid BALL OUT since the game will end.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="9" column="0" colspan="6"> + <widget class="QLabel" name="hurryStateLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Now you need to hurry. Quickly hit all CRAZY letters again to gather the extra JACKPOT bonus. You have only 5 seconds. Otherwise you will need to start from scratch.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="10" column="0" colspan="6"> + <widget class="QLabel" name="jackpotStateLabel"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Preferred" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>You did that! You have collected JACKPOT! Congratulations. Now you can continue game until you BALL OUT.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections/> +</ui> diff --git a/examples/scxml/pinball/pinball.pro b/examples/scxml/pinball/pinball.pro new file mode 100644 index 0000000..2cb002d --- /dev/null +++ b/examples/scxml/pinball/pinball.pro @@ -0,0 +1,21 @@ +QT += widgets scxml + +CONFIG += c++11 + +STATECHARTS = pinball.scxml + +SOURCES += \ + main.cpp \ + mainwindow.cpp + +FORMS += \ + mainwindow.ui + +HEADERS += \ + mainwindow.h + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/pinball +INSTALLS += target + +load(qscxmlc) diff --git a/examples/scxml/pinball/pinball.scxml b/examples/scxml/pinball/pinball.scxml new file mode 100644 index 0000000..735bca2 --- /dev/null +++ b/examples/scxml/pinball/pinball.scxml @@ -0,0 +1,394 @@ +<?xml version="1.0" ?> +<!-- +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +--> +<!-- enable-qt-mode: yes --> +<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0" + name="Pinball" datamodel="ecmascript"> + <datamodel> + <data id="highScore" expr="0"/> + <data id="score" expr="0"/> + </datamodel> + <parallel id="global"> + <parallel id="guiControl"> + <state id="cLight"> + <state id="cLightOn"> + <transition event="turnOffC" target="cLightOff"/> + </state> + <state id="cLightOff"> + <transition event="turnOnC" target="cLightOn"/> + </state> + </state> + <state id="rLight"> + <state id="rLightOn"> + <transition event="turnOffR" target="rLightOff"/> + </state> + <state id="rLightOff"> + <transition event="turnOnR" target="rLightOn"/> + </state> + </state> + <state id="aLight"> + <state id="aLightOn"> + <transition event="turnOffA" target="aLightOff"/> + </state> + <state id="aLightOff"> + <transition event="turnOnA" target="aLightOn"/> + </state> + </state> + <state id="zLight"> + <state id="zLightOn"> + <transition event="turnOffZ" target="zLightOff"/> + </state> + <state id="zLightOff"> + <transition event="turnOnZ" target="zLightOn"/> + </state> + </state> + <state id="yLight"> + <state id="yLightOn"> + <transition event="turnOffY" target="yLightOff"/> + </state> + <state id="yLightOff"> + <transition event="turnOnY" target="yLightOn"/> + </state> + </state> + <state id="hurryLight"> + <state id="hurryLightOn"> + <transition event="turnOffHurry" target="hurryLightOff"/> + </state> + <state id="hurryLightOff"> + <transition event="turnOnHurry" target="hurryLightOn"/> + </state> + </state> + <state id="jackpotLight"> + <state id="jackpotLightOn"> + <transition event="turnOffJackpot" target="jackpotLightOff"/> + </state> + <state id="jackpotLightOff"> + <transition event="turnOnJackpot" target="jackpotLightOn"/> + </state> + </state> + <state id="gameOverLight"> + <state id="gameOverLightOn"> + <transition event="turnOffGameOver" target="gameOverLightOff"/> + </state> + <state id="gameOverLightOff"> + <transition event="turnOnGameOver" target="gameOverLightOn"/> + </state> + </state> + </parallel> + + <parallel id="internalState"> + <parallel id="logicalState"> + <state id="letterState"> + <parallel id="lettersState"> + <state id="cLetter"> + <state id="cLetterOff"> + <transition event="cLetterTriggered" cond="In('onState')" target="cLetterOn"/> + </state> + <final id="cLetterOn"> + <onentry> + <raise event="letterOn"/> + </onentry> + </final> + </state> + <state id="rLetter"> + <state id="rLetterOff"> + <transition event="rLetterTriggered" cond="In('onState')" target="rLetterOn"/> + </state> + <final id="rLetterOn"> + <onentry> + <raise event="letterOn"/> + </onentry> + </final> + </state> + <state id="aLetter"> + <state id="aLetterOff"> + <transition event="aLetterTriggered" cond="In('onState')" target="aLetterOn"/> + </state> + <final id="aLetterOn"> + <onentry> + <raise event="letterOn"/> + </onentry> + </final> + </state> + <state id="zLetter"> + <state id="zLetterOff"> + <transition event="zLetterTriggered" cond="In('onState')" target="zLetterOn"/> + </state> + <final id="zLetterOn"> + <onentry> + <raise event="letterOn"/> + </onentry> + </final> + </state> + <state id="yLetter"> + <state id="yLetterOff"> + <transition event="yLetterTriggered" cond="In('onState')" target="yLetterOn"/> + </state> + <final id="yLetterOn"> + <onentry> + <raise event="letterOn"/> + </onentry> + </final> + </state> + <transition event="resetLetters" target="lettersState"/> + </parallel> + </state> + <state id="modeState"> + <state id="offState"> + <onentry> + <if cond="highScore < score"> + <assign location="highScore" expr="score"/> + </if> + <raise event="resetLetters"/> + <raise event="update"/> + </onentry> + <transition event="startTriggered" target="onState"/> + </state> + <parallel id="onState"> + <onentry> + <assign location="score" expr="0"/> + </onentry> + <state id="hurryState"> + <state id="hurryStateOff"> + <onentry> + <raise event="resetLetters"/> + <raise event="update"/> + </onentry> + <transition event="goToHurryOn" target="hurryStateOn"/> + </state> + <state id="hurryStateOn"> + <onentry> + <send event="goToHurryOff" id="hurryId" delay="5s"/> + <raise event="resetLetters"/> + <raise event="update"/> + </onentry> + <transition event="goToHurryOff" target="hurryStateOff"/> + <onexit> + <cancel sendid="hurryId"/> + </onexit> + </state> + </state> + <state id="jackpotState"> + <state id="jackpotStateOff"> + <onentry> + <raise event="update"/> + </onentry> + <transition event="goForJackpot" target="jackpotStateOn"/> + </state> + <state id="jackpotStateOn"> + <onentry> + <raise event="update"/> + </onentry> + </state> + </state> + <transition event="ballOutTriggered" target="offState"/> + </parallel> + </state> + </parallel> + + <state id="workflow"> + <state id="lightImpulseGenerator"> + <state id="lightImpulseOn"/> + <state id="lightImpulseOff"/> + + <onentry> + <raise event="update"/> + </onentry> + + <transition event="scheduleNewImpulse"> + <cancel sendid="lightId"/> + <if cond="In('offState')"> + <send event="lightImpulse" id="lightId" delay="1s"/> + <elseif cond="In('hurryStateOff')"/> + <send event="lightImpulse" id="lightId" delay="500ms"/> + <else/> + <send event="lightImpulse" id="lightId" delay="200ms"/> + </if> + </transition> + + <transition event="update"> + <raise event="scheduleNewImpulse"/> + <raise event="updateLights"/> + </transition> + + <transition event="lightImpulse" cond="In('lightImpulseOn')" target="lightImpulseOff"/> + <transition event="lightImpulse" cond="In('lightImpulseOff')" target="lightImpulseOn"/> + </state> + + <transition event="letterOn"> + <if cond="In('hurryStateOff')"> + <assign location="score" expr="score + 1000"/> + <elseif cond="In('hurryStateOn')"/> + <assign location="score" expr="score + 10000"/> + </if> + <raise event="updateLights"/> + </transition> + + <transition event="done.state.lettersState"> + <if cond="In('hurryStateOff')"> + <assign location="score" expr="score + 100000"/> + <raise event="goToHurryOn"/> + <elseif cond="In('hurryStateOn')"/> + <assign location="score" expr="score + 1000000"/> + <raise event="goToHurryOff"/> + <raise event="goForJackpot"/> + </if> + </transition> + + <transition event="updateLights"> + <send type="qt:signal" event="updateScore"> + <param name="highScore" expr="highScore"/> + <param name="score" expr="score"/> + </send> + <if cond="In('jackpotStateOn')"> + <raise event="turnOnJackpot"/> + <else/> + <raise event="turnOffJackpot"/> + </if> + + <if cond="In('lightImpulseOn')"> + <if cond="In('offState')"> + <raise event="turnOnC"/> + <raise event="turnOnR"/> + <raise event="turnOnA"/> + <raise event="turnOnZ"/> + <raise event="turnOnY"/> + <raise event="turnOnHurry"/> + <raise event="turnOnJackpot"/> + <raise event="turnOnGameOver"/> + <elseif cond="In('hurryStateOff')"/> + <if cond="In('cLetterOn')"> + <raise event="turnOnC"/> + <else/> + <raise event="turnOffC"/> + </if> + <if cond="In('rLetterOn')"> + <raise event="turnOnR"/> + <else/> + <raise event="turnOffR"/> + </if> + <if cond="In('aLetterOn')"> + <raise event="turnOnA"/> + <else/> + <raise event="turnOffA"/> + </if> + <if cond="In('zLetterOn')"> + <raise event="turnOnZ"/> + <else/> + <raise event="turnOffZ"/> + </if> + <if cond="In('yLetterOn')"> + <raise event="turnOnY"/> + <else/> + <raise event="turnOffY"/> + </if> + <raise event="turnOffHurry"/> + <raise event="turnOffGameOver"/> + <else/> + <raise event="turnOnC"/> + <raise event="turnOnR"/> + <raise event="turnOnA"/> + <raise event="turnOnZ"/> + <raise event="turnOnY"/> + <raise event="turnOnHurry"/> + <raise event="turnOffGameOver"/> + </if> + <else/> + <if cond="In('offState')"> + <raise event="turnOffC"/> + <raise event="turnOffR"/> + <raise event="turnOffA"/> + <raise event="turnOffZ"/> + <raise event="turnOffY"/> + <raise event="turnOffHurry"/> + <raise event="turnOffJackpot"/> + <elseif cond="In('hurryStateOff')"/> + <raise event="turnOffC"/> + <raise event="turnOffR"/> + <raise event="turnOffA"/> + <raise event="turnOffZ"/> + <raise event="turnOffY"/> + <else/> + <if cond="In('cLetterOn')"> + <raise event="turnOnC"/> + <else/> + <raise event="turnOffC"/> + </if> + <if cond="In('rLetterOn')"> + <raise event="turnOnR"/> + <else/> + <raise event="turnOffR"/> + </if> + <if cond="In('aLetterOn')"> + <raise event="turnOnA"/> + <else/> + <raise event="turnOffA"/> + </if> + <if cond="In('zLetterOn')"> + <raise event="turnOnZ"/> + <else/> + <raise event="turnOffZ"/> + </if> + <if cond="In('yLetterOn')"> + <raise event="turnOnY"/> + <else/> + <raise event="turnOffY"/> + </if> + </if> + <raise event="turnOffHurry"/> + <raise event="turnOffGameOver"/> + </if> + </transition> + </state> + </parallel> + </parallel> +</scxml> diff --git a/examples/scxml/scxml.pro b/examples/scxml/scxml.pro new file mode 100644 index 0000000..0ee3d2e --- /dev/null +++ b/examples/scxml/scxml.pro @@ -0,0 +1,23 @@ +TEMPLATE = subdirs + +!msvc{ +qtHaveModule(widgets) { + SUBDIRS += trafficlight-widgets-static + SUBDIRS += trafficlight-widgets-dynamic + SUBDIRS += mediaplayer-widgets-static + SUBDIRS += mediaplayer-widgets-dynamic + SUBDIRS += calculator + SUBDIRS += pinball +} + +qtHaveModule(qml) { + SUBDIRS += trafficlight-qml-static + SUBDIRS += trafficlight-qml-dynamic + SUBDIRS += mediaplayer-qml-static + SUBDIRS += mediaplayer-qml-dynamic + + SUBDIRS += mediaplayer-qml-cppdatamodel + SUBDIRS += invoke-static + SUBDIRS += invoke-dynamic +} +} diff --git a/examples/scxml/trafficlight-common/Button.qml b/examples/scxml/trafficlight-common/Button.qml new file mode 100644 index 0000000..36bec5f --- /dev/null +++ b/examples/scxml/trafficlight-common/Button.qml @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** 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 + +Item { + id: button + signal clicked + property string text: "hello" + + Rectangle { + x: 5 + y: 5 + width: parent.width - 10 + height: parent.height - 10 + radius: 5 + color: "blue" + + Text { + anchors.fill: parent + color: "white" + text: button.text + horizontalAlignment: Text.AlignHCenter + verticalAlignment: Text.AlignVCenter + } + + MouseArea { + id: mouse + anchors.fill: parent + onClicked: button.clicked() + } + } +} diff --git a/examples/scxml/trafficlight-common/Light.qml b/examples/scxml/trafficlight-common/Light.qml new file mode 100644 index 0000000..f444a9c --- /dev/null +++ b/examples/scxml/trafficlight-common/Light.qml @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** 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 + +Item { + property string color: "blue" + width: Math.min(parent.width, parent.height / 3) + height: width + + Rectangle { + x: 3 + y: 3 + width: parent.width - 2 * x + height: parent.height - 2 * y + color: parent.color + radius: width + } +} + diff --git a/examples/scxml/trafficlight-common/TrafficLight.qml b/examples/scxml/trafficlight-common/TrafficLight.qml new file mode 100644 index 0000000..4d8cb15 --- /dev/null +++ b/examples/scxml/trafficlight-common/TrafficLight.qml @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** 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 + +Window { + id: root + property QtObject stateMachine + + visible: true + width: 100 + height: 350 + color: "black" + + Item { + id: lights + width: parent.width + height: 300 + + MouseArea { + anchors.fill: parent + onClicked: { + Qt.quit(); + } + } + + Light { + id: redLight + anchors.top: parent.top + color: "red" + visible: stateMachine.red || stateMachine.redGoingGreen + } + + Light { + id: yellowLight + anchors.top: redLight.bottom + color: "yellow" + visible: stateMachine.yellow || stateMachine.blinking + } + + Light { + id: greenLight + anchors.top: yellowLight.bottom + color: "green" + visible: stateMachine.green + } + } + + Button { + id: button + width: parent.width + anchors.top: lights.bottom + anchors.bottom: parent.bottom + + text: { + if (stateMachine.working) + "Pause" + else + "Unpause" + } + + onClicked: { + if (stateMachine.working) + stateMachine.smash() + else + stateMachine.repair() + } + } +} diff --git a/examples/scxml/trafficlight-common/statemachine.scxml b/examples/scxml/trafficlight-common/statemachine.scxml new file mode 100644 index 0000000..4224e81 --- /dev/null +++ b/examples/scxml/trafficlight-common/statemachine.scxml @@ -0,0 +1,112 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +--> +<!-- enable-qt-mode: yes --> +<scxml + xmlns="http://www.w3.org/2005/07/scxml" + xmlns:qt="http://theqtcompany.com/scxml/2015/06/" + version="1.0" + name="TrafficLightStateMachine" + initial="working" +> + <state id="working" initial="yellow"> + <state id="red"> + <onentry> + <send event="startGoingGreen" delay="3s"/> + </onentry> + <transition event="startGoingGreen" target="redGoingGreen"/> + </state> + + <state id="yellow" initial="greenGoingRed"> + <state id="redGoingGreen"> + <onentry> + <send event="goGreen" delay="1s"/> + </onentry> + <transition event="goGreen" target="green"/> + </state> + + <state id="greenGoingRed"> + <onentry> + <send event="goRed" delay="1s"/> + </onentry> + <transition event="goRed" target="red"/> + </state> + </state> + + <state id="green"> + <onentry> + <send event="startGoingRed" delay="3s"/> + </onentry> + <transition event="startGoingRed" target="greenGoingRed"/> + </state> + + <transition event="smash" target="broken"/> + </state> + + <state id="broken" initial="blinking"> + <state id="blinking"> + <onentry> + <send event="unblink" delay="1s"/> + </onentry> + <transition event="unblink" target="unblinking"/> + </state> + + <state id="unblinking"> + <onentry> + <send event="blink" delay="1s"/> + </onentry> + <transition event="blink" target="blinking"/> + </state> + + <transition event="repair" target="working"/> + </state> +</scxml> diff --git a/examples/scxml/trafficlight-common/trafficlight.cpp b/examples/scxml/trafficlight-common/trafficlight.cpp new file mode 100644 index 0000000..7341c96 --- /dev/null +++ b/examples/scxml/trafficlight-common/trafficlight.cpp @@ -0,0 +1,149 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "trafficlight.h" + +#include <QtWidgets> + +class TrafficLightWidget : public QWidget +{ +public: + TrafficLightWidget(QWidget *parent = 0) + : QWidget(parent) + { + QVBoxLayout *vbox = new QVBoxLayout(this); + m_red = new LightWidget(Qt::red); + vbox->addWidget(m_red); + m_yellow = new LightWidget(Qt::yellow); + vbox->addWidget(m_yellow); + m_green = new LightWidget(Qt::green); + vbox->addWidget(m_green); + QPalette pal = palette(); + pal.setColor(QPalette::Background, Qt::black); + setPalette(pal); + setAutoFillBackground(true); + } + + LightWidget *redLight() const + { return m_red; } + LightWidget *yellowLight() const + { return m_yellow; } + LightWidget *greenLight() const + { return m_green; } + +private: + LightWidget *m_red; + LightWidget *m_yellow; + LightWidget *m_green; +}; + +TrafficLight::TrafficLight(QScxmlStateMachine *machine, QWidget *parent) + : QWidget(parent) + , m_machine(machine) +{ + QVBoxLayout *vbox = new QVBoxLayout(this); + TrafficLightWidget *widget = new TrafficLightWidget(); + vbox->addWidget(widget); + vbox->setMargin(0); + + QPushButton *button = new QPushButton; + vbox->addWidget(button); + button->setCheckable(true); + button->setText(QStringLiteral("Pause")); + connect(button, SIGNAL(toggled(bool)), this, SLOT(toggleWorking(bool))); + + Q_ASSERT(machine->init()); + + machine->connectToState(QStringLiteral("red"), + widget->redLight(), SLOT(switchLight(bool))); + machine->connectToState(QStringLiteral("redGoingGreen"), + widget->redLight(), SLOT(switchLight(bool))); + machine->connectToState(QStringLiteral("yellow"), + widget->yellowLight(), SLOT(switchLight(bool))); + machine->connectToState(QStringLiteral("blinking"), + widget->yellowLight(), SLOT(switchLight(bool))); + machine->connectToState(QStringLiteral("green"), + widget->greenLight(), SLOT(switchLight(bool))); +} + +void TrafficLight::toggleWorking(bool pause) +{ + m_machine->submitEvent(pause ? "smash" : "repair"); +} + +LightWidget::LightWidget(const QColor &color, QWidget *parent) + : QWidget(parent) + , m_color(color) + , m_on(false) +{} + +bool LightWidget::isOn() const +{ return m_on; } + +void LightWidget::setOn(bool on) +{ + if (on == m_on) + return; + m_on = on; + update(); +} + +void LightWidget::switchLight(bool onoff) +{ setOn(onoff); } + +void LightWidget::paintEvent(QPaintEvent *) +{ + if (!m_on) + return; + QPainter painter(this); + painter.setRenderHint(QPainter::Antialiasing); + painter.setBrush(m_color); + painter.drawEllipse(0, 0, width(), height()); +} diff --git a/examples/scxml/trafficlight-common/trafficlight.h b/examples/scxml/trafficlight-common/trafficlight.h new file mode 100644 index 0000000..0623249 --- /dev/null +++ b/examples/scxml/trafficlight-common/trafficlight.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#ifndef TRAFFICLIGHT_H +#define TRAFFICLIGHT_H + +#include <QScxmlStateMachine> + +#include <QWidget> + +class TrafficLight : public QWidget +{ + Q_OBJECT + +public: + TrafficLight(QScxmlStateMachine *machine, QWidget *parent = 0); + +public slots: + void toggleWorking(bool pause); + +private: + QScxmlStateMachine *m_machine; +}; + +class LightWidget: public QWidget +{ + Q_OBJECT + Q_PROPERTY(bool on READ isOn WRITE setOn) + +public: + LightWidget(const QColor &color, QWidget *parent = 0); + + bool isOn() const; + void setOn(bool on); + +public slots: + void switchLight(bool onoff); + +protected: + virtual void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE; + +private: + QColor m_color; + bool m_on; +}; + +#endif // TRAFFICLIGHT_H diff --git a/examples/scxml/trafficlight-qml-dynamic/doc/src/trafficlight-qml-dynamic.qdoc b/examples/scxml/trafficlight-qml-dynamic/doc/src/trafficlight-qml-dynamic.qdoc new file mode 100644 index 0000000..c2c4dc7 --- /dev/null +++ b/examples/scxml/trafficlight-qml-dynamic/doc/src/trafficlight-qml-dynamic.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example trafficlight-qml-dynamic + \title Qt SCXML: Traffic Light QML Example (Dynamic) + \ingroup examples-qtscxml + + \brief Demonstrates using a state-machine for a simple traffic light. +*/ diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp new file mode 100644 index 0000000..d12db7b --- /dev/null +++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + QQmlApplicationEngine engine; + engine.load(QUrl(QStringLiteral("qrc:///trafficlight-qml-dynamic.qml"))); + + return app.exec(); +} + diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.pro b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.pro new file mode 100644 index 0000000..886424e --- /dev/null +++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.pro @@ -0,0 +1,12 @@ +TEMPLATE = app + +QT += qml scxml + +SOURCES += trafficlight-qml-dynamic.cpp + +RESOURCES += trafficlight-qml-dynamic.qrc + +load(qscxmlc) + +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/trafficlight-qml-dynamic +INSTALLS += target diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml new file mode 100644 index 0000000..3b406c7 --- /dev/null +++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qml @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** 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 Scxml 1.0 as Scxml + +TrafficLight { + Scxml.StateMachineLoader { + id: loader + filename: "qrc:///statemachine.scxml" + } + + stateMachine: loader.stateMachine +} diff --git a/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc new file mode 100644 index 0000000..fa110f2 --- /dev/null +++ b/examples/scxml/trafficlight-qml-dynamic/trafficlight-qml-dynamic.qrc @@ -0,0 +1,9 @@ +<RCC> + <qresource prefix="/"> + <file alias="TrafficLight.qml">../trafficlight-common/TrafficLight.qml</file> + <file alias="Light.qml">../trafficlight-common/Light.qml</file> + <file alias="Button.qml">../trafficlight-common/Button.qml</file> + <file>trafficlight-qml-dynamic.qml</file> + <file alias="statemachine.scxml">../trafficlight-common/statemachine.scxml</file> + </qresource> +</RCC> diff --git a/examples/scxml/trafficlight-qml-static/doc/src/trafficlight-qml-static.qdoc b/examples/scxml/trafficlight-qml-static/doc/src/trafficlight-qml-static.qdoc new file mode 100644 index 0000000..6932dbc --- /dev/null +++ b/examples/scxml/trafficlight-qml-static/doc/src/trafficlight-qml-static.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example trafficlight-qml-static + \title Qt SCXML: Traffic Light QML Example (Static) + \ingroup examples-qtscxml + + \brief Demonstrates using a state-machine for a simple traffic light. +*/ diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.cpp b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.cpp new file mode 100644 index 0000000..2e671f3 --- /dev/null +++ b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.cpp @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlApplicationEngine> +#include <QQmlContext> + +#include "statemachine.h" + +int main(int argc, char *argv[]) +{ + QGuiApplication app(argc, argv); + + TrafficLightStateMachine stateMachine; + + QQmlApplicationEngine engine; + engine.rootContext()->setContextProperty(QStringLiteral("trafficLightStateMachine"), &stateMachine); + engine.load(QUrl(QStringLiteral("qrc:/trafficlight-qml-static.qml"))); + stateMachine.start(); + + return app.exec(); +} + diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.pro b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.pro new file mode 100644 index 0000000..4c19594 --- /dev/null +++ b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.pro @@ -0,0 +1,16 @@ +TEMPLATE = app + +QT += qml scxml +CONFIG += c++11 + +SOURCES += trafficlight-qml-static.cpp + +RESOURCES += trafficlight-qml-static.qrc + +STATECHARTS = ../trafficlight-common/statemachine.scxml + +load(qscxmlc) + +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/trafficlight-qml-static +INSTALLS += target + diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qml b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qml new file mode 100644 index 0000000..28024a0 --- /dev/null +++ b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +TrafficLight { + stateMachine: trafficLightStateMachine +} diff --git a/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc new file mode 100644 index 0000000..d75853c --- /dev/null +++ b/examples/scxml/trafficlight-qml-static/trafficlight-qml-static.qrc @@ -0,0 +1,8 @@ +<RCC> + <qresource prefix="/"> + <file>trafficlight-qml-static.qml</file> + <file alias="TrafficLight.qml">../trafficlight-common/TrafficLight.qml</file> + <file alias="Light.qml">../trafficlight-common/Light.qml</file> + <file alias="Button.qml">../trafficlight-common/Button.qml</file> + </qresource> +</RCC> diff --git a/examples/scxml/trafficlight-widgets-dynamic/doc/src/trafficlight-widgets-dynamic.qdoc b/examples/scxml/trafficlight-widgets-dynamic/doc/src/trafficlight-widgets-dynamic.qdoc new file mode 100644 index 0000000..236f410 --- /dev/null +++ b/examples/scxml/trafficlight-widgets-dynamic/doc/src/trafficlight-widgets-dynamic.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example trafficlight-widgets-dynamic + \title Qt SCXML: Traffic Light Example (Dynamic) + \ingroup examples-qtscxml + + \brief Demonstrates using a state-machine for a simple traffic light. +*/ diff --git a/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.cpp b/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.cpp new file mode 100644 index 0000000..223da17 --- /dev/null +++ b/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.cpp @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "../trafficlight-common/trafficlight.h" + +#include <QApplication> +#include <QScxmlNullDataModel> +#include <QTextStream> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + QScxmlStateMachine *machine = QScxmlStateMachine::fromFile(QStringLiteral(":statemachine.scxml")); + if (!machine->parseErrors().isEmpty()) { + QTextStream errs(stderr, QIODevice::WriteOnly); + foreach (const QScxmlError &error, machine->parseErrors()) { + errs << error.toString(); + } + + return -1; + } + + TrafficLight widget(machine); + widget.resize(110, 300); + widget.show(); + machine->setParent(&widget); + machine->start(); + + return app.exec(); +} diff --git a/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.pro b/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.pro new file mode 100644 index 0000000..ffcc2ff --- /dev/null +++ b/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.pro @@ -0,0 +1,15 @@ +QT += widgets scxml + +SOURCES = ../trafficlight-common/trafficlight.cpp +HEADERS = ../trafficlight-common/trafficlight.h + +SOURCES += trafficlight-widgets-dynamic.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/trafficlights-widgets-dynamic +INSTALLS += target + +load(qscxmlc) + +RESOURCES += \ + trafficlight-widgets-dynamic.qrc diff --git a/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.qrc b/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.qrc new file mode 100644 index 0000000..897d792 --- /dev/null +++ b/examples/scxml/trafficlight-widgets-dynamic/trafficlight-widgets-dynamic.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file alias="statemachine.scxml">../trafficlight-common/statemachine.scxml</file> + </qresource> +</RCC> diff --git a/examples/scxml/trafficlight-widgets-static/doc/src/trafficlight-widgets-static.qdoc b/examples/scxml/trafficlight-widgets-static/doc/src/trafficlight-widgets-static.qdoc new file mode 100644 index 0000000..03e0680 --- /dev/null +++ b/examples/scxml/trafficlight-widgets-static/doc/src/trafficlight-widgets-static.qdoc @@ -0,0 +1,34 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** 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. +** +** GNU Free Documentation License Usage +** 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. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! + \example trafficlight-widgets-static + \title Qt SCXML: Traffic Light Example (Static) + \ingroup examples-qtscxml + + \brief Demonstrates using a state-machine for a simple traffic light. +*/ diff --git a/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.cpp b/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.cpp new file mode 100644 index 0000000..e0d59e3 --- /dev/null +++ b/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.cpp @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include "statemachine.h" +#include "../trafficlight-common/trafficlight.h" + +#include <QApplication> + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + TrafficLightStateMachine machine; + TrafficLight widget(&machine); + widget.resize(110, 300); + widget.show(); + machine.start(); + + return app.exec(); +} diff --git a/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.pro b/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.pro new file mode 100644 index 0000000..b40a692 --- /dev/null +++ b/examples/scxml/trafficlight-widgets-static/trafficlight-widgets-static.pro @@ -0,0 +1,14 @@ +QT += widgets scxml +CONFIG += c++11 + +SOURCES = ../trafficlight-common/trafficlight.cpp +HEADERS = ../trafficlight-common/trafficlight.h +STATECHARTS = ../trafficlight-common/statemachine.scxml + +load(qscxmlc) + +SOURCES += trafficlight-widgets-static.cpp + +# install +target.path = $$[QT_INSTALL_EXAMPLES]/scxml/trafficlight-widgets-static +INSTALLS += target |