summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-17 09:45:33 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-08-17 09:45:33 (GMT)
commita00fe5c3890ba3b80ff37657d988fb52502f6f78 (patch)
treef7bc077f5758c08acf6c7ce48a4eae343d9e2686 /src
parent45305b592b13040d249dd672b2ab3520b827d135 (diff)
downloadQt-a00fe5c3890ba3b80ff37657d988fb52502f6f78.zip
Qt-a00fe5c3890ba3b80ff37657d988fb52502f6f78.tar.gz
Qt-a00fe5c3890ba3b80ff37657d988fb52502f6f78.tar.bz2
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.
Diffstat (limited to 'src')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.cpp64
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.h7
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp1
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();