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 = Q_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(QSizeF(w, h)); }
107 QSizeF size() const;
108
109 void setGeometry(const QRectF &rect) Q_DECL_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 getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const Q_DECL_OVERRIDE;
115
116 void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom);
117 void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
118 void unsetWindowFrameMargins();
119 QRectF windowFrameGeometry() const;
120 QRectF windowFrameRect() const;
121
122 // Window handling
123 Qt::WindowFlags windowFlags() const;
124 Qt::WindowType windowType() const;
125 void setWindowFlags(Qt::WindowFlags wFlags);
126 bool isActiveWindow() const;
127 void setWindowTitle(const QString &title);
128 QString windowTitle() const;
129
130 // Focus handling
131 Qt::FocusPolicy focusPolicy() const;
132 void setFocusPolicy(Qt::FocusPolicy policy);
133 static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second);
134 QGraphicsWidget *focusWidget() const;
135
136#ifndef QT_NO_SHORTCUT
137 int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut);
138 void releaseShortcut(int id);
139 void setShortcutEnabled(int id, bool enabled = true);
140 void setShortcutAutoRepeat(int id, bool enabled = true);
141#endif
142
143#ifndef QT_NO_ACTION
144 //actions
145 void addAction(QAction *action);
146#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
147 void addActions(const QList<QAction*> &actions);
148 void insertActions(QAction *before, const QList<QAction*> &actions);
149#else
150 void addActions(QList<QAction*> actions);
151 void insertActions(QAction *before, QList<QAction*> actions);
152#endif
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 Q_DECL_OVERRIDE;
165
166 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) Q_DECL_OVERRIDE;
167 virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR);
168 QRectF boundingRect() const Q_DECL_OVERRIDE;
169 QPainterPath shape() const Q_DECL_OVERRIDE;
170
171#if 0
172 void dumpFocusChain();
173#endif
174
175 using QObject::children;
176
177Q_SIGNALS:
178 void geometryChanged();
179 void layoutChanged();
180
181public Q_SLOTS:
182 bool close();
183
184protected:
185 virtual void initStyleOption(QStyleOption *option) const;
186
187 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const Q_DECL_OVERRIDE;
188 void updateGeometry() Q_DECL_OVERRIDE;
189
190 // Notification
191 QVariant itemChange(GraphicsItemChange change, const QVariant &value) Q_DECL_OVERRIDE;
192 virtual QVariant propertyChange(const QString &propertyName, const QVariant &value);
193
194 // Scene events
195 bool sceneEvent(QEvent *event) Q_DECL_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) Q_DECL_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) Q_DECL_OVERRIDE;
207 virtual bool focusNextPrevChild(bool next);
208 void focusOutEvent(QFocusEvent *event) Q_DECL_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) Q_DECL_OVERRIDE;
218 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_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
225private:
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
238inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
239{ setGeometry(QRectF(ax, ay, aw, ah)); }
240
241QT_END_NAMESPACE
242
243#endif
244
245