summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativepathview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativepathview.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp119
1 files changed, 114 insertions, 5 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index f4ebd13..06ac275 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -90,6 +90,26 @@ void QDeclarativePathViewAttached::setValue(const QByteArray &name, const QVaria
m_metaobject->setValue(name, val);
}
+
+void QDeclarativePathViewPrivate::init()
+{
+ Q_Q(QDeclarativePathView);
+ offset = 0;
+ q->setAcceptedMouseButtons(Qt::LeftButton);
+ q->setFlag(QGraphicsItem::ItemIsFocusScope);
+ q->setFiltersChildEvents(true);
+ q->connect(&tl, SIGNAL(updated()), q, SLOT(ticked()));
+ lastPosTime.invalidate();
+ static int timelineCompletedIdx = -1;
+ static int movementEndingIdx = -1;
+ if (timelineCompletedIdx == -1) {
+ timelineCompletedIdx = QDeclarativeTimeLine::staticMetaObject.indexOfSignal("completed()");
+ movementEndingIdx = QDeclarativePathView::staticMetaObject.indexOfSlot("movementEnding()");
+ }
+ QMetaObject::connect(&tl, timelineCompletedIdx,
+ q, movementEndingIdx, Qt::DirectConnection);
+}
+
QDeclarativeItem *QDeclarativePathViewPrivate::getItem(int modelIndex)
{
Q_Q(QDeclarativePathView);
@@ -284,8 +304,8 @@ void QDeclarativePathViewPrivate::updateItem(QDeclarativeItem *item, qreal perce
att->setValue(attr.toUtf8(), path->attributeAt(attr, percent));
}
QPointF pf = path->pointAt(percent);
- item->setX(qRound(pf.x() - item->width()*item->scale()/2));
- item->setY(qRound(pf.y() - item->height()*item->scale()/2));
+ item->setX(qRound(pf.x() - item->width()/2));
+ item->setY(qRound(pf.y() - item->height()/2));
}
void QDeclarativePathViewPrivate::regenerate()
@@ -314,7 +334,7 @@ void QDeclarativePathViewPrivate::regenerate()
and XmlListModel, or custom model classes defined in C++ that inherit from
QAbstractListModel.
- A ListView has a \l model, which defines the data to be displayed, and
+ The view has a \l model, which defines the data to be displayed, and
a \l delegate, which defines how the data should be displayed.
The \l delegate is instantiated for each item on the \l path.
The items may be flicked to move them along the path.
@@ -333,6 +353,9 @@ void QDeclarativePathViewPrivate::regenerate()
opacity of the items as they rotate. This additional code can be seen in the
PathAttribute documentation.)
+ The \c focus can be set to \c true to enable keyboard navigation.
+ The path view itself is a focus scope (see \l{qmlfocus#Acquiring Focus and Focus Scopes}{the focus documentation page} for more details).
+
Delegates are instantiated as needed and may be destroyed at any time.
State should \e never be stored in a delegate.
@@ -341,7 +364,7 @@ void QDeclarativePathViewPrivate::regenerate()
to set \e {clip: true} in order to have the out of view items clipped
nicely.
- \sa Path
+ \sa Path, {declarative/modelviews/pathview}{PathView example}
*/
QDeclarativePathView::QDeclarativePathView(QDeclarativeItem *parent)
@@ -848,6 +871,61 @@ void QDeclarativePathView::setInteractive(bool interactive)
}
/*!
+ \qmlproperty bool PathView::moving
+
+ This property holds whether the view is currently moving
+ due to the user either dragging or flicking the view.
+*/
+bool QDeclarativePathView::isMoving() const
+{
+ Q_D(const QDeclarativePathView);
+ return d->moving;
+}
+
+/*!
+ \qmlproperty bool PathView::flicking
+
+ This property holds whether the view is currently moving
+ due to the user flicking the view.
+*/
+bool QDeclarativePathView::isFlicking() const
+{
+ Q_D(const QDeclarativePathView);
+ return d->flicking;
+}
+
+/*!
+ \qmlsignal PathView::onMovementStarted()
+
+ This handler is called when the view begins moving due to user
+ interaction.
+*/
+
+/*!
+ \qmlsignal PathView::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 PathView::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 PathView::onFlickEnded()
+
+ This handler is called when the view stops moving due to a flick.
+*/
+
+/*!
\qmlproperty Component PathView::delegate
The delegate provides a template defining each item instantiated by the view.
@@ -964,7 +1042,11 @@ void QDeclarativePathView::mousePressEvent(QGraphicsSceneMouseEvent *event)
return;
}
- d->stealMouse = false;
+ if (d->tl.isActive() && d->flicking)
+ d->stealMouse = true; // If we've been flicked then steal the click.
+ else
+ d->stealMouse = false;
+
d->lastElapsed = 0;
d->lastDist = 0;
QDeclarativeItemPrivate::start(d->lastPosTime);
@@ -1000,6 +1082,11 @@ void QDeclarativePathView::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
d->lastDist = diff;
d->startPc = newPc;
}
+ if (!d->moving) {
+ d->moving = true;
+ emit movingChanged();
+ emit movementStarted();
+ }
}
}
@@ -1039,12 +1126,19 @@ void QDeclarativePathView::mouseReleaseEvent(QGraphicsSceneMouseEvent *)
d->moveOffset.setValue(d->offset);
d->tl.accel(d->moveOffset, velocity, accel, dist);
d->tl.callback(QDeclarativeTimeLineCallback(&d->moveOffset, d->fixOffsetCallback, d));
+ if (!d->flicking) {
+ d->flicking = true;
+ emit flickingChanged();
+ emit flickStarted();
+ }
} else {
d->fixOffset();
}
d->lastPosTime.invalidate();
ungrabMouse();
+ if (!d->tl.isActive())
+ movementEnding();
}
bool QDeclarativePathView::sendMouseEvent(QGraphicsSceneMouseEvent *event)
@@ -1372,6 +1466,21 @@ void QDeclarativePathView::ticked()
d->updateCurrent();
}
+void QDeclarativePathView::movementEnding()
+{
+ Q_D(QDeclarativePathView);
+ if (d->flicking) {
+ d->flicking = false;
+ emit flickingChanged();
+ emit flickEnded();
+ }
+ if (d->moving && !d->stealMouse) {
+ d->moving = false;
+ emit movingChanged();
+ emit movementEnded();
+ }
+}
+
// find the item closest to the snap position
int QDeclarativePathViewPrivate::calcCurrentIndex()
{