summaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp60
-rw-r--r--src/declarative/graphicsitems/qdeclarativeloader.cpp41
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview.cpp48
-rw-r--r--src/declarative/graphicsitems/qdeclarativepathview_p_p.h4
-rw-r--r--src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp4
-rw-r--r--src/declarative/qml/qdeclarativecompiledbindings.cpp2
-rw-r--r--src/declarative/qml/qdeclarativecontext.cpp4
-rw-r--r--src/declarative/qml/qdeclarativeobjectscriptclass.cpp2
8 files changed, 106 insertions, 59 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp
index 94b1cb3..6be49ba 100644
--- a/src/declarative/graphicsitems/qdeclarativelistview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp
@@ -124,8 +124,8 @@ public:
}
qreal endPosition() const {
return (view->orientation() == QDeclarativeListView::Vertical
- ? item->y() + (item->height() > 0 ? item->height() : 1)
- : item->x() + (item->width() > 0 ? item->width() : 1)) - 1;
+ ? item->y() + (item->height() >= 1.0 ? item->height() : 1)
+ : item->x() + (item->width() >= 1.0 ? item->width() : 1)) - 1;
}
void setPosition(qreal pos) {
if (view->orientation() == QDeclarativeListView::Vertical) {
@@ -736,7 +736,7 @@ void QDeclarativeListViewPrivate::layout()
}
if (!visibleItems.isEmpty()) {
qreal oldEnd = visibleItems.last()->endPosition();
- qreal pos = visibleItems.first()->endPosition() + spacing + 1;
+ qreal pos = visibleItems.first()->position() + visibleItems.first()->size() + spacing;
for (int i=1; i < visibleItems.count(); ++i) {
FxListItem *item = visibleItems.at(i);
item->setPosition(pos);
@@ -1161,30 +1161,35 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
int oldDuration = fixupDuration;
fixupDuration = moveReason == Mouse ? fixupDuration : 0;
- if (snapMode != QDeclarativeListView::NoSnap) {
+ if (currentItem && haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
+ updateHighlight();
+ qreal pos = currentItem->itemPosition();
+ qreal viewPos = position();
+ if (viewPos < pos + currentItem->itemSize() - highlightRangeEnd)
+ viewPos = pos + currentItem->itemSize() - highlightRangeEnd;
+ if (viewPos > pos - highlightRangeStart)
+ viewPos = pos - highlightRangeStart;
+
+ timeline.reset(data.move);
+ if (viewPos != position()) {
+ if (fixupDuration)
+ timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
+ else
+ timeline.set(data.move, -viewPos);
+ }
+ vTime = timeline.time();
+ } else if (snapMode != QDeclarativeListView::NoSnap) {
FxListItem *topItem = snapItemAt(position()+highlightRangeStart);
FxListItem *bottomItem = snapItemAt(position()+highlightRangeEnd);
qreal pos;
- if (topItem && bottomItem && haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
- qreal topPos = qMin(topItem->position() - highlightRangeStart, -maxExtent);
- qreal bottomPos = qMax(bottomItem->position() - highlightRangeEnd, -minExtent);
- pos = qAbs(data.move + topPos) < qAbs(data.move + bottomPos) ? topPos : bottomPos;
- } else if (topItem) {
+ if (topItem) {
pos = qMax(qMin(topItem->position() - highlightRangeStart, -maxExtent), -minExtent);
} else if (bottomItem) {
- pos = qMax(qMin(bottomItem->position() - highlightRangeStart, -maxExtent), -minExtent);
+ pos = qMax(qMin(bottomItem->position() - highlightRangeStart, -maxExtent), -minExtent);
} else {
fixupDuration = oldDuration;
return;
}
- if (currentItem && haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
- updateHighlight();
- qreal currPos = currentItem->itemPosition();
- if (pos < currPos + currentItem->itemSize() - highlightRangeEnd)
- pos = currPos + currentItem->itemSize() - highlightRangeEnd;
- if (pos > currPos - highlightRangeStart)
- pos = currPos - highlightRangeStart;
- }
qreal dist = qAbs(data.move + pos);
if (dist > 0) {
@@ -1195,25 +1200,6 @@ void QDeclarativeListViewPrivate::fixup(AxisData &data, qreal minExtent, qreal m
timeline.set(data.move, -pos);
vTime = timeline.time();
}
- } else if (haveHighlightRange && highlightRange == QDeclarativeListView::StrictlyEnforceRange) {
- if (currentItem) {
- updateHighlight();
- qreal pos = currentItem->itemPosition();
- qreal viewPos = position();
- if (viewPos < pos + currentItem->itemSize() - highlightRangeEnd)
- viewPos = pos + currentItem->itemSize() - highlightRangeEnd;
- if (viewPos > pos - highlightRangeStart)
- viewPos = pos - highlightRangeStart;
-
- timeline.reset(data.move);
- if (viewPos != position()) {
- if (fixupDuration)
- timeline.move(data.move, -viewPos, QEasingCurve(QEasingCurve::InOutQuad), fixupDuration/2);
- else
- timeline.set(data.move, -viewPos);
- }
- vTime = timeline.time();
- }
} else {
QDeclarativeFlickablePrivate::fixup(data, minExtent, maxExtent);
}
diff --git a/src/declarative/graphicsitems/qdeclarativeloader.cpp b/src/declarative/graphicsitems/qdeclarativeloader.cpp
index 109fbbb..1119b92 100644
--- a/src/declarative/graphicsitems/qdeclarativeloader.cpp
+++ b/src/declarative/graphicsitems/qdeclarativeloader.cpp
@@ -129,15 +129,41 @@ void QDeclarativeLoaderPrivate::initResize()
The loaded item can be accessed using the \l item property.
- Loader is like any other visual item and must be positioned and sized
- accordingly to become visible. Once the component is loaded, the Loader
- is automatically resized to the size of the component.
-
If the \l source or \l sourceComponent changes, any previously instantiated
items are destroyed. Setting \l source to an empty string or setting
\l sourceComponent to \c undefined destroys the currently loaded item,
freeing resources and leaving the Loader empty.
+ \section2 Loader sizing behavior
+
+ Loader is like any other visual item and must be positioned and sized
+ accordingly to become visible.
+
+ \list
+ \o If an explicit size is not specified for the Loader, the Loader
+ is automatically resized to the size of the loaded item once the
+ component is loaded.
+ \o If the size of the Loader is specified explicitly by setting
+ the width, height or by anchoring, the loaded item will be resized
+ to the size of the Loader.
+ \endlist
+
+ In both scenarios the size of the item and the Loader are identical.
+ This ensures that anchoring to the Loader is equivalent to anchoring
+ to the loaded item.
+
+ \table
+ \row
+ \o sizeloader.qml
+ \o sizeitem.qml
+ \row
+ \o \snippet doc/src/snippets/declarative/loader/sizeloader.qml 0
+ \o \snippet doc/src/snippets/declarative/loader/sizeitem.qml 0
+ \row
+ \o The red rectangle will be sized to the size of the root item.
+ \o The red rectangle will be 50x50, centered in the root item.
+ \endtable
+
\section2 Receiving signals from loaded items
@@ -343,12 +369,14 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
QDeclarativeContext *ctxt = new QDeclarativeContext(creationContext);
ctxt->setContextObject(q);
- QDeclarativeComponent *c = component;
- QObject *obj = component->create(ctxt);
+ QDeclarativeGuard<QDeclarativeComponent> c = component;
+ QObject *obj = component->beginCreate(ctxt);
if (component != c) {
// component->create could trigger a change in source that causes
// component to be set to something else. In that case we just
// need to cleanup.
+ if (c)
+ c->completeCreate();
delete obj;
delete ctxt;
return;
@@ -373,6 +401,7 @@ void QDeclarativeLoaderPrivate::_q_sourceLoaded()
delete ctxt;
source = QUrl();
}
+ component->completeCreate();
emit q->sourceChanged();
emit q->statusChanged();
emit q->progressChanged();
diff --git a/src/declarative/graphicsitems/qdeclarativepathview.cpp b/src/declarative/graphicsitems/qdeclarativepathview.cpp
index dc3d5ee..7c79afe 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepathview.cpp
@@ -373,7 +373,21 @@ 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.
+ PathView does not automatically handle keyboard navigation. This is because
+ the keys to use for navigation will depend upon the shape of the path. Navigation
+ can be added quite simply by setting \c focus to \c true and calling
+ \l decrementCurrentIndex() or \l incrementCurrentIndex(), for example to navigate
+ using the left and right arrow keys:
+
+ \code
+ PathView {
+ ...
+ focus: true
+ Keys.onLeftPressed: decrementCurrentIndex()
+ Keys.onRightPressed: incrementCurrentIndex()
+ }
+ \endcode
+
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.
@@ -523,7 +537,6 @@ int QDeclarativePathView::count() const
/*!
\qmlproperty Path PathView::path
- \default
This property holds the path used to lay out the items.
For more information see the \l Path documentation.
*/
@@ -607,6 +620,8 @@ void QDeclarativePathView::setCurrentIndex(int idx)
*/
void QDeclarativePathView::incrementCurrentIndex()
{
+ Q_D(QDeclarativePathView);
+ d->moveDirection = QDeclarativePathViewPrivate::Positive;
setCurrentIndex(currentIndex()+1);
}
@@ -625,6 +640,7 @@ void QDeclarativePathView::decrementCurrentIndex()
int idx = currentIndex()-1;
if (idx < 0)
idx = d->modelCount - 1;
+ d->moveDirection = QDeclarativePathViewPrivate::Negative;
setCurrentIndex(idx);
}
}
@@ -995,6 +1011,7 @@ void QDeclarativePathView::setDelegate(QDeclarativeComponent *delegate)
}
if (QDeclarativeVisualDataModel *dataModel = qobject_cast<QDeclarativeVisualDataModel*>(d->model)) {
dataModel->setDelegate(delegate);
+ d->modelCount = dataModel->count();
d->regenerate();
emit delegateChanged();
}
@@ -1636,7 +1653,7 @@ void QDeclarativePathViewPrivate::snapToCurrent()
if (!model || modelCount <= 0)
return;
- qreal targetOffset = modelCount - currentIndex;
+ qreal targetOffset = qmlMod(modelCount - currentIndex, modelCount);
moveReason = Other;
offsetAdj = 0.0;
@@ -1645,19 +1662,28 @@ void QDeclarativePathViewPrivate::snapToCurrent()
const int duration = highlightMoveDuration;
- if (targetOffset - offset > modelCount/2) {
+ if (moveDirection == Positive || (moveDirection == Shortest && targetOffset - offset > modelCount/2)) {
qreal distance = modelCount - targetOffset + offset;
- tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance));
- tl.set(moveOffset, modelCount);
- tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * (modelCount-targetOffset) / distance));
- } else if (targetOffset - offset <= -modelCount/2) {
+ if (targetOffset > moveOffset) {
+ tl.move(moveOffset, 0.0, QEasingCurve(QEasingCurve::InQuad), int(duration * offset / distance));
+ tl.set(moveOffset, modelCount);
+ tl.move(moveOffset, targetOffset, QEasingCurve(offset == 0.0 ? QEasingCurve::InOutQuad : QEasingCurve::OutQuad), int(duration * (modelCount-targetOffset) / distance));
+ } else {
+ tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
+ }
+ } else if (moveDirection == Negative || targetOffset - offset <= -modelCount/2) {
qreal distance = modelCount - offset + targetOffset;
- tl.move(moveOffset, modelCount, QEasingCurve(QEasingCurve::InQuad), int(duration * (modelCount-offset) / distance));
- tl.set(moveOffset, 0.0);
- tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * targetOffset / distance));
+ if (targetOffset < moveOffset) {
+ tl.move(moveOffset, modelCount, QEasingCurve(targetOffset == 0 ? QEasingCurve::InOutQuad : QEasingCurve::InQuad), int(duration * (modelCount-offset) / distance));
+ tl.set(moveOffset, 0.0);
+ tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::OutQuad), int(duration * targetOffset / distance));
+ } else {
+ tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
+ }
} else {
tl.move(moveOffset, targetOffset, QEasingCurve(QEasingCurve::InOutQuad), duration);
}
+ moveDirection = Shortest;
}
QDeclarativePathViewAttached *QDeclarativePathView::qmlAttachedProperties(QObject *obj)
diff --git a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
index b217216..6232b83 100644
--- a/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
+++ b/src/declarative/graphicsitems/qdeclarativepathview_p_p.h
@@ -82,7 +82,7 @@ public:
, dragMargin(0), deceleration(100)
, moveOffset(this, &QDeclarativePathViewPrivate::setAdjustedOffset)
, firstIndex(-1), pathItems(-1), requestedIndex(-1)
- , moveReason(Other), attType(0), highlightComponent(0), highlightItem(0)
+ , moveReason(Other), moveDirection(Shortest), attType(0), highlightComponent(0), highlightItem(0)
, moveHighlight(this, &QDeclarativePathViewPrivate::setHighlightPosition)
, highlightPosition(0)
, highlightRangeStart(0), highlightRangeEnd(0)
@@ -173,6 +173,8 @@ public:
QVariant modelVariant;
enum MovementReason { Other, SetIndex, Mouse };
MovementReason moveReason;
+ enum MovementDirection { Shortest, Negative, Positive };
+ MovementDirection moveDirection;
QDeclarativeOpenMetaObjectType *attType;
QDeclarativeComponent *highlightComponent;
QDeclarativeItem *highlightItem;
diff --git a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
index 1f01a45..4fe6c4c 100644
--- a/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
+++ b/src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
@@ -937,6 +937,10 @@ void QDeclarativeVisualDataModel::setPart(const QString &part)
int QDeclarativeVisualDataModel::count() const
{
Q_D(const QDeclarativeVisualDataModel);
+ if (d->m_visualItemModel)
+ return d->m_visualItemModel->count();
+ if (!d->m_delegate)
+ return 0;
return d->modelCount();
}
diff --git a/src/declarative/qml/qdeclarativecompiledbindings.cpp b/src/declarative/qml/qdeclarativecompiledbindings.cpp
index 5f0fd56..fbe5829 100644
--- a/src/declarative/qml/qdeclarativecompiledbindings.cpp
+++ b/src/declarative/qml/qdeclarativecompiledbindings.cpp
@@ -601,7 +601,7 @@ struct QDeclarativeBindingCompilerPrivate
QDeclarativeImports imports;
QDeclarativeEnginePrivate *engine;
- QString contextName() const { return QLatin1String("$$$SCOPE_") + QString::number((intptr_t)context, 16); }
+ QString contextName() const { return QLatin1String("$$$SCOPE_") + QString::number((quintptr)context, 16); }
bool compile(QDeclarativeJS::AST::Node *);
diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp
index 1e58a71..3ee0e6f 100644
--- a/src/declarative/qml/qdeclarativecontext.cpp
+++ b/src/declarative/qml/qdeclarativecontext.cpp
@@ -474,7 +474,7 @@ int QDeclarativeContextPrivate::context_count(QDeclarativeListProperty<QObject>
{
QDeclarativeContext *context = static_cast<QDeclarativeContext*>(prop->object);
QDeclarativeContextPrivate *d = QDeclarativeContextPrivate::get(context);
- int contextProperty = (int)(intptr_t)prop->data;
+ int contextProperty = (int)(quintptr)prop->data;
if (d->propertyValues.at(contextProperty).userType() != qMetaTypeId<QList<QObject*> >()) {
return 0;
@@ -487,7 +487,7 @@ QObject *QDeclarativeContextPrivate::context_at(QDeclarativeListProperty<QObject
{
QDeclarativeContext *context = static_cast<QDeclarativeContext*>(prop->object);
QDeclarativeContextPrivate *d = QDeclarativeContextPrivate::get(context);
- int contextProperty = (int)(intptr_t)prop->data;
+ int contextProperty = (int)(quintptr)prop->data;
if (d->propertyValues.at(contextProperty).userType() != qMetaTypeId<QList<QObject*> >()) {
return 0;
diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
index ea92111..eff59df 100644
--- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
+++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp
@@ -421,7 +421,7 @@ QScriptValue QDeclarativeObjectScriptClass::tostring(QScriptContext *context, QS
ret += QString::fromUtf8(obj->metaObject()->className());
ret += QLatin1String("(0x");
- ret += QString::number((intptr_t)obj,16);
+ ret += QString::number((quintptr)obj,16);
if (!objectName.isEmpty()) {
ret += QLatin1String(", \"");