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

source code of qtbase/src/widgets/graphicsview/qgraphicswidget.h