Qt 4.8
qgraphicswidget.h
Go to the documentation of this file.
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 
51 
53 
54 QT_MODULE(Gui)
55 
56 class QFont;
57 class QFontMetrics;
58 class QGraphicsLayout;
62 class QStyle;
63 class QStyleOption;
64 
65 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
66 
68 
70 {
71  Q_OBJECT
73  QPalette palette;
74  QFont font;
75  Qt::LayoutDirection layoutDirection;
76  QSizeF size;
77  QSizeF minimumSize;
78  QSizeF preferredSize;
79  QSizeF maximumSize;
80  QSizePolicy sizePolicy;
81  Qt::FocusPolicy focusPolicy;
82  Qt::WindowFlags windowFlags;
83  QString windowTitle;
84  QRectF geometry;
85  bool autoFillBackground;
87 public:
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 
182 Q_SIGNALS:
183  void geometryChanged();
184  void layoutChanged();
185 
186 public Q_SLOTS:
187  bool close();
188 
189 protected:
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);
212  virtual bool focusNextPrevChild(bool next);
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);
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 
234 private:
237  Q_PRIVATE_SLOT(d_func(), void _q_relayout())
238 
245  friend class QWidget;
247 };
248 
249 inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
250 { setGeometry(QRectF(ax, ay, aw, ah)); }
251 
252 #endif
253 
255 
257 
258 #endif
259 
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
The QPainter class performs low-level painting on widgets and other paint devices.
Definition: qpainter.h:86
The QApplication class manages the GUI application&#39;s control flow and main settings.
Definition: qapplication.h:99
The QGraphicsScene class provides a surface for managing a large number of 2D graphical items...
virtual void setGeometry(const QRectF &rect)
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordi...
virtual bool sceneEvent(QEvent *event)
This virtual function receives events to this item.
int type
Definition: qmetatype.cpp:239
double qreal
Definition: qglobal.h:1193
The QFontMetrics class provides font metrics information.
Definition: qfontmetrics.h:65
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
EventRef event
QPointer< QWidget > widget
#define QT_MODULE(x)
Definition: qglobal.h:2783
QScopedPointer< QGraphicsItemPrivate > d_ptr
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
The QPainterPath class provides a container for painting operations, enabling graphical shapes to be ...
Definition: qpainterpath.h:67
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
The QPointF class defines a point in the plane using floating point precision.
Definition: qpoint.h:214
The QGraphicsItem class is the base class for all graphical items in a QGraphicsScene.
Definition: qgraphicsitem.h:89
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value)
This virtual function is called by QGraphicsItem to notify custom items that some part of the item&#39;s ...
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
The QGraphicsSceneResizeEvent class provides events for widget resizing in the graphics view framewor...
GraphicsItemChange
This enum describes the state changes that are notified by QGraphicsItem::itemChange().
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QGraphicsSceneMoveEvent class provides events for widget moving in the graphics view framework...
QRectF rect() const
Returns the item&#39;s local rect as a QRectF.
WindowType
Definition: qnamespace.h:270
#define Q_SIGNALS
Definition: qobjectdefs.h:72
WidgetAttribute
Definition: qnamespace.h:376
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
virtual QPainterPath shape() const
Returns the shape of this item as a QPainterPath in local coordinates.
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
virtual void focusInEvent(QFocusEvent *event)
This event handler, for event event, can be reimplemented to receive focus in events for this item...
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover leave events for this item...
friend class QGraphicsWidget
static const QRectF boundingRect(const QPointF *points, int pointCount)
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const =0
This pure virtual function returns the size hint for which of the QGraphicsLayoutItem, using the width or height of constraint to constrain the output.
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
virtual void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
This virtual function provides the left, top, right and bottom contents margins for this QGraphicsLay...
The QStyleOption class stores the parameters used by QStyle functions.
Definition: qstyleoption.h:67
const char * layout
The QHideEvent class provides an event which is sent after a widget is hidden.
Definition: qevent.h:388
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
This event handler, for event event, can be reimplemented to receive hover move events for this item...
LayoutDirection
Definition: qnamespace.h:1580
virtual void updateGeometry()
This virtual function discards any cached size hint information.
static const char * data(const QByteArray &arr)
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
#define Q_OBJECT
Definition: qobjectdefs.h:157
#define Q_DECLARE_PRIVATE_D(Dptr, Class)
Definition: qglobal.h:2472
SizeHint
Definition: qnamespace.h:1708
The QKeySequence class encapsulates a key sequence as used by shortcuts.
Definition: qkeysequence.h:72
The QFont class specifies a font used for drawing text.
Definition: qfont.h:64
void resize(qreal w, qreal h)
This convenience function is equivalent to calling resize(QSizeF(w, h)).
#define Q_INTERFACES(x)
This macro tells Qt which interfaces the class implements.
Definition: qobjectdefs.h:79
The QStyle class is an abstract base class that encapsulates the look and feel of a GUI...
Definition: qstyle.h:68
FocusPolicy
Definition: qnamespace.h:181
The QGraphicsLayout class provides the base class for all layouts in Graphics View.
Definition: qnamespace.h:54
const QObjectList & children() const
Returns a list of child objects.
Definition: qobject.h:197
The QGraphicsView class provides a widget for displaying the contents of a QGraphicsScene.
Definition: qgraphicsview.h:64
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget=0)=0
This function, which is usually called by QGraphicsView, paints the contents of an item in local coor...
ShortcutContext
Definition: qnamespace.h:1478
#define class
WindowFrameSection
Definition: qnamespace.h:1716
The QGraphicsObject class provides a base class for all graphics items that require signals...
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Q_CORE_EXPORT QTextStream & left(QTextStream &s)
#define QT_END_HEADER
Definition: qglobal.h:137
virtual void focusOutEvent(QFocusEvent *event)
This event handler, for event event, can be reimplemented to receive focus out events for this item...
The QStyleOptionGraphicsItem class is used to describe the parameters needed to draw a QGraphicsItem...
Definition: qstyleoption.h:867
The QCloseEvent class contains parameters that describe a close event.
Definition: qevent.h:364
#define enabled
The QFocusEvent class contains event parameters for widget focus events.
Definition: qevent.h:275
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
The QGraphicsSceneHoverEvent class provides hover events in the graphics view framework.
Qt::LayoutDirection direction
The QGraphicsWidget class is the base class for all widget items in a QGraphicsScene.
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61