diff options
author | Bea Lam <bea.lam@nokia.com> | 2009-11-10 06:39:00 (GMT) |
---|---|---|
committer | Bea Lam <bea.lam@nokia.com> | 2009-11-10 06:39:00 (GMT) |
commit | 432d54d092414431e1e54daa2259384d83600bf2 (patch) | |
tree | 0ec7c9080b5dcdae1f411457f8b057145ef94366 /src/declarative | |
parent | c411c39557d31b94efb5813be9e9ef43c05a9093 (diff) | |
parent | 4459e18afd3e537c2155dadad0937e0a5cdd76c5 (diff) | |
download | Qt-432d54d092414431e1e54daa2259384d83600bf2.zip Qt-432d54d092414431e1e54daa2259384d83600bf2.tar.gz Qt-432d54d092414431e1e54daa2259384d83600bf2.tar.bz2 |
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative')
23 files changed, 413 insertions, 221 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp index 10050f2..1b94426 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsgridview.cpp @@ -565,6 +565,7 @@ void QmlGraphicsGridViewPrivate::updateTrackedItem() void QmlGraphicsGridViewPrivate::createHighlight() { Q_Q(QmlGraphicsGridView); + bool changed = false; if (highlight) { if (trackedItem == highlight) trackedItem = 0; @@ -575,6 +576,7 @@ void QmlGraphicsGridViewPrivate::createHighlight() delete highlightYAnimator; highlightXAnimator = 0; highlightYAnimator = 0; + changed = true; } if (currentItem) { @@ -606,8 +608,11 @@ void QmlGraphicsGridViewPrivate::createHighlight() highlightYAnimator->setTarget(QmlMetaProperty(highlight->item, QLatin1String("y"))); highlightYAnimator->setDuration(150); highlightYAnimator->setEnabled(autoHighlight); + changed = true; } } + if (changed) + emit q->highlightChanged(); } void QmlGraphicsGridViewPrivate::updateHighlight() @@ -887,6 +892,25 @@ QmlGraphicsItem *QmlGraphicsGridView::currentItem() } /*! + \qmlproperty Item GridView::highlightItem + + \c highlightItem holds the highlight item, which was created + from the \l highlight component. + + The highlightItem is managed by the view unless + \l highlightFollowsCurrentItem is set to false. + + \sa highlight, highlightFollowsCurrentItem +*/ +QmlGraphicsItem *QmlGraphicsGridView::highlightItem() +{ + Q_D(QmlGraphicsGridView); + if (!d->highlight) + return 0; + return d->highlight->item; +} + +/*! \qmlproperty int GridView::count This property holds the number of items in the view. */ @@ -909,7 +933,7 @@ int QmlGraphicsGridView::count() const The below example demonstrates how to make a simple highlight: \snippet doc/src/snippets/declarative/gridview/gridview.qml 1 - \sa highlightFollowsCurrentItem + \sa highlightItem, highlightFollowsCurrentItem */ QmlComponent *QmlGraphicsGridView::highlight() const { diff --git a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h index 3fd36bd..3e09cf3 100644 --- a/src/declarative/graphicsitems/qmlgraphicsgridview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsgridview_p.h @@ -62,8 +62,11 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsGridView : public QmlGraphicsFlickable Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) Q_PROPERTY(QmlGraphicsItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) + Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(QmlGraphicsItem *highlightItem READ highlightItem NOTIFY highlightChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) + Q_PROPERTY(Flow flow READ flow WRITE setFlow) Q_PROPERTY(bool keyNavigationWraps READ isWrapEnabled WRITE setWrapEnabled) Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) @@ -85,6 +88,7 @@ public: void setCurrentIndex(int idx); QmlGraphicsItem *currentItem(); + QmlGraphicsItem *highlightItem(); int count() const; QmlComponent *highlight() const; @@ -123,6 +127,7 @@ Q_SIGNALS: void currentIndexChanged(); void cellWidthChanged(); void cellHeightChanged(); + void highlightChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qmlgraphicsitem_p.h b/src/declarative/graphicsitems/qmlgraphicsitem_p.h index f98c121..e1d7342 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem_p.h @@ -232,6 +232,24 @@ public: emit q_func()->wantsFocusChanged(); } + // Reimplemented from QGraphicsItemPrivate + virtual void siblingOrderChange() + { + foreach(QmlGraphicsItemPrivate* other, siblingOrderNotifiees) + other->otherSiblingOrderChange(this); + } + QList<QmlGraphicsItemPrivate*> siblingOrderNotifiees; + void registerSiblingOrderNotification(QmlGraphicsItemPrivate* other) + { + siblingOrderNotifiees << other; + } + void unregisterSiblingOrderNotification(QmlGraphicsItemPrivate* other) + { + siblingOrderNotifiees.removeAll(other); + } + virtual void otherSiblingOrderChange(QmlGraphicsItemPrivate* other) {Q_UNUSED(other)} + + static int consistentTime; static QTime currentTime(); static void Q_DECLARATIVE_EXPORT setConsistentTime(int t); diff --git a/src/declarative/graphicsitems/qmlgraphicslistview.cpp b/src/declarative/graphicsitems/qmlgraphicslistview.cpp index 53287a6..12bf0d8 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicslistview.cpp @@ -641,6 +641,7 @@ void QmlGraphicsListViewPrivate::updateTrackedItem() void QmlGraphicsListViewPrivate::createHighlight() { Q_Q(QmlGraphicsListView); + bool changed = false; if (highlight) { if (trackedItem == highlight) trackedItem = 0; @@ -651,6 +652,7 @@ void QmlGraphicsListViewPrivate::createHighlight() delete highlightSizeAnimator; highlightPosAnimator = 0; highlightSizeAnimator = 0; + changed = true; } if (currentItem) { @@ -687,8 +689,11 @@ void QmlGraphicsListViewPrivate::createHighlight() highlightSizeAnimator->setVelocity(highlightResizeSpeed); highlightSizeAnimator->setTarget(QmlMetaProperty(highlight->item, sizeProp)); highlightSizeAnimator->setEnabled(autoHighlight); + changed = true; } } + if (changed) + emit q->highlightChanged(); } void QmlGraphicsListViewPrivate::updateHighlight() @@ -871,7 +876,7 @@ void QmlGraphicsListViewPrivate::flickX(qreal velocity) if (v > 0) dist = -dist; dist = -_moveX.value() - snapPosAt(-(_moveX.value() - highlightRangeStart) + dist) + highlightRangeStart; - if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + if ((v < 0 && dist >= 0) || (v > 0 && dist <= 0)) { timeline.reset(_moveX); fixupX(); return; @@ -929,7 +934,7 @@ void QmlGraphicsListViewPrivate::flickY(qreal velocity) if (v > 0) dist = -dist; dist = -_moveY.value() - snapPosAt(-(_moveY.value() - highlightRangeStart) + dist) + highlightRangeStart; - if (v < 0 && dist >= 0 || v > 0 && dist <= 0) { + if ((v < 0 && dist >= 0) || (v > 0 && dist <= 0)) { timeline.reset(_moveY); fixupY(); return; @@ -1202,6 +1207,25 @@ QmlGraphicsItem *QmlGraphicsListView::currentItem() } /*! + \qmlproperty Item ListView::highlightItem + + \c highlightItem holds the highlight item, which was created + from the \l highlight component. + + The highlightItem is managed by the view unless + \l highlightFollowsCurrentItem is set to false. + + \sa highlight, highlightFollowsCurrentItem +*/ +QmlGraphicsItem *QmlGraphicsListView::highlightItem() +{ + Q_D(QmlGraphicsListView); + if (!d->highlight) + return 0; + return d->highlight->item; +} + +/*! \qmlproperty int ListView::count This property holds the number of items in the view. */ @@ -1228,7 +1252,7 @@ int QmlGraphicsListView::count() const \snippet doc/src/snippets/declarative/listview/listview.qml 1 \image trivialListView.png - \sa highlightFollowsCurrentItem + \sa highlightItem, highlightFollowsCurrentItem */ QmlComponent *QmlGraphicsListView::highlight() const { diff --git a/src/declarative/graphicsitems/qmlgraphicslistview_p.h b/src/declarative/graphicsitems/qmlgraphicslistview_p.h index 3f46434..b8a6e1f 100644 --- a/src/declarative/graphicsitems/qmlgraphicslistview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicslistview_p.h @@ -66,6 +66,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsListView : public QmlGraphicsFlickable Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) + Q_PROPERTY(QmlGraphicsItem *highlightItem READ highlightItem NOTIFY highlightChanged) Q_PROPERTY(bool highlightFollowsCurrentItem READ highlightFollowsCurrentItem WRITE setHighlightFollowsCurrentItem) Q_PROPERTY(qreal highlightMoveSpeed READ highlightMoveSpeed WRITE setHighlightMoveSpeed NOTIFY highlightMoveSpeedChanged) Q_PROPERTY(qreal highlightResizeSpeed READ highlightResizeSpeed WRITE setHighlightResizeSpeed NOTIFY highlightResizeSpeedChanged) @@ -99,6 +100,7 @@ public: void setCurrentIndex(int idx); QmlGraphicsItem *currentItem(); + QmlGraphicsItem *highlightItem(); int count() const; QmlComponent *highlight() const; @@ -155,6 +157,7 @@ Q_SIGNALS: void sectionExpressionChanged(); void highlightMoveSpeedChanged(); void highlightResizeSpeedChanged(); + void highlightChanged(); protected: virtual void viewportMoved(); diff --git a/src/declarative/graphicsitems/qmlgraphicspainteditem.cpp b/src/declarative/graphicsitems/qmlgraphicspainteditem.cpp index a0d9b09..2c849c8 100644 --- a/src/declarative/graphicsitems/qmlgraphicspainteditem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspainteditem.cpp @@ -209,17 +209,12 @@ void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem * ++inpaint; - QRectF clipf = p->clipRegion().boundingRect(); - if (clipf.isEmpty()) - clipf = mapToScene(content).boundingRect(); // ### Inefficient: Maps toScene and then fromScene - else - clipf = mapToScene(clipf).boundingRect(); - - const QRect clip = mapFromScene(clipf).boundingRect().toRect(); + const QRect clip = p->clipRegion().boundingRect(); QRegion topaint(clip); topaint &= content; QRegion uncached(content); + p->setRenderHints(QPainter::SmoothPixmapTransform, d->smooth); int cachesize=0; for (int i=0; i<d->imagecache.count(); ++i) { @@ -229,7 +224,7 @@ void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem * if (!d->cachefrozen) { if (!d->imagecache[i]->dirty.isNull() && topaint.contains(d->imagecache[i]->dirty)) { QPainter qp(&d->imagecache[i]->image); - qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth); + qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache); qp.translate(-area.x(), -area.y()); if (d->fillColor.isValid()){ if(d->fillColor.alpha() < 255){ @@ -285,7 +280,7 @@ void QmlGraphicsPaintedItem::paint(QPainter *p, const QStyleOptionGraphicsItem * img.fill(d->fillColor); { QPainter qp(&img); - qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smooth); + qp.setRenderHints(QPainter::HighQualityAntialiasing | QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform, d->smoothCache); qp.translate(-r.x(),-r.y()); drawContents(&qp, r); @@ -383,5 +378,30 @@ QColor QmlGraphicsPaintedItem::fillColor() const return d->fillColor; } +/*! + \qmlproperty bool PaintedItem::smoothCache + + Controls whether the cached tiles of which the item is composed are + rendered smoothly when they are generated. + + This is in addition toe Item::smooth, which controls the smooth painting of + the already-painted cached tiles under transformation. +*/ +bool QmlGraphicsPaintedItem::smoothCache() const +{ + Q_D(const QmlGraphicsPaintedItem); + return d->smoothCache; +} + +void QmlGraphicsPaintedItem::setSmoothCache(bool on) +{ + Q_D(QmlGraphicsPaintedItem); + if (d->smoothCache != on) { + d->smoothCache = on; + clearCache(); + } +} + + QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicspainteditem_p.h b/src/declarative/graphicsitems/qmlgraphicspainteditem_p.h index 99873a7..8d629b3 100644 --- a/src/declarative/graphicsitems/qmlgraphicspainteditem_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspainteditem_p.h @@ -59,6 +59,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsPaintedItem : public QmlGraphicsItem Q_PROPERTY(QSize contentsSize READ contentsSize WRITE setContentsSize) Q_PROPERTY(QColor fillColor READ fillColor WRITE setFillColor NOTIFY fillColorChanged) Q_PROPERTY(int cacheSize READ cacheSize WRITE setCacheSize) + Q_PROPERTY(bool smoothCache READ smoothCache WRITE setSmoothCache) public: QmlGraphicsPaintedItem(QmlGraphicsItem *parent=0); @@ -70,6 +71,9 @@ public: int cacheSize() const; void setCacheSize(int pixels); + bool smoothCache() const; + void setSmoothCache(bool on); + QColor fillColor() const; void setFillColor(const QColor&); diff --git a/src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h b/src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h index a744557..a938ecf 100644 --- a/src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspainteditem_p_p.h @@ -63,7 +63,7 @@ class QmlGraphicsPaintedItemPrivate : public QmlGraphicsItemPrivate public: QmlGraphicsPaintedItemPrivate() - : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false) + : max_imagecache_size(100000), fillColor(Qt::transparent), cachefrozen(false), smoothCache(true) { } @@ -82,6 +82,7 @@ public: QSize contentsSize; QColor fillColor; bool cachefrozen; + bool smoothCache; }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp index 3b975ba..ced9d55 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspositioners.cpp @@ -52,6 +52,36 @@ QT_BEGIN_NAMESPACE +void QmlGraphicsBasePositionerPrivate::watchChanges(QmlGraphicsItem *other) +{ + Q_Q(QmlGraphicsBasePositioner); + QObject::connect(other, SIGNAL(visibleChanged()), + q, SLOT(prePositioning())); + QObject::connect(other, SIGNAL(opacityChanged()), + q, SLOT(prePositioning())); + QObject::connect(other, SIGNAL(heightChanged()), + q, SLOT(prePositioning())); + QObject::connect(other, SIGNAL(widthChanged()), + q, SLOT(prePositioning())); + static_cast<QmlGraphicsItemPrivate*>(QGraphicsItemPrivate::get(other))->registerSiblingOrderNotification(this); + watched << other; +} + +void QmlGraphicsBasePositionerPrivate::unwatchChanges(QmlGraphicsItem* other) +{ + Q_Q(QmlGraphicsBasePositioner); + QObject::disconnect(other, SIGNAL(visibleChanged()), + q, SLOT(prePositioning())); + QObject::disconnect(other, SIGNAL(opacityChanged()), + q, SLOT(prePositioning())); + QObject::disconnect(other, SIGNAL(heightChanged()), + q, SLOT(prePositioning())); + QObject::disconnect(other, SIGNAL(widthChanged()), + q, SLOT(prePositioning())); + static_cast<QmlGraphicsItemPrivate*>(QGraphicsItemPrivate::get(other))->unregisterSiblingOrderNotification(this); + watched.removeAll(other); +} + /*! \internal \class QmlGraphicsBasePositioner @@ -204,6 +234,7 @@ void QmlGraphicsBasePositioner::prePositioning() if (!isComponentComplete() || d->_movingItem) return; + d->queuedPositioning = false; if (!d->_ep) { d->_ep = true; QCoreApplication::postEvent(this, new QEvent(QEvent::User)); @@ -220,14 +251,7 @@ void QmlGraphicsBasePositioner::prePositioning() if (!child) continue; if (!d->_items.contains(child)){ - QObject::connect(child, SIGNAL(visibleChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(opacityChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(heightChanged()), - this, SLOT(prePositioning())); - QObject::connect(child, SIGNAL(widthChanged()), - this, SLOT(prePositioning())); + d->watchChanges(child); d->_items += child; } if (child->opacity() == 0.0){ @@ -390,58 +414,24 @@ Column { /*! \qmlproperty Transition Column::remove This property holds the transition to apply when removing an item from the positioner. The transition is only applied to the removed items. + Positioner transitions will only affect the position (x,y) of items. Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. - - \table - \row - \o \image positioner-remove.gif - \o - \qml -Column { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml - \endtable - */ /*! \qmlproperty Transition Column::add This property holds the transition to be applied when adding an item to the positioner. The transition will only be applied to the added item(s). + Positioner transitions will only affect the position (x,y) of items. Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. - \table - \row - \o \image positioner-add.gif - \o - \qml -Column { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml - \endtable */ /*! \qmlproperty Transition Column::move This property holds the transition to apply when moving an item within the positioner. + Positioner transitions will only affect the position (x,y) of items. This can happen when other items are added or removed from the positioner, or when items resize themselves. @@ -453,7 +443,7 @@ Column { Column { move: Transition { NumberAnimation { - properties: "y" + matchProperties: "y" ease: "easeOutBounce" } } @@ -564,49 +554,28 @@ Row { \qmlproperty Transition Row::remove This property holds the transition to apply when removing an item from the positioner. The transition will only be applied to the removed item(s). + Positioner transitions will only affect the position (x,y) of items. Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. Note that if the item counts as removed because its opacity is zero it will not be visible during the transition unless you set the opacity in the transition, like in the below example. - \qml -Row { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml */ /*! \qmlproperty Transition Row::add This property holds the transition to apply when adding an item to the positioner. The transition will only be applied to the added item(s). + Positioner transitions will only affect the position (x,y) of items. Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. - \qml -Row { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml */ /*! \qmlproperty Transition Row::move This property holds the transition to apply when moving an item within the positioner. + Positioner transitions will only affect the position (x,y) of items. This can happen when other items are added or removed from the positioner, or when items resize themselves. @@ -615,7 +584,7 @@ Row { id: positioner move: Transition { NumberAnimation { - properties: "x" + matchProperties: "x" ease: "easeOutBounce" } } @@ -735,57 +704,32 @@ Grid { \qmlproperty Transition Grid::remove This property holds the transition to apply when removing an item from the positioner. The transition is only applied to the removed item(s). + Positioner transitions will only affect the position (x,y) of items. Removed can mean that either the object has been deleted or reparented, and thus is now longer a child of the positioner, or that the object has had its opacity set to zero, and thus is no longer visible. - Note that if the item counts as removed because its opacity is - zero it will not be visible during the transition unless you set - the opacity in the transition, like in the below example. - - \qml -Grid { - remove: Transition { - NumberAnimation { - properties: "opacity" - from: 1 - to: 0 - duration: 500 - } - } -} - \endqml */ /*! \qmlproperty Transition Grid::add This property holds the transition to apply when adding an item to the positioner. The transition is only applied to the added item(s). + Positioner transitions will only affect the position (x,y) of items. Added can mean that either the object has been created or reparented, and thus is now a child or the positioner, or that the object has had its opacity increased from zero, and thus is now visible. - \qml -Grid { - add: Transition { - NumberAnimation { - properties: "opacity" - from: 0 - to: 1 - duration: 500 - } - } -} - \endqml */ /*! \qmlproperty Transition Grid::move This property holds the transition to apply when moving an item within the positioner. + Positioner transitions will only affect the position (x,y) of items. This can happen when other items are added or removed from the positioner, or when items resize themselves. @@ -794,7 +738,7 @@ Grid { Grid { move: Transition { NumberAnimation { - properties: "x,y" + matchProperties: "x,y" ease: "easeOutBounce" } } diff --git a/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h b/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h index 61b4497..d7a31a3 100644 --- a/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspositioners_p_p.h @@ -60,6 +60,7 @@ #include <private/qmlstate_p.h> #include <private/qmltransitionmanager_p_p.h> #include <private/qmlstateoperations_p.h> +#include <QtCore/QTimer> QT_BEGIN_NAMESPACE class QmlGraphicsBasePositionerPrivate : public QmlGraphicsItemPrivate @@ -70,10 +71,17 @@ public: QmlGraphicsBasePositionerPrivate() : _ep(false), _componentComplete(false), _spacing(0), aut(QmlGraphicsBasePositioner::None), moveTransition(0), addTransition(0), - removeTransition(0), _movingItem(0) + removeTransition(0), _movingItem(0), queuedPositioning(false) { } + ~QmlGraphicsBasePositionerPrivate() + { + watched.removeAll(0); + foreach(QmlGraphicsItem* other, watched) + unwatchChanges(other);//Need to deregister from a list in QmlGI Private + } + void init(QmlGraphicsBasePositioner::AutoUpdateType at) { aut = at; @@ -99,6 +107,22 @@ public: QmlTransitionManager removeTransitionManager; // QmlStateGroup *stateGroup; QmlGraphicsItem *_movingItem; + + void watchChanges(QmlGraphicsItem *other); + void unwatchChanges(QmlGraphicsItem* other); + QList<QGuard<QmlGraphicsItem> > watched; + bool queuedPositioning; + + virtual void otherSiblingOrderChange(QmlGraphicsItemPrivate* other) + { + Q_Q(QmlGraphicsBasePositioner); + Q_UNUSED(other); + if(!queuedPositioning){ + //Delay is due to many children often being reordered at once + QTimer::singleShot(0,q,SLOT(prePositioning())); + queuedPositioning = true; + } + } }; QT_END_NAMESPACE diff --git a/src/declarative/graphicsitems/qmlgraphicswebview.cpp b/src/declarative/graphicsitems/qmlgraphicswebview.cpp index 827144d..14c4352 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview.cpp +++ b/src/declarative/graphicsitems/qmlgraphicswebview.cpp @@ -166,7 +166,7 @@ class QmlGraphicsWebViewPrivate : public QmlGraphicsPaintedItemPrivate public: QmlGraphicsWebViewPrivate() - : QmlGraphicsPaintedItemPrivate(), page(0), preferredwidth(0), pagewidth(0), + : QmlGraphicsPaintedItemPrivate(), page(0), preferredwidth(0), preferredheight(0), progress(1.0), status(QmlGraphicsWebView::Null), pending(PendingNone), newWindowComponent(0), newWindowParent(0), windowObjects(this), @@ -177,8 +177,7 @@ public: QUrl url; // page url might be different if it has not loaded yet QWebPage *page; - int preferredwidth; - int pagewidth; + int preferredwidth, preferredheight; qreal progress; QmlGraphicsWebView::Status status; QString statusText; @@ -227,7 +226,8 @@ public: width: 490 height: 400 scale: 0.5 - smooth: true + smooth: false + smoothCache: true } \endqml @@ -341,22 +341,15 @@ void QmlGraphicsWebView::pageUrlChanged() { Q_D(QmlGraphicsWebView); - // Reset zooming to full - qreal zf = 1.0; if (d->preferredwidth) { - if (d->pagewidth) - zf = qreal(d->preferredwidth)/d->pagewidth; - page()->mainFrame()->setZoomFactor(zf); page()->setViewportSize(QSize(d->preferredwidth,-1)); } else { - page()->mainFrame()->setZoomFactor(zf); page()->setViewportSize(QSize(-1,-1)); } - emit zooming(zf,0,0); expandToWebPage(); if ((d->url.isEmpty() && page()->mainFrame()->url() != QUrl(QLatin1String("about:blank"))) - || d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty()) + || (d->url != page()->mainFrame()->url() && !page()->mainFrame()->url().isEmpty())) { d->url = page()->mainFrame()->url(); if (d->url == QUrl(QLatin1String("about:blank"))) @@ -406,15 +399,11 @@ void QmlGraphicsWebView::setUrl(const QUrl &url) if (isComponentComplete()) { d->url = url; - qreal zf = 1.0; if (d->preferredwidth) { - if (d->pagewidth) - zf = qreal(d->preferredwidth)/d->pagewidth; page()->setViewportSize(QSize(d->preferredwidth,-1)); } else { page()->setViewportSize(QSize(-1,-1)); } - page()->mainFrame()->setZoomFactor(zf); QUrl seturl = url; if (seturl.isEmpty()) seturl = QUrl(QLatin1String("about:blank")); @@ -444,35 +433,27 @@ void QmlGraphicsWebView::setPreferredWidth(int iw) { Q_D(QmlGraphicsWebView); if (d->preferredwidth == iw) return; - if (d->pagewidth) { - if (d->preferredwidth) { - setZoomFactor(zoomFactor()*iw/d->preferredwidth); - } else { - setZoomFactor(qreal(iw)/d->pagewidth); - } - } d->preferredwidth = iw; expandToWebPage(); emit preferredWidthChanged(); } /*! - \qmlproperty int WebView::webPageWidth - This property holds the page width suggested to the web engine. The zoomFactor - will be changed to fit this with in preferredWidth. + \qmlproperty int WebView::preferredHeight + This property holds the ideal height for displaying the current URL. + This only affects the area zoomed by heuristicZoom(). */ -int QmlGraphicsWebView::webPageWidth() const +int QmlGraphicsWebView::preferredHeight() const { Q_D(const QmlGraphicsWebView); - return d->pagewidth; + return d->preferredheight; } - -void QmlGraphicsWebView::setWebPageWidth(int pw) +void QmlGraphicsWebView::setPreferredHeight(int ih) { Q_D(QmlGraphicsWebView); - if (d->pagewidth == pw) return; - d->pagewidth = pw; - expandToWebPage(); + if (d->preferredheight == ih) return; + d->preferredheight = ih; + emit preferredHeightChanged(); } /*! @@ -715,18 +696,38 @@ void QmlGraphicsWebView::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event) delete me; } -void QmlGraphicsWebView::heuristicZoom(int clickX, int clickY) +/*! + \qmlmethod bool WebView::heuristicZoom(clickX,clickY,maxzoom) + + Finds a zoom that: + \list + \i shows a whole item + \i includes (\a clickX, \a clickY) + \i fits into the preferredWidth and preferredHeight + \i zooms by no more than \a maxzoom + \i is more than 20% above the current zoom + \endlist + + If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise, + no signal is emitted and returns false. +*/ +bool QmlGraphicsWebView::heuristicZoom(int clickX, int clickY, qreal maxzoom) { Q_D(QmlGraphicsWebView); qreal ozf = zoomFactor(); - QRect showarea = elementAreaAt(clickX, clickY, 1, 1); - qreal z = qreal(preferredWidth())*ozf/showarea.width()*.95; - if ((z/ozf > 0.99 && z/ozf <1.01) || z < qreal(d->preferredwidth)/d->pagewidth) { - // zoom out - z = qreal(d->preferredwidth)/d->pagewidth; + if (ozf >= maxzoom) + return false; + QRect showarea = elementAreaAt(clickX, clickY, d->preferredwidth/maxzoom, d->preferredheight/maxzoom); + qreal z = qMin(qreal(d->preferredwidth)*ozf/showarea.width(),qreal(d->preferredheight)*ozf/showarea.height()); + if (z > maxzoom) + z = maxzoom; + if (z/ozf > 1.2) { + QRectF r(showarea.left()/ozf*z, showarea.top()/ozf*z, showarea.width()/ozf*z, showarea.height()/ozf*z); + emit zoomTo(z,r.x()+r.width()/2, r.y()+r.height()/2); + return true; + } else { + return false; } - QRectF r(showarea.left()/ozf*z, showarea.top()/ozf*z, showarea.width()/ozf*z, showarea.height()/ozf*z); - emit zooming(z,r.x()+r.width()/2, r.y()+r.height()/2); } void QmlGraphicsWebView::mousePressEvent(QGraphicsSceneMouseEvent *event) @@ -911,7 +912,7 @@ void QmlGraphicsWebView::setZoomFactor(qreal factor) return; page()->mainFrame()->setZoomFactor(factor); - page()->setViewportSize(QSize(d->pagewidth*factor,-1)); + page()->setViewportSize(QSize(d->preferredwidth ? d->preferredwidth : -1,-1)); expandToWebPage(); emit zoomFactorChanged(); @@ -1239,15 +1240,15 @@ void QmlGraphicsWebView::setNewWindowParent(QmlGraphicsItem *parent) QRect QmlGraphicsWebView::elementAreaAt(int x, int y, int maxwidth, int maxheight) const { QWebHitTestResult hit = page()->mainFrame()->hitTestContent(QPoint(x,y)); + QRect rv = hit.boundingRect(); QWebElement element = hit.enclosingBlockElement(); - QWebElement parent = element.parent(); if (maxwidth<=0) maxwidth = INT_MAX; if (maxheight<=0) maxheight = INT_MAX; - while (!parent.isNull() && parent.geometry().width() <= maxwidth && parent.geometry().height() <= maxheight) { - element = parent; - parent = element.parent(); + while (!element.parent().isNull() && element.geometry().width() <= maxwidth && element.geometry().height() <= maxheight) { + rv = element.geometry(); + element = element.parent(); } - return element.geometry(); + return rv; } /*! diff --git a/src/declarative/graphicsitems/qmlgraphicswebview_p.h b/src/declarative/graphicsitems/qmlgraphicswebview_p.h index 6373246..7c9faf4 100644 --- a/src/declarative/graphicsitems/qmlgraphicswebview_p.h +++ b/src/declarative/graphicsitems/qmlgraphicswebview_p.h @@ -94,7 +94,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsWebView : public QmlGraphicsPaintedItem Q_PROPERTY(QString html READ html WRITE setHtml) Q_PROPERTY(int preferredWidth READ preferredWidth WRITE setPreferredWidth NOTIFY preferredWidthChanged) - Q_PROPERTY(int webPageWidth READ webPageWidth WRITE setWebPageWidth) + Q_PROPERTY(int preferredHeight READ preferredHeight WRITE setPreferredHeight NOTIFY preferredHeightChanged) Q_PROPERTY(int pixelCacheSize READ pixelCacheSize WRITE setPixelCacheSize) Q_PROPERTY(QUrl url READ url WRITE setUrl NOTIFY urlChanged) Q_PROPERTY(qreal progress READ progress NOTIFY progressChanged) @@ -127,11 +127,12 @@ public: qreal zoomFactor() const; void setZoomFactor(qreal); + Q_INVOKABLE bool heuristicZoom(int clickX, int clickY, qreal maxzoom); int preferredWidth() const; void setPreferredWidth(int); - int webPageWidth() const; - void setWebPageWidth(int); + int preferredHeight() const; + void setPreferredHeight(int); enum Status { Null, Ready, Loading, Error }; Status status() const; @@ -191,11 +192,10 @@ Q_SIGNALS: void doubleClick(int clickX, int clickY); - void zooming(qreal zoom, int centerX, int centerY); + void zoomTo(qreal zoom, int centerX, int centerY); public Q_SLOTS: QVariant evaluateJavaScript(const QString&); - void heuristicZoom(int clickX, int clickY); private Q_SLOTS: void expandToWebPage(); diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index f8e685a..105c673 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -48,6 +48,7 @@ #include <QtCore/qvarlengtharray.h> #include <QtCore/qdebug.h> #include <private/qmlbindingoptimizations_p.h> +#include <private/qscriptdeclarativeclass_p.h> #include <QtDeclarative/qmlinfo.h> QT_BEGIN_NAMESPACE @@ -69,7 +70,7 @@ void QmlContextPrivate::addScript(const QString &script, QObject *scopeObject, QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(engine); QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); - QScriptContext *scriptContext = scriptEngine->pushCleanContext(); + QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); scriptContext->pushScope(enginePriv->contextClass->newContext(q, scopeObject)); QScriptValue scope = scriptEngine->newObject(); diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index faf9f5a..d2d60ee 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -47,6 +47,7 @@ #include "QtCore/qdebug.h" #include "qmlcompiler_p.h" #include <QtScript/qscriptprogram.h> +#include <private/qscriptdeclarativeclass_p.h> Q_DECLARE_METATYPE(QList<QObject *>); @@ -117,7 +118,7 @@ void QmlExpressionPrivate::init(QmlContext *ctxt, void *expr, QmlRefCount *rc, } #endif - QScriptContext *scriptContext = scriptEngine->pushCleanContext(); + QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); scriptContext->pushScope(ep->contextClass->newContext(ctxt, me)); #if !defined(Q_OS_SYMBIAN) @@ -305,7 +306,7 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUnd if (!data->expressionFunctionValid) { - QScriptContext *scriptContext = scriptEngine->pushCleanContext(); + QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine); scriptContext->pushScope(ep->contextClass->newContext(data->context(), data->me)); if (data->expressionRewritten) { @@ -314,7 +315,12 @@ QVariant QmlExpressionPrivate::evalQtScript(QObject *secondaryScope, bool *isUnd } else { QmlRewrite::RewriteBinding rewriteBinding; - const QString code = rewriteBinding(data->expression); + bool ok = true; + const QString code = rewriteBinding(data->expression, &ok); + if (!ok) { + scriptEngine->popContext(); + return QVariant(); + } data->expressionFunction = scriptEngine->evaluate(code, data->url.toString(), data->line); } diff --git a/src/declarative/qml/qmlrewrite.cpp b/src/declarative/qml/qmlrewrite.cpp index b86f2f2..32e2fef 100644 --- a/src/declarative/qml/qmlrewrite.cpp +++ b/src/declarative/qml/qmlrewrite.cpp @@ -49,7 +49,7 @@ DEFINE_BOOL_CONFIG_OPTION(rewriteDump, QML_REWRITE_DUMP); namespace QmlRewrite { -QString RewriteBinding::operator()(const QString &code) +QString RewriteBinding::operator()(const QString &code, bool *ok) { Engine engine; NodePool pool(QString(), &engine); @@ -57,6 +57,12 @@ QString RewriteBinding::operator()(const QString &code) Parser parser(&engine); lexer.setCode(code, 0); parser.parseStatement(); + if (!parser.statement()) { + if (ok) *ok = false; + return QString(); + } else { + if (ok) *ok = true; + } return rewrite(code, 0, parser.statement()); } diff --git a/src/declarative/qml/qmlrewrite_p.h b/src/declarative/qml/qmlrewrite_p.h index 914f997..a5cb841 100644 --- a/src/declarative/qml/qmlrewrite_p.h +++ b/src/declarative/qml/qmlrewrite_p.h @@ -69,7 +69,7 @@ class RewriteBinding: protected AST::Visitor TextWriter *_writer; public: - QString operator()(const QString &code); + QString operator()(const QString &code, bool *ok = 0); protected: using AST::Visitor::visit; diff --git a/src/declarative/qml/qmlxmlhttprequest.cpp b/src/declarative/qml/qmlxmlhttprequest.cpp index 0c0cd9c..6946e7a 100644 --- a/src/declarative/qml/qmlxmlhttprequest.cpp +++ b/src/declarative/qml/qmlxmlhttprequest.cpp @@ -54,8 +54,37 @@ #include <QtCore/qdebug.h> -// ### Find real values -#define INVALID_STATE_ERR ((QScriptContext::Error)15) +// From DOM-Level-3-Core spec +// http://www.w3.org/TR/DOM-Level-3-Core/core.html +#define INDEX_SIZE_ERR 1 +#define DOMSTRING_SIZE_ERR 2 +#define HIERARCHY_REQUEST_ERR 3 +#define WRONG_DOCUMENT_ERR 4 +#define INVALID_CHARACTER_ERR 5 +#define NO_DATA_ALLOWED_ERR 6 +#define NO_MODIFICATION_ALLOWED_ERR 7 +#define NOT_FOUND_ERR 8 +#define NOT_SUPPORTED_ERR 9 +#define INUSE_ATTRIBUTE_ERR 10 +#define INVALID_STATE_ERR 11 +#define SYNTAX_ERR 12 +#define INVALID_MODIFICATION_ERR 13 +#define NAMESPACE_ERR 14 +#define INVALID_ACCESS_ERR 15 +#define VALIDATION_ERR 16 +#define TYPE_MISMATCH_ERR 17 + +#define THROW_DOM(error, desc) \ +{ \ + QScriptValue errorValue = context->throwError(QLatin1String(desc)); \ + errorValue.setProperty(QLatin1String("code"), error); \ + return errorValue; \ +} + +#define THROW_SYNTAX(desc) \ + return context->throwError(QScriptContext::SyntaxError, QLatin1String(desc)); +#define THROW_REFERENCE(desc) \ + return context->throwError(QScriptContext::ReferenceError, QLatin1String(desc)); #define D(arg) (arg)->release() #define A(arg) (arg)->addref() @@ -1063,15 +1092,44 @@ void QmlXMLHttpRequest::send(const QByteArray &data) dispatchCallback(); m_request.setUrl(m_url); + QNetworkRequest request = m_request; + if(m_method == QLatin1String("POST") || + m_method == QLatin1String("PUT")) { + QVariant var = request.header(QNetworkRequest::ContentTypeHeader); + if (var.isValid()) { + QString str = var.toString(); + int charsetIdx = str.indexOf("charset="); + if (charsetIdx == -1) { + // No charset - append + if (!str.isEmpty()) str.append(QLatin1Char(';')); + str.append(QLatin1String("charset=UTF-8")); + } else { + charsetIdx += 8; + int n = 0; + int semiColon = str.indexOf(QLatin1Char(';'), charsetIdx); + if (semiColon == -1) { + n = str.length() - charsetIdx; + } else { + n = semiColon - charsetIdx; + } + + str.replace(charsetIdx, n, QLatin1String("UTF-8")); + } + request.setHeader(QNetworkRequest::ContentTypeHeader, str); + } else { + request.setHeader(QNetworkRequest::ContentTypeHeader, + QLatin1String("text/plain;charset=UTF-8")); + } + } if (m_method == QLatin1String("GET")) - m_network = m_engine->networkAccessManager()->get(m_request); + m_network = m_engine->networkAccessManager()->get(request); else if (m_method == QLatin1String("HEAD")) - m_network = m_engine->networkAccessManager()->head(m_request); + m_network = m_engine->networkAccessManager()->head(request); else if(m_method == QLatin1String("POST")) - m_network = m_engine->networkAccessManager()->post(m_request, data); + m_network = m_engine->networkAccessManager()->post(request, data); else if(m_method == QLatin1String("PUT")) - m_network = m_engine->networkAccessManager()->put(m_request, data); + m_network = m_engine->networkAccessManager()->put(request, data); QObject::connect(m_network, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgress(qint64))); @@ -1189,10 +1247,11 @@ void QmlXMLHttpRequest::destroyNetwork() static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngine *engine) { QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (context->argumentCount() < 2 || context->argumentCount() > 5) - return context->throwError(QScriptContext::SyntaxError, QLatin1String("Incorrect argument count")); + THROW_DOM(SYNTAX_ERR, "Incorrect argument count"); // Argument 0 - Method QString method = context->argument(0).toString().toUpper(); @@ -1200,23 +1259,21 @@ static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngin method != QLatin1String("PUT") && method != QLatin1String("HEAD") && method != QLatin1String("POST")) - return context->throwError(QScriptContext::SyntaxError, QLatin1String("Unsupported method")); + THROW_DOM(SYNTAX_ERR, "Unsupported HTTP method type"); // Argument 1 - URL - QUrl url(context->argument(1).toString()); // ### Need to resolve correctly + QUrl url(context->argument(1).toString()); if (url.isRelative()) { - QmlContext *ctxt = QmlEnginePrivate::get(engine)->currentExpression?QmlEnginePrivate::get(engine)->currentExpression->context():0; - if (ctxt) - url = ctxt->resolvedUrl(url); - else - return context->throwError(QScriptContext::SyntaxError, QLatin1String("Relative URLs not supported")); + QmlContext *ctxt = QmlEnginePrivate::get(engine)->getContext(context); + Q_ASSERT(ctxt); + url = ctxt->resolvedUrl(url); } // Argument 2 - async (optional) if (context->argumentCount() > 2 && !context->argument(2).toBoolean()) - return context->throwError(QScriptContext::SyntaxError, QLatin1String("Synchronous call not supported")); + THROW_DOM(NOT_SUPPORTED_ERR, "Synchronous XMLHttpRequest calls are not supported"); // Argument 3/4 - user/pass (optional) @@ -1241,15 +1298,16 @@ static QScriptValue qmlxmlhttprequest_open(QScriptContext *context, QScriptEngin static QScriptValue qmlxmlhttprequest_setRequestHeader(QScriptContext *context, QScriptEngine *engine) { QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (context->argumentCount() != 2) - return context->throwError(QScriptContext::SyntaxError, QLatin1String("Incorrect argument count")); + THROW_SYNTAX("Incorrect argument count"); if (request->readyState() != QmlXMLHttpRequest::Opened || request->sendFlag()) - return context->throwError(INVALID_STATE_ERR, QLatin1String("Invalid state")); + THROW_DOM(INVALID_STATE_ERR, "Invalid state"); QString name = context->argument(0).toString(); @@ -1288,13 +1346,14 @@ static QScriptValue qmlxmlhttprequest_setRequestHeader(QScriptContext *context, static QScriptValue qmlxmlhttprequest_send(QScriptContext *context, QScriptEngine *engine) { QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (request->readyState() != QmlXMLHttpRequest::Opened) - return context->throwError(INVALID_STATE_ERR, QLatin1String("Invalid state")); + THROW_DOM(INVALID_STATE_ERR, "Invalid state"); if (request->sendFlag()) - return context->throwError(INVALID_STATE_ERR, QLatin1String("Invalid state")); + THROW_DOM(INVALID_STATE_ERR, "Invalid state"); QByteArray data; if (context->argumentCount() > 0) @@ -1308,7 +1367,8 @@ static QScriptValue qmlxmlhttprequest_send(QScriptContext *context, QScriptEngin static QScriptValue qmlxmlhttprequest_abort(QScriptContext *context, QScriptEngine *engine) { QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); request->abort(); @@ -1319,15 +1379,16 @@ static QScriptValue qmlxmlhttprequest_getResponseHeader(QScriptContext *context, { Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (context->argumentCount() != 1) - return context->throwError(QScriptContext::SyntaxError, QLatin1String("Incorrect argument count")); + THROW_SYNTAX("Incorrect argument count"); if (request->readyState() != QmlXMLHttpRequest::Loading && request->readyState() != QmlXMLHttpRequest::Done && request->readyState() != QmlXMLHttpRequest::HeadersReceived) - return context->throwError(INVALID_STATE_ERR, QLatin1String("Invalid state")); + THROW_DOM(INVALID_STATE_ERR, "Invalid state"); QString headerName = context->argument(0).toString(); @@ -1338,15 +1399,16 @@ static QScriptValue qmlxmlhttprequest_getAllResponseHeaders(QScriptContext *cont { Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (context->argumentCount() != 0) - return context->throwError(QScriptContext::SyntaxError, QLatin1String("Incorrect argument count")); + THROW_SYNTAX("Incorrect argument count"); if (request->readyState() != QmlXMLHttpRequest::Loading && request->readyState() != QmlXMLHttpRequest::Done && request->readyState() != QmlXMLHttpRequest::HeadersReceived) - return context->throwError(INVALID_STATE_ERR, QLatin1String("Invalid state")); + THROW_DOM(INVALID_STATE_ERR, "Invalid state"); return QScriptValue(request->headers()); } @@ -1356,7 +1418,8 @@ static QScriptValue qmlxmlhttprequest_readyState(QScriptContext *context, QScrip { Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); return QScriptValue(request->readyState()); } @@ -1365,11 +1428,12 @@ static QScriptValue qmlxmlhttprequest_status(QScriptContext *context, QScriptEng { Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (request->readyState() == QmlXMLHttpRequest::Unsent || request->readyState() == QmlXMLHttpRequest::Opened) - return context->throwError(INVALID_STATE_ERR, QLatin1String("Invalid state")); + THROW_DOM(INVALID_STATE_ERR, "Invalid state"); if (request->errorFlag()) return QScriptValue(0); @@ -1381,11 +1445,12 @@ static QScriptValue qmlxmlhttprequest_statusText(QScriptContext *context, QScrip { Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (request->readyState() == QmlXMLHttpRequest::Unsent || request->readyState() == QmlXMLHttpRequest::Opened) - return context->throwError(INVALID_STATE_ERR, QLatin1String("Invalid state")); + THROW_DOM(INVALID_STATE_ERR, "Invalid state"); if (request->errorFlag()) return QScriptValue(0); @@ -1397,19 +1462,21 @@ static QScriptValue qmlxmlhttprequest_responseText(QScriptContext *context, QScr { Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (request->readyState() != QmlXMLHttpRequest::Loading && request->readyState() != QmlXMLHttpRequest::Done) return QScriptValue(QString()); - else + else return QScriptValue(request->responseBody()); } static QScriptValue qmlxmlhttprequest_responseXML(QScriptContext *context, QScriptEngine *engine) { QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (request->readyState() != QmlXMLHttpRequest::Loading && request->readyState() != QmlXMLHttpRequest::Done) @@ -1422,7 +1489,8 @@ static QScriptValue qmlxmlhttprequest_onreadystatechange(QScriptContext *context { Q_UNUSED(engine) QmlXMLHttpRequest *request = qobject_cast<QmlXMLHttpRequest *>(context->thisObject().data().toQObject()); - if (!request) return context->throwError(QScriptContext::ReferenceError, QLatin1String("Not an XMLHttpRequest object")); + if (!request) + THROW_REFERENCE("Not an XMLHttpRequest object"); if (context->argumentCount()) request->setCallback(context->argument(0)); @@ -1459,6 +1527,13 @@ void qt_add_qmlxmlhttprequest(QScriptEngine *engine) prototype.setProperty(QLatin1String("responseXML"), engine->newFunction(qmlxmlhttprequest_responseXML), QScriptValue::ReadOnly | QScriptValue::PropertyGetter); prototype.setProperty(QLatin1String("onreadystatechange"), engine->newFunction(qmlxmlhttprequest_onreadystatechange), QScriptValue::PropertyGetter | QScriptValue::PropertySetter); + // State values + prototype.setProperty(QLatin1String("UNSENT"), 0, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + prototype.setProperty(QLatin1String("OPENED"), 1, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + prototype.setProperty(QLatin1String("HEADERS_RECEIVED"), 2, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + prototype.setProperty(QLatin1String("LOADING"), 3, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + prototype.setProperty(QLatin1String("DONE"), 4, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + // Constructor QScriptValue constructor = engine->newFunction(qmlxmlhttprequest_new, prototype); constructor.setProperty(QLatin1String("UNSENT"), 0, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); @@ -1467,6 +1542,28 @@ void qt_add_qmlxmlhttprequest(QScriptEngine *engine) constructor.setProperty(QLatin1String("LOADING"), 3, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); constructor.setProperty(QLatin1String("DONE"), 4, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); engine->globalObject().setProperty(QLatin1String("XMLHttpRequest"), constructor); + + // DOM Exception + QScriptValue domExceptionPrototype = engine->newObject(); + domExceptionPrototype.setProperty("INDEX_SIZE_ERR", INDEX_SIZE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("DOMSTRING_SIZE_ERR", DOMSTRING_SIZE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("HIERARCHY_REQUEST_ERR", HIERARCHY_REQUEST_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("WRONG_DOCUMENT_ERR", WRONG_DOCUMENT_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("INVALID_CHARACTER_ERR", INVALID_CHARACTER_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("NO_DATA_ALLOWED_ERR", NO_DATA_ALLOWED_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("NO_MODIFICATION_ALLOWED_ERR", NO_MODIFICATION_ALLOWED_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("NOT_FOUND_ERR", NOT_FOUND_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("NOT_SUPPORTED_ERR", NOT_SUPPORTED_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("INUSE_ATTRIBUTE_ERR", INUSE_ATTRIBUTE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("INVALID_STATE_ERR", INVALID_STATE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("SYNTAX_ERR", SYNTAX_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("INVALID_MODIFICATION_ERR", INVALID_MODIFICATION_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("NAMESPACE_ERR", NAMESPACE_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("INVALID_ACCESS_ERR", INVALID_ACCESS_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("VALIDATION_ERR", VALIDATION_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + domExceptionPrototype.setProperty("TYPE_MISMATCH_ERR", TYPE_MISMATCH_ERR, QScriptValue::ReadOnly | QScriptValue::Undeletable | QScriptValue::SkipInEnumeration); + + engine->globalObject().setProperty(QLatin1String("DOMException"), domExceptionPrototype); } #include "qmlxmlhttprequest.moc" diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 94cdadf..435ddae 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -388,7 +388,7 @@ void QmlAbstractAnimation::setRepeat(bool r) int QmlAbstractAnimation::currentTime() { - return qtAnimation()->currentTime(); + return qtAnimation()->currentLoopTime(); } void QmlAbstractAnimation::setCurrentTime(int time) diff --git a/src/declarative/util/qmlanimation_p_p.h b/src/declarative/util/qmlanimation_p_p.h index 1372343..21c0284 100644 --- a/src/declarative/util/qmlanimation_p_p.h +++ b/src/declarative/util/qmlanimation_p_p.h @@ -108,7 +108,7 @@ public: protected: virtual void updateCurrentTime(int) {} - virtual void updateState(State /*oldState*/, State newState) + virtual void updateState(State newState, State /*oldState*/) { if (newState == Running) { if (animAction) @@ -147,9 +147,9 @@ protected: if (animValue) animValue->setValue(value.toDouble()); } - virtual void updateState(State oldState, State newState) + virtual void updateState(State newState, State oldState) { - QVariantAnimation::updateState(oldState, newState); + QVariantAnimation::updateState(newState, oldState); if (newState == Running) { //check for new from every loop if (fromSourced) diff --git a/src/declarative/util/qmlstateoperations.cpp b/src/declarative/util/qmlstateoperations.cpp index 1b786d2..2fca002 100644 --- a/src/declarative/util/qmlstateoperations.cpp +++ b/src/declarative/util/qmlstateoperations.cpp @@ -319,6 +319,13 @@ void QmlStateChangeScript::setScript(const QmlScriptString &s) d->script = s; } +/*! + \qmlproperty script StateChangeScript::script + This property holds the name of the script. This name can be used by a + ScriptAction to target a specific script. + + \sa ScriptAction::stateChangeScriptName +*/ QString QmlStateChangeScript::name() const { Q_D(const QmlStateChangeScript); @@ -351,6 +358,11 @@ QmlStateChangeScript::ActionList QmlStateChangeScript::actions() return rv; } +QString QmlStateChangeScript::typeName() const +{ + return QLatin1String("StateChangeScript"); +} + /*! \qmlclass AnchorChanges QmlAnchorChanges \brief The AnchorChanges element allows you to change the anchors of an item in a state. diff --git a/src/declarative/util/qmlstateoperations_p.h b/src/declarative/util/qmlstateoperations_p.h index 2801f2b..861e4d0 100644 --- a/src/declarative/util/qmlstateoperations_p.h +++ b/src/declarative/util/qmlstateoperations_p.h @@ -96,6 +96,8 @@ public: virtual ActionList actions(); + virtual QString typeName() const; + QmlScriptString script() const; void setScript(const QmlScriptString &); diff --git a/src/declarative/util/qmltimer.cpp b/src/declarative/util/qmltimer.cpp index 8ee9059..c1b3504 100644 --- a/src/declarative/util/qmltimer.cpp +++ b/src/declarative/util/qmltimer.cpp @@ -271,7 +271,7 @@ void QmlTimer::ticked() emit triggered(); } -void QmlTimer::stateChanged(QAbstractAnimation::State, QAbstractAnimation::State state) +void QmlTimer::stateChanged(QAbstractAnimation::State state, QAbstractAnimation::State) { Q_D(QmlTimer); if (d->running && state != QAbstractAnimation::Running) { diff --git a/src/declarative/util/qmltransition.cpp b/src/declarative/util/qmltransition.cpp index d61359d..7eb9e53 100644 --- a/src/declarative/util/qmltransition.cpp +++ b/src/declarative/util/qmltransition.cpp @@ -74,7 +74,7 @@ public: ParallelAnimationWrapper(QObject *parent) : QParallelAnimationGroup(parent) {} QmlTransitionPrivate *trans; protected: - virtual void updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState); + virtual void updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState); }; class QmlTransitionPrivate : public QObjectPrivate @@ -124,13 +124,13 @@ void QmlTransitionPrivate::AnimationList::append(QmlAbstractAnimation *a) parent->group->addAnimation(a->qtAnimation()); } -void ParallelAnimationWrapper::updateState(QAbstractAnimation::State oldState, QAbstractAnimation::State newState) +void ParallelAnimationWrapper::updateState(QAbstractAnimation::State newState, QAbstractAnimation::State oldState) { - QParallelAnimationGroup::updateState(oldState, newState); + QParallelAnimationGroup::updateState(newState, oldState); //XXX not 100% guaranteed to be at end (if there are many zero duration animations at the end)? if (newState == Stopped && - ((direction() == QAbstractAnimation::Forward && currentTime() == duration()) || - (direction() == QAbstractAnimation::Backward && currentTime() == 0))) + ((direction() == QAbstractAnimation::Forward && currentLoopTime() == duration()) || + (direction() == QAbstractAnimation::Backward && currentLoopTime() == 0))) { trans->complete(); } |