|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
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 |