diff options
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout.cpp | 138 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout.h | 12 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 121 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.h | 25 | ||||
-rw-r--r-- | tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp | 124 |
5 files changed, 316 insertions, 104 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index a86626b553..31cc911a70 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -71,59 +71,108 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout() Q_ASSERT(d->m_vertexList.isEmpty()); } +/*! + * Creates an anchor between the edge \a firstEdge of item \a firstItem and the edge \a secondEdge + * of item \a secondItem. The magnitude of the anchor is picked up from the style. Anchors + * between a layout edge and an item edge will have a size of 0. + * If there is already an anchor between the edges, the the new anchor will replace the old one. + * + * \a firstItem and \a secondItem are automatically added to the layout if they are not part + * of the layout. This means that count() can increase with up to 2. + */ +void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, + Edge firstEdge, + QGraphicsLayoutItem *secondItem, + Edge secondEdge) +{ + Q_D(QGraphicsAnchorLayout); + d->anchor(firstItem, firstEdge, secondItem, secondEdge); + invalidate(); +} + +/*! + * \overload + * + * By calling this function the caller can specify the magnitude of the anchor with \a spacing. + * + */ void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, QGraphicsLayoutItem *secondItem, Edge secondEdge, qreal spacing) { Q_D(QGraphicsAnchorLayout); - if ((firstItem == 0) || (secondItem == 0)) { - qWarning("QGraphicsAnchorLayout::anchor: " - "Cannot anchor NULL items"); - return; - } + d->anchor(firstItem, firstEdge, secondItem, secondEdge, &spacing); + invalidate(); +} - if (firstItem == secondItem) { - qWarning("QGraphicsAnchorLayout::anchor: " - "Cannot anchor the item to itself"); - return; - } +/*! + * Creates two anchors between \a firstItem and \a secondItem, where one is for the horizontal + * edge and another one for the vertical edge that the corners \a firstCorner and \a + * secondCorner specifies. + * The magnitude of the anchors is picked up from the style. + * + * This is a convenience function, since anchoring corners can be expressed as anchoring two edges. + * For instance, + * \code + * layout->anchor(layout, QGraphicsAnchorLayout::Top, b, QGraphicsAnchorLayout::Top); + * layout->anchor(layout, QGraphicsAnchorLayout::Left, b, QGraphicsAnchorLayout::Left); + * \endcode + * + * has the same effect as + * + * \code + * layout->anchor(layout, Qt::TopLeft, b, Qt::TopLeft); + * \endcode + * + * If there is already an anchor between the edge pairs, it will be replaced by the anchors that + * this function specifies. + * + * \a firstItem and \a secondItem are automatically added to the layout if they are not part + * of the layout. This means that count() can increase with up to 2. + */ +void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, + Qt::Corner firstCorner, + QGraphicsLayoutItem *secondItem, + Qt::Corner secondCorner) +{ + Q_D(QGraphicsAnchorLayout); - if (d->edgeOrientation(secondEdge) != d->edgeOrientation(firstEdge)) { - qWarning("QGraphicsAnchorLayout::anchor: " - "Cannot anchor edges of different orientations"); - return; - } + // Horizontal anchor + QGraphicsAnchorLayout::Edge firstEdge = (firstCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left); + QGraphicsAnchorLayout::Edge secondEdge = (secondCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left); + d->anchor(firstItem, firstEdge, secondItem, secondEdge); - // In QGraphicsAnchorLayout, items are represented in its internal - // graph as four anchors that connect: - // - Left -> HCenter - // - HCenter-> Right - // - Top -> VCenter - // - VCenter -> Bottom - - // Ensure that the internal anchors have been created for both items. - if (firstItem != this && !d->items.contains(firstItem)) { - d->createItemEdges(firstItem); - d->addChildLayoutItem(firstItem); - } - if (secondItem != this && !d->items.contains(secondItem)) { - d->createItemEdges(secondItem); - d->addChildLayoutItem(secondItem); - } + // Vertical anchor + firstEdge = (firstCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top); + secondEdge = (secondCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top); + d->anchor(firstItem, firstEdge, secondItem, secondEdge); - // Use heuristics to find out what the user meant with this anchor. - d->correctEdgeDirection(firstItem, firstEdge, secondItem, secondEdge); - - // Create actual anchor between firstItem and secondItem. - AnchorData *data; - if (spacing >= 0) { - data = new AnchorData(spacing); - d->addAnchor(firstItem, firstEdge, secondItem, secondEdge, data); - } else { - data = new AnchorData(-spacing); - d->addAnchor(secondItem, secondEdge, firstItem, firstEdge, data); - } + invalidate(); +} + +/*! + * \overload + * + * By calling this function the caller can specify the magnitude of the anchor with \a spacing. + * + */ +void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, + Qt::Corner firstCorner, + QGraphicsLayoutItem *secondItem, + Qt::Corner secondCorner, qreal spacing) +{ + Q_D(QGraphicsAnchorLayout); + + // Horizontal anchor + QGraphicsAnchorLayout::Edge firstEdge = (firstCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left); + QGraphicsAnchorLayout::Edge secondEdge = (secondCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left); + d->anchor(firstItem, firstEdge, secondItem, secondEdge, &spacing); + + // Vertical anchor + firstEdge = (firstCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top); + secondEdge = (secondCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top); + d->anchor(firstItem, firstEdge, secondItem, secondEdge, &spacing); invalidate(); } @@ -167,8 +216,7 @@ void QGraphicsAnchorLayout::setSpacing(qreal spacing, Qt::Orientations orientati qreal QGraphicsAnchorLayout::spacing(Qt::Orientation orientation) const { Q_D(const QGraphicsAnchorLayout); - // Qt::Horizontal == 0x1, Qt::Vertical = 0x2 - return d->spacing[orientation - 1]; + return d->effectiveSpacing(QGraphicsAnchorLayoutPrivate::Orientation(orientation - 1)); } void QGraphicsAnchorLayout::setGeometry(const QRectF &geom) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.h b/src/gui/graphicsview/qgraphicsanchorlayout.h index 74075ff7fd..1f622ebc2d 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout.h @@ -72,8 +72,18 @@ public: virtual ~QGraphicsAnchorLayout(); void anchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, + QGraphicsLayoutItem *secondItem, Edge secondEdge); + + void anchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, QGraphicsLayoutItem *secondItem, Edge secondEdge, - qreal spacing = 0); + qreal spacing); + + void anchor(QGraphicsLayoutItem *firstItem, Qt::Corner firstCorner, + QGraphicsLayoutItem *secondItem, Qt::Corner secondCorner); + + void anchor(QGraphicsLayoutItem *firstItem, Qt::Corner firstCorner, + QGraphicsLayoutItem *secondItem, Qt::Corner secondCorner, + qreal spacing); void removeAnchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, QGraphicsLayoutItem *secondItem, Edge secondEdge); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 502da5de01..8b661e345b 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -536,6 +536,75 @@ void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem * } } +/*! + * \internal + * + * Helper function that is called from the anchor functions in the public API. + * If \a spacing is 0, it will pick up the spacing defined by the style. + */ +void QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem, + QGraphicsAnchorLayout::Edge firstEdge, + QGraphicsLayoutItem *secondItem, + QGraphicsAnchorLayout::Edge secondEdge, + qreal *spacing) +{ + Q_Q(QGraphicsAnchorLayout); + if ((firstItem == 0) || (secondItem == 0)) { + qWarning("QGraphicsAnchorLayout::anchor(): " + "Cannot anchor NULL items"); + return; + } + + if (firstItem == secondItem) { + qWarning("QGraphicsAnchorLayout::anchor(): " + "Cannot anchor the item to itself"); + return; + } + + if (edgeOrientation(secondEdge) != edgeOrientation(firstEdge)) { + qWarning("QGraphicsAnchorLayout::anchor(): " + "Cannot anchor edges of different orientations"); + return; + } + + // In QGraphicsAnchorLayout, items are represented in its internal + // graph as four anchors that connect: + // - Left -> HCenter + // - HCenter-> Right + // - Top -> VCenter + // - VCenter -> Bottom + + // Ensure that the internal anchors have been created for both items. + if (firstItem != q && !items.contains(firstItem)) { + createItemEdges(firstItem); + addChildLayoutItem(firstItem); + } + if (secondItem != q && !items.contains(secondItem)) { + createItemEdges(secondItem); + addChildLayoutItem(secondItem); + } + + // Use heuristics to find out what the user meant with this anchor. + correctEdgeDirection(firstItem, firstEdge, secondItem, secondEdge); + + AnchorData *data; + if (!spacing) { + // If we anchor to the layout edges or if we anchor + // Right->Right or Left->Left, our default spacing will be 0 + if (firstItem == q || secondItem == q || firstEdge == secondEdge) + data = new AnchorData(0); + else + data = new AnchorData; // otherwise, ask the style later + addAnchor(firstItem, firstEdge, secondItem, secondEdge, data); + } else if (*spacing >= 0) { + data = new AnchorData(*spacing); + addAnchor(firstItem, firstEdge, secondItem, secondEdge, data); + } else { + data = new AnchorData(-*spacing); + addAnchor(secondItem, secondEdge, firstItem, firstEdge, data); + } +} + void QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *firstItem, QGraphicsAnchorLayout::Edge firstEdge, QGraphicsLayoutItem *secondItem, @@ -697,6 +766,28 @@ void QGraphicsAnchorLayoutPrivate::correctEdgeDirection(QGraphicsLayoutItem *&fi } } +qreal QGraphicsAnchorLayoutPrivate::effectiveSpacing(Orientation orientation) const +{ + Q_Q(const QGraphicsAnchorLayout); + qreal s = spacing[orientation]; + if (s < 0) { + QGraphicsLayoutItem *parent = q->parentLayoutItem(); + while (parent && parent->isLayout()) { + parent = parent->parentLayoutItem(); + } + if (parent) { + QGraphicsItem *parentItem = parent->graphicsItem(); + if (parentItem && parentItem->isWidget()) { + QGraphicsWidget *w = static_cast<QGraphicsWidget*>(parentItem); + s = w->style()->pixelMetric(orientation == Horizontal + ? QStyle::PM_LayoutHorizontalSpacing + : QStyle::PM_LayoutVerticalSpacing); + } + } + } + return s; +} + /*! \internal @@ -750,6 +841,9 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs( // restoreSimplifiedGraph(orientation); // should not be here //q->dumpGraph(); + // Reset the nominal sizes of each anchor based on the current item sizes + setAnchorSizeHintsFromDefaults(orientation); + // Traverse all graph edges and store the possible paths to each vertex findPaths(orientation); @@ -850,6 +944,33 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs( graphPaths[orientation].clear(); // ### } +void QGraphicsAnchorLayoutPrivate::setAnchorSizeHintsFromDefaults(Orientation orientation) +{ + Graph<AnchorVertex, AnchorData> &g = graph[orientation]; + QSet<AnchorVertex *> setOfVertices = g.vertices(); + + for (QSet<AnchorVertex *>::const_iterator it = setOfVertices.begin(); it != setOfVertices.end(); ++it) { + AnchorVertex *v = *it; + QList<AnchorVertex *> adjacents = g.adjacentVertices(v); + for (int i = 0; i < adjacents.count(); ++i) { + AnchorVertex *v1 = adjacents.at(i); + AnchorData *data = g.edgeData(v, v1); + if (!data->hasSize) { + bool forward = data->origin == v; + if (forward) { + qreal s = effectiveSpacing(orientation); + data->minSize = s; + data->prefSize = s; + data->maxSize = s; + data->sizeAtMinimum = s; + data->sizeAtPreferred = s; + data->sizeAtMaximum = s; + } + } + } + } +} + void QGraphicsAnchorLayoutPrivate::setAnchorSizeHintsFromItems(Orientation orientation) { QPair<QGraphicsLayoutItem *, QGraphicsAnchorLayout::Edge> beginningKey; diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 605a8e2b2c..9e6c1bc871 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -133,12 +133,17 @@ struct AnchorData : public QSimplexVariable { : QSimplexVariable(), minSize(minimumSize), prefSize(preferredSize), maxSize(maximumSize), sizeAtMinimum(preferredSize), sizeAtPreferred(preferredSize), sizeAtMaximum(preferredSize), - skipInPreferred(0), type(Normal) {} + skipInPreferred(0), type(Normal), hasSize(true) {} - AnchorData(qreal size = 0) + AnchorData(qreal size) : QSimplexVariable(), minSize(size), prefSize(size), maxSize(size), sizeAtMinimum(size), sizeAtPreferred(size), sizeAtMaximum(size), - skipInPreferred(0), type(Normal) {} + skipInPreferred(0), type(Normal), hasSize(true) {} + + AnchorData() + : QSimplexVariable(), minSize(0), prefSize(0), maxSize(0), + sizeAtMinimum(0), sizeAtPreferred(0), sizeAtMaximum(0), + skipInPreferred(0), type(Normal), hasSize(false) {} inline QString toString() const; QString name; @@ -163,12 +168,13 @@ struct AnchorData : public QSimplexVariable { uint skipInPreferred : 1; uint type : 2; // either Normal, Sequential or Parallel + uint hasSize : 1; // if false, get size from style. protected: AnchorData(Type type, qreal size = 0) : QSimplexVariable(), minSize(size), prefSize(size), maxSize(size), sizeAtMinimum(size), sizeAtPreferred(size), sizeAtMaximum(size), - skipInPreferred(0), type(type) {} + skipInPreferred(0), type(type), hasSize(true) {} }; inline QString AnchorData::toString() const @@ -288,6 +294,13 @@ public: void createItemEdges(QGraphicsLayoutItem *item); void removeCenterConstraints(QGraphicsLayoutItem *item, Orientation orientation); + // helper function used by the 4 API functions + void anchor(QGraphicsLayoutItem *firstItem, + QGraphicsAnchorLayout::Edge firstEdge, + QGraphicsLayoutItem *secondItem, + QGraphicsAnchorLayout::Edge secondEdge, + qreal *spacing = 0); + // Anchor Manipulation methods void addAnchor(QGraphicsLayoutItem *firstItem, QGraphicsAnchorLayout::Edge firstEdge, @@ -306,6 +319,9 @@ public: QGraphicsAnchorLayout::Edge &firstEdge, QGraphicsLayoutItem *&secondItem, QGraphicsAnchorLayout::Edge &secondEdge); + // for getting the actual spacing (will query the style if the + // spacing is not explicitly set). + qreal effectiveSpacing(Orientation orientation) const; // Activation methods void simplifyGraph(Orientation orientation); @@ -313,6 +329,7 @@ public: void calculateGraphs(); void calculateGraphs(Orientation orientation); void setAnchorSizeHintsFromItems(Orientation orientation); + void setAnchorSizeHintsFromDefaults(Orientation orientation); void findPaths(Orientation orientation); void constraintsFromPaths(Orientation orientation); QList<QSimplexConstraint *> constraintsFromSizeHints(const QList<AnchorData *> &anchors); diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index de6caac501..10b55d7b60 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -2,6 +2,7 @@ #include <qgraphicsanchorlayout.h> #include <qgraphicswidget.h> #include <qgraphicsproxywidget.h> +#include <QtGui/qgraphicsview.h> class tst_QGraphicsAnchorLayout : public QObject { Q_OBJECT; @@ -14,11 +15,26 @@ private slots: void fairDistribution(); }; +class RectWidget : public QGraphicsWidget +{ +public: + RectWidget(QGraphicsItem *parent = 0) : QGraphicsWidget(parent){} + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) + { + Q_UNUSED(option); + Q_UNUSED(widget); + painter->drawRoundRect(rect()); + painter->drawLine(rect().topLeft(), rect().bottomRight()); + painter->drawLine(rect().bottomLeft(), rect().topRight()); + } +}; + static QGraphicsWidget *createItem(const QSizeF &minimum = QSizeF(100.0, 100.0), const QSizeF &preferred = QSize(150.0, 100.0), const QSizeF &maximum = QSizeF(200.0, 100.0)) { - QGraphicsWidget *w = new QGraphicsWidget; + QGraphicsWidget *w = new RectWidget; w->setMinimumSize(minimum); w->setPreferredSize(preferred); w->setMaximumSize(maximum); @@ -56,28 +72,28 @@ void tst_QGraphicsAnchorLayout::diagonal() l->setContentsMargins(0, 0, 0, 0); // vertical - l->anchor(a, QGraphicsAnchorLayout::Top, l, QGraphicsAnchorLayout::Top); - l->anchor(b, QGraphicsAnchorLayout::Top, l, QGraphicsAnchorLayout::Top); + l->anchor(a, QGraphicsAnchorLayout::Top, l, QGraphicsAnchorLayout::Top, 0); + l->anchor(b, QGraphicsAnchorLayout::Top, l, QGraphicsAnchorLayout::Top, 0); - l->anchor(c, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Bottom); - l->anchor(c, QGraphicsAnchorLayout::Top, b, QGraphicsAnchorLayout::Bottom); - l->anchor(c, QGraphicsAnchorLayout::Bottom, d, QGraphicsAnchorLayout::Top); - l->anchor(c, QGraphicsAnchorLayout::Bottom, e, QGraphicsAnchorLayout::Top); + l->anchor(c, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Bottom, 0); + l->anchor(c, QGraphicsAnchorLayout::Top, b, QGraphicsAnchorLayout::Bottom, 0); + l->anchor(c, QGraphicsAnchorLayout::Bottom, d, QGraphicsAnchorLayout::Top, 0); + l->anchor(c, QGraphicsAnchorLayout::Bottom, e, QGraphicsAnchorLayout::Top, 0); - l->anchor(d, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom); - l->anchor(e, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom); + l->anchor(d, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); + l->anchor(e, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); // horizontal - l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left); - l->anchor(l, QGraphicsAnchorLayout::Left, d, QGraphicsAnchorLayout::Left); - l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left); + l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left, 0); + l->anchor(l, QGraphicsAnchorLayout::Left, d, QGraphicsAnchorLayout::Left, 0); + l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left, 0); - l->anchor(a, QGraphicsAnchorLayout::Right, c, QGraphicsAnchorLayout::Left); - l->anchor(c, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left); + l->anchor(a, QGraphicsAnchorLayout::Right, c, QGraphicsAnchorLayout::Left, 0); + l->anchor(c, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left, 0); - l->anchor(b, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right); - l->anchor(e, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right); - l->anchor(d, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left); + l->anchor(b, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); + l->anchor(e, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); + l->anchor(d, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left, 0); QCOMPARE(l->count(), 5); @@ -155,23 +171,23 @@ void tst_QGraphicsAnchorLayout::parallel() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - l->anchor(l, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Top); - l->anchor(a, QGraphicsAnchorLayout::Bottom, b, QGraphicsAnchorLayout::Top); - l->anchor(b, QGraphicsAnchorLayout::Bottom, c, QGraphicsAnchorLayout::Top); - l->anchor(c, QGraphicsAnchorLayout::Bottom, d, QGraphicsAnchorLayout::Top); - l->anchor(d, QGraphicsAnchorLayout::Bottom, e, QGraphicsAnchorLayout::Top); - l->anchor(e, QGraphicsAnchorLayout::Bottom, f, QGraphicsAnchorLayout::Top); - l->anchor(f, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom); - - l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left); - l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left); - l->anchor(a, QGraphicsAnchorLayout::Right, c, QGraphicsAnchorLayout::Left); - l->anchor(b, QGraphicsAnchorLayout::Right, d, QGraphicsAnchorLayout::Left); - l->anchor(b, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left); - l->anchor(c, QGraphicsAnchorLayout::Right, f, QGraphicsAnchorLayout::Left); - l->anchor(d, QGraphicsAnchorLayout::Right, f, QGraphicsAnchorLayout::Left); - l->anchor(e, QGraphicsAnchorLayout::Right, f, QGraphicsAnchorLayout::Left); - l->anchor(f, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right); + l->anchor(l, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Top, 0); + l->anchor(a, QGraphicsAnchorLayout::Bottom, b, QGraphicsAnchorLayout::Top, 0); + l->anchor(b, QGraphicsAnchorLayout::Bottom, c, QGraphicsAnchorLayout::Top, 0); + l->anchor(c, QGraphicsAnchorLayout::Bottom, d, QGraphicsAnchorLayout::Top, 0); + l->anchor(d, QGraphicsAnchorLayout::Bottom, e, QGraphicsAnchorLayout::Top, 0); + l->anchor(e, QGraphicsAnchorLayout::Bottom, f, QGraphicsAnchorLayout::Top, 0); + l->anchor(f, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); + + l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left, 0); + l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left, 0); + l->anchor(a, QGraphicsAnchorLayout::Right, c, QGraphicsAnchorLayout::Left, 0); + l->anchor(b, QGraphicsAnchorLayout::Right, d, QGraphicsAnchorLayout::Left, 0); + l->anchor(b, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left, 0); + l->anchor(c, QGraphicsAnchorLayout::Right, f, QGraphicsAnchorLayout::Left, 0); + l->anchor(d, QGraphicsAnchorLayout::Right, f, QGraphicsAnchorLayout::Left, 0); + l->anchor(e, QGraphicsAnchorLayout::Right, f, QGraphicsAnchorLayout::Left, 0); + l->anchor(f, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); QCOMPARE(l->count(), 6); @@ -234,15 +250,15 @@ void tst_QGraphicsAnchorLayout::snake() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - l->anchor(l, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Top); - l->anchor(a, QGraphicsAnchorLayout::Bottom, b, QGraphicsAnchorLayout::Top); - l->anchor(b, QGraphicsAnchorLayout::Bottom, c, QGraphicsAnchorLayout::Top); - l->anchor(c, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom); + l->anchor(l, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Top, 0); + l->anchor(a, QGraphicsAnchorLayout::Bottom, b, QGraphicsAnchorLayout::Top, 0); + l->anchor(b, QGraphicsAnchorLayout::Bottom, c, QGraphicsAnchorLayout::Top, 0); + l->anchor(c, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); - l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left); - l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Right); - l->anchor(b, QGraphicsAnchorLayout::Left, c, QGraphicsAnchorLayout::Left); - l->anchor(c, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right); + l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left, 0); + l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Right, 0); + l->anchor(b, QGraphicsAnchorLayout::Left, c, QGraphicsAnchorLayout::Left, 0); + l->anchor(c, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); QCOMPARE(l->count(), 3); @@ -298,18 +314,18 @@ void tst_QGraphicsAnchorLayout::fairDistribution() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - l->anchor(l, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Top); - l->anchor(a, QGraphicsAnchorLayout::Bottom, b, QGraphicsAnchorLayout::Top); - l->anchor(b, QGraphicsAnchorLayout::Bottom, c, QGraphicsAnchorLayout::Top); - l->anchor(c, QGraphicsAnchorLayout::Bottom, d, QGraphicsAnchorLayout::Top); - l->anchor(d, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom); - - l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left); - l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left); - l->anchor(b, QGraphicsAnchorLayout::Right, c, QGraphicsAnchorLayout::Left); - l->anchor(c, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right); - l->anchor(l, QGraphicsAnchorLayout::Left, d, QGraphicsAnchorLayout::Left); - l->anchor(d, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right); + l->anchor(l, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Top, 0); + l->anchor(a, QGraphicsAnchorLayout::Bottom, b, QGraphicsAnchorLayout::Top, 0); + l->anchor(b, QGraphicsAnchorLayout::Bottom, c, QGraphicsAnchorLayout::Top, 0); + l->anchor(c, QGraphicsAnchorLayout::Bottom, d, QGraphicsAnchorLayout::Top, 0); + l->anchor(d, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); + + l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left, 0); + l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left, 0); + l->anchor(b, QGraphicsAnchorLayout::Right, c, QGraphicsAnchorLayout::Left, 0); + l->anchor(c, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); + l->anchor(l, QGraphicsAnchorLayout::Left, d, QGraphicsAnchorLayout::Left, 0); + l->anchor(d, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); QCOMPARE(l->count(), 4); |