Qt 4.8
qlayout.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 QLAYOUT_H
43 #define QLAYOUT_H
44 
45 #include <QtCore/qobject.h>
46 #include <QtGui/qlayoutitem.h>
47 #include <QtGui/qsizepolicy.h>
48 #include <QtCore/qrect.h>
49 #include <QtCore/qmargins.h>
50 
51 #include <limits.h>
52 
54 
56 
57 QT_MODULE(Gui)
58 
59 class QLayout;
60 class QSize;
61 
62 #ifdef QT3_SUPPORT
63 class Q_GUI_EXPORT QLayoutIterator
64 {
65 public:
66  inline QT3_SUPPORT_CONSTRUCTOR QLayoutIterator(QLayout *i) : layout(i), index(0) {}
67  inline QLayoutIterator(const QLayoutIterator &i)
68  : layout(i.layout), index(i.index) {}
69  inline QLayoutIterator &operator=(const QLayoutIterator &i) {
70  layout = i.layout;
71  index = i.index;
72  return *this;
73  }
74  inline QT3_SUPPORT QLayoutItem *operator++();
75  inline QT3_SUPPORT QLayoutItem *current();
76  inline QT3_SUPPORT QLayoutItem *takeCurrent();
77  inline QT3_SUPPORT void deleteCurrent();
78 
79 private:
80  // hack to avoid deprecated warning
81  friend class QLayout;
82  inline QLayoutIterator(QLayout *i, bool) : layout(i), index(0) {}
83  QLayout *layout;
84  int index;
85 };
86 #endif
87 
88 class QLayoutPrivate;
89 
90 class Q_GUI_EXPORT QLayout : public QObject, public QLayoutItem
91 {
92  Q_OBJECT
94 
96  int margin;
97  int spacing;
98  SizeConstraint sizeConstraint;
99 public:
106  SetMinAndMaxSize
107 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
108  , Auto = SetDefaultConstraint,
109  FreeResize = SetNoConstraint,
110  Minimum = SetMinimumSize,
111  Fixed = SetFixedSize
112 #endif
113  };
114 
115  QLayout(QWidget *parent);
116  QLayout();
117  ~QLayout();
118 
119  int margin() const;
120  int spacing() const;
121 
122  void setMargin(int);
123  void setSpacing(int);
124 
125  void setContentsMargins(int left, int top, int right, int bottom);
126  void setContentsMargins(const QMargins &margins);
127  void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
128  QMargins contentsMargins() const;
129  QRect contentsRect() const;
130 
131  bool setAlignment(QWidget *w, Qt::Alignment alignment);
132  bool setAlignment(QLayout *l, Qt::Alignment alignment);
133 #ifdef Q_NO_USING_KEYWORD
134  inline void setAlignment(Qt::Alignment alignment) { QLayoutItem::setAlignment(alignment); }
135 #else
137 #endif
138 
139  void setSizeConstraint(SizeConstraint);
140  SizeConstraint sizeConstraint() const;
141 #ifdef QT3_SUPPORT
142  inline QT3_SUPPORT void setResizeMode(SizeConstraint s) {setSizeConstraint(s);}
143  inline QT3_SUPPORT SizeConstraint resizeMode() const {return sizeConstraint();}
144 #endif
145  void setMenuBar(QWidget *w);
146  QWidget *menuBar() const;
147 
148  QWidget *parentWidget() const;
149 
150  void invalidate();
151  QRect geometry() const;
152  bool activate();
153  void update();
154 
155  void addWidget(QWidget *w);
156  virtual void addItem(QLayoutItem *) = 0;
157 
158  void removeWidget(QWidget *w);
159  void removeItem(QLayoutItem *);
160 
161  Qt::Orientations expandingDirections() const;
162  QSize minimumSize() const;
163  QSize maximumSize() const;
164  virtual void setGeometry(const QRect&);
165  virtual QLayoutItem *itemAt(int index) const = 0;
166  virtual QLayoutItem *takeAt(int index) = 0;
167  virtual int indexOf(QWidget *) const;
168  virtual int count() const = 0;
169  bool isEmpty() const;
170 
171  int totalHeightForWidth(int w) const;
172  QSize totalMinimumSize() const;
173  QSize totalMaximumSize() const;
174  QSize totalSizeHint() const;
175  QLayout *layout();
176 
177  void setEnabled(bool);
178  bool isEnabled() const;
179 
180 #ifdef QT3_SUPPORT
181  QT3_SUPPORT void freeze(int w=0, int h=0);
182  QT3_SUPPORT bool isTopLevel() const;
183 #endif
184 
185  static QSize closestAcceptableSize(const QWidget *w, const QSize &s);
186 
187 protected:
188  void widgetEvent(QEvent *);
189  void childEvent(QChildEvent *e);
190  void addChildLayout(QLayout *l);
191  void addChildWidget(QWidget *w);
192  bool adoptLayout(QLayout *layout);
193 #ifdef QT3_SUPPORT
194  QT3_SUPPORT void deleteAllItems();
195 #endif
196 
197  QRect alignmentRect(const QRect&) const;
198 protected:
200 
201 private:
203 
204  static void activateRecursiveHelper(QLayoutItem *item);
205 
206  friend class QApplicationPrivate;
207  friend class QWidget;
208 
209 public:
210 #ifdef QT3_SUPPORT
211  QT3_SUPPORT_CONSTRUCTOR QLayout(QWidget *parent, int margin, int spacing = -1,
212  const char *name = 0);
213  QT3_SUPPORT_CONSTRUCTOR QLayout(QLayout *parentLayout, int spacing = -1, const char *name = 0);
214  QT3_SUPPORT_CONSTRUCTOR QLayout(int spacing, const char *name = 0);
215  inline QT3_SUPPORT QWidget *mainWidget() const { return parentWidget(); }
216  inline QT3_SUPPORT void remove(QWidget *w) { removeWidget(w); }
217  inline QT3_SUPPORT void add(QWidget *w) { addWidget(w); }
218 
219  QT3_SUPPORT void setAutoAdd(bool a);
220  QT3_SUPPORT bool autoAdd() const;
221  inline QT3_SUPPORT QLayoutIterator iterator() { return QLayoutIterator(this,true); }
222 
223  inline QT3_SUPPORT int defaultBorder() const { return spacing(); }
224 #endif
225 };
226 
227 #ifdef QT3_SUPPORT
228 inline QLayoutItem *QLayoutIterator::operator++() { return layout->itemAt(++index); }
229 inline QLayoutItem *QLayoutIterator::current() { return layout->itemAt(index); }
230 inline QLayoutItem *QLayoutIterator::takeCurrent() { return layout->takeAt(index); }
231 inline void QLayoutIterator::deleteCurrent() { delete layout->takeAt(index); }
232 #endif
233 
234 //### support old includes
235 #if 1 //def QT3_SUPPORT
237 #include <QtGui/qboxlayout.h>
238 #include <QtGui/qgridlayout.h>
240 #endif
241 
243 
245 
246 #endif // QLAYOUT_H
double d
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual QRect geometry() const =0
Returns the rectangle covered by this layout item.
#define add(aName)
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual bool isEmpty() const =0
Implemented in subclasses to return whether this item is empty, i.
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual void invalidate()
Invalidates any cached information in this layout item.
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual Qt::Orientations expandingDirections() const =0
Returns whether this layout item can make use of more space than sizeHint().
friend class QLayout
Definition: qwidget.h:752
#define QT_END_INCLUDE_NAMESPACE
This macro is equivalent to QT_BEGIN_NAMESPACE.
Definition: qglobal.h:92
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
long ASN1_INTEGER_get ASN1_INTEGER * a
virtual QSize minimumSize() const =0
Implemented in subclasses to return the minimum size of this item.
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
void setAlignment(Qt::Alignment a)
Sets the alignment of this item to alignment.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
virtual void childEvent(QChildEvent *)
This event handler can be reimplemented in a subclass to receive child events.
Definition: qobject.cpp:1332
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
const char * name
const char * layout
#define Q_OBJECT
Definition: qobjectdefs.h:157
static QWidget * parentWidget(const QWidget *w)
virtual void setGeometry(const QRect &)=0
Implemented in subclasses to set this item&#39;s geometry to r.
The QChildEvent class contains event parameters for child object events.
Definition: qcoreevent.h:353
SizeConstraint
The possible values are:
Definition: qlayout.h:100
static QSizeF closestAcceptableSize(const QSizeF &proposed, const QGraphicsWidget *widget)
virtual QLayout * layout()
If this item is a QLayout, it is returned as a QLayout; otherwise 0 is returned.
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
virtual QSize maximumSize() const =0
Implemented in subclasses to return the maximum size of this item.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
QFactoryLoader * l
quint16 index
#define QT_BEGIN_INCLUDE_NAMESPACE
This macro is equivalent to QT_END_NAMESPACE.
Definition: qglobal.h:91
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QMargins class defines the four margins of a rectangle.
Definition: qmargins.h:53
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define QT_END_HEADER
Definition: qglobal.h:137