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
49QT_BEGIN_NAMESPACE
50
51
52static const Q_DECL_UNUSED int QLAYOUTSIZE_MAX = INT_MAX/256/16;
53
54class QLayout;
55class QLayoutItem;
56class QSpacerItem;
57class QWidget;
58class QSize;
59
60class Q_WIDGETS_EXPORT QLayoutItem
61{
62public:
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#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
78 virtual QWidget *widget();
79#else
80 virtual QWidget *widget() const;
81#endif
82 virtual QLayout *layout();
83 virtual QSpacerItem *spacerItem();
84
85 Qt::Alignment alignment() const { return align; }
86 void setAlignment(Qt::Alignment a);
87 virtual QSizePolicy::ControlTypes controlTypes() const;
88
89protected:
90 Qt::Alignment align;
91};
92
93inline QLayoutItem::QLayoutItem(Qt::Alignment aalignment)
94 : align(aalignment) { }
95
96class Q_WIDGETS_EXPORT QSpacerItem : public QLayoutItem
97{
98public:
99 QSpacerItem(int w, int h,
100 QSizePolicy::Policy hData = QSizePolicy::Minimum,
101 QSizePolicy::Policy vData = QSizePolicy::Minimum)
102 : width(w), height(h), sizeP(hData, vData) { }
103 ~QSpacerItem();
104
105 void changeSize(int w, int h,
106 QSizePolicy::Policy hData = QSizePolicy::Minimum,
107 QSizePolicy::Policy vData = QSizePolicy::Minimum);
108 QSize sizeHint() const override;
109 QSize minimumSize() const override;
110 QSize maximumSize() const override;
111 Qt::Orientations expandingDirections() const override;
112 bool isEmpty() const override;
113 void setGeometry(const QRect&) override;
114 QRect geometry() const override;
115 QSpacerItem *spacerItem() override;
116 QSizePolicy sizePolicy() const { return sizeP; }
117
118private:
119 int width;
120 int height;
121 QSizePolicy sizeP;
122 QRect rect;
123};
124
125class Q_WIDGETS_EXPORT QWidgetItem : public QLayoutItem
126{
127 Q_DISABLE_COPY(QWidgetItem)
128
129public:
130 explicit QWidgetItem(QWidget *w) : wid(w) { }
131 ~QWidgetItem();
132
133 QSize sizeHint() const override;
134 QSize minimumSize() const override;
135 QSize maximumSize() const override;
136 Qt::Orientations expandingDirections() const override;
137 bool isEmpty() const override;
138 void setGeometry(const QRect&) override;
139 QRect geometry() const override;
140#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
141 QWidget *widget() override;
142#else
143 QWidget *widget() const override;
144#endif
145
146 bool hasHeightForWidth() const override;
147 int heightForWidth(int) const override;
148 QSizePolicy::ControlTypes controlTypes() const override;
149protected:
150 QWidget *wid;
151};
152
153class Q_WIDGETS_EXPORT QWidgetItemV2 : public QWidgetItem
154{
155public:
156 explicit QWidgetItemV2(QWidget *widget);
157 ~QWidgetItemV2();
158
159 QSize sizeHint() const override;
160 QSize minimumSize() const override;
161 QSize maximumSize() const override;
162 int heightForWidth(int width) const override;
163
164private:
165 enum { Dirty = -123, HfwCacheMaxSize = 3 };
166
167 inline bool useSizeCache() const;
168 void updateCacheIfNecessary() const;
169 inline void invalidateSizeCache() {
170 q_cachedMinimumSize.setWidth(Dirty);
171 q_hfwCacheSize = 0;
172 }
173
174 mutable QSize q_cachedMinimumSize;
175 mutable QSize q_cachedSizeHint;
176 mutable QSize q_cachedMaximumSize;
177 mutable QSize q_cachedHfws[HfwCacheMaxSize];
178 mutable short q_firstCachedHfw;
179 mutable short q_hfwCacheSize;
180 void *d;
181
182 friend class QWidgetPrivate;
183
184 Q_DISABLE_COPY(QWidgetItemV2)
185};
186
187QT_END_NAMESPACE
188
189#endif // QLAYOUTITEM_H
190

source code of qtbase/src/widgets/kernel/qlayoutitem.h