qgraphicswidget.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 QGRAPHICSWIDGET_H
  40. #define QGRAPHICSWIDGET_H
  41. #include <QtGui/qfont.h>
  42. #include <QtWidgets/qgraphicslayoutitem.h>
  43. #include <QtWidgets/qgraphicsitem.h>
  44. #include <QtGui/qpalette.h>
  45. QT_BEGIN_NAMESPACE
  46. class QFont;
  47. class QFontMetrics;
  48. class QGraphicsLayout;
  49. class QGraphicsSceneMoveEvent;
  50. class QGraphicsWidgetPrivate;
  51. class QGraphicsSceneResizeEvent;
  52. class QStyle;
  53. class QStyleOption;
  54. #if !defined(QT_NO_GRAPHICSVIEW)
  55. class QGraphicsWidgetPrivate;
  56. class Q_WIDGETS_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLayoutItem
  57. {
  58. Q_OBJECT
  59. Q_INTERFACES(QGraphicsItem QGraphicsLayoutItem)
  60. Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
  61. Q_PROPERTY(QFont font READ font WRITE setFont)
  62. Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
  63. Q_PROPERTY(QSizeF size READ size WRITE resize NOTIFY geometryChanged)
  64. Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize)
  65. Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize)
  66. Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize)
  67. Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
  68. Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
  69. Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
  70. Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
  71. Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
  72. Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
  73. Q_PROPERTY(QGraphicsLayout* layout READ layout WRITE setLayout NOTIFY layoutChanged)
  74. public:
  75. QGraphicsWidget(QGraphicsItem *parent = Q_NULLPTR, Qt::WindowFlags wFlags = Qt::WindowFlags());
  76. ~QGraphicsWidget();
  77. QGraphicsLayout *layout() const;
  78. void setLayout(QGraphicsLayout *layout);
  79. void adjustSize();
  80. Qt::LayoutDirection layoutDirection() const;
  81. void setLayoutDirection(Qt::LayoutDirection direction);
  82. void unsetLayoutDirection();
  83. QStyle *style() const;
  84. void setStyle(QStyle *style);
  85. QFont font() const;
  86. void setFont(const QFont &font);
  87. QPalette palette() const;
  88. void setPalette(const QPalette &palette);
  89. bool autoFillBackground() const;
  90. void setAutoFillBackground(bool enabled);
  91. void resize(const QSizeF &size);
  92. inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); }
  93. QSizeF size() const;
  94. void setGeometry(const QRectF &rect) Q_DECL_OVERRIDE;
  95. inline void setGeometry(qreal x, qreal y, qreal w, qreal h);
  96. inline QRectF rect() const { return QRectF(QPointF(), size()); }
  97. void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom);
  98. void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const Q_DECL_OVERRIDE;
  99. void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom);
  100. void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
  101. void unsetWindowFrameMargins();
  102. QRectF windowFrameGeometry() const;
  103. QRectF windowFrameRect() const;
  104. // Window handling
  105. Qt::WindowFlags windowFlags() const;
  106. Qt::WindowType windowType() const;
  107. void setWindowFlags(Qt::WindowFlags wFlags);
  108. bool isActiveWindow() const;
  109. void setWindowTitle(const QString &title);
  110. QString windowTitle() const;
  111. // Focus handling
  112. Qt::FocusPolicy focusPolicy() const;
  113. void setFocusPolicy(Qt::FocusPolicy policy);
  114. static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second);
  115. QGraphicsWidget *focusWidget() const;
  116. #ifndef QT_NO_SHORTCUT
  117. int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut);
  118. void releaseShortcut(int id);
  119. void setShortcutEnabled(int id, bool enabled = true);
  120. void setShortcutAutoRepeat(int id, bool enabled = true);
  121. #endif
  122. #ifndef QT_NO_ACTION
  123. //actions
  124. void addAction(QAction *action);
  125. #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
  126. void addActions(const QList<QAction*> &actions);
  127. void insertActions(QAction *before, const QList<QAction*> &actions);
  128. #else
  129. void addActions(QList<QAction*> actions);
  130. void insertActions(QAction *before, QList<QAction*> actions);
  131. #endif
  132. void insertAction(QAction *before, QAction *action);
  133. void removeAction(QAction *action);
  134. QList<QAction*> actions() const;
  135. #endif
  136. void setAttribute(Qt::WidgetAttribute attribute, bool on = true);
  137. bool testAttribute(Qt::WidgetAttribute attribute) const;
  138. enum {
  139. Type = 11
  140. };
  141. int type() const Q_DECL_OVERRIDE;
  142. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) Q_DECL_OVERRIDE;
  143. virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
  144. QRectF boundingRect() const Q_DECL_OVERRIDE;
  145. QPainterPath shape() const Q_DECL_OVERRIDE;
  146. #if 0
  147. void dumpFocusChain();
  148. #endif
  149. using QObject::children;
  150. Q_SIGNALS:
  151. void geometryChanged();
  152. void layoutChanged();
  153. public Q_SLOTS:
  154. bool close();
  155. protected:
  156. virtual void initStyleOption(QStyleOption *option) const;
  157. QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const Q_DECL_OVERRIDE;
  158. void updateGeometry() Q_DECL_OVERRIDE;
  159. // Notification
  160. QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE;
  161. virtual QVariant propertyChange(const QString &propertyName, const QVariant &value);
  162. // Scene events
  163. bool sceneEvent(QEvent *event) Q_DECL_OVERRIDE;
  164. virtual bool windowFrameEvent(QEvent *e);
  165. virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF& pos) const;
  166. // Base event handlers
  167. bool event(QEvent *event) Q_DECL_OVERRIDE;
  168. //virtual void actionEvent(QActionEvent *event);
  169. virtual void changeEvent(QEvent *event);
  170. virtual void closeEvent(QCloseEvent *event);
  171. //void create(WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true);
  172. //void destroy(bool destroyWindow = true, bool destroySubWindows = true);
  173. void focusInEvent(QFocusEvent *event) Q_DECL_OVERRIDE;
  174. virtual bool focusNextPrevChild(bool next);
  175. void focusOutEvent(QFocusEvent *event) Q_DECL_OVERRIDE;
  176. virtual void hideEvent(QHideEvent *event);
  177. //virtual int metric(PaintDeviceMetric m ) const;
  178. virtual void moveEvent(QGraphicsSceneMoveEvent *event);
  179. virtual void polishEvent();
  180. //void resetInputContext ();
  181. virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
  182. virtual void showEvent(QShowEvent *event);
  183. //virtual void tabletEvent(QTabletEvent *event);
  184. virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
  185. virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;
  186. virtual void grabMouseEvent(QEvent *event);
  187. virtual void ungrabMouseEvent(QEvent *event);
  188. virtual void grabKeyboardEvent(QEvent *event);
  189. virtual void ungrabKeyboardEvent(QEvent *event);
  190. QGraphicsWidget(QGraphicsWidgetPrivate &, QGraphicsItem *parent, Qt::WindowFlags wFlags = Qt::WindowFlags());
  191. private:
  192. Q_DISABLE_COPY(QGraphicsWidget)
  193. Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsWidget)
  194. friend class QGraphicsScene;
  195. friend class QGraphicsScenePrivate;
  196. friend class QGraphicsView;
  197. friend class QGraphicsItem;
  198. friend class QGraphicsItemPrivate;
  199. friend class QGraphicsLayout;
  200. friend class QWidget;
  201. friend class QApplication;
  202. };
  203. inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
  204. { setGeometry(QRectF(ax, ay, aw, ah)); }
  205. #endif
  206. QT_END_NAMESPACE
  207. #endif