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