Qt 4.8
qgraphicslayout_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QGRAPHICSLAYOUT_P_H
43 #define QGRAPHICSLAYOUT_P_H
44 
45 //
46 // W A R N I N G
47 // -------------
48 //
49 // This file is not part of the Qt API. It exists for the convenience
50 // of other Qt classes. This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QtCore/qglobal.h>
57 
58 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
59 
60 #include "qgraphicslayout.h"
61 #include "qgraphicslayoutitem_p.h"
62 #include <QtGui/qstyle.h>
63 #include <QtGui/qwidget.h>
64 #include <QtGui/qstyleoption.h>
65 
67 
69 class QGraphicsWidget;
70 
71 #ifdef QT_DEBUG
73 {
74  static int checked_env = -1;
75  if(checked_env == -1)
76  checked_env = !!qgetenv("QT_GRAPHICSLAYOUT_DEBUG").toInt();
77  return checked_env;
78 }
79 #endif
80 
81 
83 {
84 public:
85  inline QLayoutStyleInfo() { invalidate(); }
87  : m_valid(true), m_style(style), m_widget(widget)
88  {
89  Q_ASSERT(style);
90  if (widget) //###
91  m_styleOption.initFrom(widget);
94  }
95 
96  inline void invalidate() { m_valid = false; m_style = 0; m_widget = 0; }
97 
98  inline QStyle *style() const { return m_style; }
99  inline QWidget *widget() const { return m_widget; }
100 
101  inline bool operator==(const QLayoutStyleInfo &other)
102  { return m_style == other.m_style && m_widget == other.m_widget; }
103  inline bool operator!=(const QLayoutStyleInfo &other)
104  { return !(*this == other); }
105 
106  inline void setDefaultSpacing(Qt::Orientation o, qreal spacing){
107  if (spacing >= 0)
108  m_defaultSpacing[o - 1] = spacing;
109  }
110 
112  return m_defaultSpacing[o - 1];
113  }
114 
116  QSizePolicy::ControlType control2,
117  Qt::Orientation orientation) const
118  {
119  Q_ASSERT(style());
120  return style()->layoutSpacing(control1, control2, orientation, &m_styleOption, widget());
121  }
122 private:
123  bool m_valid;
128 };
129 
131 {
133 
134 public:
135  QGraphicsLayoutPrivate() : QGraphicsLayoutItemPrivate(0, true), left(-1.0), top(-1.0), right(-1.0), bottom(-1.0),
136  activated(true) { }
137 
138  void reparentChildItems(QGraphicsItem *newParent);
139  void getMargin(qreal *result, qreal userMargin, QStyle::PixelMetric pm) const;
140  Qt::LayoutDirection visualDirection() const;
141 
142  void addChildLayoutItem(QGraphicsLayoutItem *item);
143  void activateRecursive(QGraphicsLayoutItem *item);
144 
145  qreal left, top, right, bottom;
146  bool activated;
147 };
148 
149 
151 
152 #endif //QT_NO_GRAPHICSVIEW
153 
154 #endif
Q_CORE_EXPORT QByteArray qgetenv(const char *varName)
double qreal
Definition: qglobal.h:1193
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool operator!=(const QLayoutStyleInfo &other)
QLayoutStyleInfo(QStyle *style, QWidget *widget)
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=0, const QWidget *widget=0) const =0
Returns the value of the given pixel metric.
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
bool qt_graphicsLayoutDebug()
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
PixelMetric
This enum describes the various available pixel metrics.
Definition: qstyle.h:474
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
bool operator==(const QLayoutStyleInfo &other)
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
int layoutSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation, const QStyleOption *option=0, const QWidget *widget=0) const
Returns the spacing that should be used between control1 and control2 in a layout.
Definition: qstyle.cpp:2395
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QStyle * style() const
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
LayoutDirection
Definition: qnamespace.h:1580
void setDefaultSpacing(Qt::Orientation o, qreal spacing)
QStyleOption m_styleOption
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
qreal perItemSpacing(QSizePolicy::ControlType control1, QSizePolicy::ControlType control2, Qt::Orientation orientation) const
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QWidget * widget() const
qreal defaultSpacing(Qt::Orientation o) const
int toInt(bool *ok=0, int base=10) const
Returns the byte array converted to an int using base base, which is 10 by default and must be betwee...
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
Orientation
Definition: qnamespace.h:174
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.