summaryrefslogtreecommitdiffstats
path: root/src/gui
diff options
context:
space:
mode:
authorJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-27 10:54:47 (GMT)
committerJan-Arve Sæther <jan-arve.saether@nokia.com>2009-10-27 10:54:47 (GMT)
commit8a9ab43e572443eefbf19d59740fdc64d25d1005 (patch)
treeaef9429f4e0e7d9d7b97c3951f11e2440348371b /src/gui
parentdd89851abe4b0d0a3c293b5cadace00eb3f75a47 (diff)
downloadQt-8a9ab43e572443eefbf19d59740fdc64d25d1005.zip
Qt-8a9ab43e572443eefbf19d59740fdc64d25d1005.tar.gz
Qt-8a9ab43e572443eefbf19d59740fdc64d25d1005.tar.bz2
Respect the per-item layoutSpacing() if the style uses that feature.
We move the QLayoutStyleInfo class out of the gridlayout engine to a common header file so that anchor layout also can utilize it. Due to that we now can have a per-item spacing we have to change the 'effectiveSpacing' argument of refreshSizeHints to just take a QLayoutStyleInfo pointer that we will later query for the actual spacing used.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout.cpp7
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.cpp78
-rw-r--r--src/gui/graphicsview/qgraphicsanchorlayout_p.h17
-rw-r--r--src/gui/graphicsview/qgraphicslayout_p.h51
-rw-r--r--src/gui/graphicsview/qgridlayoutengine_p.h25
5 files changed, 109 insertions, 69 deletions
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout.cpp b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
index 081572f..00d3478 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout.cpp
@@ -400,7 +400,7 @@ void QGraphicsAnchorLayout::setSpacing(qreal spacing)
qreal QGraphicsAnchorLayout::horizontalSpacing() const
{
Q_D(const QGraphicsAnchorLayout);
- return d->effectiveSpacing(QGraphicsAnchorLayoutPrivate::Horizontal);
+ return d->styleInfo().defaultSpacing(Qt::Horizontal);
}
/*!
@@ -411,7 +411,7 @@ qreal QGraphicsAnchorLayout::horizontalSpacing() const
qreal QGraphicsAnchorLayout::verticalSpacing() const
{
Q_D(const QGraphicsAnchorLayout);
- return d->effectiveSpacing(QGraphicsAnchorLayoutPrivate::Vertical);
+ return d->styleInfo().defaultSpacing(Qt::Vertical);
}
/*!
@@ -481,7 +481,8 @@ void QGraphicsAnchorLayout::invalidate()
{
Q_D(QGraphicsAnchorLayout);
QGraphicsLayout::invalidate();
- d->calculateGraphCacheDirty = 1;
+ d->calculateGraphCacheDirty = true;
+ d->styleInfoDirty = true;
}
/*!
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
index 8c8c303..5bc6708 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.cpp
@@ -141,7 +141,7 @@ static void internalSizeHints(QSizePolicy::Policy policy,
*expSize = *prefSize;
}
-void AnchorData::refreshSizeHints(qreal effectiveSpacing)
+void AnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo)
{
const bool isInternalAnchor = from->m_item == to->m_item;
@@ -196,7 +196,20 @@ void AnchorData::refreshSizeHints(qreal effectiveSpacing)
// their effective size hints might be narrowed down due to their size policies.
prefSizeHint = prefSize;
} else {
- prefSizeHint = effectiveSpacing;
+ const Qt::Orientation orient = Qt::Orientation(QGraphicsAnchorLayoutPrivate::edgeOrientation(from->m_edge) + 1);
+ qreal s = styleInfo->defaultSpacing(orient);
+ if (s < 0) {
+ QSizePolicy::ControlType controlTypeFrom = from->m_item->sizePolicy().controlType();
+ QSizePolicy::ControlType controlTypeTo = to->m_item->sizePolicy().controlType();
+ s = styleInfo->perItemSpacing(controlTypeFrom, controlTypeTo, orient);
+
+ // ### Currently we do not support negative anchors inside the graph.
+ // To avoid those being created by a negative style spacing, we must
+ // make this test.
+ if (s < 0)
+ s = 0;
+ }
+ prefSizeHint = s;
}
maxSizeHint = QWIDGETSIZE_MAX;
}
@@ -227,17 +240,17 @@ void ParallelAnchorData::updateChildrenSizes()
secondEdge->updateChildrenSizes();
}
-void ParallelAnchorData::refreshSizeHints(qreal effectiveSpacing)
+void ParallelAnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo)
{
- refreshSizeHints_helper(effectiveSpacing);
+ refreshSizeHints_helper(styleInfo);
}
-void ParallelAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
+void ParallelAnchorData::refreshSizeHints_helper(const QLayoutStyleInfo *styleInfo,
bool refreshChildren)
{
if (refreshChildren) {
- firstEdge->refreshSizeHints(effectiveSpacing);
- secondEdge->refreshSizeHints(effectiveSpacing);
+ firstEdge->refreshSizeHints(styleInfo);
+ secondEdge->refreshSizeHints(styleInfo);
}
// ### should we warn if the parallel connection is invalid?
@@ -362,12 +375,12 @@ void SequentialAnchorData::updateChildrenSizes()
}
}
-void SequentialAnchorData::refreshSizeHints(qreal effectiveSpacing)
+void SequentialAnchorData::refreshSizeHints(const QLayoutStyleInfo *styleInfo)
{
- refreshSizeHints_helper(effectiveSpacing);
+ refreshSizeHints_helper(styleInfo);
}
-void SequentialAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
+void SequentialAnchorData::refreshSizeHints_helper(const QLayoutStyleInfo *styleInfo,
bool refreshChildren)
{
minSize = 0;
@@ -380,7 +393,7 @@ void SequentialAnchorData::refreshSizeHints_helper(qreal effectiveSpacing,
// If it's the case refresh children information first
if (refreshChildren)
- edge->refreshSizeHints(effectiveSpacing);
+ edge->refreshSizeHints(styleInfo);
minSize += edge->minSize;
prefSize += edge->prefSize;
@@ -458,7 +471,7 @@ QString GraphPath::toString() const
#endif
QGraphicsAnchorLayoutPrivate::QGraphicsAnchorLayoutPrivate()
- : calculateGraphCacheDirty(1)
+ : calculateGraphCacheDirty(true), styleInfoDirty(true)
{
for (int i = 0; i < NOrientations; ++i) {
for (int j = 0; j < 3; ++j) {
@@ -1565,34 +1578,32 @@ void QGraphicsAnchorLayoutPrivate::correctEdgeDirection(QGraphicsLayoutItem *&fi
}
}
-qreal QGraphicsAnchorLayoutPrivate::effectiveSpacing(Orientation orientation) const
+QLayoutStyleInfo &QGraphicsAnchorLayoutPrivate::styleInfo() const
{
- Q_Q(const QGraphicsAnchorLayout);
- qreal s = spacings[orientation];
- if (s < 0) {
- // ### make sure behaviour is the same as in QGraphicsGridLayout
+ if (styleInfoDirty) {
+ Q_Q(const QGraphicsAnchorLayout);
+ //### Fix this if QGV ever gets support for Metal style or different Aqua sizes.
+ QWidget *wid = 0;
+
QGraphicsLayoutItem *parent = q->parentLayoutItem();
while (parent && parent->isLayout()) {
parent = parent->parentLayoutItem();
}
+ QGraphicsWidget *w = 0;
if (parent) {
QGraphicsItem *parentItem = parent->graphicsItem();
- if (parentItem && parentItem->isWidget()) {
- QGraphicsWidget *w = static_cast<QGraphicsWidget*>(parentItem);
- s = w->style()->pixelMetric(orientation == Horizontal
- ? QStyle::PM_LayoutHorizontalSpacing
- : QStyle::PM_LayoutVerticalSpacing);
- }
+ if (parentItem && parentItem->isWidget())
+ w = static_cast<QGraphicsWidget*>(parentItem);
}
- }
- // ### Currently we do not support negative anchors inside the graph.
- // To avoid those being created by a negative style spacing, we must
- // make this test.
- if (s < 0)
- s = 0;
+ QStyle *style = w ? w->style() : QApplication::style();
+ cachedStyleInfo = QLayoutStyleInfo(style, wid);
+ cachedStyleInfo.setDefaultSpacing(Qt::Horizontal, spacings[0]);
+ cachedStyleInfo.setDefaultSpacing(Qt::Vertical, spacings[1]);
- return s;
+ styleInfoDirty = false;
+ }
+ return cachedStyleInfo;
}
/*!
@@ -1620,7 +1631,7 @@ void QGraphicsAnchorLayoutPrivate::calculateGraphs()
dumpGraph(QString::fromAscii("%1-after").arg(count));
#endif
- calculateGraphCacheDirty = 0;
+ calculateGraphCacheDirty = false;
}
// ### Maybe getGraphParts could return the variables when traversing, at least
@@ -1847,12 +1858,11 @@ void QGraphicsAnchorLayoutPrivate::setAnchorSizeHintsFromItems(Orientation orien
Graph<AnchorVertex, AnchorData> &g = graph[orientation];
QList<QPair<AnchorVertex *, AnchorVertex *> > vertices = g.connections();
- qreal spacing = effectiveSpacing(orientation);
-
+ QLayoutStyleInfo styleInf = styleInfo();
for (int i = 0; i < vertices.count(); ++i) {
AnchorData *data = g.edgeData(vertices.at(i).first, vertices.at(i).second);;
Q_ASSERT(data->from && data->to);
- data->refreshSizeHints(spacing);
+ data->refreshSizeHints(&styleInf);
}
}
diff --git a/src/gui/graphicsview/qgraphicsanchorlayout_p.h b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
index d45c004..9b7d41e 100644
--- a/src/gui/graphicsview/qgraphicsanchorlayout_p.h
+++ b/src/gui/graphicsview/qgraphicsanchorlayout_p.h
@@ -159,7 +159,7 @@ struct AnchorData : public QSimplexVariable {
type(Normal), hasSize(true), isLayoutAnchor(false) {}
virtual void updateChildrenSizes() {}
- virtual void refreshSizeHints(qreal effectiveSpacing);
+ virtual void refreshSizeHints(const QLayoutStyleInfo *styleInfo);
virtual ~AnchorData() {}
@@ -226,9 +226,9 @@ struct SequentialAnchorData : public AnchorData
}
virtual void updateChildrenSizes();
- virtual void refreshSizeHints(qreal effectiveSpacing);
+ virtual void refreshSizeHints(const QLayoutStyleInfo *styleInfo);
- void refreshSizeHints_helper(qreal effectiveSpacing, bool refreshChildren = true);
+ void refreshSizeHints_helper(const QLayoutStyleInfo *styleInfo, bool refreshChildren = true);
void setVertices(const QVector<AnchorVertex*> &vertices)
{
@@ -261,9 +261,9 @@ struct ParallelAnchorData : public AnchorData
}
virtual void updateChildrenSizes();
- virtual void refreshSizeHints(qreal effectiveSpacing);
+ virtual void refreshSizeHints(const QLayoutStyleInfo *styleInfo);
- void refreshSizeHints_helper(qreal effectiveSpacing, bool refreshChildren = true);
+ void refreshSizeHints_helper(const QLayoutStyleInfo *styleInfo, bool refreshChildren = true);
AnchorData* firstEdge;
AnchorData* secondEdge;
@@ -423,9 +423,8 @@ public:
Qt::AnchorPoint &firstEdge,
QGraphicsLayoutItem *&secondItem,
Qt::AnchorPoint &secondEdge);
- // for getting the actual spacing (will query the style if the
- // spacing is not explicitly set).
- qreal effectiveSpacing(Orientation orientation) const;
+
+ QLayoutStyleInfo &styleInfo() const;
// Activation methods
void simplifyGraph(Orientation orientation);
@@ -524,6 +523,8 @@ public:
#endif
uint calculateGraphCacheDirty : 1;
+ mutable uint styleInfoDirty : 1;
+ mutable QLayoutStyleInfo cachedStyleInfo;
friend class QGraphicsAnchorPrivate;
};
diff --git a/src/gui/graphicsview/qgraphicslayout_p.h b/src/gui/graphicsview/qgraphicslayout_p.h
index 59c6dba..4aeae39 100644
--- a/src/gui/graphicsview/qgraphicslayout_p.h
+++ b/src/gui/graphicsview/qgraphicslayout_p.h
@@ -60,6 +60,8 @@
#include "qgraphicslayout.h"
#include "qgraphicslayoutitem_p.h"
#include <QtGui/qstyle.h>
+#include <QtGui/qwidget.h>
+#include <QtGui/qstyleoption.h>
QT_BEGIN_NAMESPACE
@@ -76,6 +78,55 @@ inline bool qt_graphicsLayoutDebug()
}
#endif
+
+class QLayoutStyleInfo
+{
+public:
+ inline QLayoutStyleInfo() { invalidate(); }
+ inline QLayoutStyleInfo(QStyle *style, QWidget *widget)
+ : m_valid(true), m_style(style), m_widget(widget)
+ {
+ Q_ASSERT(style);
+ if (widget) //###
+ m_styleOption.initFrom(widget);
+ m_defaultSpacing[0] = style->pixelMetric(QStyle::PM_LayoutHorizontalSpacing);
+ m_defaultSpacing[1] = style->pixelMetric(QStyle::PM_LayoutVerticalSpacing);
+ }
+
+ inline void invalidate() { m_valid = false; m_style = 0; m_widget = 0; }
+
+ inline QStyle *style() const { return m_style; }
+ inline QWidget *widget() const { return m_widget; }
+
+ inline bool operator==(const QLayoutStyleInfo &other)
+ { return m_style == other.m_style && m_widget == other.m_widget; }
+ inline bool operator!=(const QLayoutStyleInfo &other)
+ { return !(*this == other); }
+
+ inline void setDefaultSpacing(Qt::Orientation o, qreal spacing){
+ if (spacing >= 0)
+ m_defaultSpacing[o - 1] = spacing;
+ }
+
+ inline qreal defaultSpacing(Qt::Orientation o) const {
+ return m_defaultSpacing[o - 1];
+ }
+
+ inline qreal perItemSpacing(QSizePolicy::ControlType control1,
+ QSizePolicy::ControlType control2,
+ Qt::Orientation orientation) const
+ {
+ Q_ASSERT(style());
+ return style()->layoutSpacing(control1, control2, orientation, &m_styleOption, widget());
+ }
+private:
+ bool m_valid;
+ QStyle *m_style;
+ QWidget *m_widget;
+ QStyleOption m_styleOption;
+ qreal m_defaultSpacing[2];
+};
+
class Q_AUTOTEST_EXPORT QGraphicsLayoutPrivate : public QGraphicsLayoutItemPrivate
{
Q_DECLARE_PUBLIC(QGraphicsLayout)
diff --git a/src/gui/graphicsview/qgridlayoutengine_p.h b/src/gui/graphicsview/qgridlayoutengine_p.h
index a42a537..ed335a8 100644
--- a/src/gui/graphicsview/qgridlayoutengine_p.h
+++ b/src/gui/graphicsview/qgridlayoutengine_p.h
@@ -59,7 +59,7 @@
#include "qmap.h"
#include "qpair.h"
#include "qvector.h"
-
+#include "qgraphicslayout_p.h"
#include <float.h>
QT_BEGIN_NAMESPACE
@@ -128,29 +128,6 @@ public:
};
-class QLayoutStyleInfo
-{
-public:
- inline QLayoutStyleInfo() { invalidate(); }
- inline QLayoutStyleInfo(QStyle *style, QWidget *widget)
- : q_valid(true), q_style(style), q_widget(widget) {}
-
- inline void invalidate() { q_valid = false; q_style = 0; q_widget = 0; }
-
- inline QStyle *style() const { return q_style; }
- inline QWidget *widget() const { return q_widget; }
-
- inline bool operator==(const QLayoutStyleInfo &other)
- { return q_style == other.q_style && q_widget == other.q_widget; }
- inline bool operator!=(const QLayoutStyleInfo &other)
- { return !(*this == other); }
-
-private:
- bool q_valid;
- QStyle *q_style;
- QWidget *q_widget;
-};
-
class QGridLayoutBox
{
public: