summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems')
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable.cpp80
-rw-r--r--src/declarative/graphicsitems/qdeclarativeflickable_p.h16
-rw-r--r--src/declarative/graphicsitems/qdeclarativegridview.cpp19
-rw-r--r--src/declarative/graphicsitems/qdeclarativeitem.cpp5
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp18
-rw-r--r--src/declarative/graphicsitems/qdeclarativepath.cpp4
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp33
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p.h4
8 files changed, 134 insertions, 45 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable.cpp b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
index a7a8983..a03a51d 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeflickable.cpp
@@ -230,13 +230,17 @@ void QDeclarativeFlickablePrivate::flick(AxisData &data, qreal minExtent, qreal
timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this));
if (!flickingHorizontally && q->xflick()) {
flickingHorizontally = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingHorizontallyChanged();
+ if (!flickingVertically)
+ emit q->flickStarted();
}
if (!flickingVertically && q->yflick()) {
flickingVertically = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingVerticallyChanged();
+ if (!flickingHorizontally)
+ emit q->flickStarted();
}
} else {
timeline.reset(data.move);
@@ -365,6 +369,37 @@ void QDeclarativeFlickablePrivate::updateBeginningEnd()
*/
/*!
+ \qmlsignal Flickable::onMovementStarted()
+
+ This handler is called when the view begins moving due to user
+ interaction.
+*/
+
+/*!
+ \qmlsignal Flickable::onMovementEnded()
+
+ This handler is called when the view stops moving due to user
+ interaction. If a flick was generated, this handler will
+ be triggered once the flick stops. If a flick was not
+ generated, the handler will be triggered when the
+ user stops dragging - i.e. a mouse or touch release.
+*/
+
+/*!
+ \qmlsignal Flickable::onFlickStarted()
+
+ This handler is called when the view is flicked. A flick
+ starts from the point that the mouse or touch is released,
+ while still in motion.
+*/
+
+/*!
+ \qmlsignal Flickable::onFlickEnded()
+
+ This handler is called when the view stops moving due to a flick.
+*/
+
+/*!
\qmlproperty real Flickable::visibleArea.xPosition
\qmlproperty real Flickable::visibleArea.widthRatio
\qmlproperty real Flickable::visibleArea.yPosition
@@ -474,9 +509,10 @@ void QDeclarativeFlickable::setInteractive(bool interactive)
d->vTime = d->timeline.time();
d->flickingHorizontally = false;
d->flickingVertically = false;
- emit flickingChanged(); // deprecated
+ emit flickingChanged();
emit flickingHorizontallyChanged();
emit flickingVerticallyChanged();
+ emit flickEnded();
}
emit interactiveChanged();
}
@@ -799,8 +835,10 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event)
d->vData.velocity = qMin(event->delta() - d->vData.smoothVelocity.value(), qreal(-250.0));
d->flickingVertically = false;
d->flickY(d->vData.velocity);
- if (d->flickingVertically)
+ if (d->flickingVertically) {
+ d->vMoved = true;
movementStarting();
+ }
event->accept();
} else if (xflick()) {
if (event->delta() > 0)
@@ -809,8 +847,10 @@ void QDeclarativeFlickable::wheelEvent(QGraphicsSceneWheelEvent *event)
d->hData.velocity = qMin(event->delta() - d->hData.smoothVelocity.value(), qreal(-250.0));
d->flickingHorizontally = false;
d->flickX(d->hData.velocity);
- if (d->flickingHorizontally)
+ if (d->flickingHorizontally) {
+ d->hMoved = true;
movementStarting();
+ }
event->accept();
} else {
QDeclarativeItem::wheelEvent(event);
@@ -1269,11 +1309,11 @@ void QDeclarativeFlickable::setFlickDeceleration(qreal deceleration)
bool QDeclarativeFlickable::isFlicking() const
{
Q_D(const QDeclarativeFlickable);
- qmlInfo(this) << "'flicking' is deprecated. Please use 'flickingHorizontally' and 'flickingVertically' instead.";
return d->flickingHorizontally || d->flickingVertically;
}
/*!
+ \qmlproperty bool Flickable::flicking
\qmlproperty bool Flickable::flickingHorizontally
\qmlproperty bool Flickable::flickingVertically
@@ -1322,11 +1362,11 @@ void QDeclarativeFlickable::setPressDelay(int delay)
bool QDeclarativeFlickable::isMoving() const
{
Q_D(const QDeclarativeFlickable);
- qmlInfo(this) << "'moving' is deprecated. Please use 'movingHorizontally' or 'movingVertically' instead.";
return d->movingHorizontally || d->movingVertically;
}
/*!
+ \qmlproperty bool Flickable::moving
\qmlproperty bool Flickable::movingHorizontally
\qmlproperty bool Flickable::movingVertically
@@ -1350,13 +1390,17 @@ void QDeclarativeFlickable::movementStarting()
Q_D(QDeclarativeFlickable);
if (d->hMoved && !d->movingHorizontally) {
d->movingHorizontally = true;
- emit movingChanged(); // deprecated
+ emit movingChanged();
emit movingHorizontallyChanged();
+ if (!d->movingVertically)
+ emit movementStarted();
}
- if (d->vMoved && !d->movingVertically) {
+ else if (d->vMoved && !d->movingVertically) {
d->movingVertically = true;
- emit movingChanged(); // deprecated
+ emit movingChanged();
emit movingVerticallyChanged();
+ if (!d->movingHorizontally)
+ emit movementStarted();
}
}
@@ -1365,25 +1409,33 @@ void QDeclarativeFlickable::movementEnding()
Q_D(QDeclarativeFlickable);
if (d->flickingHorizontally) {
d->flickingHorizontally = false;
- emit flickingChanged(); // deprecated
+ emit flickingChanged();
emit flickingHorizontallyChanged();
+ if (!d->flickingVertically)
+ emit flickEnded();
}
if (d->flickingVertically) {
d->flickingVertically = false;
- emit flickingChanged(); // deprecated
+ emit flickingChanged();
emit flickingVerticallyChanged();
+ if (!d->flickingHorizontally)
+ emit flickEnded();
}
if (d->movingHorizontally) {
d->movingHorizontally = false;
d->hMoved = false;
- emit movingChanged(); // deprecated
+ emit movingChanged();
emit movingHorizontallyChanged();
+ if (!d->movingVertically)
+ emit movementEnded();
}
if (d->movingVertically) {
d->movingVertically = false;
d->vMoved = false;
- emit movingChanged(); // deprecated
+ emit movingChanged();
emit movingVerticallyChanged();
+ if (!d->movingHorizontally)
+ emit movementEnded();
}
d->hData.smoothVelocity.setValue(0);
d->vData.smoothVelocity.setValue(0);
diff --git a/src/declarative/graphicsitems/qdeclarativeflickable_p.h b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
index 7944e2b..05887b8 100644
--- a/src/declarative/graphicsitems/qdeclarativeflickable_p.h
+++ b/src/declarative/graphicsitems/qdeclarativeflickable_p.h
@@ -68,10 +68,10 @@ class Q_DECLARATIVE_EXPORT QDeclarativeFlickable : public QDeclarativeItem
Q_PROPERTY(BoundsBehavior boundsBehavior READ boundsBehavior WRITE setBoundsBehavior NOTIFY boundsBehaviorChanged)
Q_PROPERTY(qreal maximumFlickVelocity READ maximumFlickVelocity WRITE setMaximumFlickVelocity NOTIFY maximumFlickVelocityChanged)
Q_PROPERTY(qreal flickDeceleration READ flickDeceleration WRITE setFlickDeceleration NOTIFY flickDecelerationChanged)
- Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged) // deprecated
+ Q_PROPERTY(bool moving READ isMoving NOTIFY movingChanged)
Q_PROPERTY(bool movingHorizontally READ isMovingHorizontally NOTIFY movingHorizontallyChanged)
Q_PROPERTY(bool movingVertically READ isMovingVertically NOTIFY movingVerticallyChanged)
- Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged) // deprecated
+ Q_PROPERTY(bool flicking READ isFlicking NOTIFY flickingChanged)
Q_PROPERTY(bool flickingHorizontally READ isFlickingHorizontally NOTIFY flickingHorizontallyChanged)
Q_PROPERTY(bool flickingVertically READ isFlickingVertically NOTIFY flickingVerticallyChanged)
Q_PROPERTY(FlickableDirection flickDirection READ flickDirection WRITE setFlickDirection NOTIFY flickableDirectionChanged) // deprecated
@@ -120,10 +120,10 @@ public:
qreal contentY() const;
void setContentY(qreal pos);
- bool isMoving() const; // deprecated
+ bool isMoving() const;
bool isMovingHorizontally() const;
bool isMovingVertically() const;
- bool isFlicking() const; // deprecated
+ bool isFlicking() const;
bool isFlickingHorizontally() const;
bool isFlickingVertically() const;
@@ -160,10 +160,10 @@ Q_SIGNALS:
void contentHeightChanged();
void contentXChanged();
void contentYChanged();
- void movingChanged(); // deprecated
+ void movingChanged();
void movingHorizontallyChanged();
void movingVerticallyChanged();
- void flickingChanged(); // deprecated
+ void flickingChanged();
void flickingHorizontallyChanged();
void flickingVerticallyChanged();
void horizontalVelocityChanged();
@@ -177,6 +177,10 @@ Q_SIGNALS:
void maximumFlickVelocityChanged();
void flickDecelerationChanged();
void pressDelayChanged();
+ void movementStarted();
+ void movementEnded();
+ void flickStarted();
+ void flickEnded();
protected:
virtual bool sceneEventFilter(QGraphicsItem *, QEvent *);
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp
index 396acd0..fe78c84 100644
--- a/src/declarative/graphicsitems/qdeclarativegridview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp
@@ -347,8 +347,7 @@ public:
void QDeclarativeGridViewPrivate::init()
{
Q_Q(QDeclarativeGridView);
- QObject::connect(q, SIGNAL(movingHorizontallyChanged()), q, SLOT(animStopped()));
- QObject::connect(q, SIGNAL(movingVerticallyChanged()), q, SLOT(animStopped()));
+ QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped()));
q->setFlag(QGraphicsItem::ItemIsFocusScope);
q->setFlickableDirection(QDeclarativeFlickable::VerticalFlick);
addItemChangeListener(this, Geometry);
@@ -878,13 +877,15 @@ void QDeclarativeGridViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this));
if (!flickingHorizontally && q->xflick()) {
flickingHorizontally = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingHorizontallyChanged();
+ emit q->flickStarted();
}
if (!flickingVertically && q->yflick()) {
flickingVertically = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingVerticallyChanged();
+ emit q->flickStarted();
}
} else {
timeline.reset(data.move);
@@ -2311,13 +2312,9 @@ void QDeclarativeGridView::destroyingItem(QDeclarativeItem *item)
void QDeclarativeGridView::animStopped()
{
Q_D(QDeclarativeGridView);
- if ((!d->movingVertically && d->flow == QDeclarativeGridView::LeftToRight)
- || (!d->movingHorizontally && d->flow == QDeclarativeGridView::TopToBottom))
- {
- d->bufferMode = QDeclarativeGridViewPrivate::NoBuffer;
- if (d->haveHighlightRange && d->highlightRange == QDeclarativeGridView::StrictlyEnforceRange)
- d->updateHighlight();
- }
+ d->bufferMode = QDeclarativeGridViewPrivate::NoBuffer;
+ if (d->haveHighlightRange && d->highlightRange == QDeclarativeGridView::StrictlyEnforceRange)
+ d->updateHighlight();
}
void QDeclarativeGridView::refill()
diff --git a/src/declarative/graphicsitems/qdeclarativeitem.cpp b/src/declarative/graphicsitems/qdeclarativeitem.cpp
index 9433ba0..f251ba1 100644
--- a/src/declarative/graphicsitems/qdeclarativeitem.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeitem.cpp
@@ -1194,7 +1194,10 @@ QDeclarativeKeysAttached *QDeclarativeKeysAttached::qmlAttachedProperties(QObjec
width and height, \l {anchor-layout}{anchoring} and key handling.
You can subclass QDeclarativeItem to provide your own custom visual item that inherits
- these features.
+ these features. Note that, because it does not draw anything, QDeclarativeItem sets the
+ QGraphicsItem::ItemHasNoContents flag. If you subclass QDeclarativeItem to create a visual
+ item, you will need to unset this flag.
+
*/
/*!
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 20106cb..46e9ce3 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -525,8 +525,7 @@ void QDeclarativeListViewPrivate::init()
Q_Q(QDeclarativeListView);
q->setFlag(QGraphicsItem::ItemIsFocusScope);
addItemChangeListener(this, Geometry);
- QObject::connect(q, SIGNAL(movingHorizontallyChanged()), q, SLOT(animStopped()));
- QObject::connect(q, SIGNAL(movingVerticallyChanged()), q, SLOT(animStopped()));
+ QObject::connect(q, SIGNAL(movementEnded()), q, SLOT(animStopped()));
q->setFlickableDirection(QDeclarativeFlickable::VerticalFlick);
::memset(sectionCache, 0, sizeof(QDeclarativeItem*) * sectionCacheSize);
}
@@ -1260,13 +1259,15 @@ void QDeclarativeListViewPrivate::flick(AxisData &data, qreal minExtent, qreal m
timeline.callback(QDeclarativeTimeLineCallback(&data.move, fixupCallback, this));
if (!flickingHorizontally && q->xflick()) {
flickingHorizontally = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingHorizontallyChanged();
+ emit q->flickStarted();
}
if (!flickingVertically && q->yflick()) {
flickingVertically = true;
- emit q->flickingChanged(); // deprecated
+ emit q->flickingChanged();
emit q->flickingVerticallyChanged();
+ emit q->flickStarted();
}
correctFlick = true;
} else {
@@ -2890,12 +2891,9 @@ void QDeclarativeListView::destroyingItem(QDeclarativeItem *item)
void QDeclarativeListView::animStopped()
{
Q_D(QDeclarativeListView);
- if ((!d->movingVertically && d->orient == QDeclarativeListView::Vertical) || (!d->movingHorizontally && d->orient == QDeclarativeListView::Horizontal))
- {
- d->bufferMode = QDeclarativeListViewPrivate::NoBuffer;
- if (d->haveHighlightRange && d->highlightRange == QDeclarativeListView::StrictlyEnforceRange)
- d->updateHighlight();
- }
+ d->bufferMode = QDeclarativeListViewPrivate::NoBuffer;
+ if (d->haveHighlightRange && d->highlightRange == QDeclarativeListView::StrictlyEnforceRange)
+ d->updateHighlight();
}
QDeclarativeListViewAttached *QDeclarativeListView::qmlAttachedProperties(QObject *obj)
diff --git a/src/declarative/graphicsitems/qdeclarativepath.cpp b/src/declarative/graphicsitems/qdeclarativepath.cpp
index 3d0df87..2d08c7c 100644
--- a/src/declarative/graphicsitems/qdeclarativepath.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepath.cpp
@@ -377,7 +377,9 @@ void QDeclarativePath::createPointCache() const
{
Q_D(const QDeclarativePath);
qreal pathLength = d->_path.length();
- const int points = int(pathLength*2);
+ // more points means less jitter between items as they move along the
+ // path, but takes longer to generate
+ const int points = int(pathLength*5);
const int lastElement = d->_path.elementCount() - 1;
d->_pointCache.resize(points+1);
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index 503d096..207cc25 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -49,6 +49,7 @@
#include <qlistmodelinterface_p.h>
#include <QGraphicsSceneEvent>
+#include <qmath.h>
#include <math.h>
QT_BEGIN_NAMESPACE
@@ -279,8 +280,8 @@ void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal perce
att->setValue(attr.toUtf8(), path->attributeAt(attr, percent));
}
QPointF pf = path->pointAt(percent);
- item->setX(pf.x() - item->width()*item->scale()/2);
- item->setY(pf.y() - item->height()*item->scale()/2);
+ item->setX(qRound(pf.x() - item->width()*item->scale()/2));
+ item->setY(qRound(pf.y() - item->height()*item->scale()/2));
}
void QDeclarativePathViewPrivate::regenerate()
@@ -527,6 +528,33 @@ void QDeclarativePathView::setCurrentIndex(int idx)
}
/*!
+ \qmlmethod PathView::incrementCurrentIndex()
+
+ Increments the current index.
+*/
+void QDeclarativePathView::incrementCurrentIndex()
+{
+ setCurrentIndex(currentIndex()+1);
+}
+
+
+/*!
+ \qmlmethod PathView::decrementCurrentIndex()
+
+ Decrements the current index.
+*/
+void QDeclarativePathView::decrementCurrentIndex()
+{
+ Q_D(QDeclarativePathView);
+ if (d->model && d->model->count()) {
+ int idx = currentIndex()-1;
+ if (idx < 0)
+ idx = d->model->count() - 1;
+ setCurrentIndex(idx);
+ }
+}
+
+/*!
\qmlproperty real PathView::offset
The offset specifies how far along the path the items are from their initial positions.
@@ -1312,6 +1340,7 @@ int QDeclarativePathViewPrivate::calcCurrentIndex()
if (offset < 0)
offset += model->count();
current = qRound(qAbs(qmlMod(model->count() - offset, model->count())));
+ current = current % model->count();
}
return current;
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p.h
index 85f47fd..349a01c 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p.h
@@ -132,6 +132,10 @@ public:
static QDeclarativePathViewAttached *qmlAttachedProperties(QObject *);
+public Q_SLOTS:
+ void incrementCurrentIndex();
+ void decrementCurrentIndex();
+
Q_SIGNALS:
void currentIndexChanged();
void offsetChanged();