From 7a5fdc99bb3d7fde52428a5fbc4ae1f25de12b5c Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 27 Oct 2009 16:30:51 +1000 Subject: Try to be a bit more clever with snapping. --- examples/declarative/parallax/ParallaxView.qml | 2 + src/declarative/fx/qfxflickable.cpp | 26 ++++++++-- src/declarative/fx/qfxflickable.h | 4 ++ src/declarative/fx/qfxflickable_p.h | 5 +- src/declarative/fx/qfxlistview.cpp | 69 +++++++++++++++++++++++++- 5 files changed, 99 insertions(+), 7 deletions(-) diff --git a/examples/declarative/parallax/ParallaxView.qml b/examples/declarative/parallax/ParallaxView.qml index 1708ad1..bad9b85 100644 --- a/examples/declarative/parallax/ParallaxView.qml +++ b/examples/declarative/parallax/ParallaxView.qml @@ -29,6 +29,8 @@ Item { preferredHighlightBegin: 0 preferredHighlightEnd: 0 highlightRangeMode: "StrictlyEnforceRange" + + flickDeceleration: 1000 } ListView { diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index cbfe9f6..92e79dd 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -157,7 +157,7 @@ QFxFlickablePrivate::QFxFlickablePrivate() : viewport(new QFxItem), _moveX(viewport, &QFxItem::setX), _moveY(viewport, &QFxItem::setY) , vWidth(-1), vHeight(-1), overShoot(true), flicked(false), moving(false), stealMouse(false) , pressed(false), atXEnd(false), atXBeginning(true), atYEnd(false), atYBeginning(true) - , interactive(true), maxVelocity(5000), reportedVelocitySmoothing(100) + , interactive(true), deceleration(500), maxVelocity(5000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0) , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) { @@ -202,7 +202,7 @@ void QFxFlickablePrivate::flickX(qreal velocity) v = maxVelocity; } timeline.reset(_moveX); - timeline.accel(_moveX, v, 500, maxDistance); + timeline.accel(_moveX, v, deceleration, maxDistance); timeline.execute(fixupXEvent); if (!flicked) { flicked = true; @@ -238,7 +238,7 @@ void QFxFlickablePrivate::flickY(qreal velocity) v = maxVelocity; } timeline.reset(_moveY); - timeline.accel(_moveY, v, 500, maxDistance); + timeline.accel(_moveY, v, deceleration, maxDistance); timeline.execute(fixupYEvent); if (!flicked) { flicked = true; @@ -1131,7 +1131,7 @@ bool QFxFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) } /*! - \qmlproperty int Flickable::maximumFlickVelocity + \qmlproperty real Flickable::maximumFlickVelocity This property holds the maximum velocity that the user can flick the view in pixels/second. The default is 5000 pixels/s @@ -1150,6 +1150,24 @@ void QFxFlickable::setMaximumFlickVelocity(qreal v) d->maxVelocity = v; } +/*! + \qmlproperty real Flickable::maximumFlickVelocity + This property holds the rate at which a flick will decelerate. + + The default is 500. +*/ +qreal QFxFlickable::flickDeceleration() const +{ + Q_D(const QFxFlickable); + return d->deceleration; +} + +void QFxFlickable::setFlickDeceleration(qreal deceleration) +{ + Q_D(QFxFlickable); + d->deceleration = deceleration; +} + bool QFxFlickable::isFlicking() const { Q_D(const QFxFlickable); diff --git a/src/declarative/fx/qfxflickable.h b/src/declarative/fx/qfxflickable.h index aaf4e0f..4c80e8f 100644 --- a/src/declarative/fx/qfxflickable.h +++ b/src/declarative/fx/qfxflickable.h @@ -67,6 +67,7 @@ class Q_DECLARATIVE_EXPORT QFxFlickable : public QFxItem Q_PROPERTY(bool overShoot READ overShoot WRITE setOverShoot) Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity) + Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration) Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) @@ -118,6 +119,9 @@ public: qreal maximumFlickVelocity() const; void setMaximumFlickVelocity(qreal); + qreal flickDeceleration() const; + void setFlickDeceleration(qreal); + bool isInteractive() const; void setInteractive(bool); diff --git a/src/declarative/fx/qfxflickable_p.h b/src/declarative/fx/qfxflickable_p.h index 7224f21..07d66b8 100644 --- a/src/declarative/fx/qfxflickable_p.h +++ b/src/declarative/fx/qfxflickable_p.h @@ -70,8 +70,8 @@ class QFxFlickablePrivate : public QFxItemPrivate public: QFxFlickablePrivate(); void init(); - void flickX(qreal velocity); - void flickY(qreal velocity); + virtual void flickX(qreal velocity); + virtual void flickY(qreal velocity); virtual void fixupX(); virtual void fixupY(); void updateBeginningEnd(); @@ -106,6 +106,7 @@ public: QTime pressTime; QmlTimeLineEvent fixupXEvent; QmlTimeLineEvent fixupYEvent; + qreal deceleration; qreal maxVelocity; QTime velocityTime; QPointF lastFlickablePosition; diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 28d2bb2..ca3132f 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -287,6 +287,11 @@ public: return index; } + //XXX Rough. Only works for fixed size items. + qreal snapPosAt(qreal pos) { + return qRound((pos - startPosition()) / averageSize) * averageSize + startPosition(); + } + int lastVisibleIndex() const { int lastIndex = -1; for (int i = visibleItems.count()-1; i >= 0; --i) { @@ -365,6 +370,8 @@ public: void fixupPosition(); virtual void fixupY(); virtual void fixupX(); + virtual void flickX(qreal velocity); + virtual void flickY(qreal velocity); QFxVisualModel *model; QVariant modelVariant; @@ -750,7 +757,6 @@ void QFxListViewPrivate::updateCurrent(int modelIndex) updateHighlight(); return; } - FxListItem *oldCurrentItem = currentItem; currentIndex = modelIndex; currentItem = createItem(modelIndex); @@ -822,6 +828,67 @@ void QFxListViewPrivate::fixupX() } } +void QFxListViewPrivate::flickX(qreal velocity) +{ + Q_Q(QFxListView); + + if (!haveHighlightRange || highlightRange != QFxListView::StrictlyEnforceRange) + QFxFlickablePrivate::flickX(velocity); + + qreal maxDistance = -1; + // -ve velocity means list is moving up + if (velocity > 0) { + if (_moveX.value() < q->minXExtent()) + maxDistance = qAbs(q->minXExtent() -_moveX.value() + (overShoot?30:0)); + flickTargetX = q->minXExtent(); + } else { + if (_moveX.value() > q->maxXExtent()) + maxDistance = qAbs(q->maxXExtent() - _moveX.value()) + (overShoot?30:0); + flickTargetX = q->maxXExtent(); + } + if (maxDistance > 0) { + qreal v = velocity; + if (maxVelocity != -1 && maxVelocity < qAbs(v)) { + if (v < 0) + v = -maxVelocity; + else + v = maxVelocity; + } + qreal accel = deceleration; + qreal maxAccel = (v * v) / (2.0f * maxDistance); + if (maxAccel < accel) { + // If we are not flicking to the end then attempt to stop exactly on an item boundary + qreal dist = (v * v) / accel / 2.0; + if (v > 0) + dist = -dist; + dist = -_moveX.value() - snapPosAt(-_moveX.value() + dist + highlightRangeStart); + if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + timeline.reset(_moveX); + fixupX(); + return; + } + accel = (v * v) / (2.0f * qAbs(dist)); + } + timeline.reset(_moveX); + timeline.accel(_moveX, v, accel, maxDistance); + timeline.execute(fixupXEvent); + if (!flicked) { + flicked = true; + emit q->flickingChanged(); + emit q->flickStarted(); + } + } else { + timeline.reset(_moveX); + fixupX(); + } +} + +void QFxListViewPrivate::flickY(qreal velocity) +{ + if (!haveHighlightRange || highlightRange != QFxListView::StrictlyEnforceRange) + QFxFlickablePrivate::flickY(velocity); +} + //---------------------------------------------------------------------------- /*! -- cgit v0.12 From de7614050fb1626270fbb1ec19d90d7e6060ac75 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 27 Oct 2009 16:33:26 +1000 Subject: Oops. --- src/declarative/fx/qfxlistview.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index ca3132f..fbb91b1 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -885,8 +885,7 @@ void QFxListViewPrivate::flickX(qreal velocity) void QFxListViewPrivate::flickY(qreal velocity) { - if (!haveHighlightRange || highlightRange != QFxListView::StrictlyEnforceRange) - QFxFlickablePrivate::flickY(velocity); + QFxFlickablePrivate::flickY(velocity); } //---------------------------------------------------------------------------- -- cgit v0.12 From 3b2372c9dda9dbe6b6356d2c264e1b5b499c72a4 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 27 Oct 2009 15:34:38 +1000 Subject: SameGame cleans up blocks now. Blocks now delete themselves on their death. --- demos/declarative/samegame/content/BoomBlock.qml | 1 + 1 file changed, 1 insertion(+) diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 34f6f56..b0c297b 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -49,6 +49,7 @@ Item { id:block PropertyChanges { target: particles; opacity: 1 } PropertyChanges { target: particles; emitting: false } // i.e. emit only once PropertyChanges { target: img; opacity: 0 } + StateChangeScript { script: block.destroy(1000); } } ] } -- cgit v0.12 From ec0a81544521eedc1bbd2d2e5133470bc8eaab0d Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 27 Oct 2009 17:39:21 +1000 Subject: Fix build target for standalone qmldebugger. --- tools/qmldebugger/standalone/standalone.pro | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/qmldebugger/standalone/standalone.pro b/tools/qmldebugger/standalone/standalone.pro index 72e3ef5..72d051f 100644 --- a/tools/qmldebugger/standalone/standalone.pro +++ b/tools/qmldebugger/standalone/standalone.pro @@ -1,4 +1,5 @@ -DESTDIR = ../../bin +DESTDIR = ../../../bin +TARGET = qmldebugger include(qmldebugger.pri) -- cgit v0.12 From 67eaf2cef1f9624c4a74164a18cd46f502419922 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 27 Oct 2009 17:40:36 +1000 Subject: Show property type in separate column like Creator debugger. --- tools/qmldebugger/standalone/objectpropertiesview.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tools/qmldebugger/standalone/objectpropertiesview.cpp b/tools/qmldebugger/standalone/objectpropertiesview.cpp index ae9e8be..f86a69e 100644 --- a/tools/qmldebugger/standalone/objectpropertiesview.cpp +++ b/tools/qmldebugger/standalone/objectpropertiesview.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -45,11 +46,13 @@ ObjectPropertiesView::ObjectPropertiesView(QmlEngineDebug *client, QWidget *pare m_tree = new QTreeWidget(this); m_tree->setAlternatingRowColors(true); m_tree->setExpandsOnDoubleClick(false); - m_tree->setHeaderLabels(QStringList() << tr("Property") << tr("Value")); + m_tree->setHeaderLabels(QStringList() + << tr("Name") << tr("Value") << tr("Type")); QObject::connect(m_tree, SIGNAL(itemActivated(QTreeWidgetItem *, int)), this, SLOT(itemActivated(QTreeWidgetItem *))); - m_tree->setColumnCount(2); + m_tree->setColumnCount(3); + m_tree->header()->setDefaultSectionSize(150); layout->addWidget(m_tree); } @@ -130,11 +133,11 @@ void ObjectPropertiesView::setObject(const QmlDebugObjectReference &object) binding->setText(1, p.binding()); binding->setForeground(1, Qt::darkGreen); } + + item->setText(2, p.valueTypeName()); item->setExpanded(true); } - - m_tree->resizeColumnToContents(0); } void ObjectPropertiesView::watchCreated(QmlDebugWatch *watch) @@ -175,9 +178,7 @@ void ObjectPropertiesView::valueChanged(const QByteArray &name, const QVariant & PropertiesViewItem *item = static_cast(m_tree->topLevelItem(i)); if (item->property.name() == name) { if (value.isNull()) { - item->setText(1, QLatin1String("") - + QLatin1String(" : ") - + item->property.valueTypeName()); + item->setText(1, QLatin1String("")); } else { item->setText(1, value.toString()); } -- cgit v0.12 From 8df0b615766e6fa44a0ec45938f297a039d5060f Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 27 Oct 2009 17:43:49 +1000 Subject: minor fixes --- tools/qmldebugger/standalone/qmldebugger.cpp | 2 -- tools/qmldebugger/standalone/watchtable.cpp | 2 +- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/tools/qmldebugger/standalone/qmldebugger.cpp b/tools/qmldebugger/standalone/qmldebugger.cpp index 5455878..5882cb2 100644 --- a/tools/qmldebugger/standalone/qmldebugger.cpp +++ b/tools/qmldebugger/standalone/qmldebugger.cpp @@ -60,9 +60,7 @@ QmlDebugger::QmlDebugger(QWidget *parent) QObject::connect(&client, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError))); - m_tabs->setCurrentIndex(1); - connectToHost(); } void QmlDebugger::setHost(const QString &host) diff --git a/tools/qmldebugger/standalone/watchtable.cpp b/tools/qmldebugger/standalone/watchtable.cpp index ee74cfb..a7fd052 100644 --- a/tools/qmldebugger/standalone/watchtable.cpp +++ b/tools/qmldebugger/standalone/watchtable.cpp @@ -216,7 +216,7 @@ void WatchTableModel::togglePropertyWatch(const QmlDebugObjectReference &object, QString desc = property.name() + QLatin1String(" on\n") + object.className() - + QLatin1String(": ") + + QLatin1String(":\n") + (object.name().isEmpty() ? QLatin1String("") : object.name()); addWatch(watch, desc); emit watchCreated(watch); -- cgit v0.12 From 8f4b6a6cdd6243a4f099c5e8634d213629637709 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 27 Oct 2009 17:51:34 +1000 Subject: Fix context so files can be saved in Inspector mode, and colour Inspector output differently from appplication output. --- tools/qmldebugger/creatorplugin/inspectoroutputpane.cpp | 2 ++ tools/qmldebugger/creatorplugin/qmlinspectormode.cpp | 4 ++-- tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp | 13 +++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/tools/qmldebugger/creatorplugin/inspectoroutputpane.cpp b/tools/qmldebugger/creatorplugin/inspectoroutputpane.cpp index d3f9913..5023e3e 100644 --- a/tools/qmldebugger/creatorplugin/inspectoroutputpane.cpp +++ b/tools/qmldebugger/creatorplugin/inspectoroutputpane.cpp @@ -102,7 +102,9 @@ void InspectorOutputPane::addErrorOutput(RunControl *, const QString &text) void InspectorOutputPane::addInspectorStatus(const QString &text) { + m_textEdit->setTextColor(Qt::darkGreen); m_textEdit->append(text); m_textEdit->moveCursor(QTextCursor::End); + m_textEdit->setTextColor(Qt::black); } diff --git a/tools/qmldebugger/creatorplugin/qmlinspectormode.cpp b/tools/qmldebugger/creatorplugin/qmlinspectormode.cpp index 9367b19..aec661c 100644 --- a/tools/qmldebugger/creatorplugin/qmlinspectormode.cpp +++ b/tools/qmldebugger/creatorplugin/qmlinspectormode.cpp @@ -168,7 +168,7 @@ void QmlInspectorMode::connectionStateChanged() switch (m_conn->state()) { default: case QAbstractSocket::UnconnectedState: - emit statusMessage(tr("[Inspector] disconnected\n\n")); + emit statusMessage(tr("[Inspector] disconnected.\n\n")); m_addressEdit->setEnabled(true); m_portSpinBox->setEnabled(true); break; @@ -180,7 +180,7 @@ void QmlInspectorMode::connectionStateChanged() break; case QAbstractSocket::ConnectedState: { - emit statusMessage(tr("[Inspector] connected\n")); + emit statusMessage(tr("[Inspector] connected.\n")); m_addressEdit->setEnabled(false); m_portSpinBox->setEnabled(false); diff --git a/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp b/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp index c743974..5108c35 100644 --- a/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp +++ b/tools/qmldebugger/creatorplugin/qmlinspectorplugin.cpp @@ -55,18 +55,15 @@ bool QmlInspectorPlugin::initialize(const QStringList &arguments, QString *error Core::ICore *core = Core::ICore::instance(); Core::UniqueIDManager *uidm = core->uniqueIDManager(); - QList modeContext; - modeContext.append(uidm->uniqueIdentifier(QmlInspector::Constants::C_INSPECTOR)); - - QList inspectorContext; - inspectorContext.append(uidm->uniqueIdentifier(Core::Constants::C_EDITORMANAGER)); - inspectorContext.append(uidm->uniqueIdentifier(QmlInspector::Constants::C_INSPECTOR)); - inspectorContext.append(uidm->uniqueIdentifier(Core::Constants::C_NAVIGATION_PANE)); + QList context; + context.append(uidm->uniqueIdentifier(QmlInspector::Constants::C_INSPECTOR)); + context.append(uidm->uniqueIdentifier(Core::Constants::C_EDITORMANAGER)); + context.append(uidm->uniqueIdentifier(Core::Constants::C_NAVIGATION_PANE)); m_inspectMode = new QmlInspectorMode(this); connect(m_inspectMode, SIGNAL(startViewer()), SLOT(startViewer())); connect(m_inspectMode, SIGNAL(stopViewer()), SLOT(stopViewer())); - m_inspectMode->setContext(modeContext); + m_inspectMode->setContext(context); addObject(m_inspectMode); m_outputPane = new InspectorOutputPane; -- cgit v0.12 From e3af2d86b4b592e4b277c828c37ea845329feada Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 27 Oct 2009 19:06:03 +1000 Subject: Update dynamic example The start of a prettier version. Not yet complete, does not full resolve the task. Task-number: QT-2270 --- examples/declarative/dynamic/DynRect.qml | 9 -- examples/declarative/dynamic/Sun.qml | 22 +++ examples/declarative/dynamic/dynamic.js | 59 -------- examples/declarative/dynamic/dynamic.qml | 157 +++++++++++++-------- examples/declarative/dynamic/images/face-smile.png | Bin 0 -> 15408 bytes examples/declarative/dynamic/images/star.png | Bin 0 -> 349 bytes examples/declarative/dynamic/images/sun.png | Bin 0 -> 8153 bytes examples/declarative/dynamic/star.png | Bin 262 -> 0 bytes examples/declarative/dynamic/sunCreation.js | 69 +++++++++ 9 files changed, 188 insertions(+), 128 deletions(-) delete mode 100644 examples/declarative/dynamic/DynRect.qml create mode 100644 examples/declarative/dynamic/Sun.qml delete mode 100644 examples/declarative/dynamic/dynamic.js create mode 100644 examples/declarative/dynamic/images/face-smile.png create mode 100644 examples/declarative/dynamic/images/star.png create mode 100644 examples/declarative/dynamic/images/sun.png delete mode 100644 examples/declarative/dynamic/star.png create mode 100644 examples/declarative/dynamic/sunCreation.js diff --git a/examples/declarative/dynamic/DynRect.qml b/examples/declarative/dynamic/DynRect.qml deleted file mode 100644 index 06141ea..0000000 --- a/examples/declarative/dynamic/DynRect.qml +++ /dev/null @@ -1,9 +0,0 @@ -import Qt 4.6 - -Item { - states: State{ name: "dying"; PropertyChanges{ target: newRect; opacity: 0 } } - transitions: Transition{ - NumberAnimation{ properties: "opacity"; target: newRect; duration:500 } - } - Rectangle {color: "steelblue"; width: 100; height: 100; id: newRect } -} diff --git a/examples/declarative/dynamic/Sun.qml b/examples/declarative/dynamic/Sun.qml new file mode 100644 index 0000000..16d9907 --- /dev/null +++ b/examples/declarative/dynamic/Sun.qml @@ -0,0 +1,22 @@ +import Qt 4.6 + +Image { + id: sun + property bool created: false + onCreatedChanged: if(created){window.activeSuns++;}else{window.activeSuns--;} + + source: "images/sun.png"; + + //x and y get set when instantiated + //head offscreen + y: NumberAnimation { + to: parent.height; + duration: 10000; + running: created + } + + states: State { + name: "OffScreen"; when: created && y > window.height/2;//Below the ground + StateChangeScript { script: { sun.created = false; sun.destroy() } } + } +} diff --git a/examples/declarative/dynamic/dynamic.js b/examples/declarative/dynamic/dynamic.js deleted file mode 100644 index 8bfdba3..0000000 --- a/examples/declarative/dynamic/dynamic.js +++ /dev/null @@ -1,59 +0,0 @@ -var dynamicObject = null; -var fourthBox = null; -var component = null; -var started = false; - -function createQml(p) { - return createQmlObject('DynRect {}', p, 'DynPart.qml'); -} - -function destroyDynamicObject() { - if (!(dynamicObject == null)) { - dynamicObject.destroy(); - dynamicObject = null; - } -} - -function instantCreateWithComponent() {//Like create, but assumes instant readyness - if (dynamicObject != null)//Already made - return null; - component = createComponent("dynamic.qml"); - dynamicObject = component.createObject(); - - if (dynamicObject == null) { - print("error creating component"); - } else { - dynamicObject.parent = targetItem; - return dynamicObject; - } - return null; -} - -function finishCreation() { - if (component.isReady && dynamicObject == null) { - dynamicObject = component.createObject(); - dynamicObject.parent = targetItem; - } else if (component.isError) { - dynamicObject = null; - print("error creating component"); - print(component.errorsString()); - } -} - -function createWithComponent() { - if (component != null) { - return finishCreation(); - } - if (started != false) { - finishCreation();//Remakes if destroyed - return dynamicObject; - } - started = true; - component = createComponent("dynamic.qml"); - finishCreation(); - if (dynamicObject != null) { - return dynamicObject; - } - component.statusChanged.connect(finishCreation); - return null; -} diff --git a/examples/declarative/dynamic/dynamic.qml b/examples/declarative/dynamic/dynamic.qml index 2c6a8e0..aea9b0f 100644 --- a/examples/declarative/dynamic/dynamic.qml +++ b/examples/declarative/dynamic/dynamic.qml @@ -1,79 +1,116 @@ import Qt 4.6 -Rectangle { - id: page - width: 800 - height: 800 - color: "black" - Script { source: "dynamic.js" } +Item { + id: window + //This is a desktop example + width: 1024; height: 480 + property int activeSuns: 0 - property bool extendStars: false - property var fourthBox: undefined - - Item { id: targetItem; x: 100; y: 100; } - Item { id: targetItem2; x: 0; y: 300; } + // sky + Rectangle { id: sky + anchors { left: parent.left; top: parent.top; right: toolbox.right; bottom: parent.verticalCenter } + gradient: Gradient { + GradientStop { id: stopA; position: 0.0; color: "#0E1533" } + GradientStop { id: stopB; position: 1.0; color: "#437284" } + } + } - Rectangle { - id: rect - width: 100 - height: 100 - color: "green" + // stars (when there's no sun) + Particles { id: stars + x: 0; y: 0; width: parent.width; height: parent.height/2 + source: "images/star.png"; angleDeviation: 360; velocity: 0 + velocityDeviation: 0; count: parent.width / 10; fadeInDuration: 2800 + opacity: 1 + } - MouseRegion { - anchors.fill: parent - onClicked: { var a = createWithComponent(); } + // ground, which has a z such that the sun can set behind it + Rectangle { id: ground + z: 2 + anchors { left: parent.left; top: parent.verticalCenter; right: toolbox.right; bottom: parent.bottom } + gradient: Gradient { + GradientStop { position: 0.0; color: "ForestGreen" } + GradientStop { position: 1.0; color: "DarkGreen" } } } - Rectangle { - id: rect2 - width: 100 - height: 100 - y: 100 - color: "red" + states: State { name: "Day"; when: window.activeSuns > 0 + PropertyChanges { target: stopA; color: "DeepSkyBlue"} + PropertyChanges { target: stopB; color: "SkyBlue"} + PropertyChanges { target: stars; opacity: 0 } + } - MouseRegion { - anchors.fill:parent - onClicked: { destroyDynamicObject(); } - } + transitions: Transition { + PropertyAnimation { duration: 3000 } + ColorAnimation { duration: 3000 } } + //TODO: Below feature needs beautification to meet minimum standards + // toolbox Rectangle { - id: rect3 - width: 100 - height: 100 - y: 200 - color: "blue" + id: toolbox + z: 3 //Above ground + color: "white" + width: 480 + anchors { right: parent.right; top:parent.top; bottom: parent.bottom } + Column{ + id: toolboxPositioner + anchors.centerIn: parent + spacing: 1 + Sun { + id: sunButton + Script { source: "sunCreation.js" } + MouseRegion { + anchors.fill: parent; + onPressed: startDrag(mouse); + onPositionChanged: moveDrag(mouse); + onReleased: endDrag(mouse); + } + } + Text{ text: "Active Suns: " + activeSuns } + Rectangle { width: 440; height: 1; color: "black" } + Text{ text: "Arbitrary Javascript: " } + TextEdit { + id: jsText + width: 460 + height: 80 + readOnly: false + focusOnPress: true + + text: "window.activeSuns++;" + } + Rectangle { + width: 80 + height: 20 + color: "lightsteelblue" + Text{ anchors.centerIn: parent; text: "Execute" } + MouseRegion { + anchors.fill: parent; + onClicked: eval(jsText.text.toString()); + } + } - MouseRegion { - anchors.fill: parent - onClicked: { - if (fourthBox == null || fourthBox == undefined) { - var a = createQml(targetItem2); - if (a != null) { - a.parent = targetItem2;//BUG: this should happen automatically - fourthBox = a; - print(a.toStr()); - extendStars = true; - } - } else { - fourthBox.state = 'dying'; - fourthBox.destroy(500); - fourthBox = null; - extendStars = false; + Rectangle { width: 440; height: 1; color: "black" } + Text{ text: "Arbitrary QML: " } + TextEdit { + id: qmlText + width: 460 + height: 180 + readOnly: false + focusOnPress: true + + text: "import Qt 4.6\nImage { id: smile; x: 10; y: 10; \n source: 'images/face-smile.png';\n opacity: NumberAnimation{ \n running:true; to: 0; duration: 1500;\n }\n Component.onCompleted: smile.destroy(1500);\n}" + } + Rectangle { + width: 80 + height: 20 + color: "lightsteelblue" + Text{ anchors.centerIn: parent; text: "Create" } + MouseRegion { + anchors.fill: parent; + onClicked: {var obj=createQmlObject(qmlText.text, window, 'CustomObject'); obj.parent=window;} } } } } - Particles { - x: 0 - y: 0 - z: 10 - count: 20 - lifeSpan: 500 - width: 100 - height: if (extendStars) { 400; } else { 300; } - source: "star.png" - } } diff --git a/examples/declarative/dynamic/images/face-smile.png b/examples/declarative/dynamic/images/face-smile.png new file mode 100644 index 0000000..3d66d72 Binary files /dev/null and b/examples/declarative/dynamic/images/face-smile.png differ diff --git a/examples/declarative/dynamic/images/star.png b/examples/declarative/dynamic/images/star.png new file mode 100644 index 0000000..27ef924 Binary files /dev/null and b/examples/declarative/dynamic/images/star.png differ diff --git a/examples/declarative/dynamic/images/sun.png b/examples/declarative/dynamic/images/sun.png new file mode 100644 index 0000000..7713ca5 Binary files /dev/null and b/examples/declarative/dynamic/images/sun.png differ diff --git a/examples/declarative/dynamic/star.png b/examples/declarative/dynamic/star.png deleted file mode 100644 index defbde5..0000000 Binary files a/examples/declarative/dynamic/star.png and /dev/null differ diff --git a/examples/declarative/dynamic/sunCreation.js b/examples/declarative/dynamic/sunCreation.js new file mode 100644 index 0000000..d9e5dce --- /dev/null +++ b/examples/declarative/dynamic/sunCreation.js @@ -0,0 +1,69 @@ +var sunComponent = null; +var draggedItem = null; +var startingMouse; +//Until QT-2385 is resolved we need to convert to scene coordinates manually +var xOffset; +var yOffset; + +function startDrag(mouse) +{ + xOffset = toolbox.x + toolboxPositioner.x; + yOffset = toolbox.y + toolboxPositioner.y; + startingMouse = mouse; + loadComponent(); +} + +//Creation is split into two functions due to an asyncronous wait while +//possible external files are loaded. + +function loadComponent() { + if (sunComponent != null) //Already loaded the component + createSun(); + + sunComponent = createComponent("Sun.qml"); + if(sunComponent.isLoading){ + component.statusChanged.connect(finishCreation); + }else{//Depending on the content, it can be ready or error immediately + createSun(); + } +} + +function createSun() { + if (sunComponent.isReady && draggedItem == null) { + draggedItem = sunComponent.createObject(); + draggedItem.parent = window; + draggedItem.x = startingMouse.x + xOffset; + draggedItem.y = startingMouse.y + yOffset; + draggedItem.z = 4;//On top + } else if (sunComponent.isError) { + draggedItem = null; + print("error creating component"); + print(component.errorsString()); + } +} + +function moveDrag(mouse) +{ + if(draggedItem == null) + return; + + draggedItem.x = mouse.x + xOffset; + draggedItem.y = mouse.y + yOffset; +} + +function endDrag(mouse) +{ + if(draggedItem == null) + return; + + if(draggedItem.x + draggedItem.width > toolbox.x //Don't drop it in the toolbox + || draggedItem.y > ground.y){//Don't drop it on the ground + draggedItem.destroy(); + draggedItem = null; + }else{ + draggedItem.z = 1; + draggedItem.created = true; + draggedItem = null; + } +} + -- cgit v0.12 From e92c4b557b07e34a47615a1f7f9a5aff9e981aa6 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 27 Oct 2009 19:39:50 +1000 Subject: Support return values in synthesized methods --- src/declarative/qml/qmlcompiler.cpp | 1 + src/declarative/qml/qmlvmemetaobject.cpp | 6 ++++-- tests/auto/declarative/qmlecmascript/data/methods.3.qml | 7 +++++++ tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmlecmascript/data/methods.3.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index 60282dc..ad74446 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2234,6 +2234,7 @@ bool QmlCompiler::buildDynamicMeta(QmlParser::Object *obj, DynamicMetaMode mode) } sig.append(")"); QMetaMethodBuilder b = builder.addSlot(sig); + b.setReturnType("QVariant"); b.setParameterNames(s.parameterNames); ((QmlVMEMetaData *)dynamicData.data())->methodCount++; diff --git a/src/declarative/qml/qmlvmemetaobject.cpp b/src/declarative/qml/qmlvmemetaobject.cpp index 3e1d931..83f904b 100644 --- a/src/declarative/qml/qmlvmemetaobject.cpp +++ b/src/declarative/qml/qmlvmemetaobject.cpp @@ -269,10 +269,11 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) QString code = QString::fromRawData(body, data->bodyLength); + QVariant rv; if (0 == (metaData->methodData() + id)->parameterCount) { QmlExpression expr(ctxt, code, object); expr.setTrackChange(false); - expr.value(); + rv = expr.value(); } else { QmlContext newCtxt(ctxt); QMetaMethod m = method(_id); @@ -281,8 +282,9 @@ int QmlVMEMetaObject::metaCall(QMetaObject::Call c, int _id, void **a) newCtxt.setContextProperty(QString::fromLatin1(names.at(ii)), *(QVariant *)a[ii + 1]); QmlExpression expr(&newCtxt, code, object); expr.setTrackChange(false); - expr.value(); + rv = expr.value(); } + if (a[0]) *reinterpret_cast(a[0]) = rv; } return -1; } diff --git a/tests/auto/declarative/qmlecmascript/data/methods.3.qml b/tests/auto/declarative/qmlecmascript/data/methods.3.qml new file mode 100644 index 0000000..2efcf6a --- /dev/null +++ b/tests/auto/declarative/qmlecmascript/data/methods.3.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +Object { + function testFunction() { return 19; } + + property int test: testFunction() +} diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index a0e65c5..67a98b1 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -152,6 +152,13 @@ void tst_qmlecmascript::methods() QCOMPARE(object->methodCalled(), false); QCOMPARE(object->methodIntCalled(), true); } + + { + QmlComponent component(&engine, TEST_FILE("methods.3.qml")); + QObject *object = component.create(); + QVERIFY(object != 0); + QCOMPARE(object->property("test").toInt(), 19); + } } void tst_qmlecmascript::bindingLoop() -- cgit v0.12 From 5f9091771eaa26db5ad35e4788c13ac011512b61 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 27 Oct 2009 20:03:35 +1000 Subject: Doc --- doc/src/declarative/pics/repeater-index.png | Bin 0 -> 3024 bytes doc/src/snippets/declarative/repeater-index.qml | 15 +++++++++++++++ src/declarative/fx/qfxrepeater.cpp | 12 ++++++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 doc/src/declarative/pics/repeater-index.png create mode 100644 doc/src/snippets/declarative/repeater-index.qml diff --git a/doc/src/declarative/pics/repeater-index.png b/doc/src/declarative/pics/repeater-index.png new file mode 100644 index 0000000..3dbe6d0 Binary files /dev/null and b/doc/src/declarative/pics/repeater-index.png differ diff --git a/doc/src/snippets/declarative/repeater-index.qml b/doc/src/snippets/declarative/repeater-index.qml new file mode 100644 index 0000000..9063967 --- /dev/null +++ b/doc/src/snippets/declarative/repeater-index.qml @@ -0,0 +1,15 @@ +import Qt 4.6 + +Rectangle { + width: 50; height: childrenRect.height; color: "white" + +//! [0] + Column { + Repeater { + model: 10 + Text { text: "I'm item " + index } + } + } +//! [0] +} + diff --git a/src/declarative/fx/qfxrepeater.cpp b/src/declarative/fx/qfxrepeater.cpp index 182dcc7..94954e7 100644 --- a/src/declarative/fx/qfxrepeater.cpp +++ b/src/declarative/fx/qfxrepeater.cpp @@ -72,10 +72,18 @@ QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Repeater,QFxRepeater) The model may be either an object list, a string list, a number or a Qt model. In each case, the data element and the index is exposed to each instantiated - component. The index is always exposed as an accessible \c index property. + component. + + The index is always exposed as an accessible \c index property. In the case of an object or string list, the data element (of type string or object) is available as the \c modelData property. In the case of a Qt model, - all roles are available as named properties just like in the view classes. + all roles are available as named properties just like in the view classes. The + following example shows how to use the index property inside the instantiated + items. + + \snippet doc/src/snippets/declarative/repeater-index.qml 0 + + \image repeater-index.png Items instantiated by the Repeater are inserted, in order, as children of the Repeater's parent. The insertion starts immediately after -- cgit v0.12