qgraphicslayoutitem.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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 QGRAPHICSLAYOUTITEM_H
  40. #define QGRAPHICSLAYOUTITEM_H
  41. #include <QtCore/qscopedpointer.h>
  42. #include <QtWidgets/qsizepolicy.h>
  43. #include <QtGui/qevent.h>
  44. QT_BEGIN_NAMESPACE
  45. #if !defined(QT_NO_GRAPHICSVIEW)
  46. class QGraphicsLayoutItemPrivate;
  47. class QGraphicsItem;
  48. class Q_WIDGETS_EXPORT QGraphicsLayoutItem
  49. {
  50. public:
  51. QGraphicsLayoutItem(QGraphicsLayoutItem *parent = Q_NULLPTR, bool isLayout = false);
  52. virtual ~QGraphicsLayoutItem();
  53. void setSizePolicy(const QSizePolicy &policy);
  54. void setSizePolicy(QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType = QSizePolicy::DefaultType);
  55. QSizePolicy sizePolicy() const;
  56. void setMinimumSize(const QSizeF &size);
  57. inline void setMinimumSize(qreal w, qreal h);
  58. QSizeF minimumSize() const;
  59. void setMinimumWidth(qreal width);
  60. inline qreal minimumWidth() const;
  61. void setMinimumHeight(qreal height);
  62. inline qreal minimumHeight() const;
  63. void setPreferredSize(const QSizeF &size);
  64. inline void setPreferredSize(qreal w, qreal h);
  65. QSizeF preferredSize() const;
  66. void setPreferredWidth(qreal width);
  67. inline qreal preferredWidth() const;
  68. void setPreferredHeight(qreal height);
  69. inline qreal preferredHeight() const;
  70. void setMaximumSize(const QSizeF &size);
  71. inline void setMaximumSize(qreal w, qreal h);
  72. QSizeF maximumSize() const;
  73. void setMaximumWidth(qreal width);
  74. inline qreal maximumWidth() const;
  75. void setMaximumHeight(qreal height);
  76. inline qreal maximumHeight() const;
  77. virtual void setGeometry(const QRectF &rect);
  78. QRectF geometry() const;
  79. virtual void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
  80. QRectF contentsRect() const;
  81. QSizeF effectiveSizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
  82. virtual void updateGeometry();
  83. QGraphicsLayoutItem *parentLayoutItem() const;
  84. void setParentLayoutItem(QGraphicsLayoutItem *parent);
  85. bool isLayout() const;
  86. QGraphicsItem *graphicsItem() const;
  87. bool ownedByLayout() const;
  88. protected:
  89. void setGraphicsItem(QGraphicsItem *item);
  90. void setOwnedByLayout(bool ownedByLayout);
  91. QGraphicsLayoutItem(QGraphicsLayoutItemPrivate &dd);
  92. virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const = 0;
  93. QScopedPointer<QGraphicsLayoutItemPrivate> d_ptr;
  94. private:
  95. QSizeF *effectiveSizeHints(const QSizeF &constraint) const;
  96. Q_DECLARE_PRIVATE(QGraphicsLayoutItem)
  97. friend class QGraphicsLayout;
  98. };
  99. Q_DECLARE_INTERFACE(QGraphicsLayoutItem, "org.qt-project.Qt.QGraphicsLayoutItem")
  100. inline void QGraphicsLayoutItem::setMinimumSize(qreal aw, qreal ah)
  101. { setMinimumSize(QSizeF(aw, ah)); }
  102. inline void QGraphicsLayoutItem::setPreferredSize(qreal aw, qreal ah)
  103. { setPreferredSize(QSizeF(aw, ah)); }
  104. inline void QGraphicsLayoutItem::setMaximumSize(qreal aw, qreal ah)
  105. { setMaximumSize(QSizeF(aw, ah)); }
  106. inline qreal QGraphicsLayoutItem::minimumWidth() const
  107. { return effectiveSizeHint(Qt::MinimumSize).width(); }
  108. inline qreal QGraphicsLayoutItem::minimumHeight() const
  109. { return effectiveSizeHint(Qt::MinimumSize).height(); }
  110. inline qreal QGraphicsLayoutItem::preferredWidth() const
  111. { return effectiveSizeHint(Qt::PreferredSize).width(); }
  112. inline qreal QGraphicsLayoutItem::preferredHeight() const
  113. { return effectiveSizeHint(Qt::PreferredSize).height(); }
  114. inline qreal QGraphicsLayoutItem::maximumWidth() const
  115. { return effectiveSizeHint(Qt::MaximumSize).width(); }
  116. inline qreal QGraphicsLayoutItem::maximumHeight() const
  117. { return effectiveSizeHint(Qt::MaximumSize).height(); }
  118. #endif
  119. QT_END_NAMESPACE
  120. #endif