|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
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 |
|
50 QT_BEGIN_HEADER |
|
51 |
|
52 QT_BEGIN_NAMESPACE |
|
53 |
|
54 QT_MODULE(Gui) |
|
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 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW |
|
66 |
|
67 class QGraphicsWidgetPrivate; |
|
68 |
|
69 class 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) |
|
77 Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy) |
|
78 Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags) |
|
79 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle) |
|
80 Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry) |
|
81 public: |
|
82 QGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0); |
|
83 ~QGraphicsWidget(); |
|
84 |
|
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 void resize(const QSizeF &size); |
|
103 inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); } |
|
104 QSizeF size() const; |
|
105 |
|
106 void setGeometry(const QRectF &rect); |
|
107 inline void setGeometry(qreal x, qreal y, qreal w, qreal h); |
|
108 inline QRectF rect() const { return QRectF(QPointF(), size()); } |
|
109 |
|
110 void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom); |
|
111 void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const; |
|
112 |
|
113 void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom); |
|
114 void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const; |
|
115 void unsetWindowFrameMargins(); |
|
116 QRectF windowFrameGeometry() const; |
|
117 QRectF windowFrameRect() const; |
|
118 |
|
119 // Window handling |
|
120 Qt::WindowFlags windowFlags() const; |
|
121 Qt::WindowType windowType() const; |
|
122 void setWindowFlags(Qt::WindowFlags wFlags); |
|
123 bool isActiveWindow() const; |
|
124 void setWindowTitle(const QString &title); |
|
125 QString windowTitle() const; |
|
126 |
|
127 // Focus handling |
|
128 Qt::FocusPolicy focusPolicy() const; |
|
129 void setFocusPolicy(Qt::FocusPolicy policy); |
|
130 static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second); |
|
131 QGraphicsWidget *focusWidget() const; |
|
132 |
|
133 #ifndef QT_NO_SHORTCUT |
|
134 int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut); |
|
135 void releaseShortcut(int id); |
|
136 void setShortcutEnabled(int id, bool enabled = true); |
|
137 void setShortcutAutoRepeat(int id, bool enabled = true); |
|
138 #endif |
|
139 |
|
140 #ifndef QT_NO_ACTION |
|
141 //actions |
|
142 void addAction(QAction *action); |
|
143 void addActions(QList<QAction*> actions); |
|
144 void insertAction(QAction *before, QAction *action); |
|
145 void insertActions(QAction *before, QList<QAction*> actions); |
|
146 void removeAction(QAction *action); |
|
147 QList<QAction*> actions() const; |
|
148 #endif |
|
149 |
|
150 void setAttribute(Qt::WidgetAttribute attribute, bool on = true); |
|
151 bool testAttribute(Qt::WidgetAttribute attribute) const; |
|
152 |
|
153 enum { |
|
154 Type = 11 |
|
155 }; |
|
156 int type() const; |
|
157 |
|
158 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
159 virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); |
|
160 QRectF boundingRect() const; |
|
161 QPainterPath shape() const; |
|
162 |
|
163 #if 0 |
|
164 void dumpFocusChain(); |
|
165 #endif |
|
166 |
|
167 // ### Qt 5: Disambiguate |
|
168 #ifdef Q_NO_USING_KEYWORD |
|
169 const QObjectList &children() const { return QObject::children(); } |
|
170 #else |
|
171 using QObject::children; |
|
172 #endif |
|
173 |
|
174 public Q_SLOTS: |
|
175 bool close(); |
|
176 |
|
177 protected: |
|
178 virtual void initStyleOption(QStyleOption *option) const; |
|
179 |
|
180 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const; |
|
181 void updateGeometry(); |
|
182 |
|
183 // Notification |
|
184 QVariant itemChange(GraphicsItemChange change, const QVariant &value); |
|
185 virtual QVariant propertyChange(const QString &propertyName, const QVariant &value); |
|
186 |
|
187 // Scene events |
|
188 bool sceneEvent(QEvent *event); |
|
189 virtual bool windowFrameEvent(QEvent *e); |
|
190 virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF& pos) const; |
|
191 |
|
192 // Base event handlers |
|
193 bool event(QEvent *event); |
|
194 //virtual void actionEvent(QActionEvent *event); |
|
195 virtual void changeEvent(QEvent *event); |
|
196 virtual void closeEvent(QCloseEvent *event); |
|
197 //void create(WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true); |
|
198 //void destroy(bool destroyWindow = true, bool destroySubWindows = true); |
|
199 void focusInEvent(QFocusEvent *event); |
|
200 virtual bool focusNextPrevChild(bool next); |
|
201 void focusOutEvent(QFocusEvent *event); |
|
202 virtual void hideEvent(QHideEvent *event); |
|
203 //virtual bool macEvent(EventHandlerCallRef caller, EventRef event); |
|
204 //virtual int metric(PaintDeviceMetric m ) const; |
|
205 virtual void moveEvent(QGraphicsSceneMoveEvent *event); |
|
206 virtual void polishEvent(); |
|
207 //virtual bool qwsEvent(QWSEvent *event); |
|
208 //void resetInputContext (); |
|
209 virtual void resizeEvent(QGraphicsSceneResizeEvent *event); |
|
210 virtual void showEvent(QShowEvent *event); |
|
211 //virtual void tabletEvent(QTabletEvent *event); |
|
212 //virtual bool winEvent(MSG *message, long *result); |
|
213 //virtual bool x11Event(XEvent *event); |
|
214 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event); |
|
215 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event); |
|
216 virtual void grabMouseEvent(QEvent *event); |
|
217 virtual void ungrabMouseEvent(QEvent *event); |
|
218 virtual void grabKeyboardEvent(QEvent *event); |
|
219 virtual void ungrabKeyboardEvent(QEvent *event); |
|
220 QGraphicsWidget(QGraphicsWidgetPrivate &, QGraphicsItem *parent, QGraphicsScene *, Qt::WindowFlags wFlags = 0); |
|
221 |
|
222 private: |
|
223 Q_DISABLE_COPY(QGraphicsWidget) |
|
224 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsWidget) |
|
225 friend class QGraphicsScene; |
|
226 friend class QGraphicsScenePrivate; |
|
227 friend class QGraphicsView; |
|
228 friend class QGraphicsItem; |
|
229 friend class QGraphicsItemPrivate; |
|
230 friend class QGraphicsLayout; |
|
231 friend class QWidget; |
|
232 friend class QApplication; |
|
233 }; |
|
234 |
|
235 inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah) |
|
236 { setGeometry(QRectF(ax, ay, aw, ah)); } |
|
237 |
|
238 #endif |
|
239 |
|
240 QT_END_NAMESPACE |
|
241 |
|
242 QT_END_HEADER |
|
243 |
|
244 #endif |
|
245 |