summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2009-10-23 05:43:01 (GMT)
committerMartin Jones <martin.jones@nokia.com>2009-10-23 05:43:01 (GMT)
commitb7b31c15c4544d7e08bfe7b3b21e5144bfdcda10 (patch)
treef407a352b366cd04956c5aaa63d4fa1ec0811a4a
parent74861c8076d7f58d5b06e1be2855666d3d17ddc8 (diff)
parent126b3c0804eac70c1af7223fc4a77e34155eb2e1 (diff)
downloadQt-b7b31c15c4544d7e08bfe7b3b21e5144bfdcda10.zip
Qt-b7b31c15c4544d7e08bfe7b3b21e5144bfdcda10.tar.gz
Qt-b7b31c15c4544d7e08bfe7b3b21e5144bfdcda10.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
-rw-r--r--examples/declarative/follow/click.wavbin0 -> 3056 bytes
-rw-r--r--examples/declarative/follow/paddle.wavbin0 -> 5320 bytes
-rw-r--r--examples/declarative/follow/pong.qml39
-rw-r--r--src/declarative/qml/qmlscriptparser.cpp41
-rw-r--r--src/declarative/util/qmlanimation.cpp2
-rw-r--r--src/declarative/util/qmlconnection.cpp23
-rw-r--r--src/declarative/util/qmlconnection.h7
7 files changed, 41 insertions, 71 deletions
diff --git a/examples/declarative/follow/click.wav b/examples/declarative/follow/click.wav
new file mode 100644
index 0000000..26c46f8
--- /dev/null
+++ b/examples/declarative/follow/click.wav
Binary files differ
diff --git a/examples/declarative/follow/paddle.wav b/examples/declarative/follow/paddle.wav
new file mode 100644
index 0000000..604e0e5
--- /dev/null
+++ b/examples/declarative/follow/paddle.wav
Binary files differ
diff --git a/examples/declarative/follow/pong.qml b/examples/declarative/follow/pong.qml
index 10ded36..d39e913 100644
--- a/examples/declarative/follow/pong.qml
+++ b/examples/declarative/follow/pong.qml
@@ -3,24 +3,26 @@ import Qt 4.6
Rectangle {
id: page
width: 640; height: 480
- color: "#000000"
+ color: "Black"
// Make a ball to bounce
Rectangle {
// Add a property for the target y coordinate
- property var targetY : page.height-10
+ property var targetY : page.height - 10
property var direction : "right"
id: ball
- color: "#00ee00"
+ color: "Lime"
x: 20; width: 20; height: 20; z: 1
// Move the ball to the right and back to the left repeatedly
x: SequentialAnimation {
running: true; repeat: true
- NumberAnimation { to: page.width-40; duration: 2000 }
+ NumberAnimation { to: page.width - 40; duration: 2000 }
+ ScriptAction { script: Qt.playSound('paddle.wav') }
PropertyAction { target: ball; property: "direction"; value: "left" }
NumberAnimation { to: 20; duration: 2000 }
+ ScriptAction { script: Qt.playSound('paddle.wav') }
PropertyAction { target: ball; property: "direction"; value: "right" }
}
@@ -29,10 +31,13 @@ Rectangle {
// Detect the ball hitting the top or bottom of the view and bounce it
onYChanged: {
- if (y <= 0)
- targetY = page.height-20;
- else if (y >= page.height-20)
+ if (y <= 0) {
+ Qt.playSound('click.wav');
+ targetY = page.height - 20;
+ } else if (y >= page.height - 20) {
+ Qt.playSound('click.wav');
targetY = 0;
+ }
}
}
@@ -40,17 +45,17 @@ Rectangle {
// coordinates of the ball.
Rectangle {
id: leftBat
- color: "#00ee00"
+ color: "Lime"
x: 2; width: 20; height: 90
y: SpringFollow {
- source: ball.y-45; velocity: 300
+ source: ball.y - 45; velocity: 300
enabled: ball.direction == 'left'
}
}
Rectangle {
id: rightBat
- color: "#00ee00"
- x: page.width-22; width: 20; height: 90
+ color: "Lime"
+ x: page.width - 22; width: 20; height: 90
y: SpringFollow {
source: ball.y-45; velocity: 300
enabled: ball.direction == 'right'
@@ -58,12 +63,12 @@ Rectangle {
}
// The rest, to make it look realistic, if neither ever scores...
- Rectangle { color: "#00ee00"; x: page.width/2-80; y: 0; width: 40; height: 60 }
- Rectangle { color: "#000000"; x: page.width/2-70; y: 10; width: 20; height: 40 }
- Rectangle { color: "#00ee00"; x: page.width/2+40; y: 0; width: 40; height: 60 }
- Rectangle { color: "#000000"; x: page.width/2+50; y: 10; width: 20; height: 40 }
+ Rectangle { color: "Lime"; x: page.width/2-80; y: 0; width: 40; height: 60 }
+ Rectangle { color: "Black"; x: page.width/2-70; y: 10; width: 20; height: 40 }
+ Rectangle { color: "Lime"; x: page.width/2+40; y: 0; width: 40; height: 60 }
+ Rectangle { color: "Black"; x: page.width/2+50; y: 10; width: 20; height: 40 }
Repeater {
- model: page.height/20
- Rectangle { color: "#00ee00"; x: page.width/2-5; y: index*20; width: 10; height: 10 }
+ model: page.height / 20
+ Rectangle { color: "Lime"; x: page.width/2-5; y: index * 20; width: 10; height: 10 }
}
}
diff --git a/src/declarative/qml/qmlscriptparser.cpp b/src/declarative/qml/qmlscriptparser.cpp
index 6e5f315..fb84651 100644
--- a/src/declarative/qml/qmlscriptparser.cpp
+++ b/src/declarative/qml/qmlscriptparser.cpp
@@ -365,46 +365,7 @@ Object *ProcessAST::defineObjectBinding(AST::UiQualifiedId *qualifiedId,
const QString objectType = asString(objectTypeName);
const AST::SourceLocation typeLocation = objectTypeName->identifierToken;
- if (objectType == QLatin1String("Connection")) {
-
- Object *obj = defineObjectBinding_helper(/*propertyName = */0, objectType, typeLocation, location);
-
- _stateStack.pushObject(obj);
-
- AST::UiObjectMemberList *it = initializer->members;
- for (; it; it = it->next) {
- AST::UiScriptBinding *scriptBinding = AST::cast<AST::UiScriptBinding *>(it->member);
- if (! scriptBinding)
- continue;
-
- QString propertyName = asString(scriptBinding->qualifiedId);
- if (propertyName == QLatin1String("script")) {
- QString script;
-
- if (AST::ExpressionStatement *stmt = AST::cast<AST::ExpressionStatement *>(scriptBinding->statement)) {
- script = getVariant(stmt->expression).asScript();
- } else {
- script = asString(scriptBinding->statement);
- }
-
- LocationSpan l = this->location(scriptBinding->statement->firstSourceLocation(),
- scriptBinding->statement->lastSourceLocation());
-
- _stateStack.pushProperty(QLatin1String("script"), l);
- Value *value = new Value;
- value->value = QmlParser::Variant(script);
- value->location = l;
- currentProperty()->addValue(value);
- _stateStack.pop();
- } else {
- accept(it->member);
- }
- }
-
- _stateStack.pop(); // object
-
- return obj;
- } else if (objectType == QLatin1String("Script")) {
+ if (objectType == QLatin1String("Script")) {
AST::UiObjectMemberList *it = initializer->members;
for (; it; it = it->next) {
diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp
index 98453ed..f103a6b 100644
--- a/src/declarative/util/qmlanimation.cpp
+++ b/src/declarative/util/qmlanimation.cpp
@@ -826,7 +826,7 @@ void QmlScriptAction::setStateChangeScriptName(const QString &name)
void QmlScriptActionPrivate::execute()
{
- QmlScriptString scriptStr = hasRunScriptScript ? script : runScriptScript;
+ QmlScriptString scriptStr = hasRunScriptScript ? runScriptScript : script;
const QString &str = scriptStr.script();
if (!str.isEmpty()) {
diff --git a/src/declarative/util/qmlconnection.cpp b/src/declarative/util/qmlconnection.cpp
index 2a7cf6c..5475fb2 100644
--- a/src/declarative/util/qmlconnection.cpp
+++ b/src/declarative/util/qmlconnection.cpp
@@ -51,11 +51,12 @@ QT_BEGIN_NAMESPACE
class QmlConnectionPrivate : public QObjectPrivate
{
public:
- QmlConnectionPrivate() : boundsignal(0), signalSender(0), componentcomplete(false) {}
+ QmlConnectionPrivate() : boundsignal(0), signalSender(0), scriptset(false), componentcomplete(false) {}
QmlBoundSignal *boundsignal;
QObject *signalSender;
- QString script;
+ QmlScriptString script;
+ bool scriptset;
QString signal;
bool componentcomplete;
};
@@ -154,7 +155,7 @@ void QmlConnection::connectIfValid()
if (!d->componentcomplete)
return;
// boundsignal must not exist
- if ((d->signalSender || parent()) && !d->signal.isEmpty() && !d->script.isEmpty()) {
+ if ((d->signalSender || parent()) && !d->signal.isEmpty() && d->scriptset) {
// create
// XXX scope?
int sigIdx = -1;
@@ -187,7 +188,7 @@ void QmlConnection::connectIfValid()
return;
}
- d->boundsignal = new QmlBoundSignal(qmlContext(this), d->script, sender, mo->method(sigIdx), this);
+ d->boundsignal = new QmlBoundSignal(qmlContext(this), d->script.script(), sender, mo->method(sigIdx), this);
}
}
@@ -196,7 +197,7 @@ void QmlConnection::disconnectIfValid()
Q_D(QmlConnection);
if (!d->componentcomplete)
return;
- if ((d->signalSender || parent()) && !d->signal.isEmpty() && !d->script.isEmpty()) {
+ if ((d->signalSender || parent()) && !d->signal.isEmpty() && d->scriptset) {
// boundsignal must exist
// destroy
delete d->boundsignal;
@@ -213,31 +214,33 @@ void QmlConnection::componentComplete()
/*!
- \qmlproperty string Connection::script
+ \qmlproperty script Connection::script
This property holds the JavaScript executed whenever the signal is sent.
This is the default attribute of Connection.
*/
-QString QmlConnection::script() const
+QmlScriptString QmlConnection::script() const
{
Q_D(const QmlConnection);
return d->script;
}
-void QmlConnection::setScript(const QString& script)
+void QmlConnection::setScript(const QmlScriptString& script)
{
Q_D(QmlConnection);
if ((d->signalSender || parent()) && !d->signal.isEmpty()) {
- if (d->script.isEmpty()) {
+ if (!d->scriptset) {
// mustn't exist - create
+ d->scriptset = true;
d->script = script;
connectIfValid();
} else {
// must exist - update
d->script = script;
- d->boundsignal->expression()->setExpression(script);
+ d->boundsignal->expression()->setExpression(script.script());
}
} else {
+ d->scriptset = true;
d->script = script;
}
}
diff --git a/src/declarative/util/qmlconnection.h b/src/declarative/util/qmlconnection.h
index dcaac34..3d69c6f 100644
--- a/src/declarative/util/qmlconnection.h
+++ b/src/declarative/util/qmlconnection.h
@@ -45,6 +45,7 @@
#include <QtCore/qobject.h>
#include <QtCore/qstring.h>
#include <QtDeclarative/qml.h>
+#include <QtDeclarative/qmlscriptstring.h>
QT_BEGIN_HEADER
@@ -62,7 +63,7 @@ class Q_DECLARATIVE_EXPORT QmlConnection : public QObject, public QmlParserStatu
Q_INTERFACES(QmlParserStatus)
Q_PROPERTY(QObject *sender READ signalSender WRITE setSignalSender)
- Q_PROPERTY(QString script READ script WRITE setScript)
+ Q_PROPERTY(QmlScriptString script READ script WRITE setScript)
Q_PROPERTY(QString signal READ signal WRITE setSignal)
public:
@@ -71,8 +72,8 @@ public:
QObject *signalSender() const;
void setSignalSender(QObject *);
- QString script() const;
- void setScript(const QString&);
+ QmlScriptString script() const;
+ void setScript(const QmlScriptString&);
QString signal() const;
void setSignal(const QString&);