From cdb910b166c6d139dac3a7801d6aac848d8b51d9 Mon Sep 17 00:00:00 2001 From: No'am Rosenthal Date: Thu, 26 Nov 2009 15:17:27 -0800 Subject: WIP: QmlScxml --- examples/examples.pro | 2 +- examples/qml/blackjack/blackjack.pro | 5 + examples/qml/blackjack/blackjack.qml | 95 ++++++++++++++ examples/qml/blackjack/blackjack.scxml | 224 +++++++++++++++++++++++++++++++++ examples/qml/blackjack/main.cpp | 58 +++++++++ qmlscxml/qmlscxml.cpp | 42 +++++++ qmlscxml/qmlscxml.h | 40 ++++++ src/qscxml.cpp | 5 +- 8 files changed, 468 insertions(+), 3 deletions(-) create mode 100644 examples/qml/blackjack/blackjack.pro create mode 100644 examples/qml/blackjack/blackjack.qml create mode 100644 examples/qml/blackjack/blackjack.scxml create mode 100644 examples/qml/blackjack/main.cpp diff --git a/examples/examples.pro b/examples/examples.pro index 53d0ca3..0af767f 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,2 +1,2 @@ TEMPLATE = subdirs -SUBDIRS += blackjack calc mediaplayer \ No newline at end of file +SUBDIRS += blackjack calc mediaplayer scc qml diff --git a/examples/qml/blackjack/blackjack.pro b/examples/qml/blackjack/blackjack.pro new file mode 100644 index 0000000..eac00d5 --- /dev/null +++ b/examples/qml/blackjack/blackjack.pro @@ -0,0 +1,5 @@ +TEMPLATE = app +QT += declarative +target = blackjack +include(../../../qmlscxml/qmlscxml.pri) +SOURCES += main.cpp diff --git a/examples/qml/blackjack/blackjack.qml b/examples/qml/blackjack/blackjack.qml new file mode 100644 index 0000000..976661a --- /dev/null +++ b/examples/qml/blackjack/blackjack.qml @@ -0,0 +1,95 @@ +import Qt 4.6 +import Scxml 1.0 + +Rectangle { + color: "white" + width: 400 + height: 300 + Scxml { + id: controller + source: "blackjack.scxml" + } + + Text { + id: welcomeText + text: "Blackjack" + font.pixelSize: 24 + states: [ + State { + name: "placeBets" + when: controller.current.waitForBet + PropertyChanges { + target: welcomeText + text: "Please place your bet" + } + }, + State { + name: "game" + when: controller.current.game + PropertyChanges { + target: welcomeText + text: "Welcome" + } + } + ] + } + Rectangle { + color: "white" + x: 100 + y: 100 + Text { + color: "blue" + text: "You have " + controller.data.points + " points" + } + } + Rectangle { + color: "white" + id: betEditBg + x: 80 + y: 400 + width: 100 + height: 20 + TextInput { + id: betEdit + color: "black" + anchors.fill: parent + text: controller.data.pointsToBet + } + states: [ + State { + name: "placeBets" + when: controller.current.waitForBet + PropertyChanges { + target: betEditBg + color: "#ffcc33" + opacity: 1 + } + }, + State { + name: "default" + when: !controller.current.waitForBet + PropertyChanges { + target: betEditBg + opacity: 0 + } + } + ] + } + Rectangle { + anchors.left: betEditBg.right + anchors.top: betEditBg.top + anchors.bottom: betEditBg.bottom + width: 100 + color: "blue" + MouseRegion { + anchors.fill: parent + onClicked: { controller.events.bet.raise(); } + } + Text { + color: "yellow" + text: "Bet" + } + } + + +} diff --git a/examples/qml/blackjack/blackjack.scxml b/examples/qml/blackjack/blackjack.scxml new file mode 100644 index 0000000..ab1b9cd --- /dev/null +++ b/examples/qml/blackjack/blackjack.scxml @@ -0,0 +1,224 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [[welcomeLabel,"text","Game Over"]] + + + + + + + [[newRoundButton,"enabled",true]] + + + + + + + + + + + + + [[welcomeLabel,"text","You Lost..."]] + + + + [[welcomeLabel,"text","You It's a draw."]] + + + + + + + + + + + + + diff --git a/examples/qml/blackjack/main.cpp b/examples/qml/blackjack/main.cpp new file mode 100644 index 0000000..dd7777a --- /dev/null +++ b/examples/qml/blackjack/main.cpp @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include +#include +#include +#include +int main(int argc, char ** argv) +{ + QApplication app(argc, argv); + + QmlView view(NULL); + QmlComponent component(view.engine(), "blackjack.qml"); + QGraphicsObject* o = qobject_cast(component.create()); + view.scene()->addItem(o); + view.show(); + return app.exec(); +} diff --git a/qmlscxml/qmlscxml.cpp b/qmlscxml/qmlscxml.cpp index 2183945..04a4c89 100644 --- a/qmlscxml/qmlscxml.cpp +++ b/qmlscxml/qmlscxml.cpp @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of SCXML on Qt labs +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #include "qmlscxml.h" #include "qscxml.h" #include @@ -147,12 +187,14 @@ void QmlScxml::setSource(const QUrl & u) void QmlScxml::onDataChanged(const QString & key) { + qDebug() << "onDataChanged" << key; m_data->blockSignals(true); scxml->setData(key,(*m_data)[key]); m_data->blockSignals(false); } void QmlScxml::onDataChanged(const QString & key, const QVariant & value) { + qDebug() << "onDataChanged" << key << value; if (m_data) { (*m_data)[key] = value; } diff --git a/qmlscxml/qmlscxml.h b/qmlscxml/qmlscxml.h index b44b45f..c727ecc 100644 --- a/qmlscxml/qmlscxml.h +++ b/qmlscxml/qmlscxml.h @@ -1,3 +1,43 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of SCXML on Qt labs +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ #ifndef QMLSCXML_H #define QMLSCXML_H diff --git a/src/qscxml.cpp b/src/qscxml.cpp index d6142e5..a0b2019 100644 --- a/src/qscxml.cpp +++ b/src/qscxml.cpp @@ -455,7 +455,7 @@ static QScriptValue invoke(QScriptContext *context, QScriptEngine *engine) return QScriptValue(); } -static QScriptValue dataAccess(QScriptContext *context, QScriptEngine *) +static QScriptValue dataAccess(QScriptContext *context, QScriptEngine * engine) { if (context->argumentCount() == 0) { // getter @@ -464,7 +464,8 @@ static QScriptValue dataAccess(QScriptContext *context, QScriptEngine *) // setter QScriptValue val = context->argument(0); context->callee().setProperty("value",val); - QScxml* scxml = qobject_cast(context->callee().property("scxml").toQObject()); + qDebug() << "data set" << val.toVariant() << context->callee().property("key").toString(); + QScxml* scxml = qobject_cast(engine->globalObject().property("scxml").toQObject()); if (scxml) { scxml->dataChanged(context->callee().property("key").toString(),val.toVariant()); } -- cgit v1.2.3