QtBase  v6.3.1
qlayoutitem.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of the QtWidgets 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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QLAYOUTITEM_H
41 #define QLAYOUTITEM_H
42 
43 #include <QtWidgets/qtwidgetsglobal.h>
44 #include <QtWidgets/qsizepolicy.h>
45 #include <QtCore/qrect.h>
46 
47 #include <limits.h>
48 
50 
51 
52 inline constexpr int QLAYOUTSIZE_MAX = INT_MAX/256/16;
53 
54 class QLayout;
55 class QLayoutItem;
56 class QSpacerItem;
57 class QWidget;
58 class QSize;
59 
60 class Q_WIDGETS_EXPORT QLayoutItem
61 {
62 public:
63  inline explicit QLayoutItem(Qt::Alignment alignment = Qt::Alignment());
64  virtual ~QLayoutItem();
65  virtual QSize sizeHint() const = 0;
66  virtual QSize minimumSize() const = 0;
67  virtual QSize maximumSize() const = 0;
68  virtual Qt::Orientations expandingDirections() const = 0;
69  virtual void setGeometry(const QRect&) = 0;
70  virtual QRect geometry() const = 0;
71  virtual bool isEmpty() const = 0;
72  virtual bool hasHeightForWidth() const;
73  virtual int heightForWidth(int) const;
74  virtual int minimumHeightForWidth(int) const;
75  virtual void invalidate();
76 
77  virtual QWidget *widget() const;
78  virtual QLayout *layout();
79  virtual QSpacerItem *spacerItem();
80 
81  Qt::Alignment alignment() const { return align; }
83  virtual QSizePolicy::ControlTypes controlTypes() const;
84 
85 protected:
87 };
88 
90  : align(aalignment) { }
91 
92 class Q_WIDGETS_EXPORT QSpacerItem : public QLayoutItem
93 {
94 public:
95  QSpacerItem(int w, int h,
98  : width(w), height(h), sizeP(hData, vData) { }
99  ~QSpacerItem();
100 
101  void changeSize(int w, int h,
104  QSize sizeHint() const override;
105  QSize minimumSize() const override;
106  QSize maximumSize() const override;
107  Qt::Orientations expandingDirections() const override;
108  bool isEmpty() const override;
109  void setGeometry(const QRect&) override;
110  QRect geometry() const override;
111  QSpacerItem *spacerItem() override;
112  QSizePolicy sizePolicy() const { return sizeP; }
113 
114 private:
115  int width;
116  int height;
117  QSizePolicy sizeP;
118  QRect rect;
119 };
120 
121 class Q_WIDGETS_EXPORT QWidgetItem : public QLayoutItem
122 {
124 
125 public:
126  explicit QWidgetItem(QWidget *w) : wid(w) { }
128 
129  QSize sizeHint() const override;
130  QSize minimumSize() const override;
131  QSize maximumSize() const override;
132  Qt::Orientations expandingDirections() const override;
133  bool isEmpty() const override;
134  void setGeometry(const QRect&) override;
135  QRect geometry() const override;
136  QWidget *widget() const override;
137 
138  bool hasHeightForWidth() const override;
139  int heightForWidth(int) const override;
140  int minimumHeightForWidth(int) const override;
141  QSizePolicy::ControlTypes controlTypes() const override;
142 protected:
144 };
145 
146 class Q_WIDGETS_EXPORT QWidgetItemV2 : public QWidgetItem
147 {
148 public:
149  explicit QWidgetItemV2(QWidget *widget);
150  ~QWidgetItemV2();
151 
152  QSize sizeHint() const override;
153  QSize minimumSize() const override;
154  QSize maximumSize() const override;
155  int heightForWidth(int width) const override;
156 
157 private:
158  enum { Dirty = -123, HfwCacheMaxSize = 3 };
159 
160  inline bool useSizeCache() const;
161  void updateCacheIfNecessary() const;
162  inline void invalidateSizeCache() {
163  q_cachedMinimumSize.setWidth(Dirty);
164  q_hfwCacheSize = 0;
165  }
166 
167  mutable QSize q_cachedMinimumSize;
168  mutable QSize q_cachedSizeHint;
169  mutable QSize q_cachedMaximumSize;
170  mutable QSize q_cachedHfws[HfwCacheMaxSize];
171  mutable short q_firstCachedHfw;
172  mutable short q_hfwCacheSize;
173  void *d;
174 
175  friend class QWidgetPrivate;
176 
178 };
179 
181 
182 #endif // QLAYOUTITEM_H
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:62
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:61
QLayoutItem(Qt::Alignment alignment=Qt::Alignment())
Definition: qlayoutitem.h:89
virtual Qt::Orientations expandingDirections() const =0
virtual QSize minimumSize() const =0
virtual bool isEmpty() const =0
virtual QRect geometry() const =0
Qt::Alignment align
Definition: qlayoutitem.h:86
virtual ~QLayoutItem()
Qt::Alignment alignment() const
Definition: qlayoutitem.h:81
virtual void setGeometry(const QRect &)=0
virtual QSize maximumSize() const =0
virtual QSize sizeHint() const =0
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:59
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:55
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition: qsizepolicy.h:54
The QSpacerItem class provides blank space in a layout.
Definition: qlayoutitem.h:93
QSpacerItem(int w, int h, QSizePolicy::Policy hData=QSizePolicy::Minimum, QSizePolicy::Policy vData=QSizePolicy::Minimum)
Definition: qlayoutitem.h:95
QSizePolicy sizePolicy() const
Definition: qlayoutitem.h:112
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:133
The QWidgetItem class is a layout item that represents a widget.
Definition: qlayoutitem.h:122
QWidget * wid
Definition: qlayoutitem.h:143
QWidgetItem(QWidget *w)
Definition: qlayoutitem.h:126
QOpenGLWidget * widget
[1]
rect
[4]
uint alignment
union Alignment_ Alignment
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
constexpr QT_BEGIN_NAMESPACE int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:52
GLfloat GLfloat GLfloat w
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLsizei width
GLfloat GLfloat GLfloat GLfloat h
label setAlignment(Qt::AlignLeft|Qt::AlignTop)
[0]
QVBoxLayout * layout