source: trunk/src/gui/graphicsview/qgraphicswidget.h@ 500

Last change on this file since 500 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 9.1 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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 QObject, public QGraphicsItem, public QGraphicsLayoutItem
70{
71 Q_OBJECT
72 Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
73 Q_PROPERTY(QFont font READ font WRITE setFont)
74 Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
75 Q_PROPERTY(QSizeF size READ size WRITE resize)
76 Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
77 Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
78 Q_PROPERTY(bool visible READ isVisible WRITE setVisible)
79 Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
80 Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
81 Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity)
82 Q_PROPERTY(QPointF pos READ pos WRITE setPos)
83 Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry)
84
85public:
86 QGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
87 ~QGraphicsWidget();
88
89 QGraphicsLayout *layout() const;
90 void setLayout(QGraphicsLayout *layout);
91 void adjustSize();
92
93 Qt::LayoutDirection layoutDirection() const;
94 void setLayoutDirection(Qt::LayoutDirection direction);
95 void unsetLayoutDirection();
96
97 QStyle *style() const;
98 void setStyle(QStyle *style);
99
100 QFont font() const;
101 void setFont(const QFont &font);
102
103 QPalette palette() const;
104 void setPalette(const QPalette &palette);
105
106 void resize(const QSizeF &size);
107 inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); }
108 QSizeF size() const;
109
110 void setGeometry(const QRectF &rect);
111 inline void setGeometry(qreal x, qreal y, qreal w, qreal h);
112 inline QRectF rect() const { return QRectF(QPointF(), size()); }
113
114 void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom);
115 void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
116
117 void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom);
118 void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
119 void unsetWindowFrameMargins();
120 QRectF windowFrameGeometry() const;
121 QRectF windowFrameRect() const;
122
123 // Window handling
124 Qt::WindowFlags windowFlags() const;
125 Qt::WindowType windowType() const;
126 void setWindowFlags(Qt::WindowFlags wFlags);
127 bool isActiveWindow() const;
128 void setWindowTitle(const QString &title);
129 QString windowTitle() const;
130
131 // Focus handling
132 Qt::FocusPolicy focusPolicy() const;
133 void setFocusPolicy(Qt::FocusPolicy policy);
134 static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second);
135 QGraphicsWidget *focusWidget() const;
136
137#ifndef QT_NO_SHORTCUT
138 int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut);
139 void releaseShortcut(int id);
140 void setShortcutEnabled(int id, bool enabled = true);
141 void setShortcutAutoRepeat(int id, bool enabled = true);
142#endif
143
144#ifndef QT_NO_ACTION
145 //actions
146 void addAction(QAction *action);
147 void addActions(QList<QAction*> actions);
148 void insertAction(QAction *before, QAction *action);
149 void insertActions(QAction *before, QList<QAction*> actions);
150 void removeAction(QAction *action);
151 QList<QAction*> actions() const;
152#endif
153
154 void setAttribute(Qt::WidgetAttribute attribute, bool on = true);
155 bool testAttribute(Qt::WidgetAttribute attribute) const;
156
157 enum {
158 Type = 11
159 };
160 int type() const;
161
162 void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
163 virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
164 QRectF boundingRect() const;
165 QPainterPath shape() const;
166
167#if 0
168 void dumpFocusChain();
169#endif
170
171 // ### Qt 5: Disambiguate
172#ifdef Q_NO_USING_KEYWORD
173 const QObjectList &children() const { return QObject::children(); }
174#else
175 using QObject::children;
176#endif
177
178public Q_SLOTS:
179 bool close();
180
181protected:
182 virtual void initStyleOption(QStyleOption *option) const;
183
184 QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
185 void updateGeometry();
186
187 // Notification
188 QVariant itemChange(GraphicsItemChange change, const QVariant &value);
189 virtual QVariant propertyChange(const QString &propertyName, const QVariant &value);
190
191 // Scene events
192 bool sceneEvent(QEvent *event);
193 virtual bool windowFrameEvent(QEvent *e);
194 virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF& pos) const;
195
196 // Base event handlers
197 bool event(QEvent *event);
198 //virtual void actionEvent(QActionEvent *event);
199 virtual void changeEvent(QEvent *event);
200 virtual void closeEvent(QCloseEvent *event);
201 //void create(WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true);
202 //void destroy(bool destroyWindow = true, bool destroySubWindows = true);
203 void focusInEvent(QFocusEvent *event);
204 virtual bool focusNextPrevChild(bool next);
205 void focusOutEvent(QFocusEvent *event);
206 virtual void hideEvent(QHideEvent *event);
207 //virtual bool macEvent(EventHandlerCallRef caller, EventRef event);
208 //virtual int metric(PaintDeviceMetric m ) const;
209 virtual void moveEvent(QGraphicsSceneMoveEvent *event);
210 virtual void polishEvent();
211 //virtual bool qwsEvent(QWSEvent *event);
212 //void resetInputContext ();
213 virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
214 virtual void showEvent(QShowEvent *event);
215 //virtual void tabletEvent(QTabletEvent *event);
216 //virtual bool winEvent(MSG *message, long *result);
217 //virtual bool x11Event(XEvent *event);
218 virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
219 virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
220 virtual void grabMouseEvent(QEvent *event);
221 virtual void ungrabMouseEvent(QEvent *event);
222 virtual void grabKeyboardEvent(QEvent *event);
223 virtual void ungrabKeyboardEvent(QEvent *event);
224 QGraphicsWidget(QGraphicsWidgetPrivate &, QGraphicsItem *parent, QGraphicsScene *, Qt::WindowFlags wFlags = 0);
225
226private:
227 Q_DISABLE_COPY(QGraphicsWidget)
228 Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QGraphicsWidget)
229 friend class QGraphicsScene;
230 friend class QGraphicsScenePrivate;
231 friend class QGraphicsView;
232 friend class QGraphicsItem;
233 friend class QGraphicsItemPrivate;
234 friend class QGraphicsLayout;
235 friend class QWidget;
236 friend class QApplication;
237};
238
239inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
240{ setGeometry(QRectF(ax, ay, aw, ah)); }
241
242#endif
243
244QT_END_NAMESPACE
245
246QT_END_HEADER
247
248#endif
249
Note: See TracBrowser for help on using the repository browser.