1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the QtGui 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 Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/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 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef QGRAPHICSWIDGET_H
43#define QGRAPHICSWIDGET_H
44
45#include <QtGui/qfont.h>
46#include <QtGui/qgraphicslayoutitem.h>
47#include <QtGui/qgraphicsitem.h>
48#include <QtGui/qpalette.h>
49
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(Gui)
55
56class QFont;
57class QFontMetrics;
58class QGraphicsLayout;
59class QGraphicsSceneMoveEvent;
60class QGraphicsWidgetPrivate;
61class QGraphicsSceneResizeEvent;
62class QStyle;
63class QStyleOption;
64
65#if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
66
67class QGraphicsWidgetPrivate;
68
69class Q_GUI_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLayoutItem
70{
71 Q_OBJECT
72 Q_INTERFACES(QGraphicsItem QGraphicsLayoutItem)
73 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
74 Q_PROPERTY(QFont font READ font WRITE setFont)
75 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
76 Q_PROPERTY(QSizeF size READ size WRITE resize NOTIFY geometryChanged)
77 Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize)
78 Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize)
79 Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize)
80 Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
81 Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
82 Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
83 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
84 Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
85 Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
86 Q_PROPERTY(QGraphicsLayout* layout READ layout WRITE setLayout NOTIFY layoutChanged)
87public:
88 QGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
89 ~QGraphicsWidget();
90 QGraphicsLayout *layout() const;
91 void setLayout(QGraphicsLayout *layout);
92 void adjustSize();
93
94 Qt::LayoutDirection layoutDirection() const;
95 void setLayoutDirection(Qt::LayoutDirection direction);
96 void unsetLayoutDirection();
97
98 QStyle *style() const;
99 void setStyle(QStyle *style);
100
101 QFont font() const;
102 void setFont(const QFont &font);
103
104 QPalette palette() const;
105 void setPalette(const QPalette &palette);
106
107 bool autoFillBackground() const;
108 void setAutoFillBackground(bool enabled);
109
110 void resize(const QSizeF &size);
111 inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); }
112 QSizeF size() const;
113
114 void setGeometry(const QRectF &rect);
115 inline void setGeometry(qreal x, qreal y, qreal w, qreal h);
116 inline QRectF rect() const { return QRectF(QPointF(), size()); }
117
118 void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom);
119 void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
120
121 void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom);
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(QList<QAction*> actions);
152 void insertAction(QAction *before, QAction *action);
153 void insertActions(QAction *before, QList<QAction*> actions);
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;
165
166 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
167 virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
168 QRectF boundingRect() const;
169 QPainterPath shape() const;
170
171#if 0
172 void dumpFocusChain();
173#endif
174
175 // ### Qt 5: Disambiguate
176#ifdef Q_NO_USING_KEYWORD
177 const QObjectList &children() const { return QObject::children(); }
178#else
179 using QObject::children;
180#endif
181
182Q_SIGNALS:
183 void geometryChanged();
184 void layoutChanged();
185
186public Q_SLOTS:
187 bool close();
188
189protected:
190 virtual void initStyleOption(QStyleOption *option) const;
191
192 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
193 void updateGeometry();
194
195 // Notification
196 QVariant itemChange(GraphicsItemChange change, const QVariant &value);
197 virtual QVariant propertyChange(const QString &propertyName, const QVariant &value);
198
199 // Scene events
200 bool sceneEvent(QEvent *event);
201 virtual bool windowFrameEvent(QEvent *e);
202 virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF& pos) const;
203
204 // Base event handlers
205 bool event(QEvent *event);
206 //virtual void actionEvent(QActionEvent *event);
207 virtual void changeEvent(QEvent *event);
208 virtual void closeEvent(QCloseEvent *event);
209 //void create(WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true);
210 //void destroy(bool destroyWindow = true, bool destroySubWindows = true);
211 void focusInEvent(QFocusEvent *event);
212 virtual bool focusNextPrevChild(bool next);
213 void focusOutEvent(QFocusEvent *event);
214 virtual void hideEvent(QHideEvent *event);
215 //virtual bool macEvent(EventHandlerCallRef caller, EventRef event);
216 //virtual int metric(PaintDeviceMetric m ) const;
217 virtual void moveEvent(QGraphicsSceneMoveEvent *event);
218 virtual void polishEvent();
219 //virtual bool qwsEvent(QWSEvent *event);
220 //void resetInputContext ();
221 virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
222 virtual void showEvent(QShowEvent *event);
223 //virtual void tabletEvent(QTabletEvent *event);
224 //virtual bool winEvent(MSG *message, long *result);
225 //virtual bool x11Event(XEvent *event);
226 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
227 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
228 virtual void grabMouseEvent(QEvent *event);
229 virtual void ungrabMouseEvent(QEvent *event);
230 virtual void grabKeyboardEvent(QEvent *event);
231 virtual void ungrabKeyboardEvent(QEvent *event);
232 QGraphicsWidget(QGraphicsWidgetPrivate &, QGraphicsItem *parent, QGraphicsScene *, Qt::WindowFlags wFlags = 0);
233
234private:
235 Q_DISABLE_COPY(QGraphicsWidget)
236 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsWidget)
237 Q_PRIVATE_SLOT(d_func(), void _q_relayout())
238
239 friend class QGraphicsScene;
240 friend class QGraphicsScenePrivate;
241 friend class QGraphicsView;
242 friend class QGraphicsItem;
243 friend class QGraphicsItemPrivate;
244 friend class QGraphicsLayout;
245 friend class QWidget;
246 friend class QApplication;
247};
248
249inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
250{ setGeometry(QRectF(ax, ay, aw, ah)); }
251
252#endif
253
254QT_END_NAMESPACE
255
256QT_END_HEADER
257
258#endif
259
260