qlayoutitem.h 5.5 KB

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