src/gui/graphicsview/qgraphicslayout_p.h
changeset 3 41300fa6a67c
parent 0 1918ee327afb
child 4 3b1da2848fc7
--- a/src/gui/graphicsview/qgraphicslayout_p.h	Tue Jan 26 12:42:25 2010 +0200
+++ b/src/gui/graphicsview/qgraphicslayout_p.h	Tue Feb 02 00:43:10 2010 +0200
@@ -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 @@
 }
 #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)