summaryrefslogtreecommitdiffstats
path: root/src/declarative/graphicsitems/qdeclarativepositioners.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativepositioners.cpp')
-rw-r--r--src/declarative/graphicsitems/qdeclarativepositioners.cpp121
1 files changed, 104 insertions, 17 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativepositioners.cpp b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
index 21c33e2..8796e63 100644
--- a/src/declarative/graphicsitems/qdeclarativepositioners.cpp
+++ b/src/declarative/graphicsitems/qdeclarativepositioners.cpp
@@ -46,6 +46,7 @@
#include <qdeclarativestate_p.h>
#include <qdeclarativestategroup_p.h>
#include <qdeclarativestateoperations_p.h>
+#include <qdeclarativeinfo.h>
#include <QtCore/qmath.h>
#include <QDebug>
@@ -75,7 +76,6 @@ void QDeclarativeBasePositionerPrivate::unwatchChanges(QDeclarativeItem* other)
/*!
\internal
\class QDeclarativeBasePositioner
- \ingroup group_layouts
\brief The QDeclarativeBasePositioner class provides a base for QDeclarativeGraphics layouts.
To create a QDeclarativeGraphics Positioner, simply subclass QDeclarativeBasePositioner and implement
@@ -165,6 +165,7 @@ void QDeclarativeBasePositioner::componentComplete()
QDeclarativeItem::componentComplete();
positionedItems.reserve(d->QGraphicsItemPrivate::children.count());
prePositioning();
+ reportConflictingAnchors();
}
QVariant QDeclarativeBasePositioner::itemChange(GraphicsItemChange change,
@@ -203,7 +204,11 @@ void QDeclarativeBasePositioner::prePositioning()
if (!isComponentComplete())
return;
+ if (d->doingPositioning)
+ return;
+
d->queuedPositioning = false;
+ d->doingPositioning = true;
//Need to order children by creation order modified by stacking order
QList<QGraphicsItem *> children = d->QGraphicsItemPrivate::children;
qSort(children.begin(), children.end(), d->insertionOrder);
@@ -241,6 +246,7 @@ void QDeclarativeBasePositioner::prePositioning()
doPositioning(&contentSize);
if(d->addTransition || d->moveTransition)
finishApplyTransitions();
+ d->doingPositioning = false;
//Set implicit size to the size of its children
setImplicitHeight(contentSize.height());
setImplicitWidth(contentSize.width());
@@ -329,7 +335,6 @@ Column {
\qml
Column {
spacing: 2
- remove: ...
add: ...
move: ...
...
@@ -339,7 +344,8 @@ Column {
Note that the positioner assumes that the x and y positions of its children
will not change. If you manually change the x or y properties in script, bind
- the x or y properties, or use anchors on a child of a positioner, then the
+ the x or y properties, use anchors on a child of a positioner, or have the
+ height of a child depend on the position of a child, then the
positioner may exhibit strange behaviour.
*/
@@ -377,7 +383,7 @@ Column {
move: Transition {
NumberAnimation {
properties: "y"
- easing.type: "OutBounce"
+ easing.type: Easing.OutBounce
}
}
}
@@ -403,7 +409,6 @@ Column {
\internal
\class QDeclarativeColumn
\brief The QDeclarativeColumn class lines up items vertically.
- \ingroup group_positioners
*/
QDeclarativeColumn::QDeclarativeColumn(QDeclarativeItem *parent)
: QDeclarativeBasePositioner(Vertical, parent)
@@ -436,6 +441,30 @@ void QDeclarativeColumn::doPositioning(QSizeF *contentSize)
contentSize->setHeight(voffset - spacing());
}
+void QDeclarativeColumn::reportConflictingAnchors()
+{
+ QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this));
+ for (int ii = 0; ii < positionedItems.count(); ++ii) {
+ const PositionedItem &child = positionedItems.at(ii);
+ if (child.item) {
+ QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors;
+ if (anchors) {
+ QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors();
+ if (usedAnchors & QDeclarativeAnchors::TopAnchor ||
+ usedAnchors & QDeclarativeAnchors::BottomAnchor ||
+ usedAnchors & QDeclarativeAnchors::VCenterAnchor ||
+ anchors->fill() || anchors->centerIn()) {
+ d->anchorConflict = true;
+ break;
+ }
+ }
+ }
+ }
+ if (d->anchorConflict) {
+ qmlInfo(this) << "Cannot specify top, bottom, verticalCenter, fill or centerIn anchors for items inside Column";
+ }
+}
+
/*!
\qmlclass Row QDeclarativeRow
\since 4.7
@@ -464,7 +493,8 @@ Row {
Note that the positioner assumes that the x and y positions of its children
will not change. If you manually change the x or y properties in script, bind
- the x or y properties, or use anchors on a child of a positioner, then the
+ the x or y properties, use anchors on a child of a positioner, or have the
+ width of a child depend on the position of a child, then the
positioner may exhibit strange behaviour.
*/
@@ -523,7 +553,6 @@ Row {
\internal
\class QDeclarativeRow
\brief The QDeclarativeRow class lines up items horizontally.
- \ingroup group_positioners
*/
QDeclarativeRow::QDeclarativeRow(QDeclarativeItem *parent)
: QDeclarativeBasePositioner(Horizontal, parent)
@@ -551,6 +580,28 @@ void QDeclarativeRow::doPositioning(QSizeF *contentSize)
contentSize->setWidth(hoffset - spacing());
}
+void QDeclarativeRow::reportConflictingAnchors()
+{
+ QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this));
+ for (int ii = 0; ii < positionedItems.count(); ++ii) {
+ const PositionedItem &child = positionedItems.at(ii);
+ if (child.item) {
+ QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors;
+ if (anchors) {
+ QDeclarativeAnchors::Anchors usedAnchors = anchors->usedAnchors();
+ if (usedAnchors & QDeclarativeAnchors::LeftAnchor ||
+ usedAnchors & QDeclarativeAnchors::RightAnchor ||
+ usedAnchors & QDeclarativeAnchors::HCenterAnchor ||
+ anchors->fill() || anchors->centerIn()) {
+ d->anchorConflict = true;
+ break;
+ }
+ }
+ }
+ }
+ if (d->anchorConflict)
+ qmlInfo(this) << "Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row";
+}
/*!
\qmlclass Grid QDeclarativeGrid
@@ -595,7 +646,8 @@ Grid {
Note that the positioner assumes that the x and y positions of its children
will not change. If you manually change the x or y properties in script, bind
- the x or y properties, or use anchors on a child of a positioner, then the
+ the x or y properties, use anchors on a child of a positioner, or have the
+ width or height of a child depend on the position of a child, then the
positioner may exhibit strange behaviour.
*/
/*!
@@ -652,8 +704,6 @@ Grid {
\internal
\class QDeclarativeGrid
\brief The QDeclarativeGrid class lays out items in a grid.
- \ingroup group_layouts
-
*/
QDeclarativeGrid::QDeclarativeGrid(QDeclarativeItem *parent) :
QDeclarativeBasePositioner(Both, parent), m_rows(-1), m_columns(-1), m_flow(LeftToRight)
@@ -697,14 +747,14 @@ void QDeclarativeGrid::setRows(const int rows)
}
/*!
- \qmlproperty enumeration Flow::flow
+ \qmlproperty enumeration Grid::flow
This property holds the flow of the layout.
- Possible values are \c LeftToRight (default) and \c TopToBottom.
+ Possible values are \c Grid.LeftToRight (default) and \c Grid.TopToBottom.
- If \a flow is \c LeftToRight, the items are positioned next to
+ If \a flow is \c Grid.LeftToRight, the items are positioned next to
to each other from left to right, then wrapped to the next line.
- If \a flow is \c TopToBottom, the items are positioned next to each
+ If \a flow is \c Grid.TopToBottom, the items are positioned next to each
other from top to bottom, then wrapped to the next column.
*/
QDeclarativeGrid::Flow QDeclarativeGrid::flow() const
@@ -823,6 +873,22 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
}
}
+void QDeclarativeGrid::reportConflictingAnchors()
+{
+ QDeclarativeBasePositionerPrivate *d = static_cast<QDeclarativeBasePositionerPrivate*>(QDeclarativeBasePositionerPrivate::get(this));
+ for (int ii = 0; ii < positionedItems.count(); ++ii) {
+ const PositionedItem &child = positionedItems.at(ii);
+ if (child.item) {
+ QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors;
+ if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) {
+ d->anchorConflict = true;
+ break;
+ }
+ }
+ }
+ if (d->anchorConflict)
+ qmlInfo(this) << "Cannot specify anchors for items inside Grid";
+}
/*!
\qmlclass Flow QDeclarativeFlow
@@ -830,6 +896,11 @@ void QDeclarativeGrid::doPositioning(QSizeF *contentSize)
\brief The Flow item lines up its children side by side, wrapping as necessary.
\inherits Item
+ Note that the positioner assumes that the x and y positions of its children
+ will not change. If you manually change the x or y properties in script, bind
+ the x or y properties, use anchors on a child of a positioner, or have the
+ width or height of a child depend on the position of a child, then the
+ positioner may exhibit strange behaviour.
*/
/*!
@@ -894,12 +965,12 @@ QDeclarativeFlow::QDeclarativeFlow(QDeclarativeItem *parent)
\qmlproperty enumeration Flow::flow
This property holds the flow of the layout.
- Possible values are \c LeftToRight (default) and \c TopToBottom.
+ Possible values are \c Flow.LeftToRight (default) and \c Flow.TopToBottom.
- If \a flow is \c LeftToRight, the items are positioned next to
+ If \a flow is \c Flow.LeftToRight, the items are positioned next to
to each other from left to right until the width of the Flow
is exceeded, then wrapped to the next line.
- If \a flow is \c TopToBottom, the items are positioned next to each
+ If \a flow is \c Flow.TopToBottom, the items are positioned next to each
other from top to bottom until the height of the Flow is exceeded,
then wrapped to the next column.
*/
@@ -966,5 +1037,21 @@ void QDeclarativeFlow::doPositioning(QSizeF *contentSize)
}
}
+void QDeclarativeFlow::reportConflictingAnchors()
+{
+ Q_D(QDeclarativeFlow);
+ for (int ii = 0; ii < positionedItems.count(); ++ii) {
+ const PositionedItem &child = positionedItems.at(ii);
+ if (child.item) {
+ QDeclarativeAnchors *anchors = QDeclarativeItemPrivate::get(child.item)->_anchors;
+ if (anchors && (anchors->usedAnchors() || anchors->fill() || anchors->centerIn())) {
+ d->anchorConflict = true;
+ break;
+ }
+ }
+ }
+ if (d->anchorConflict)
+ qmlInfo(this) << "Cannot specify anchors for items inside Flow";
+}
QT_END_NAMESPACE