From a00fe5c3890ba3b80ff37657d988fb52502f6f78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Arve=20S=C3=A6ther?= Date: Mon, 17 Aug 2009 11:45:33 +0200 Subject: Small change in the "spacing API". In order to be consistent with QGraphicsGridLayout(QGGL), we remove the void setSpacing(Qt::Orientations ); qreal spacing(Qt::Orientations ); in favor to void setHorizontalSpacing(qreal spacing); void setVerticalSpacing(qreal spacing); void setSpacing(qreal spacing); qreal horizontalSpacing() const; qreal verticalSpacing() const; The API for setting and retrieving spacings should now be the same as in QGGL. --- src/gui/graphicsview/qgraphicsanchorlayout.cpp | 64 +++++++++++++++++++++--- src/gui/graphicsview/qgraphicsanchorlayout.h | 7 ++- src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 1 + 3 files changed, 63 insertions(+), 9 deletions(-) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index 98e4b32..9084c2c 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -79,6 +79,14 @@ QGraphicsAnchorLayout::~QGraphicsAnchorLayout() * * \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. + * + * The spacing an anchor will get depends on the type of anchor. For instance, anchors from the + * Right edge of one item to the Left edge of another (or vice versa) will use the default + * horizontal spacing. The same behaviour applies to Bottom to Top anchors, (but they will use + * 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 */ void QGraphicsAnchorLayout::anchor(QGraphicsLayoutItem *firstItem, Edge firstEdge, @@ -203,19 +211,61 @@ void QGraphicsAnchorLayout::removeAnchor(QGraphicsLayoutItem *firstItem, Edge fi invalidate(); } -void QGraphicsAnchorLayout::setSpacing(qreal spacing, Qt::Orientations orientations /*= Qt::Horizontal|Qt::Vertical*/) +/*! + Sets the default horizontal spacing for the anchor layout to \a spacing. + + \sa horizontalSpacing, setVerticalSpacing, setSpacing +*/ +void QGraphicsAnchorLayout::setHorizontalSpacing(qreal spacing) +{ + Q_D(QGraphicsAnchorLayout); + d->spacings[0] = spacing; +} + +/*! + Sets the default vertical spacing for the anchor layout to \a spacing. + + \sa verticalSpacing, setHorizontalSpacing, setSpacing +*/ +void QGraphicsAnchorLayout::setVerticalSpacing(qreal spacing) +{ + Q_D(QGraphicsAnchorLayout); + d->spacings[1] = spacing; +} + +/*! + Sets the default horizontal and the default vertical spacing for the anchor layout to \a spacing. + + If an item is anchored with no spacing associated with the anchor, it will use the default + spacing. + \sa setHorizontalSpacing, setVerticalSpacing +*/ +void QGraphicsAnchorLayout::setSpacing(qreal spacing) { Q_D(QGraphicsAnchorLayout); - if (orientations & Qt::Horizontal) - d->spacings[0] = spacing; - if (orientations & Qt::Vertical) - d->spacings[1] = spacing; + d->spacings[0] = d->spacings[1] = spacing; +} + +/*! + Returns the default horizontal spacing for the anchor layout. + + \sa verticalSpacing, setHorizontalSpacing +*/ +qreal QGraphicsAnchorLayout::horizontalSpacing() const +{ + Q_D(const QGraphicsAnchorLayout); + return d->effectiveSpacing(QGraphicsAnchorLayoutPrivate::Horizontal); } -qreal QGraphicsAnchorLayout::spacing(Qt::Orientation orientation) const +/*! + Returns the default vertical spacing for the anchor layout. + + \sa horizontalSpacing, setVerticalSpacing +*/ +qreal QGraphicsAnchorLayout::verticalSpacing() const { Q_D(const QGraphicsAnchorLayout); - return d->effectiveSpacing(QGraphicsAnchorLayoutPrivate::Orientation(orientation - 1)); + return d->effectiveSpacing(QGraphicsAnchorLayoutPrivate::Vertical); } void QGraphicsAnchorLayout::setGeometry(const QRectF &geom) diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.h b/src/gui/graphicsview/qgraphicsanchorlayout.h index 249996e..8010b31 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.h +++ b/src/gui/graphicsview/qgraphicsanchorlayout.h @@ -103,8 +103,11 @@ public: inline void anchorGeometry(QGraphicsLayoutItem *item, QGraphicsLayoutItem *relativeTo, qreal spacing); - void setSpacing(qreal spacing, Qt::Orientations orientations = Qt::Horizontal|Qt::Vertical); - qreal spacing(Qt::Orientation) const; + void setHorizontalSpacing(qreal spacing); + void setVerticalSpacing(qreal spacing); + void setSpacing(qreal spacing); + qreal horizontalSpacing() const; + qreal verticalSpacing() const; void removeAt(int index); void setGeometry(const QRectF &rect); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 0e35566..b1ce6d1 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -1181,6 +1181,7 @@ qreal QGraphicsAnchorLayoutPrivate::effectiveSpacing(Orientation orientation) co Q_Q(const QGraphicsAnchorLayout); qreal s = spacings[orientation]; if (s < 0) { + // ### make sure behaviour is the same as in QGraphicsGridLayout QGraphicsLayoutItem *parent = q->parentLayoutItem(); while (parent && parent->isLayout()) { parent = parent->parentLayoutItem(); -- cgit v0.12