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
52[[maybe_unused]] static const 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 virtual QWidget *widget() const;
78 virtual QLayout *layout();
79 virtual QSpacerItem *spacerItem();
80
81 Qt::Alignment alignment() const { return align; }
82 void setAlignment(Qt::Alignment a);
83 virtual QSizePolicy::ControlTypes controlTypes() const;
84
85protected:
86 Qt::Alignment align;
87};
88
89inline QLayoutItem::QLayoutItem(Qt::Alignment aalignment)
90 : align(aalignment) { }
91
92class Q_WIDGETS_EXPORT QSpacerItem : public QLayoutItem
93{
94public:
95 QSpacerItem(int w, int h,
96 QSizePolicy::Policy hData = QSizePolicy::Minimum,
97 QSizePolicy::Policy vData = QSizePolicy::Minimum)
98 : width(w), height(h), sizeP(hData, vData) { }
99 ~QSpacerItem();
100
101 void changeSize(int w, int h,
102 QSizePolicy::Policy hData = QSizePolicy::Minimum,
103 QSizePolicy::Policy vData = QSizePolicy::Minimum);
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
114private:
115 int width;
116 int height;
117 QSizePolicy sizeP;
118 QRect rect;
119};
120
121class Q_WIDGETS_EXPORT QWidgetItem : public QLayoutItem
122{
123 Q_DISABLE_COPY(QWidgetItem)
124
125public:
126 explicit QWidgetItem(QWidget *w) : wid(w) { }
127 ~QWidgetItem();
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 QSizePolicy::ControlTypes controlTypes() const override;
141protected:
142 QWidget *wid;
143};
144
145class Q_WIDGETS_EXPORT QWidgetItemV2 : public QWidgetItem
146{
147public:
148 explicit QWidgetItemV2(QWidget *widget);
149 ~QWidgetItemV2();
150
151 QSize sizeHint() const override;
152 QSize minimumSize() const override;
153 QSize maximumSize() const override;
154 int heightForWidth(int width) const override;
155
156private:
157 enum { Dirty = -123, HfwCacheMaxSize = 3 };
158
159 inline bool useSizeCache() const;
160 void updateCacheIfNecessary() const;
161 inline void invalidateSizeCache() {
162 q_cachedMinimumSize.setWidth(Dirty);
163 q_hfwCacheSize = 0;
164 }
165
166 mutable QSize q_cachedMinimumSize;
167 mutable QSize q_cachedSizeHint;
168 mutable QSize q_cachedMaximumSize;
169 mutable QSize q_cachedHfws[HfwCacheMaxSize];
170 mutable short q_firstCachedHfw;
171 mutable short q_hfwCacheSize;
172 void *d;
173
174 friend class QWidgetPrivate;
175
176 Q_DISABLE_COPY(QWidgetItemV2)
177};
178
179QT_END_NAMESPACE
180
181#endif // QLAYOUTITEM_H
182