From 4610f2b6e28c97b73b7231cac33b828f17b99ca1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Wed, 1 Jul 2009 11:50:45 +0200 Subject: Add QGraphicsLayout::anchor() overloads and query the default spacing. This commit fixes several related issues: 1. QGAL::anchor() had a spacing argument that defaulted to 0. That made it impossible to know if the user meant that the spacing should be 0 or if the spacing should be picked from the style. Instead we have to overload anchor, so now we have one function that does not take spacing as an argument. That one will create an anchor where the spacing is queried from the style. The other overload allows the user to explicitly set the spacing, thus the default spacing is ignored. 2. Make sure we pick up the spacing correctly from the style if needed. setAnchorSizeHintsFromDefaults() will set the correct spacing on anchors that was created without specifying a spacing value. 3. Add QGAL::anchor(Qt::Corner, ...) convenience function with an overload (for the same reason as explained in 1.) 4. Added QGraphicsAnchorLayoutPrivate::anchor() as a helper function that is called from all the 4 public API anchor() functions so that we don't need to have duplicate code for argument checking etc. 5. Fix autotests. They assumed that anchor() without a spacing argument created a spacing of 0. --- src/gui/graphicsview/qgraphicsanchorlayout.cpp | 138 ++++++++++++++------- src/gui/graphicsview/qgraphicsanchorlayout.h | 12 +- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 121 ++++++++++++++++++ src/gui/graphicsview/qgraphicsanchorlayout_p.h | 25 +++- .../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 a86626b..31cc911 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 74075ff..1f622eb 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 502da5d..8b661e3 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(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 &g = graph[orientation]; + QSet setOfVertices = g.vertices(); + + for (QSet::const_iterator it = setOfVertices.begin(); it != setOfVertices.end(); ++it) { + AnchorVertex *v = *it; + QList 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 beginningKey; diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 605a8e2..9e6c1bc 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 constraintsFromSizeHints(const QList &anchors); diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index de6caac..10b55d7 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -2,6 +2,7 @@ #include #include #include +#include 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); -- cgit v0.12