From 14c6433781fb946aab6e7f77fd190469e5fcfb94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Wed, 19 Aug 2009 11:46:06 +0200 Subject: update API to what was agreed on the API review meeting yesterday: The changes are: * Move enums in QGraphicsAnchorLayout::Edge to Qt::AnchorPoint. Prefix them with Anchor since they are not edges in general. * Rename anchor() to addAnchor() * Rename anchorCorner() -> addCornerAnchors() * Rename anchorWidth() -> addLeftAndRightAnchors() * Rename anchorHeight() -> addTopAndBottomAnchors() * Rename anchorGeometry() -> addAllAnchors() * remove the overloads that take a spacing argument, and add setAnchorSpacing() to accommodate for that. * Added anchorSpacing() (implementation missing) * Added unsetAnchorSpacing(). (implementation missing) * made sizeHint() protected. Updated all examples and autotest to reflect this API change. --- examples/graphicsview/anchorlayout/main.cpp | 81 +++-- examples/layouts/anchorlayout/window.cpp | 35 +- examples/layouts/anchorlayout/window.h | 4 +- src/corelib/global/qnamespace.h | 11 + src/gui/graphicsview/qgraphicsanchorlayout.cpp | 140 +++----- src/gui/graphicsview/qgraphicsanchorlayout.h | 109 ++---- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 238 +++++++------ src/gui/graphicsview/qgraphicsanchorlayout_p.h | 83 +++-- .../tst_qgraphicsanchorlayout.cpp | 379 +++++++++++++-------- 9 files changed, 584 insertions(+), 496 deletions(-) diff --git a/examples/graphicsview/anchorlayout/main.cpp b/examples/graphicsview/anchorlayout/main.cpp index 1c87fa0..5427bbf 100644 --- a/examples/graphicsview/anchorlayout/main.cpp +++ b/examples/graphicsview/anchorlayout/main.cpp @@ -44,37 +44,60 @@ int main(int argc, char **argv) w->setLayout(l); // vertical - 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, 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, 0); - l->anchor(e, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); - - l->anchor(c, QGraphicsAnchorLayout::Top, f, QGraphicsAnchorLayout::Top, 0); - l->anchor(c, QGraphicsAnchorLayout::VCenter, f, QGraphicsAnchorLayout::Bottom, 0); - l->anchor(f, QGraphicsAnchorLayout::Bottom, g, QGraphicsAnchorLayout::Top, 0); - l->anchor(c, QGraphicsAnchorLayout::Bottom, g, QGraphicsAnchorLayout::Bottom, 0); + l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorTop, l, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorTop, l, Qt::AnchorTop, 0); + + l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorTop, a, Qt::AnchorBottom, 0); + l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorTop, b, Qt::AnchorBottom, 0); + l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, d, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, e, Qt::AnchorTop, 0); + + l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(d, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(e, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + + l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorTop, f, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom, 0); + l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop); + l->setAnchorSpacing(f, Qt::AnchorBottom, g, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorBottom, g, Qt::AnchorBottom, 0); // horizontal - 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, 0); - l->anchor(c, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left, 0); - - 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); - - l->anchor(l, QGraphicsAnchorLayout::Left, f, QGraphicsAnchorLayout::Left, 0); - l->anchor(l, QGraphicsAnchorLayout::Left, g, QGraphicsAnchorLayout::Left, 0); - l->anchor(f, QGraphicsAnchorLayout::Right, g, QGraphicsAnchorLayout::Right, 0); + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); + l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, d, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); + + l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, c, Qt::AnchorLeft, 0); + l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(c, Qt::AnchorRight, e, Qt::AnchorLeft, 0); + + l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(b, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(e, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(d, Qt::AnchorRight, e, Qt::AnchorLeft, 0); + + l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, f, Qt::AnchorLeft, 0); + l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, g, Qt::AnchorLeft, 0); + l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight); + l->setAnchorSpacing(f, Qt::AnchorRight, g, Qt::AnchorRight, 0); scene.addItem(w); scene.setBackgroundBrush(Qt::darkGreen); diff --git a/examples/layouts/anchorlayout/window.cpp b/examples/layouts/anchorlayout/window.cpp index d8d68e2..cab1b60 100644 --- a/examples/layouts/anchorlayout/window.cpp +++ b/examples/layouts/anchorlayout/window.cpp @@ -190,17 +190,17 @@ void Window::rebuildLayout() QGraphicsLayoutItem *startItem = layoutItemAt(m_ui.anchors->model(), i, 0); if (!startItem) continue; - QGraphicsAnchorLayout::Edge startEdge = (QGraphicsAnchorLayout::Edge)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); + Qt::AnchorPoint startEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); if (!ok) continue; QGraphicsLayoutItem *endItem = layoutItemAt(m_ui.anchors->model(), i, 2); if (!endItem) continue; - QGraphicsAnchorLayout::Edge endEdge = (QGraphicsAnchorLayout::Edge)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); + Qt::AnchorPoint endEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); if (!ok) continue; - m_layout->anchor(startItem, startEdge, endItem, endEdge); + m_layout->addAnchor(startItem, startEdge, endItem, endEdge); } } @@ -232,8 +232,8 @@ static const char *strEdges[] = {"Left", "VCenter", "Bottom"}; -void Window::setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, QGraphicsAnchorLayout::Edge startEdge, - QGraphicsLayoutItem *endItem, const QString &endName, QGraphicsAnchorLayout::Edge endEdge, int row /*= -1*/) +void Window::setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, Qt::AnchorPoint startEdge, + QGraphicsLayoutItem *endItem, const QString &endName, Qt::AnchorPoint endEdge, int row /*= -1*/) { if (row == -1) { row = m_ui.anchors->rowCount(); @@ -286,7 +286,7 @@ void Window::addAnchorRow() QString defaultName = defaultLayoutItem->isLayout() ? QLatin1String("layout") : defaultLayoutItem->graphicsItem()->data(0).toString(); - setAnchorData(defaultLayoutItem, defaultName, QGraphicsAnchorLayout::Right, defaultLayoutItem, defaultName, QGraphicsAnchorLayout::Left, rc); + setAnchorData(defaultLayoutItem, defaultName, Qt::AnchorRight, defaultLayoutItem, defaultName, Qt::AnchorLeft, rc); rebuildLayout(); } } @@ -324,7 +324,6 @@ bool Window::saveLayout(const QString& fileName) xml.writeAttribute(QLatin1String("id"), name); for (int p = 0; p < 3; ++p) { const char *propertyNames[] = {"minimumSize", "preferredSize", "maximumSize"}; - int b; typedef QSizeF (QGraphicsLayoutItem::*QGLISizeGetter)(void) const; QGLISizeGetter sizeGetters[] = { &QGraphicsLayoutItem::minimumSize, &QGraphicsLayoutItem::preferredSize, @@ -353,13 +352,13 @@ bool Window::saveLayout(const QString& fileName) QGraphicsLayoutItem *startItem = layoutItemAt(m_ui.anchors->model(), i, 0); if (!startItem) continue; - QGraphicsAnchorLayout::Edge startEdge = (QGraphicsAnchorLayout::Edge)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); + Qt::AnchorPoint startEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 1)->data(Qt::UserRole).toInt(&ok)); if (!ok) continue; QGraphicsLayoutItem *endItem = layoutItemAt(m_ui.anchors->model(), i, 2); if (!endItem) continue; - QGraphicsAnchorLayout::Edge endEdge = (QGraphicsAnchorLayout::Edge)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); + Qt::AnchorPoint endEdge = (Qt::AnchorPoint)(m_ui.anchors->item(i, 3)->data(Qt::UserRole).toInt(&ok)); if (!ok) continue; @@ -416,24 +415,24 @@ static bool parseProperty(QXmlStreamReader *xml, QString *name, QSizeF *size) return false; } -static bool parseEdge(const QString &itemEdge, QByteArray *id, QGraphicsAnchorLayout::Edge *edge) +static bool parseEdge(const QString &itemEdge, QByteArray *id, Qt::AnchorPoint *edge) { QStringList item_edge = itemEdge.split(QLatin1Char('.')); bool ok = item_edge.count() == 2; if (ok) { QByteArray strEdge = item_edge.at(1).toAscii().toLower(); if (strEdge == "left") { - *edge = QGraphicsAnchorLayout::Left; + *edge = Qt::AnchorLeft; } else if (strEdge == "hcenter") { - *edge = QGraphicsAnchorLayout::HCenter; + *edge = Qt::AnchorHorizontalCenter; } else if (strEdge == "right") { - *edge = QGraphicsAnchorLayout::Right; + *edge = Qt::AnchorRight; } else if (strEdge == "top") { - *edge = QGraphicsAnchorLayout::Top; + *edge = Qt::AnchorTop; } else if (strEdge == "vcenter") { - *edge = QGraphicsAnchorLayout::VCenter; + *edge = Qt::AnchorVerticalCenter; } else if (strEdge == "bottom") { - *edge = QGraphicsAnchorLayout::Bottom; + *edge = Qt::AnchorBottom; } else { ok = false; } @@ -482,7 +481,7 @@ bool Window::loadLayout(const QString& fileName, QGraphicsAnchorLayout *layout) QString first = attrs.value("first").toString(); QString second = attrs.value("second").toString(); QByteArray startID; - QGraphicsAnchorLayout::Edge startEdge; + Qt::AnchorPoint startEdge; QGraphicsLayoutItem *startItem = 0; if (parseEdge(first, &startID, &startEdge)) { if (startID == "this") { @@ -497,7 +496,7 @@ bool Window::loadLayout(const QString& fileName, QGraphicsAnchorLayout *layout) } QByteArray endID; - QGraphicsAnchorLayout::Edge endEdge; + Qt::AnchorPoint endEdge; QGraphicsLayoutItem *endItem = 0; if (parseEdge(second, &endID, &endEdge)) { if (endID == "this") { diff --git a/examples/layouts/anchorlayout/window.h b/examples/layouts/anchorlayout/window.h index c81dbac..f87b2c9 100644 --- a/examples/layouts/anchorlayout/window.h +++ b/examples/layouts/anchorlayout/window.h @@ -36,8 +36,8 @@ private: void setItemData(const QString &name, const QSizeF &min, const QSizeF &pref, const QSizeF &max); QGraphicsLayoutItem *addItem(const QString &name = QString()); void addAnchorRow(); - void setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, QGraphicsAnchorLayout::Edge startEdge, - QGraphicsLayoutItem *endItem, const QString &endName, QGraphicsAnchorLayout::Edge endEdge, int row = -1); + void setAnchorData(QGraphicsLayoutItem *startItem, const QString &startName, Qt::AnchorPoint startEdge, + QGraphicsLayoutItem *endItem, const QString &endName, Qt::AnchorPoint endEdge, int row = -1); bool saveLayout(const QString& fileName); bool loadLayout(const QString& fileName, QGraphicsAnchorLayout *layout); diff --git a/src/corelib/global/qnamespace.h b/src/corelib/global/qnamespace.h index 7770fd6..5b63fe1 100644 --- a/src/corelib/global/qnamespace.h +++ b/src/corelib/global/qnamespace.h @@ -1419,6 +1419,17 @@ public: RightToLeft }; + enum AnchorPoint { + AnchorLeft = 0, + AnchorHorizontalCenter, + AnchorRight, + AnchorTop, + AnchorVerticalCenter, + AnchorBottom + }; + + + enum DropAction { CopyAction = 0x1, MoveAction = 0x2, diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index a0e1101..db79dae 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -56,7 +56,7 @@ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; QGraphicsWidget *a = new QGraphicsWidget; QGraphicsWidget *b = new QGraphicsWidget; - l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left); + l->anchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); \endcode Here is the right edge of item A anchored to the left edge of item B, with the result that @@ -114,7 +114,7 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout() /*! * 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. + * 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 @@ -126,31 +126,27 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout() * the default vertical spacing). For all other anchor combinations, the spacing will be 0. * All anchoring functions will follow this rule. * - * \sa removeAnchor, anchorCorner, anchorWidth, anchorHeight, anchorGeometry + * The spacing can also be set manually by using setAnchorSpacing() method. + * + * \sa removeAnchor, addCornerAnchors, addLeftAndRightAnchors, addTopAndBottomAnchors, addAllAnchors */ -void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, - Edge firstEdge, - QGraphicsLayoutItem *secondItem, - Edge secondEdge) +void QGraphicsAnchorLayout::addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + QGraphicsLayoutItem *secondItem, Qt::AnchorPoint 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) +void QGraphicsAnchorLayout::setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge, + qreal spacing) { Q_D(QGraphicsAnchorLayout); - d->anchor(firstItem, firstEdge, secondItem, secondEdge, &spacing); + + if (!d->setAnchorSize(firstItem, firstEdge, secondItem, secondEdge, spacing)) { + qWarning("setAnchorSpacing: The anchor does not exist."); + } invalidate(); } @@ -163,14 +159,14 @@ void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, * 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); + * layout->addAnchor(layout, Qt::AnchorTop, b, Qt::AnchorTop); + * layout->addAnchor(layout, Qt::AnchorLeft, b, Qt::AnchorLeft); * \endcode * * has the same effect as * * \code - * layout->anchorCorner(layout, Qt::TopLeft, b, Qt::TopLeft); + * layout->addCornerAnchors(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 @@ -179,116 +175,76 @@ void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, * \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::anchorCorner(QGraphicsLayoutItem *firstItem, - Qt::Corner firstCorner, - QGraphicsLayoutItem *secondItem, - Qt::Corner secondCorner) +void QGraphicsAnchorLayout::addCornerAnchors(QGraphicsLayoutItem *firstItem, + Qt::Corner firstCorner, + QGraphicsLayoutItem *secondItem, + Qt::Corner secondCorner) { Q_D(QGraphicsAnchorLayout); // Horizontal anchor - QGraphicsAnchorLayout::Edge firstEdge = (firstCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left); - QGraphicsAnchorLayout::Edge secondEdge = (secondCorner & 1 ? QGraphicsAnchorLayout::Right: QGraphicsAnchorLayout::Left); + Qt::AnchorPoint firstEdge = (firstCorner & 1 ? Qt::AnchorRight: Qt::AnchorLeft); + Qt::AnchorPoint secondEdge = (secondCorner & 1 ? Qt::AnchorRight: Qt::AnchorLeft); d->anchor(firstItem, firstEdge, secondItem, secondEdge); // Vertical anchor - firstEdge = (firstCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top); - secondEdge = (secondCorner & 2 ? QGraphicsAnchorLayout::Bottom: QGraphicsAnchorLayout::Top); + firstEdge = (firstCorner & 2 ? Qt::AnchorBottom: Qt::AnchorTop); + secondEdge = (secondCorner & 2 ? Qt::AnchorBottom: Qt::AnchorTop); 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::anchorCorner(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(); -} - -/*! - \fn QGraphicsAnchorLayout::anchorWidth(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo = 0) + \fn QGraphicsAnchorLayout::addLeftAndRightAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge) This convenience function is equivalent to calling \code - if (!relativeTo) - relativeTo = lay; - lay->anchor(relativeTo, QGraphicsAnchorLayout::Left, item, QGraphicsAnchorLayout::Left); - lay->anchor(relativeTo, QGraphicsAnchorLayout::Right, item, QGraphicsAnchorLayout::Right); + l->addAnchor(firstEdge, Qt::AnchorLeft, secondEdge, Qt::AnchorLeft); + l->addAnchor(firstEdge, Qt::AnchorRight, secondEdge, Qt::AnchorRight); \endcode */ /*! - \fn QGraphicsAnchorLayout::anchorWidth(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo, qreal spacing) - - \overload - - By calling this function the caller can specify the magnitude of the anchor with \a spacing. -*/ - -/*! - \fn QGraphicsAnchorLayout::anchorHeight(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo = 0) + \fn QGraphicsAnchorLayout::addTopAndBottomAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge) This convenience function is equivalent to calling \code - if (!relativeTo) - relativeTo = lay; - lay->anchor(relativeTo, QGraphicsAnchorLayout::Top, item, QGraphicsAnchorLayout::Top); - lay->anchor(relativeTo, QGraphicsAnchorLayout::Bottom, item, QGraphicsAnchorLayout::Bottom); + l->addAnchor(firstEdge, Qt::AnchorTop, secondEdge, Qt::AnchorTop); + l->addAnchor(firstEdge, Qt::AnchorBottom, secondEdge, Qt::AnchorBottom); \endcode */ /*! - \fn QGraphicsAnchorLayout::anchorHeight(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo, qreal spacing) - - \overload - - By calling this function the caller can specify the magnitude of the anchor with \a spacing. -*/ - -/*! - \fn QGraphicsAnchorLayout::anchorGeometry(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo = 0) + \fn QGraphicsAnchorLayout::addAllAnchors(QGraphicsLayoutItem *firstEdge, QGraphicsLayoutItem *secondEdge) This convenience function is equivalent to calling \code - anchorWidth(item, relativeTo); - anchorHeight(item, relativeTo); + l->addLeftAndRightAnchors(firstEdge, secondEdge); + l->addTopAndBottomAnchors(firstEdge, secondEdge); \endcode */ -/*! - \fn QGraphicsAnchorLayout::anchorGeometry(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo, qreal spacing) - - \overload +qreal QGraphicsAnchorLayout::anchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) const +{ + qWarning("// ### TO BE IMPLEMENTED"); + return 0; +} - By calling this function the caller can specify the magnitude of the anchor with \a spacing. -*/ +void QGraphicsAnchorLayout::unsetAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) +{ + qWarning("// ### TO BE IMPLEMENTED"); + invalidate(); +} /*! Removes the anchor between the edge \a firstEdge of item \a firstItem and the edge \a secondEdge of item \a secondItem. If such an anchor does not exist, the layout will be left unchanged. */ -void QGraphicsAnchorLayout::removeAnchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, - QGraphicsLayoutItem *secondItem, Edge secondEdge) +void QGraphicsAnchorLayout::removeAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) { Q_D(QGraphicsAnchorLayout); if ((firstItem == 0) || (secondItem == 0)) { diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.h b/src/gui/graphicsview/qgraphicsanchorlayout.h index f0ffcbd..f2335a8 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout.h @@ -59,49 +59,35 @@ class QGraphicsAnchorLayoutPrivate; class Q_GUI_EXPORT QGraphicsAnchorLayout : public QGraphicsLayout { public: - enum Edge { - Left = 0, - HCenter, - Right, - Top, - VCenter, - Bottom - }; - QGraphicsAnchorLayout(QGraphicsLayoutItem *parent = 0); virtual ~QGraphicsAnchorLayout(); - void anchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, - QGraphicsLayoutItem *secondItem, Edge secondEdge); + void addAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge); - void anchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, - QGraphicsLayoutItem *secondItem, Edge secondEdge, - qreal spacing); + void setAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge, + qreal spacing); - void anchorCorner(QGraphicsLayoutItem *firstItem, Qt::Corner firstCorner, - QGraphicsLayoutItem *secondItem, Qt::Corner secondCorner); + void addCornerAnchors(QGraphicsLayoutItem *firstItem, Qt::Corner firstCorner, + QGraphicsLayoutItem *secondItem, Qt::Corner secondCorner); - void anchorCorner(QGraphicsLayoutItem *firstItem, Qt::Corner firstCorner, - QGraphicsLayoutItem *secondItem, Qt::Corner secondCorner, - qreal spacing); + inline void addLeftAndRightAnchors(QGraphicsLayoutItem *firstItem, + QGraphicsLayoutItem *secondItem); - void removeAnchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, - QGraphicsLayoutItem *secondItem, Edge secondEdge); + inline void addTopAndBottomAnchors(QGraphicsLayoutItem *firstItem, + QGraphicsLayoutItem *secondItem); - inline void anchorWidth(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo = 0); - inline void anchorWidth(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo, qreal spacing); + inline void addAllAnchors(QGraphicsLayoutItem *firstItem, + QGraphicsLayoutItem *secondItem); - inline void anchorHeight(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo = 0); - inline void anchorHeight(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo, qreal spacing); + qreal anchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge) const; + void unsetAnchorSpacing(const QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge); - inline void anchorGeometry(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo = 0); - inline void anchorGeometry(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo, qreal spacing); + void removeAnchor(QGraphicsLayoutItem *firstItem, Qt::AnchorPoint firstEdge, + QGraphicsLayoutItem *secondItem, Qt::AnchorPoint secondEdge); void setHorizontalSpacing(qreal spacing); void setVerticalSpacing(qreal spacing); @@ -115,6 +101,7 @@ public: QGraphicsLayoutItem *itemAt(int index) const; void invalidate(); +protected: QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; private: @@ -122,58 +109,26 @@ private: Q_DECLARE_PRIVATE(QGraphicsAnchorLayout) }; -void QGraphicsAnchorLayout::anchorWidth(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo) -{ - if (!relativeTo) - relativeTo = this; - - anchor(relativeTo, Left, item, Left); - anchor(item, Right, relativeTo, Right); -} - -void QGraphicsAnchorLayout::anchorWidth(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo, - qreal spacing) -{ - anchor(relativeTo, Left, item, Left, spacing); - anchor(item, Right, relativeTo, Right, spacing); -} - -void QGraphicsAnchorLayout::anchorHeight(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo) -{ - if (!relativeTo) - relativeTo = this; - - anchor(relativeTo, Top, item, Top); - anchor(item, Bottom, relativeTo, Bottom); -} -void QGraphicsAnchorLayout::anchorHeight(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo, - qreal spacing) +void QGraphicsAnchorLayout::addLeftAndRightAnchors(QGraphicsLayoutItem *firstItem, + QGraphicsLayoutItem *secondItem) { - anchor(relativeTo, Top, item, Top, spacing); - anchor(item, Bottom, relativeTo, Bottom, spacing); + addAnchor(secondItem, Qt::AnchorLeft, firstItem, Qt::AnchorLeft); + addAnchor(firstItem, Qt::AnchorRight, secondItem, Qt::AnchorRight); } -void QGraphicsAnchorLayout::anchorGeometry(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo) +void QGraphicsAnchorLayout::addTopAndBottomAnchors(QGraphicsLayoutItem *firstItem, + QGraphicsLayoutItem *secondItem) { - if (!relativeTo) - relativeTo = this; - - anchorWidth(item, relativeTo); - anchorHeight(item, relativeTo); + addAnchor(secondItem, Qt::AnchorTop, firstItem, Qt::AnchorTop); + addAnchor(firstItem, Qt::AnchorBottom, secondItem, Qt::AnchorBottom); } -void QGraphicsAnchorLayout::anchorGeometry(QGraphicsLayoutItem *item, - QGraphicsLayoutItem *relativeTo, - qreal spacing) +void QGraphicsAnchorLayout::addAllAnchors(QGraphicsLayoutItem *firstItem, + QGraphicsLayoutItem *secondItem) { - anchorWidth(item, relativeTo, spacing); - anchorHeight(item, relativeTo, spacing); + addLeftAndRightAnchors(firstItem, secondItem); + addTopAndBottomAnchors(firstItem, secondItem); } #endif diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 4e45fc7..436ce2c 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -56,14 +56,14 @@ void AnchorData::refreshSizeHints(qreal effectiveSpacing) minSize = item->minimumWidth(); prefSize = item->preferredWidth(); maxSize = item->maximumWidth(); - hasCenter = (from->m_edge == QGraphicsAnchorLayout::HCenter - || to->m_edge == QGraphicsAnchorLayout::HCenter); + hasCenter = (from->m_edge == Qt::AnchorHorizontalCenter + || to->m_edge == Qt::AnchorHorizontalCenter); } else { minSize = item->minimumHeight(); prefSize = item->preferredHeight(); maxSize = item->maximumHeight(); - hasCenter = (from->m_edge == QGraphicsAnchorLayout::VCenter - || to->m_edge == QGraphicsAnchorLayout::VCenter); + hasCenter = (from->m_edge == Qt::AnchorVerticalCenter + || to->m_edge == Qt::AnchorVerticalCenter); } if (hasCenter) { @@ -288,21 +288,20 @@ QGraphicsAnchorLayoutPrivate::QGraphicsAnchorLayoutPrivate() } } -QGraphicsAnchorLayout::Edge QGraphicsAnchorLayoutPrivate::oppositeEdge( - QGraphicsAnchorLayout::Edge edge) +Qt::AnchorPoint QGraphicsAnchorLayoutPrivate::oppositeEdge(Qt::AnchorPoint edge) { switch (edge) { - case QGraphicsAnchorLayout::Left: - edge = QGraphicsAnchorLayout::Right; + case Qt::AnchorLeft: + edge = Qt::AnchorRight; break; - case QGraphicsAnchorLayout::Right: - edge = QGraphicsAnchorLayout::Left; + case Qt::AnchorRight: + edge = Qt::AnchorLeft; break; - case QGraphicsAnchorLayout::Top: - edge = QGraphicsAnchorLayout::Bottom; + case Qt::AnchorTop: + edge = Qt::AnchorBottom; break; - case QGraphicsAnchorLayout::Bottom: - edge = QGraphicsAnchorLayout::Top; + case Qt::AnchorBottom: + edge = Qt::AnchorTop; break; default: break; @@ -502,8 +501,8 @@ bool QGraphicsAnchorLayoutPrivate::simplifyGraphIteration(QGraphicsAnchorLayoutP stack.push(v); QVector candidates; - const QGraphicsAnchorLayout::Edge centerEdge = pickEdge(QGraphicsAnchorLayout::HCenter, orientation); - const QGraphicsAnchorLayout::Edge layoutEdge = oppositeEdge(v->m_edge); + const Qt::AnchorPoint centerEdge = pickEdge(Qt::AnchorHorizontalCenter, orientation); + const Qt::AnchorPoint layoutEdge = oppositeEdge(v->m_edge); bool dirty = false; @@ -710,9 +709,9 @@ void QGraphicsAnchorLayoutPrivate::restoreSimplifiedGraph(Orientation orientatio } QGraphicsAnchorLayoutPrivate::Orientation -QGraphicsAnchorLayoutPrivate::edgeOrientation(QGraphicsAnchorLayout::Edge edge) +QGraphicsAnchorLayoutPrivate::edgeOrientation(Qt::AnchorPoint edge) { - return edge > QGraphicsAnchorLayout::Right ? Vertical : Horizontal; + return edge > Qt::AnchorRight ? Vertical : Horizontal; } /*! @@ -731,22 +730,22 @@ void QGraphicsAnchorLayoutPrivate::createLayoutEdges() // Horizontal AnchorData *data = new AnchorData(0, 0, QWIDGETSIZE_MAX); - addAnchor(layout, QGraphicsAnchorLayout::Left, layout, - QGraphicsAnchorLayout::Right, data); + addAnchor(layout, Qt::AnchorLeft, layout, + Qt::AnchorRight, data); data->skipInPreferred = 1; // Set the Layout Left edge as the root of the horizontal graph. - AnchorVertex *v = internalVertex(layout, QGraphicsAnchorLayout::Left); + AnchorVertex *v = internalVertex(layout, Qt::AnchorLeft); graph[Horizontal].setRootVertex(v); // Vertical data = new AnchorData(0, 0, QWIDGETSIZE_MAX); - addAnchor(layout, QGraphicsAnchorLayout::Top, layout, - QGraphicsAnchorLayout::Bottom, data); + addAnchor(layout, Qt::AnchorTop, layout, + Qt::AnchorBottom, data); data->skipInPreferred = 1; // Set the Layout Top edge as the root of the vertical graph. - v = internalVertex(layout, QGraphicsAnchorLayout::Top); + v = internalVertex(layout, Qt::AnchorTop); graph[Vertical].setRootVertex(v); } @@ -754,11 +753,11 @@ void QGraphicsAnchorLayoutPrivate::deleteLayoutEdges() { Q_Q(QGraphicsAnchorLayout); - Q_ASSERT(internalVertex(q, QGraphicsAnchorLayout::HCenter) == NULL); - Q_ASSERT(internalVertex(q, QGraphicsAnchorLayout::VCenter) == NULL); + Q_ASSERT(internalVertex(q, Qt::AnchorHorizontalCenter) == NULL); + Q_ASSERT(internalVertex(q, Qt::AnchorVerticalCenter) == NULL); - removeAnchor(q, QGraphicsAnchorLayout::Left, q, QGraphicsAnchorLayout::Right); - removeAnchor(q, QGraphicsAnchorLayout::Top, q, QGraphicsAnchorLayout::Bottom); + removeAnchor(q, Qt::AnchorLeft, q, Qt::AnchorRight); + removeAnchor(q, Qt::AnchorTop, q, Qt::AnchorBottom); } void QGraphicsAnchorLayoutPrivate::createItemEdges(QGraphicsLayoutItem *item) @@ -773,8 +772,8 @@ void QGraphicsAnchorLayoutPrivate::createItemEdges(QGraphicsLayoutItem *item) int maximumSize = item->maximumWidth(); AnchorData *data = new AnchorData(minimumSize, preferredSize, maximumSize); - addAnchor(item, QGraphicsAnchorLayout::Left, item, - QGraphicsAnchorLayout::Right, data); + addAnchor(item, Qt::AnchorLeft, item, + Qt::AnchorRight, data); // Vertical minimumSize = item->minimumHeight(); @@ -782,8 +781,8 @@ void QGraphicsAnchorLayoutPrivate::createItemEdges(QGraphicsLayoutItem *item) maximumSize = item->maximumHeight(); data = new AnchorData(minimumSize, preferredSize, maximumSize); - addAnchor(item, QGraphicsAnchorLayout::Top, item, - QGraphicsAnchorLayout::Bottom, data); + addAnchor(item, Qt::AnchorTop, item, + Qt::AnchorBottom, data); } /*! @@ -798,14 +797,14 @@ void QGraphicsAnchorLayoutPrivate::createItemEdges(QGraphicsLayoutItem *item) these anchors must have the same time at all times. */ void QGraphicsAnchorLayoutPrivate::createCenterAnchors( - QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge) + QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge) { Orientation orientation; switch (centerEdge) { - case QGraphicsAnchorLayout::HCenter: + case Qt::AnchorHorizontalCenter: orientation = Horizontal; break; - case QGraphicsAnchorLayout::VCenter: + case Qt::AnchorVerticalCenter: orientation = Vertical; break; default: @@ -820,15 +819,15 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors( return; // Orientation code - QGraphicsAnchorLayout::Edge firstEdge; - QGraphicsAnchorLayout::Edge lastEdge; + Qt::AnchorPoint firstEdge; + Qt::AnchorPoint lastEdge; if (orientation == Horizontal) { - firstEdge = QGraphicsAnchorLayout::Left; - lastEdge = QGraphicsAnchorLayout::Right; + firstEdge = Qt::AnchorLeft; + lastEdge = Qt::AnchorRight; } else { - firstEdge = QGraphicsAnchorLayout::Top; - lastEdge = QGraphicsAnchorLayout::Bottom; + firstEdge = Qt::AnchorTop; + lastEdge = Qt::AnchorBottom; } AnchorVertex *first = internalVertex(item, firstEdge); @@ -858,15 +857,15 @@ void QGraphicsAnchorLayoutPrivate::createCenterAnchors( } void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( - QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge, + QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge, bool substitute) { Orientation orientation; switch (centerEdge) { - case QGraphicsAnchorLayout::HCenter: + case Qt::AnchorHorizontalCenter: orientation = Horizontal; break; - case QGraphicsAnchorLayout::VCenter: + case Qt::AnchorVerticalCenter: orientation = Vertical; break; default: @@ -877,15 +876,15 @@ void QGraphicsAnchorLayoutPrivate::removeCenterAnchors( Q_ASSERT(!graphSimplified[orientation]); // Orientation code - QGraphicsAnchorLayout::Edge firstEdge; - QGraphicsAnchorLayout::Edge lastEdge; + Qt::AnchorPoint firstEdge; + Qt::AnchorPoint lastEdge; if (orientation == Horizontal) { - firstEdge = QGraphicsAnchorLayout::Left; - lastEdge = QGraphicsAnchorLayout::Right; + firstEdge = Qt::AnchorLeft; + lastEdge = Qt::AnchorRight; } else { - firstEdge = QGraphicsAnchorLayout::Top; - lastEdge = QGraphicsAnchorLayout::Bottom; + firstEdge = Qt::AnchorTop; + lastEdge = Qt::AnchorBottom; } AnchorVertex *center = internalVertex(item, centerEdge); @@ -952,11 +951,11 @@ void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem * // so that we can remove those easily AnchorVertex *first = internalVertex(item, orientation == Horizontal ? - QGraphicsAnchorLayout::Left : - QGraphicsAnchorLayout::Top); + Qt::AnchorLeft : + Qt::AnchorTop); AnchorVertex *center = internalVertex(item, orientation == Horizontal ? - QGraphicsAnchorLayout::HCenter : - QGraphicsAnchorLayout::VCenter); + Qt::AnchorHorizontalCenter : + Qt::AnchorVerticalCenter); // Skip if no center constraints exist if (!center) @@ -981,26 +980,26 @@ void QGraphicsAnchorLayoutPrivate::removeCenterConstraints(QGraphicsLayoutItem * * If \a spacing is 0, it will pick up the spacing defined by the style. */ void QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem, - QGraphicsAnchorLayout::Edge firstEdge, + Qt::AnchorPoint firstEdge, QGraphicsLayoutItem *secondItem, - QGraphicsAnchorLayout::Edge secondEdge, + Qt::AnchorPoint secondEdge, qreal *spacing) { Q_Q(QGraphicsAnchorLayout); if ((firstItem == 0) || (secondItem == 0)) { - qWarning("QGraphicsAnchorLayout::anchor(): " + qWarning("QGraphicsAnchorLayout::addAnchor(): " "Cannot anchor NULL items"); return; } if (firstItem == secondItem) { - qWarning("QGraphicsAnchorLayout::anchor(): " + qWarning("QGraphicsAnchorLayout::addAnchor(): " "Cannot anchor the item to itself"); return; } if (edgeOrientation(secondEdge) != edgeOrientation(firstEdge)) { - qWarning("QGraphicsAnchorLayout::anchor(): " + qWarning("QGraphicsAnchorLayout::addAnchor(): " "Cannot anchor edges of different orientations"); return; } @@ -1047,7 +1046,7 @@ void QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem, // Right ? 0 0 if (firstItem != q && secondItem != q - && pickEdge(firstEdge, Horizontal) != QGraphicsAnchorLayout::HCenter + && pickEdge(firstEdge, Horizontal) != Qt::AnchorHorizontalCenter && oppositeEdge(firstEdge) == secondEdge) { data = new AnchorData; // ask the style later } else { @@ -1064,9 +1063,9 @@ void QGraphicsAnchorLayoutPrivate::anchor(QGraphicsLayoutItem *firstItem, } void QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *firstItem, - QGraphicsAnchorLayout::Edge firstEdge, + Qt::AnchorPoint firstEdge, QGraphicsLayoutItem *secondItem, - QGraphicsAnchorLayout::Edge secondEdge, + Qt::AnchorPoint secondEdge, AnchorData *data) { Q_Q(QGraphicsAnchorLayout); @@ -1099,10 +1098,51 @@ void QGraphicsAnchorLayoutPrivate::addAnchor(QGraphicsLayoutItem *firstItem, graph[edgeOrientation(firstEdge)].createEdge(v1, v2, data); } +void QGraphicsAnchorLayoutPrivate::removeAnchor(QGraphicsLayoutItem *firstItem, + Qt::AnchorPoint firstEdge, + QGraphicsLayoutItem *secondItem, + Qt::AnchorPoint secondEdge) +{ + // Guarantee that the graph is no simplified when adding this anchor, + // anchor manipulation always happen in the full graph + restoreSimplifiedGraph(edgeOrientation(firstEdge)); + + // Look for both vertices + AnchorVertex *v1 = internalVertex(firstItem, firstEdge); + AnchorVertex *v2 = internalVertex(secondItem, secondEdge); + + Q_ASSERT(v1 && v2); + + // Remove edge from graph + graph[edgeOrientation(firstEdge)].removeEdge(v1, v2); + + // Decrease vertices reference count (may trigger a deletion) + removeInternalVertex(firstItem, firstEdge); + removeInternalVertex(secondItem, secondEdge); +} + +bool QGraphicsAnchorLayoutPrivate::setAnchorSize(const QGraphicsLayoutItem *firstItem, + Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, + Qt::AnchorPoint secondEdge, + qreal anchorSize) +{ + // ### we can avoid restoration if we really want to + restoreSimplifiedGraph(edgeOrientation(firstEdge)); + AnchorVertex *v1 = internalVertex(firstItem, firstEdge); + AnchorVertex *v2 = internalVertex(secondItem, secondEdge); + + AnchorData *data = graph[edgeOrientation(firstEdge)].edgeData(v1, v2); + if (data) + data->setFixedSize(anchorSize); + + return data; +} + AnchorVertex *QGraphicsAnchorLayoutPrivate::addInternalVertex(QGraphicsLayoutItem *item, - QGraphicsAnchorLayout::Edge edge) + Qt::AnchorPoint edge) { - QPair pair(item, edge); + QPair pair(item, edge); QPair v = m_vertexList.value(pair); if (!v.first) { @@ -1121,9 +1161,9 @@ AnchorVertex *QGraphicsAnchorLayoutPrivate::addInternalVertex(QGraphicsLayoutIte * returns 0 if it did not exist. */ void QGraphicsAnchorLayoutPrivate::removeInternalVertex(QGraphicsLayoutItem *item, - QGraphicsAnchorLayout::Edge edge) + Qt::AnchorPoint edge) { - QPair pair(item, edge); + QPair pair(item, edge); QPair v = m_vertexList.value(pair); if (!v.first) { @@ -1141,37 +1181,14 @@ void QGraphicsAnchorLayoutPrivate::removeInternalVertex(QGraphicsLayoutItem *ite m_vertexList.insert(pair, v); if ((v.second == 2) && - ((edge == QGraphicsAnchorLayout::HCenter) || - (edge == QGraphicsAnchorLayout::VCenter))) { + ((edge == Qt::AnchorHorizontalCenter) || + (edge == Qt::AnchorVerticalCenter))) { removeCenterAnchors(item, edge, true); } } } -void QGraphicsAnchorLayoutPrivate::removeAnchor(QGraphicsLayoutItem *firstItem, - QGraphicsAnchorLayout::Edge firstEdge, - QGraphicsLayoutItem *secondItem, - QGraphicsAnchorLayout::Edge secondEdge) -{ - // Guarantee that the graph is no simplified when adding this anchor, - // anchor manipulation always happen in the full graph - restoreSimplifiedGraph(edgeOrientation(firstEdge)); - - // Look for both vertices - AnchorVertex *v1 = internalVertex(firstItem, firstEdge); - AnchorVertex *v2 = internalVertex(secondItem, secondEdge); - - Q_ASSERT(v1 && v2); - - // Remove edge from graph - graph[edgeOrientation(firstEdge)].removeEdge(v1, v2); - - // Decrease vertices reference count (may trigger a deletion) - removeInternalVertex(firstItem, firstEdge); - removeInternalVertex(secondItem, secondEdge); -} - -void QGraphicsAnchorLayoutPrivate::removeVertex(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge edge) +void QGraphicsAnchorLayoutPrivate::removeVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge) { if (AnchorVertex *v = internalVertex(item, edge)) { Graph &g = graph[edgeOrientation(edge)]; @@ -1190,14 +1207,13 @@ void QGraphicsAnchorLayoutPrivate::removeAnchors(QGraphicsLayoutItem *item) Q_ASSERT(!graphSimplified[Horizontal] && !graphSimplified[Vertical]); // remove the center anchor first!! - removeCenterAnchors(item, QGraphicsAnchorLayout::HCenter, false); - removeVertex(item, QGraphicsAnchorLayout::Left); - removeVertex(item, QGraphicsAnchorLayout::Right); - - removeCenterAnchors(item, QGraphicsAnchorLayout::VCenter, false); - removeVertex(item, QGraphicsAnchorLayout::Top); - removeVertex(item, QGraphicsAnchorLayout::Bottom); + removeCenterAnchors(item, Qt::AnchorHorizontalCenter, false); + removeVertex(item, Qt::AnchorLeft); + removeVertex(item, Qt::AnchorRight); + removeCenterAnchors(item, Qt::AnchorVerticalCenter, false); + removeVertex(item, Qt::AnchorTop); + removeVertex(item, Qt::AnchorBottom); } /*! @@ -1225,14 +1241,14 @@ void QGraphicsAnchorLayoutPrivate::removeAnchors(QGraphicsLayoutItem *item) and Layout Right as another item's Left. */ void QGraphicsAnchorLayoutPrivate::correctEdgeDirection(QGraphicsLayoutItem *&firstItem, - QGraphicsAnchorLayout::Edge &firstEdge, + Qt::AnchorPoint &firstEdge, QGraphicsLayoutItem *&secondItem, - QGraphicsAnchorLayout::Edge &secondEdge) + Qt::AnchorPoint &secondEdge) { Q_Q(QGraphicsAnchorLayout); - QGraphicsAnchorLayout::Edge effectiveFirst = firstEdge; - QGraphicsAnchorLayout::Edge effectiveSecond = secondEdge; + Qt::AnchorPoint effectiveFirst = firstEdge; + Qt::AnchorPoint effectiveSecond = secondEdge; if (firstItem == q) effectiveFirst = QGraphicsAnchorLayoutPrivate::oppositeEdge(firstEdge); @@ -1375,7 +1391,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs( // objective function. // Retrieve that path - AnchorVertex *v = internalVertex(q, pickEdge(QGraphicsAnchorLayout::Right, orientation)); + AnchorVertex *v = internalVertex(q, pickEdge(Qt::AnchorRight, orientation)); GraphPath trunkPath = graphPaths[orientation].value(v); if (!trunkConstraints.isEmpty()) { @@ -1607,13 +1623,13 @@ QGraphicsAnchorLayoutPrivate::getGraphParts(Orientation orientation) // Find layout vertices and edges for the current orientation. AnchorVertex *layoutFirstVertex = \ - internalVertex(q, pickEdge(QGraphicsAnchorLayout::Left, orientation)); + internalVertex(q, pickEdge(Qt::AnchorLeft, orientation)); AnchorVertex *layoutCentralVertex = \ - internalVertex(q, pickEdge(QGraphicsAnchorLayout::HCenter, orientation)); + internalVertex(q, pickEdge(Qt::AnchorHorizontalCenter, orientation)); AnchorVertex *layoutLastVertex = \ - internalVertex(q, pickEdge(QGraphicsAnchorLayout::Right, orientation)); + internalVertex(q, pickEdge(Qt::AnchorRight, orientation)); Q_ASSERT(layoutFirstVertex && layoutLastVertex); @@ -1710,10 +1726,10 @@ void QGraphicsAnchorLayoutPrivate::setItemsGeometries() AnchorVertex *firstH, *secondH, *firstV, *secondV; foreach (QGraphicsLayoutItem *item, items) { - firstH = internalVertex(item, QGraphicsAnchorLayout::Left); - secondH = internalVertex(item, QGraphicsAnchorLayout::Right); - firstV = internalVertex(item, QGraphicsAnchorLayout::Top); - secondV = internalVertex(item, QGraphicsAnchorLayout::Bottom); + firstH = internalVertex(item, Qt::AnchorLeft); + secondH = internalVertex(item, Qt::AnchorRight); + firstV = internalVertex(item, Qt::AnchorTop); + secondV = internalVertex(item, Qt::AnchorBottom); QPointF topLeft(firstH->distance, firstV->distance); QPointF bottomRight(secondH->distance, secondV->distance); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h index 7e7cee8..742108d 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h @@ -48,7 +48,7 @@ /* The public QGraphicsAnchorLayout interface represents an anchorage point - as a pair of a and a . + as a pair of a and a . Internally though, it has a graph of anchorage points (vertices) and anchors (edges), represented by the AnchorVertex and AnchorData structs @@ -61,17 +61,17 @@ Represents a vertex (anchorage point) in the internal graph */ struct AnchorVertex { - AnchorVertex(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge edge) + AnchorVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge) : m_item(item), m_edge(edge) {} AnchorVertex() - : m_item(0), m_edge(QGraphicsAnchorLayout::Edge(0)) {} + : m_item(0), m_edge(Qt::AnchorPoint(0)) {} #ifdef QT_DEBUG inline QString toString() const; #endif QGraphicsLayoutItem *m_item; - QGraphicsAnchorLayout::Edge m_edge; + Qt::AnchorPoint m_edge; // Current distance from this vertex to the layout edge (Left or Top) // Value is calculated from the current anchors sizes. @@ -86,22 +86,22 @@ inline QString AnchorVertex::toString() const } QString edge; switch (m_edge) { - case QGraphicsAnchorLayout::Left: + case Qt::AnchorLeft: edge = QLatin1String("Left"); break; - case QGraphicsAnchorLayout::HCenter: + case Qt::AnchorHorizontalCenter: edge = QLatin1String("HorizontalCenter"); break; - case QGraphicsAnchorLayout::Right: + case Qt::AnchorRight: edge = QLatin1String("Right"); break; - case QGraphicsAnchorLayout::Top: + case Qt::AnchorTop: edge = QLatin1String("Top"); break; - case QGraphicsAnchorLayout::VCenter: + case Qt::AnchorVerticalCenter: edge = QLatin1String("VerticalCenter"); break; - case QGraphicsAnchorLayout::Bottom: + case Qt::AnchorBottom: edge = QLatin1String("Bottom"); break; default: @@ -165,6 +165,17 @@ struct AnchorData : public QSimplexVariable { QString name; #endif + inline void setFixedSize(qreal size) + { + minSize = size; + prefSize = size; + maxSize = size; + sizeAtMinimum = size; + sizeAtPreferred = size; + sizeAtMaximum = size; + hasSize = true; + } + // Anchor is semantically directed AnchorVertex *from; AnchorVertex *to; @@ -310,17 +321,17 @@ public: QGraphicsAnchorLayoutPrivate(); - static QGraphicsAnchorLayout::Edge oppositeEdge( - QGraphicsAnchorLayout::Edge edge); + static Qt::AnchorPoint oppositeEdge( + Qt::AnchorPoint edge); - static Orientation edgeOrientation(QGraphicsAnchorLayout::Edge edge); + static Orientation edgeOrientation(Qt::AnchorPoint edge); - static QGraphicsAnchorLayout::Edge pickEdge(QGraphicsAnchorLayout::Edge edge, Orientation orientation) + static Qt::AnchorPoint pickEdge(Qt::AnchorPoint edge, Orientation orientation) { if (orientation == Vertical && int(edge) <= 2) - return (QGraphicsAnchorLayout::Edge)(edge + 3); + return (Qt::AnchorPoint)(edge + 3); else if (orientation == Horizontal && int(edge) >= 3) { - return (QGraphicsAnchorLayout::Edge)(edge - 3); + return (Qt::AnchorPoint)(edge - 3); } return edge; } @@ -329,37 +340,43 @@ public: void createLayoutEdges(); void deleteLayoutEdges(); void createItemEdges(QGraphicsLayoutItem *item); - void createCenterAnchors(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge); - void removeCenterAnchors(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge centerEdge, bool substitute = true); + void createCenterAnchors(QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge); + void removeCenterAnchors(QGraphicsLayoutItem *item, Qt::AnchorPoint centerEdge, bool substitute = true); void removeCenterConstraints(QGraphicsLayoutItem *item, Orientation orientation); // helper function used by the 4 API functions void anchor(QGraphicsLayoutItem *firstItem, - QGraphicsAnchorLayout::Edge firstEdge, + Qt::AnchorPoint firstEdge, QGraphicsLayoutItem *secondItem, - QGraphicsAnchorLayout::Edge secondEdge, + Qt::AnchorPoint secondEdge, qreal *spacing = 0); // Anchor Manipulation methods void addAnchor(QGraphicsLayoutItem *firstItem, - QGraphicsAnchorLayout::Edge firstEdge, + Qt::AnchorPoint firstEdge, QGraphicsLayoutItem *secondItem, - QGraphicsAnchorLayout::Edge secondEdge, + Qt::AnchorPoint secondEdge, AnchorData *data); void removeAnchor(QGraphicsLayoutItem *firstItem, - QGraphicsAnchorLayout::Edge firstEdge, + Qt::AnchorPoint firstEdge, QGraphicsLayoutItem *secondItem, - QGraphicsAnchorLayout::Edge secondEdge); + Qt::AnchorPoint secondEdge); + + bool setAnchorSize(const QGraphicsLayoutItem *firstItem, + Qt::AnchorPoint firstEdge, + const QGraphicsLayoutItem *secondItem, + Qt::AnchorPoint secondEdge, + qreal anchorSize); void removeAnchors(QGraphicsLayoutItem *item); - void removeVertex(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge edge); + void removeVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge); void correctEdgeDirection(QGraphicsLayoutItem *&firstItem, - QGraphicsAnchorLayout::Edge &firstEdge, + Qt::AnchorPoint &firstEdge, QGraphicsLayoutItem *&secondItem, - QGraphicsAnchorLayout::Edge &secondEdge); + Qt::AnchorPoint &secondEdge); // for getting the actual spacing (will query the style if the // spacing is not explicitly set). qreal effectiveSpacing(Orientation orientation) const; @@ -377,18 +394,18 @@ public: QList constraintsFromSizeHints(const QList &anchors); QList > getGraphParts(Orientation orientation); - inline AnchorVertex *internalVertex(const QPair &itemEdge) + inline AnchorVertex *internalVertex(const QPair &itemEdge) { return m_vertexList.value(itemEdge).first; } - inline AnchorVertex *internalVertex(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge edge) + inline AnchorVertex *internalVertex(const QGraphicsLayoutItem *item, Qt::AnchorPoint edge) { - return internalVertex(qMakePair(item, edge)); + return internalVertex(qMakePair(const_cast(item), edge)); } - AnchorVertex *addInternalVertex(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge edge); - void removeInternalVertex(QGraphicsLayoutItem *item, QGraphicsAnchorLayout::Edge edge); + AnchorVertex *addInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge); + void removeInternalVertex(QGraphicsLayoutItem *item, Qt::AnchorPoint edge); // Geometry interpolation methods void setItemsGeometries(); @@ -421,7 +438,7 @@ public: // Mapping between high level anchorage points (Item, Edge) to low level // ones (Graph Vertices) - QHash, QPair > m_vertexList; + QHash, QPair > m_vertexList; // Internal graph of anchorage points and anchors, for both orientations Graph graph[2]; diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp index 624e80d..a579ba5 100644 --- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp +++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp @@ -57,7 +57,7 @@ void tst_QGraphicsAnchorLayout::simple() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - l->anchor(w1, QGraphicsAnchorLayout::Right, w2, QGraphicsAnchorLayout::Left); + l->addAnchor(w1, Qt::AnchorRight, w2, Qt::AnchorLeft); QGraphicsWidget p; p.setLayout(l); @@ -81,28 +81,45 @@ void tst_QGraphicsAnchorLayout::diagonal() l->setContentsMargins(0, 0, 0, 0); // vertical - 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, 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, 0); - l->anchor(e, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); + l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorTop, l, Qt::AnchorTop, 0); + + l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorTop, l, Qt::AnchorTop, 0); + + l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorTop, a, Qt::AnchorBottom, 0); + l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorTop, b, Qt::AnchorBottom, 0); + l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, d, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, e, Qt::AnchorTop, 0); + + l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(d, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(e, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); // horizontal - 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, 0); - l->anchor(c, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left, 0); - - 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); + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); + l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, d, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); + + l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, c, Qt::AnchorLeft, 0); + l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(c, Qt::AnchorRight, e, Qt::AnchorLeft, 0); + + l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(b, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(e, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(d, Qt::AnchorRight, e, Qt::AnchorLeft, 0); QCOMPARE(l->count(), 5); @@ -180,23 +197,39 @@ void tst_QGraphicsAnchorLayout::parallel() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - 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); + l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); + l->setAnchorSpacing(l, Qt::AnchorTop, a, Qt::AnchorTop, 0); + l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorBottom, b, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorBottom, c, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, d, Qt::AnchorTop, 0); + l->addAnchor(d, Qt::AnchorBottom, e, Qt::AnchorTop); + l->setAnchorSpacing(d, Qt::AnchorBottom, e, Qt::AnchorTop, 0); + l->addAnchor(e, Qt::AnchorBottom, f, Qt::AnchorTop); + l->setAnchorSpacing(e, Qt::AnchorBottom, f, Qt::AnchorTop, 0); + l->addAnchor(f, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(f, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, c, Qt::AnchorLeft, 0); + l->addAnchor(b, Qt::AnchorRight, d, Qt::AnchorLeft); + l->setAnchorSpacing(b, Qt::AnchorRight, d, Qt::AnchorLeft, 0); + l->addAnchor(b, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(b, Qt::AnchorRight, e, Qt::AnchorLeft, 0); + l->addAnchor(c, Qt::AnchorRight, f, Qt::AnchorLeft); + l->setAnchorSpacing(c, Qt::AnchorRight, f, Qt::AnchorLeft, 0); + l->addAnchor(d, Qt::AnchorRight, f, Qt::AnchorLeft); + l->setAnchorSpacing(d, Qt::AnchorRight, f, Qt::AnchorLeft, 0); + l->addAnchor(e, Qt::AnchorRight, f, Qt::AnchorLeft); + l->setAnchorSpacing(e, Qt::AnchorRight, f, Qt::AnchorLeft, 0); + l->addAnchor(f, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(f, Qt::AnchorRight, l, Qt::AnchorRight, 0); QCOMPARE(l->count(), 6); @@ -255,13 +288,18 @@ void tst_QGraphicsAnchorLayout::parallel2() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - l->anchor(l, QGraphicsAnchorLayout::Top, a, QGraphicsAnchorLayout::Top, 0); - l->anchor(a, QGraphicsAnchorLayout::Bottom, b, QGraphicsAnchorLayout::Top, 0); - l->anchor(b, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); + l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); + l->setAnchorSpacing(l, Qt::AnchorTop, a, Qt::AnchorTop, 0); + l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorBottom, b, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(b, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); - l->anchorWidth(l, a); - l->anchor(l, QGraphicsAnchorLayout::Left, b, QGraphicsAnchorLayout::Left, 0); - l->anchor(b, QGraphicsAnchorLayout::Right, a, QGraphicsAnchorLayout::Right, 0); + l->addLeftAndRightAnchors(l, a); + l->addAnchor(l, Qt::AnchorLeft, b, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, b, Qt::AnchorLeft, 0); + l->addAnchor(b, Qt::AnchorRight, a, Qt::AnchorRight); + l->setAnchorSpacing(b, Qt::AnchorRight, a, Qt::AnchorRight, 0); QCOMPARE(l->count(), 2); @@ -303,15 +341,23 @@ void tst_QGraphicsAnchorLayout::snake() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - 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, 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); + l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); + l->setAnchorSpacing(l, Qt::AnchorTop, a, Qt::AnchorTop, 0); + l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorBottom, b, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorBottom, c, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorRight); + l->setAnchorSpacing(a, Qt::AnchorRight, b, Qt::AnchorRight, 0); + l->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft); + l->setAnchorSpacing(b, Qt::AnchorLeft, c, Qt::AnchorLeft, 0); + l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(c, Qt::AnchorRight, l, Qt::AnchorRight, 0); QCOMPARE(l->count(), 3); @@ -362,18 +408,26 @@ void tst_QGraphicsAnchorLayout::snakeOppositeDirections() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - 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->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); + l->setAnchorSpacing(l, Qt::AnchorTop, a, Qt::AnchorTop, 0); + l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorBottom, b, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorBottom, c, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); - l->anchor(l, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Left, 0); + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); // Both a and c are 'pointing' to b - l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Right, 0); - l->anchor(c, QGraphicsAnchorLayout::Left, b, QGraphicsAnchorLayout::Left, 0); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorRight); + l->setAnchorSpacing(a, Qt::AnchorRight, b, Qt::AnchorRight, 0); + l->addAnchor(c, Qt::AnchorLeft, b, Qt::AnchorLeft); + l->setAnchorSpacing(c, Qt::AnchorLeft, b, Qt::AnchorLeft, 0); - l->anchor(c, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); + l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(c, Qt::AnchorRight, l, Qt::AnchorRight, 0); QCOMPARE(l->count(), 3); @@ -429,18 +483,29 @@ void tst_QGraphicsAnchorLayout::fairDistribution() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - 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); + l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); + l->setAnchorSpacing(l, Qt::AnchorTop, a, Qt::AnchorTop, 0); + l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorBottom, b, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorBottom, c, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, d, Qt::AnchorTop, 0); + l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(d, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); + l->addAnchor(b, Qt::AnchorRight, c, Qt::AnchorLeft); + l->setAnchorSpacing(b, Qt::AnchorRight, c, Qt::AnchorLeft, 0); + l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(c, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, d, Qt::AnchorLeft, 0); + l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(d, Qt::AnchorRight, l, Qt::AnchorRight, 0); QCOMPARE(l->count(), 4); @@ -503,19 +568,30 @@ void tst_QGraphicsAnchorLayout::fairDistributionOppositeDirections() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - 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, l, QGraphicsAnchorLayout::Bottom, 0); - - l->anchor(a, QGraphicsAnchorLayout::Left, l, QGraphicsAnchorLayout::Left, 0); - l->anchor(b, QGraphicsAnchorLayout::Left, a, QGraphicsAnchorLayout::Right, 0); - l->anchor(c, QGraphicsAnchorLayout::Left, b, QGraphicsAnchorLayout::Right, 0); - l->anchor(d, QGraphicsAnchorLayout::Left, c, QGraphicsAnchorLayout::Right, 0); - l->anchor(d, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); - l->anchorWidth(l, e, 0); + l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); + l->setAnchorSpacing(l, Qt::AnchorTop, a, Qt::AnchorTop, 0); + l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorBottom, b, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorBottom, c, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, d, Qt::AnchorTop, 0); + l->addAnchor(d, Qt::AnchorBottom, e, Qt::AnchorTop); + l->setAnchorSpacing(d, Qt::AnchorBottom, e, Qt::AnchorTop, 0); + l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(e, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + + l->addAnchor(a, Qt::AnchorLeft, l, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorLeft, l, Qt::AnchorLeft, 0); + l->addAnchor(b, Qt::AnchorLeft, a, Qt::AnchorRight); + l->setAnchorSpacing(b, Qt::AnchorLeft, a, Qt::AnchorRight, 0); + l->addAnchor(c, Qt::AnchorLeft, b, Qt::AnchorRight); + l->setAnchorSpacing(c, Qt::AnchorLeft, b, Qt::AnchorRight, 0); + l->addAnchor(d, Qt::AnchorLeft, c, Qt::AnchorRight); + l->setAnchorSpacing(d, Qt::AnchorLeft, c, Qt::AnchorRight, 0); + l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(d, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addLeftAndRightAnchors(l, e); QCOMPARE(l->count(), 5); @@ -564,19 +640,31 @@ void tst_QGraphicsAnchorLayout::proportionalPreferred() QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; l->setContentsMargins(0, 0, 0, 0); - 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(l, QGraphicsAnchorLayout::Left, b, QGraphicsAnchorLayout::Left, 0); - l->anchor(a, QGraphicsAnchorLayout::Right, c, QGraphicsAnchorLayout::Left, 0); - l->anchor(a, QGraphicsAnchorLayout::Right, d, QGraphicsAnchorLayout::Left, 0); - l->anchor(b, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); - l->anchor(c, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); - l->anchor(d, QGraphicsAnchorLayout::Right, l, QGraphicsAnchorLayout::Right, 0); + l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop); + l->setAnchorSpacing(l, Qt::AnchorTop, a, Qt::AnchorTop, 0); + l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorBottom, b, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorBottom, c, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, d, Qt::AnchorTop, 0); + l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(d, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); + l->addAnchor(l, Qt::AnchorLeft, b, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, b, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, c, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, d, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, d, Qt::AnchorLeft, 0); + l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(b, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(c, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(d, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(d, Qt::AnchorRight, l, Qt::AnchorRight, 0); QCOMPARE(l->count(), 4); @@ -631,37 +719,60 @@ void tst_QGraphicsAnchorLayout::example() l->setContentsMargins(0, 0, 0, 0); // vertical - 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, 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, 0); - l->anchor(e, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom, 0); - - l->anchor(c, QGraphicsAnchorLayout::Top, f, QGraphicsAnchorLayout::Top, 0); - l->anchor(c, QGraphicsAnchorLayout::VCenter, f, QGraphicsAnchorLayout::Bottom, 0); - l->anchor(f, QGraphicsAnchorLayout::Bottom, g, QGraphicsAnchorLayout::Top, 0); - l->anchor(c, QGraphicsAnchorLayout::Bottom, g, QGraphicsAnchorLayout::Bottom, 0); + l->addAnchor(a, Qt::AnchorTop, l, Qt::AnchorTop); + l->setAnchorSpacing(a, Qt::AnchorTop, l, Qt::AnchorTop, 0); + l->addAnchor(b, Qt::AnchorTop, l, Qt::AnchorTop); + l->setAnchorSpacing(b, Qt::AnchorTop, l, Qt::AnchorTop, 0); + + l->addAnchor(c, Qt::AnchorTop, a, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorTop, a, Qt::AnchorBottom, 0); + l->addAnchor(c, Qt::AnchorTop, b, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorTop, b, Qt::AnchorBottom, 0); + l->addAnchor(c, Qt::AnchorBottom, d, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, d, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, e, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorBottom, e, Qt::AnchorTop, 0); + + l->addAnchor(d, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(d, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + l->addAnchor(e, Qt::AnchorBottom, l, Qt::AnchorBottom); + l->setAnchorSpacing(e, Qt::AnchorBottom, l, Qt::AnchorBottom, 0); + + l->addAnchor(c, Qt::AnchorTop, f, Qt::AnchorTop); + l->setAnchorSpacing(c, Qt::AnchorTop, f, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorVerticalCenter, f, Qt::AnchorBottom, 0); + l->addAnchor(f, Qt::AnchorBottom, g, Qt::AnchorTop); + l->setAnchorSpacing(f, Qt::AnchorBottom, g, Qt::AnchorTop, 0); + l->addAnchor(c, Qt::AnchorBottom, g, Qt::AnchorBottom); + l->setAnchorSpacing(c, Qt::AnchorBottom, g, Qt::AnchorBottom, 0); // horizontal - 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, 0); - l->anchor(c, QGraphicsAnchorLayout::Right, e, QGraphicsAnchorLayout::Left, 0); - - 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); - - l->anchor(l, QGraphicsAnchorLayout::Left, f, QGraphicsAnchorLayout::Left, 0); - l->anchor(l, QGraphicsAnchorLayout::Left, g, QGraphicsAnchorLayout::Left, 0); - l->anchor(f, QGraphicsAnchorLayout::Right, g, QGraphicsAnchorLayout::Right, 0); + l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, a, Qt::AnchorLeft, 0); + l->addAnchor(l, Qt::AnchorLeft, d, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, d, Qt::AnchorLeft, 0); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, b, Qt::AnchorLeft, 0); + + l->addAnchor(a, Qt::AnchorRight, c, Qt::AnchorLeft); + l->setAnchorSpacing(a, Qt::AnchorRight, c, Qt::AnchorLeft, 0); + l->addAnchor(c, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(c, Qt::AnchorRight, e, Qt::AnchorLeft, 0); + + l->addAnchor(b, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(b, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(e, Qt::AnchorRight, l, Qt::AnchorRight); + l->setAnchorSpacing(e, Qt::AnchorRight, l, Qt::AnchorRight, 0); + l->addAnchor(d, Qt::AnchorRight, e, Qt::AnchorLeft); + l->setAnchorSpacing(d, Qt::AnchorRight, e, Qt::AnchorLeft, 0); + + l->addAnchor(l, Qt::AnchorLeft, f, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, f, Qt::AnchorLeft, 0); + l->addAnchor(l, Qt::AnchorLeft, g, Qt::AnchorLeft); + l->setAnchorSpacing(l, Qt::AnchorLeft, g, Qt::AnchorLeft, 0); + l->addAnchor(f, Qt::AnchorRight, g, Qt::AnchorRight); + l->setAnchorSpacing(f, Qt::AnchorRight, g, Qt::AnchorRight, 0); QCOMPARE(l->count(), 7); @@ -706,14 +817,14 @@ void tst_QGraphicsAnchorLayout::setSpacing() QGraphicsWidget *c = createItem(min, pref, max); QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout; - l->anchorCorner(l, Qt::TopLeftCorner, a, Qt::TopLeftCorner); - l->anchorCorner(b, Qt::TopRightCorner, l, Qt::TopRightCorner); - l->anchor(a, QGraphicsAnchorLayout::Right, b, QGraphicsAnchorLayout::Left); + l->addCornerAnchors(l, Qt::TopLeftCorner, a, Qt::TopLeftCorner); + l->addCornerAnchors(b, Qt::TopRightCorner, l, Qt::TopRightCorner); + l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorLeft); - l->anchorWidth(c); + l->addLeftAndRightAnchors(l, c); - l->anchor(a, QGraphicsAnchorLayout::Bottom, c, QGraphicsAnchorLayout::Top); - l->anchor(c, QGraphicsAnchorLayout::Bottom, l, QGraphicsAnchorLayout::Bottom); + l->addAnchor(a, Qt::AnchorBottom, c, Qt::AnchorTop); + l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom); QGraphicsWidget *p = new QGraphicsWidget(0, Qt::Window); -- cgit v0.12