qgraphicswidget.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QGRAPHICSWIDGET_H
00043 #define QGRAPHICSWIDGET_H
00044 
00045 #include <QtGui/qfont.h>
00046 #include <QtGui/qgraphicslayoutitem.h>
00047 #include <QtGui/qgraphicsitem.h>
00048 #include <QtGui/qpalette.h>
00049 
00050 QT_BEGIN_HEADER
00051 
00052 QT_BEGIN_NAMESPACE
00053 
00054 QT_MODULE(Gui)
00055 
00056 class QFont;
00057 class QFontMetrics;
00058 class QGraphicsLayout;
00059 class QGraphicsSceneMoveEvent;
00060 class QGraphicsWidgetPrivate;
00061 class QGraphicsSceneResizeEvent;
00062 class QStyle;
00063 class QStyleOption;
00064 
00065 #if !defined(QT_NO_GRAPHICSVIEW) || (QT_EDITION & QT_MODULE_GRAPHICSVIEW) != QT_MODULE_GRAPHICSVIEW
00066 
00067 class QGraphicsWidgetPrivate;
00068 
00069 class Q_GUI_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLayoutItem
00070 {
00071     Q_OBJECT
00072     Q_INTERFACES(QGraphicsItem QGraphicsLayoutItem)
00073     Q_PROPERTY(QPalette palette READ palette WRITE setPalette)
00074     Q_PROPERTY(QFont font READ font WRITE setFont)
00075     Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection)
00076     Q_PROPERTY(QSizeF size READ size WRITE resize NOTIFY geometryChanged)
00077     Q_PROPERTY(QSizeF minimumSize READ minimumSize WRITE setMinimumSize)
00078     Q_PROPERTY(QSizeF preferredSize READ preferredSize WRITE setPreferredSize)
00079     Q_PROPERTY(QSizeF maximumSize READ maximumSize WRITE setMaximumSize)
00080     Q_PROPERTY(QSizePolicy sizePolicy READ sizePolicy WRITE setSizePolicy)
00081     Q_PROPERTY(Qt::FocusPolicy focusPolicy READ focusPolicy WRITE setFocusPolicy)
00082     Q_PROPERTY(Qt::WindowFlags windowFlags READ windowFlags WRITE setWindowFlags)
00083     Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle)
00084     Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
00085     Q_PROPERTY(bool autoFillBackground READ autoFillBackground WRITE setAutoFillBackground)
00086     Q_PROPERTY(QGraphicsLayout* layout READ layout WRITE setLayout NOTIFY layoutChanged)
00087 public:
00088     QGraphicsWidget(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
00089     ~QGraphicsWidget();
00090     QGraphicsLayout *layout() const;
00091     void setLayout(QGraphicsLayout *layout);
00092     void adjustSize();
00093 
00094     Qt::LayoutDirection layoutDirection() const;
00095     void setLayoutDirection(Qt::LayoutDirection direction);
00096     void unsetLayoutDirection();
00097 
00098     QStyle *style() const;
00099     void setStyle(QStyle *style);
00100 
00101     QFont font() const;
00102     void setFont(const QFont &font);
00103 
00104     QPalette palette() const;
00105     void setPalette(const QPalette &palette);
00106 
00107     bool autoFillBackground() const;
00108     void setAutoFillBackground(bool enabled);
00109 
00110     void resize(const QSizeF &size);
00111     inline void resize(qreal w, qreal h) { resize(QSizeF(w, h)); }
00112     QSizeF size() const;
00113 
00114     void setGeometry(const QRectF &rect);
00115     inline void setGeometry(qreal x, qreal y, qreal w, qreal h);
00116     inline QRectF rect() const { return QRectF(QPointF(), size()); }
00117 
00118     void setContentsMargins(qreal left, qreal top, qreal right, qreal bottom);
00119     void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
00120 
00121     void setWindowFrameMargins(qreal left, qreal top, qreal right, qreal bottom);
00122     void getWindowFrameMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const;
00123     void unsetWindowFrameMargins();
00124     QRectF windowFrameGeometry() const;
00125     QRectF windowFrameRect() const;
00126 
00127     // Window handling
00128     Qt::WindowFlags windowFlags() const;
00129     Qt::WindowType windowType() const;
00130     void setWindowFlags(Qt::WindowFlags wFlags);
00131     bool isActiveWindow() const;
00132     void setWindowTitle(const QString &title);
00133     QString windowTitle() const;
00134 
00135     // Focus handling
00136     Qt::FocusPolicy focusPolicy() const;
00137     void setFocusPolicy(Qt::FocusPolicy policy);
00138     static void setTabOrder(QGraphicsWidget *first, QGraphicsWidget *second);
00139     QGraphicsWidget *focusWidget() const;
00140 
00141 #ifndef QT_NO_SHORTCUT
00142     int grabShortcut(const QKeySequence &sequence, Qt::ShortcutContext context = Qt::WindowShortcut);
00143     void releaseShortcut(int id);
00144     void setShortcutEnabled(int id, bool enabled = true);
00145     void setShortcutAutoRepeat(int id, bool enabled = true);
00146 #endif
00147 
00148 #ifndef QT_NO_ACTION
00149     //actions
00150     void addAction(QAction *action);
00151     void addActions(QList<QAction*> actions);
00152     void insertAction(QAction *before, QAction *action);
00153     void insertActions(QAction *before, QList<QAction*> actions);
00154     void removeAction(QAction *action);
00155     QList<QAction*> actions() const;
00156 #endif
00157 
00158     void setAttribute(Qt::WidgetAttribute attribute, bool on = true);
00159     bool testAttribute(Qt::WidgetAttribute attribute) const;
00160 
00161     enum {
00162         Type = 11
00163     };
00164     int type() const;
00165 
00166     void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00167     virtual void paintWindowFrame(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
00168     QRectF boundingRect() const;
00169     QPainterPath shape() const;
00170 
00171 #if 0
00172     void dumpFocusChain();
00173 #endif
00174 
00175     // ### Qt 5: Disambiguate
00176 #ifdef Q_NO_USING_KEYWORD
00177     const QObjectList &children() const { return QObject::children(); }
00178 #else
00179     using QObject::children;
00180 #endif
00181 
00182 Q_SIGNALS:
00183     void geometryChanged();
00184     void layoutChanged();
00185 
00186 public Q_SLOTS:
00187     bool close();
00188 
00189 protected:
00190     virtual void initStyleOption(QStyleOption *option) const;
00191 
00192     QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const;
00193     void updateGeometry();
00194 
00195     // Notification
00196     QVariant itemChange(GraphicsItemChange change, const QVariant &value);
00197     virtual QVariant propertyChange(const QString &propertyName, const QVariant &value);
00198 
00199     // Scene events
00200     bool sceneEvent(QEvent *event);
00201     virtual bool windowFrameEvent(QEvent *e);
00202     virtual Qt::WindowFrameSection windowFrameSectionAt(const QPointF& pos) const;
00203 
00204     // Base event handlers
00205     bool event(QEvent *event);
00206     //virtual void actionEvent(QActionEvent *event);
00207     virtual void changeEvent(QEvent *event);
00208     virtual void closeEvent(QCloseEvent *event);
00209     //void create(WId window = 0, bool initializeWindow = true, bool destroyOldWindow = true);
00210     //void destroy(bool destroyWindow = true, bool destroySubWindows = true);
00211     void focusInEvent(QFocusEvent *event);
00212     virtual bool focusNextPrevChild(bool next);
00213     void focusOutEvent(QFocusEvent *event);
00214     virtual void hideEvent(QHideEvent *event);
00215     //virtual bool macEvent(EventHandlerCallRef caller, EventRef event);
00216     //virtual int metric(PaintDeviceMetric m ) const;
00217     virtual void moveEvent(QGraphicsSceneMoveEvent *event);
00218     virtual void polishEvent();
00219     //virtual bool qwsEvent(QWSEvent *event);
00220     //void resetInputContext ();
00221     virtual void resizeEvent(QGraphicsSceneResizeEvent *event);
00222     virtual void showEvent(QShowEvent *event);
00223     //virtual void tabletEvent(QTabletEvent *event);
00224     //virtual bool winEvent(MSG *message, long *result);
00225     //virtual bool x11Event(XEvent *event);
00226     virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
00227     virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
00228     virtual void grabMouseEvent(QEvent *event);
00229     virtual void ungrabMouseEvent(QEvent *event);
00230     virtual void grabKeyboardEvent(QEvent *event);
00231     virtual void ungrabKeyboardEvent(QEvent *event);
00232     QGraphicsWidget(QGraphicsWidgetPrivate &, QGraphicsItem *parent, QGraphicsScene *, Qt::WindowFlags wFlags = 0);
00233 
00234 private:
00235     Q_DISABLE_COPY(QGraphicsWidget)
00236     Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr.data(), QGraphicsWidget)
00237     friend class QGraphicsScene;
00238     friend class QGraphicsScenePrivate;
00239     friend class QGraphicsView;
00240     friend class QGraphicsItem;
00241     friend class QGraphicsItemPrivate;
00242     friend class QGraphicsLayout;
00243     friend class QWidget;
00244     friend class QApplication;
00245 };
00246 
00247 inline void QGraphicsWidget::setGeometry(qreal ax, qreal ay, qreal aw, qreal ah)
00248 { setGeometry(QRectF(ax, ay, aw, ah)); }
00249 
00250 #endif
00251 
00252 QT_END_NAMESPACE
00253 
00254 QT_END_HEADER
00255 
00256 #endif
00257