From 7051254771882e88f64f9b5578d975f29efab0b6 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 10:54:11 +1000 Subject: current -> currentItem property in ListView and GridView --- examples/declarative/listview/highlight.qml | 2 +- examples/declarative/loader/Browser.qml | 2 +- src/declarative/QmlChanges.txt | 2 ++ src/declarative/fx/qfxgridview.cpp | 4 ++-- src/declarative/fx/qfxgridview.h | 2 +- src/declarative/fx/qfxlistview.cpp | 4 ++-- src/declarative/fx/qfxlistview.h | 2 +- 7 files changed, 10 insertions(+), 8 deletions(-) diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index e707ac0..cb92ad9 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -44,7 +44,7 @@ Rectangle { id: PetHighlight Rectangle { width: 200; height: 50; color: "#FFFF88" - y: SpringFollow { source: List1.current.y; spring: 3; damping: 0.1 } + y: SpringFollow { source: List1.currentItem.y; spring: 3; damping: 0.1 } } } ListView { diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml index 196cdc5..6711de4 100644 --- a/examples/declarative/loader/Browser.qml +++ b/examples/declarative/loader/Browser.qml @@ -82,7 +82,7 @@ Rectangle { focus: true Keys.onPressed: { if (event.key == Qt.Key_Return || event.key == Qt.Key_Select) { - View.current.launch(); + View.currentItem.launch(); event.accepted = true; } } diff --git a/src/declarative/QmlChanges.txt b/src/declarative/QmlChanges.txt index eace089..fe923a7 100644 --- a/src/declarative/QmlChanges.txt +++ b/src/declarative/QmlChanges.txt @@ -64,6 +64,8 @@ WebView: mouseY -> clickY (parameter to onDoubleClick) WebView: cacheSize -> pixelCacheSize Repeater: component -> delegate Repeater: dataSource -> model +ListView: current -> currentItem +GridView: current -> currentItem Additions: MouseRegion: add "acceptedButtons" property diff --git a/src/declarative/fx/qfxgridview.cpp b/src/declarative/fx/qfxgridview.cpp index f49375a..d4cf691 100644 --- a/src/declarative/fx/qfxgridview.cpp +++ b/src/declarative/fx/qfxgridview.cpp @@ -795,10 +795,10 @@ void QFxGridView::setDelegate(QmlComponent *delegate) /*! \qmlproperty int GridView::currentIndex - \qmlproperty Item GridView::current + \qmlproperty Item GridView::currentItem \c currentIndex holds the index of the current item. - \c current is the current item. Note that the position of the current item + \c currentItem is the current item. Note that the position of the current item may only be approximate until it becomes visible in the view. */ int QFxGridView::currentIndex() const diff --git a/src/declarative/fx/qfxgridview.h b/src/declarative/fx/qfxgridview.h index 734039c..e08ba9e 100644 --- a/src/declarative/fx/qfxgridview.h +++ b/src/declarative/fx/qfxgridview.h @@ -60,7 +60,7 @@ class Q_DECLARATIVE_EXPORT QFxGridView : public QFxFlickable Q_PROPERTY(QVariant model READ model WRITE setModel) Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) //### currentItem + Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index a07b3c0..6596735 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -983,10 +983,10 @@ void QFxListView::setDelegate(QmlComponent *delegate) /*! \qmlproperty int ListView::currentIndex - \qmlproperty Item ListView::current + \qmlproperty Item ListView::currentItem \c currentIndex holds the index of the current item. - \c current is the current item. Note that the position of the current item + \c currentItem is the current item. Note that the position of the current item may only be approximate until it becomes visible in the view. */ int QFxListView::currentIndex() const diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 829e202..4a124cb 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -67,7 +67,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(QVariant model READ model WRITE setModel) Q_PROPERTY(QmlComponent *delegate READ delegate WRITE setDelegate) //### what happens if delegate is not a QFxItem? Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) - Q_PROPERTY(QFxItem *current READ currentItem NOTIFY currentIndexChanged) //### currentItem + Q_PROPERTY(QFxItem *currentItem READ currentItem NOTIFY currentIndexChanged) Q_PROPERTY(int count READ count NOTIFY countChanged) Q_PROPERTY(QmlComponent *highlight READ highlight WRITE setHighlight) Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem -- cgit v0.12 From 2984be68041afc154fab2a0b9eb6618caf26cf71 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 14:28:39 +1000 Subject: Avoid spurious flicks due to quick clicking motions. --- src/declarative/fx/qfxflickable.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/declarative/fx/qfxflickable.cpp b/src/declarative/fx/qfxflickable.cpp index c227899..1e6ad5a 100644 --- a/src/declarative/fx/qfxflickable.cpp +++ b/src/declarative/fx/qfxflickable.cpp @@ -48,6 +48,16 @@ QT_BEGIN_NAMESPACE + +// These are highly device dependant. +// DragThreshold determines how far the "mouse" must move before +// we begin a drag. +// FlickThreshold determines how far the "mouse" must have moved +// before we perform a flick. +static const int DragThreshold = 8; +static const int FlickThreshold = 20; + + class QFxFlickableVisibleArea : public QObject { Q_OBJECT @@ -147,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(-1), reportedVelocitySmoothing(100) + , interactive(true), maxVelocity(5000), reportedVelocitySmoothing(100) , delayedPressEvent(0), delayedPressTarget(0), pressDelay(0) , horizontalVelocity(this), verticalVelocity(this), vTime(0), visibleArea(0) { @@ -327,8 +337,6 @@ void QFxFlickablePrivate::updateBeginningEnd() visibleArea->updateVisible(); } -static const int FlickThreshold = 5; - QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,Flickable,QFxFlickable) /*! @@ -602,7 +610,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) if (q->yflick()) { int dy = int(event->pos().y() - pressPos.y()); - if (qAbs(dy) > FlickThreshold || pressTime.elapsed() > 200) { + if (qAbs(dy) > DragThreshold || pressTime.elapsed() > 200) { qreal newY = dy + pressY; const qreal minY = q->minYExtent(); const qreal maxY = q->maxYExtent(); @@ -615,14 +623,14 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) moved = true; } else if (!q->overShoot()) rejectY = true; - if (qAbs(dy) > FlickThreshold) + if (qAbs(dy) > DragThreshold) stealMouse = true; } } if (q->xflick()) { int dx = int(event->pos().x() - pressPos.x()); - if (qAbs(dx) > FlickThreshold || pressTime.elapsed() > 200) { + if (qAbs(dx) > DragThreshold || pressTime.elapsed() > 200) { qreal newX = dx + pressX; const qreal minX = q->minXExtent(); const qreal maxX = q->maxXExtent(); @@ -635,7 +643,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) moved = true; } else if (!q->overShoot()) rejectX = true; - if (qAbs(dx) > FlickThreshold) + if (qAbs(dx) > DragThreshold) stealMouse = true; } } @@ -666,7 +674,7 @@ void QFxFlickablePrivate::handleMouseMoveEvent(QGraphicsSceneMouseEvent *event) lastPos = event->pos(); } -void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) +void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *event) { Q_Q(QFxFlickable); pressed = false; @@ -674,12 +682,12 @@ void QFxFlickablePrivate::handleMouseReleaseEvent(QGraphicsSceneMouseEvent *) return; vTime = timeline.time(); - if (qAbs(velocityY) > 10) + if (qAbs(velocityY) > 10 && qAbs(event->pos().y() - pressPos.y()) > FlickThreshold) flickY(velocityY); else fixupY(); - if (qAbs(velocityX) > 10) + if (qAbs(velocityX) > 10 && qAbs(event->pos().x() - pressPos.x()) > FlickThreshold) flickX(velocityX); else fixupX(); @@ -1093,6 +1101,8 @@ bool QFxFlickable::sceneEventFilter(QGraphicsItem *i, QEvent *e) /*! \qmlproperty int Flickable::maximumFlickVelocity This property holds the maximum velocity that the user can flick the view in pixels/second. + + The default is 5000 pixels/s */ qreal QFxFlickable::maximumFlickVelocity() const { -- cgit v0.12 From e4648700e7e3c84c61d6b012f7d480394b889c31 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 11 Sep 2009 15:48:20 +1000 Subject: Fix moving an item to the first visible position. Also fix the type of some properties/variables. --- src/declarative/fx/qfxlistview.cpp | 32 ++++++++++++++++---------------- src/declarative/fx/qfxlistview.h | 6 +++--- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/declarative/fx/qfxlistview.cpp b/src/declarative/fx/qfxlistview.cpp index 6596735..ac9b6ca 100644 --- a/src/declarative/fx/qfxlistview.cpp +++ b/src/declarative/fx/qfxlistview.cpp @@ -172,11 +172,11 @@ public: QFxListViewPrivate() : model(0), currentItem(0), tmpCurrent(0), orient(Qt::Vertical) , visiblePos(0), visibleIndex(0) - , averageSize(100), currentIndex(-1), requestedIndex(-1) + , averageSize(100.0), currentIndex(-1), requestedIndex(-1) , currItemMode(QFxListView::Free), snapPos(0), highlightComponent(0), highlight(0), trackedItem(0) - , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0) + , moveReason(Other), buffer(0), highlightPosAnimator(0), highlightSizeAnimator(0), spacing(0.0) , ownModel(false), wrap(false), autoHighlight(true) - , fixCurrentVisibility(false) {} + {} void init(); void clear(); @@ -205,7 +205,7 @@ public: else q->setViewportX(pos); } - int size() const { + qreal size() const { Q_Q(const QFxListView); return orient == Qt::Vertical ? q->height() : q->width(); } @@ -384,12 +384,11 @@ public: QmlEaseFollow *highlightSizeAnimator; QString sectionExpression; QString currentSection; - int spacing; + qreal spacing; - int ownModel : 1; - int wrap : 1; - int autoHighlight : 1; - int fixCurrentVisibility : 1; + bool ownModel : 1; + bool wrap : 1; + bool autoHighlight : 1; }; void QFxListViewPrivate::init() @@ -755,7 +754,6 @@ void QFxListViewPrivate::updateCurrent(int modelIndex) FxListItem *oldCurrentItem = currentItem; currentIndex = modelIndex; currentItem = createItem(modelIndex); - fixCurrentVisibility = true; if (oldCurrentItem && (!currentItem || oldCurrentItem->item != currentItem->item)) oldCurrentItem->attached->setIsCurrentItem(false); if (currentItem) { @@ -1149,13 +1147,13 @@ void QFxListView::setSnapPosition(int pos) This property holds the spacing to leave between items. */ -int QFxListView::spacing() const +qreal QFxListView::spacing() const { Q_D(const QFxListView); return d->spacing; } -void QFxListView::setSpacing(int spacing) +void QFxListView::setSpacing(qreal spacing) { Q_D(QFxListView); if (spacing != d->spacing) { @@ -1640,6 +1638,7 @@ void QFxListView::destroyRemoved() void QFxListView::itemsMoved(int from, int to, int count) { Q_D(QFxListView); + qreal firstItemPos = d->visibleItems.first()->position(); QHash moved; int moveBy = 0; @@ -1653,11 +1652,9 @@ void QFxListView::itemsMoved(int from, int to, int count) moveBy += item->size(); it = d->visibleItems.erase(it); } else { - if (item->index > from && item->index != -1) { - // move everything after the moved items. + // move everything after the moved items. + if (item->index > from && item->index != -1) item->index -= count; - item->setPosition(item->position()-moveBy); - } ++it; } } @@ -1698,6 +1695,9 @@ void QFxListView::itemsMoved(int from, int to, int count) while (moved.count()) d->releaseItem(moved.take(moved.begin().key())); + // Ensure we don't cause an ugly list scroll. + d->visibleItems.first()->setPosition(firstItemPos); + d->layout(); } diff --git a/src/declarative/fx/qfxlistview.h b/src/declarative/fx/qfxlistview.h index 4a124cb..095c27b 100644 --- a/src/declarative/fx/qfxlistview.h +++ b/src/declarative/fx/qfxlistview.h @@ -73,7 +73,7 @@ class Q_DECLARATIVE_EXPORT QFxListView : public QFxFlickable Q_PROPERTY(bool autoHighlight READ autoHighlight WRITE setAutoHighlight) //### highlightFollowsCurrentItem Q_PROPERTY(CurrentItemPositioning currentItemPositioning READ currentItemPositioning WRITE setCurrentItemPositioning) //### mode Q_PROPERTY(int snapPosition READ snapPosition WRITE setSnapPosition) - Q_PROPERTY(int spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) //### qreal + Q_PROPERTY(qreal spacing READ spacing WRITE setSpacing NOTIFY spacingChanged) Q_PROPERTY(Qt::Orientation orientation READ orientation WRITE setOrientation) Q_PROPERTY(bool wrap READ isWrapEnabled WRITE setWrapEnabled) //### keyNavigationWraps, stops at end when held Q_PROPERTY(int cacheBuffer READ cacheBuffer WRITE setCacheBuffer) @@ -115,8 +115,8 @@ public: int snapPosition() const; void setSnapPosition(int pos); - int spacing() const; - void setSpacing(int spacing); + qreal spacing() const; + void setSpacing(qreal spacing); Qt::Orientation orientation() const; void setOrientation(Qt::Orientation); -- cgit v0.12 From efc7963a15c204db48cb3b6560366410b640e5c3 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Fri, 11 Sep 2009 15:54:19 +1000 Subject: Don't need to save and restore painter for tiling. --- src/declarative/fx/qfximage.cpp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/declarative/fx/qfximage.cpp b/src/declarative/fx/qfximage.cpp index 79b3ae1..3ac3f3c 100644 --- a/src/declarative/fx/qfximage.cpp +++ b/src/declarative/fx/qfximage.cpp @@ -252,17 +252,12 @@ void QFxImage::paint(QPainter *p, const QStyleOptionGraphicsItem *, QWidget *) if (width() != d->pix.width() || height() != d->pix.height()) { if (d->fillMode >= Tile) { - p->save(); - p->setClipRect(0, 0, width(), height(), Qt::IntersectClip); - if (d->fillMode == Tile) p->drawTiledPixmap(QRectF(0,0,width(),height()), d->pix); else if (d->fillMode == TileVertically) p->drawTiledPixmap(QRectF(0,0,d->pix.width(),height()), d->pix); else p->drawTiledPixmap(QRectF(0,0,width(),d->pix.height()), d->pix); - - p->restore(); } else { qreal widthScale = width() / qreal(d->pix.width()); qreal heightScale = height() / qreal(d->pix.height()); -- cgit v0.12