Qt 4.8
qlayoutitem.h
Go to the documentation of this file.
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 
51 
53 
54 QT_MODULE(Gui)
55 
56 static const int QLAYOUTSIZE_MAX = INT_MAX/256/16;
57 
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 
97 {
98 public:
99  QSpacerItem(int w, int h,
102  : width(w), height(h), sizeP(hData, vData) { }
103  void changeSize(int w, int h,
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;
114 
115 private:
116  int width;
117  int height;
120 };
121 
123 {
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:
142 };
143 
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 
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 
176 };
177 
179 
181 
182 #endif // QLAYOUTITEM_H
void invalidateSizeCache()
Definition: qlayoutitem.h:160
static qreal minimumHeightForWidth(qreal width, qreal minh, qreal maxh, const QGraphicsWidget *widget, bool heightForWidth=true)
Used to calculate the Precondition: widget should support either hfw or wfh.
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual QRect geometry() const =0
Returns the rectangle covered by this layout item.
QLayoutItem(Qt::Alignment alignment=0)
Constructs a layout item with an alignment.
Definition: qlayoutitem.h:93
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
virtual bool isEmpty() const =0
Implemented in subclasses to return whether this item is empty, i.
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
QWidgetItem(QWidget *w)
Creates an item containing the given widget.
Definition: qlayoutitem.h:127
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
virtual Qt::Orientations expandingDirections() const =0
Returns whether this layout item can make use of more space than sizeHint().
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
long ASN1_INTEGER_get ASN1_INTEGER * a
short q_firstCachedHfw
Definition: qlayoutitem.h:169
virtual QSize minimumSize() const =0
Implemented in subclasses to return the minimum size of this item.
virtual bool hasHeightForWidth() const
Returns true if this layout&#39;s preferred height depends on its width; otherwise returns false...
virtual QSpacerItem * spacerItem()
If this item is a QSpacerItem, it is returned as a QSpacerItem; otherwise 0 is returned.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QLayoutItem class provides an abstract item that a QLayout manipulates.
Definition: qlayoutitem.h:64
static bool isEmpty(const char *str)
QSize q_cachedMaximumSize
Definition: qlayoutitem.h:167
The QSpacerItem class provides blank space in a layout.
Definition: qlayoutitem.h:96
The QLayout class is the base class of geometry managers.
Definition: qlayout.h:90
const char * layout
The QWidgetItem class is a layout item that represents a widget.
Definition: qlayoutitem.h:122
QSizePolicy sizeP
Definition: qlayoutitem.h:118
virtual void setGeometry(const QRect &)=0
Implemented in subclasses to set this item&#39;s geometry to r.
virtual QSize sizeHint() const =0
Implemented in subclasses to return the preferred size of this item.
virtual QSize maximumSize() const =0
Implemented in subclasses to return the maximum size of this item.
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
Qt::Alignment alignment() const
Returns the alignment of this item.
Definition: qlayoutitem.h:85
virtual QWidget * widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned.
virtual int heightForWidth(int) const
Returns the preferred height for this layout item, given the width w.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
QWidget * wid
Definition: qlayoutitem.h:141
short q_hfwCacheSize
Definition: qlayoutitem.h:170
Qt::Alignment align
Definition: qlayoutitem.h:90
QSize q_cachedSizeHint
Definition: qlayoutitem.h:166
static const int QLAYOUTSIZE_MAX
Definition: qlayoutitem.h:56
#define class
#define QT_END_HEADER
Definition: qglobal.h:137
QSpacerItem(int w, int h, QSizePolicy::Policy hData=QSizePolicy::Minimum, QSizePolicy::Policy vData=QSizePolicy::Minimum)
Constructs a spacer item with preferred width w, preferred height h, horizontal size policy hPolicy a...
Definition: qlayoutitem.h:99
#define INT_MAX
QSize q_cachedMinimumSize
Definition: qlayoutitem.h:165