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