diff options
author | Anselmo Lacerda S. de Melo <anselmo.melo@openbossa.org> | 2009-09-15 15:49:53 (GMT) |
---|---|---|
committer | Jan-Arve Sæther <jan-arve.saether@nokia.com> | 2009-09-18 08:28:26 (GMT) |
commit | 301ba29eb8b08d9c040ee80c8a6e4e98bea91dee (patch) | |
tree | a9616fe41e7d01d26746341217d7b4d7215c5afd | |
parent | ac101a65abd1143ee8f91481e1d5d87b75f944ec (diff) | |
download | Qt-301ba29eb8b08d9c040ee80c8a6e4e98bea91dee.zip Qt-301ba29eb8b08d9c040ee80c8a6e4e98bea91dee.tar.gz Qt-301ba29eb8b08d9c040ee80c8a6e4e98bea91dee.tar.bz2 |
QGraphicsAnchorLayout: Initial support for Size Policy
In this commit we introduce initial support for Size Policy.
The size policies supported now are:
* QSizePolicy::Fixed
* QSizePolicy::Minimum
* QSizePolicy::Maximum
* QSizePolicy::Preferred
* QSizePolicy::Ignored
Signed-off-by: Anselmo Lacerda S. de Melo <anselmo.melo@openbossa.org>
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout.cpp | 1 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsanchorlayout_p.cpp | 43 |
2 files changed, 39 insertions, 5 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp index 12124ab..78b6b53 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp @@ -434,7 +434,6 @@ void QGraphicsAnchorLayout::invalidate() */ QSizeF QGraphicsAnchorLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const { - Q_UNUSED(which); Q_UNUSED(constraint); Q_D(const QGraphicsAnchorLayout); diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp index 23601f9..f7266e2 100644 --- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp +++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp @@ -98,17 +98,52 @@ void AnchorData::refreshSizeHints(qreal effectiveSpacing) bool hasCenter = false; QGraphicsLayoutItem *item = from->m_item; + QSizePolicy policy = item->sizePolicy(); + if (QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge) == QGraphicsAnchorLayoutPrivate::Horizontal) { - minSize = item->minimumWidth(); + + // minSize, prefSize and maxSize are initialized + // with item's preferred Size: this is QSizePolicy::Fixed. + // + // Then we check each flag to find the resultant QSizePolicy, + // according to the following table: + // + // constant value + // QSizePolicy::Fixed 0 + // QSizePolicy::Minimum GrowFlag + // QSizePolicy::Maximum ShrinkFlag + // QSizePolicy::Preferred GrowFlag | ShrinkFlag + // QSizePolicy::Ignored GrowFlag | ShrinkFlag | IgnoreFlag prefSize = item->preferredWidth(); - maxSize = item->maximumWidth(); + minSize = prefSize; + maxSize = prefSize; + + if (policy.horizontalPolicy() & QSizePolicy::GrowFlag) + maxSize = item->maximumWidth(); + + if (policy.horizontalPolicy() & QSizePolicy::ShrinkFlag) + minSize = item->minimumWidth(); + + if (policy.horizontalPolicy() & QSizePolicy::IgnoreFlag) + prefSize = minSize; + hasCenter = (from->m_edge == Qt::AnchorHorizontalCenter || to->m_edge == Qt::AnchorHorizontalCenter); } else { - minSize = item->minimumHeight(); prefSize = item->preferredHeight(); - maxSize = item->maximumHeight(); + minSize = prefSize; + maxSize = prefSize; + + if (policy.verticalPolicy() & QSizePolicy::GrowFlag) + maxSize = item->maximumHeight(); + + if (policy.verticalPolicy() & QSizePolicy::ShrinkFlag) + minSize = item->minimumHeight(); + + if (policy.verticalPolicy() & QSizePolicy::IgnoreFlag) + prefSize = minSize; + hasCenter = (from->m_edge == Qt::AnchorVerticalCenter || to->m_edge == Qt::AnchorVerticalCenter); } |