qlayout.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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 QLAYOUT_H
  40. #define QLAYOUT_H
  41. #include <QtCore/qobject.h>
  42. #include <QtWidgets/qlayoutitem.h>
  43. #include <QtWidgets/qsizepolicy.h>
  44. #include <QtCore/qrect.h>
  45. #include <QtCore/qmargins.h>
  46. #include <limits.h>
  47. QT_BEGIN_NAMESPACE
  48. class QLayout;
  49. class QSize;
  50. class QLayoutPrivate;
  51. class Q_WIDGETS_EXPORT QLayout : public QObject, public QLayoutItem
  52. {
  53. Q_OBJECT
  54. Q_DECLARE_PRIVATE(QLayout)
  55. Q_PROPERTY(int margin READ margin WRITE setMargin)
  56. Q_PROPERTY(int spacing READ spacing WRITE setSpacing)
  57. Q_PROPERTY(SizeConstraint sizeConstraint READ sizeConstraint WRITE setSizeConstraint)
  58. public:
  59. enum SizeConstraint {
  60. SetDefaultConstraint,
  61. SetNoConstraint,
  62. SetMinimumSize,
  63. SetFixedSize,
  64. SetMaximumSize,
  65. SetMinAndMaxSize
  66. };
  67. Q_ENUM(SizeConstraint)
  68. QLayout(QWidget *parent);
  69. QLayout();
  70. ~QLayout();
  71. int margin() const;
  72. int spacing() const;
  73. void setMargin(int);
  74. void setSpacing(int);
  75. void setContentsMargins(int left, int top, int right, int bottom);
  76. void setContentsMargins(const QMargins &margins);
  77. void getContentsMargins(int *left, int *top, int *right, int *bottom) const;
  78. QMargins contentsMargins() const;
  79. QRect contentsRect() const;
  80. bool setAlignment(QWidget *w, Qt::Alignment alignment);
  81. bool setAlignment(QLayout *l, Qt::Alignment alignment);
  82. using QLayoutItem::setAlignment;
  83. void setSizeConstraint(SizeConstraint);
  84. SizeConstraint sizeConstraint() const;
  85. void setMenuBar(QWidget *w);
  86. QWidget *menuBar() const;
  87. QWidget *parentWidget() const;
  88. void invalidate() Q_DECL_OVERRIDE;
  89. QRect geometry() const Q_DECL_OVERRIDE;
  90. bool activate();
  91. void update();
  92. void addWidget(QWidget *w);
  93. virtual void addItem(QLayoutItem *) = 0;
  94. void removeWidget(QWidget *w);
  95. void removeItem(QLayoutItem *);
  96. Qt::Orientations expandingDirections() const Q_DECL_OVERRIDE;
  97. QSize minimumSize() const Q_DECL_OVERRIDE;
  98. QSize maximumSize() const Q_DECL_OVERRIDE;
  99. virtual void setGeometry(const QRect&) Q_DECL_OVERRIDE;
  100. virtual QLayoutItem *itemAt(int index) const = 0;
  101. virtual QLayoutItem *takeAt(int index) = 0;
  102. virtual int indexOf(QWidget *) const;
  103. virtual int count() const = 0;
  104. bool isEmpty() const Q_DECL_OVERRIDE;
  105. QSizePolicy::ControlTypes controlTypes() const Q_DECL_OVERRIDE;
  106. // ### Qt 6 make this function virtual
  107. QLayoutItem *replaceWidget(QWidget *from, QWidget *to, Qt::FindChildOptions options = Qt::FindChildrenRecursively);
  108. int totalHeightForWidth(int w) const;
  109. QSize totalMinimumSize() const;
  110. QSize totalMaximumSize() const;
  111. QSize totalSizeHint() const;
  112. QLayout *layout() Q_DECL_OVERRIDE;
  113. void setEnabled(bool);
  114. bool isEnabled() const;
  115. static QSize closestAcceptableSize(const QWidget *w, const QSize &s);
  116. protected:
  117. void widgetEvent(QEvent *);
  118. void childEvent(QChildEvent *e) Q_DECL_OVERRIDE;
  119. void addChildLayout(QLayout *l);
  120. void addChildWidget(QWidget *w);
  121. bool adoptLayout(QLayout *layout);
  122. QRect alignmentRect(const QRect&) const;
  123. protected:
  124. QLayout(QLayoutPrivate &d, QLayout*, QWidget*);
  125. private:
  126. Q_DISABLE_COPY(QLayout)
  127. static void activateRecursiveHelper(QLayoutItem *item);
  128. friend class QApplicationPrivate;
  129. friend class QWidget;
  130. };
  131. QT_END_NAMESPACE
  132. //### support old includes
  133. #include <QtWidgets/qboxlayout.h>
  134. #include <QtWidgets/qgridlayout.h>
  135. #endif // QLAYOUT_H