1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** Contact: Qt Software Information ([email protected])
|
---|
5 | **
|
---|
6 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
7 | **
|
---|
8 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
9 | ** Commercial Usage
|
---|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
11 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
12 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
13 | ** a written agreement between you and Nokia.
|
---|
14 | **
|
---|
15 | ** GNU Lesser General Public License Usage
|
---|
16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
17 | ** General Public License version 2.1 as published by the Free Software
|
---|
18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
19 | ** packaging of this file. Please review the following information to
|
---|
20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
22 | **
|
---|
23 | ** In addition, as a special exception, Nokia gives you certain
|
---|
24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
---|
25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
---|
26 | ** package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you are unsure which license is appropriate for your use, please
|
---|
37 | ** contact the sales department at [email protected].
|
---|
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
|
---|