diff options
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 145 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.h | 43 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem_p.h | 4 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicswidget.cpp | 81 |
4 files changed, 166 insertions, 107 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index b83f9db..6d87c36 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1260,6 +1260,28 @@ QGraphicsWidget *QGraphicsItem::window() const } /*! + \since 4.6 + + Return the graphics item cast to a QGraphicsObject, if the class is actually a + graphics object, 0 otherwise. +*/ +QGraphicsObject *QGraphicsItem::toGraphicsObject() +{ + return d_ptr->isObject ? static_cast<QGraphicsObject *>(this) : 0; +} + +/*! + \since 4.6 + + Return the graphics item cast to a QGraphicsObject, if the class is actually a + graphics object, 0 otherwise. +*/ +const QGraphicsObject *QGraphicsItem::toGraphicsObject() const +{ + return d_ptr->isObject ? static_cast<const QGraphicsObject *>(this) : 0; +} + +/*! Sets this item's parent item to \a parent. If this item already has a parent, it is first removed from the previous parent. If \a parent is 0, this item will become a top-level item. @@ -1799,6 +1821,9 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo void QGraphicsItem::setVisible(bool visible) { d_ptr->setVisibleHelper(visible, /* explicit = */ true); + + if (d_ptr->isObject) + emit static_cast<QGraphicsObject *>(this)->visibleChanged(); } /*! @@ -1920,6 +1945,9 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo void QGraphicsItem::setEnabled(bool enabled) { d_ptr->setEnabledHelper(enabled, /* explicitly = */ true); + + if (d_ptr->isObject) + emit static_cast<QGraphicsObject *>(this)->enabledChanged(); } /*! @@ -2082,6 +2110,8 @@ void QGraphicsItem::setOpacity(qreal opacity) /*maybeDirtyClipPath=*/false, /*force=*/false, /*ignoreOpacity=*/true); + if (d_ptr->isObject) + emit static_cast<QGraphicsObject *>(this)->opacityChanged(); } /*! @@ -2524,6 +2554,8 @@ void QGraphicsItemPrivate::setPosHelper(const QPointF &pos) this->pos = pos; dirtySceneTransform = 1; inSetPosHelper = 0; + if (isObject) + emit static_cast<QGraphicsObject *>(q)->positionChanged(); } /*! @@ -6324,6 +6356,108 @@ static void qt_graphicsItem_highlightSelected( } /*! + \class QGraphicsObject + \brief The QGraphicsObject class provides a base class for all graphics items that + require signals, slots and properties. + \since 4.6 + \ingroup graphicsview-api + + The class extends a QGraphicsItem with QObject's signal/slot and property mechanisms. + It maps many of QGraphicsItem's basic setters and getters to properties and adds notification + signals for many of them. +*/ + +/*! + Constructs a QGraphicsObject with \a parent. +*/ +QGraphicsObject::QGraphicsObject(QGraphicsItem *parent) + : QGraphicsItem(parent) +{ + QGraphicsItem::d_ptr->isObject = true; +} + +/*! + \internal +*/ +QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene) + : QGraphicsItem(dd, parent, scene) +{ + QGraphicsItem::d_ptr->isObject = true; +} + +/*! + \property QGraphicsObject::opacity + \brief the opacity of the item + + \sa QGraphicsItem::setOpacity, QGraphicsItem::opacity +*/ + +/*! + \fn QGraphicsObject::opacityChanged() + + This signal gets emitted whenever the opacity of the item changes + + \sa opacity +*/ + +/*! + \property QGraphicsObject::pos + \brief the position of the item + + Describes the items position. + + \sa QGraphicsItem::setPos, QGraphicsItem::pos, positionChanged +*/ + +/*! + \fn QGraphicsObject::positionChanged() + + This signal gets emitted whenever the position of the item changes + + \sa pos +*/ + +/*! + \property QGraphicsObject::enabled + \brief whether the item is enabled or not + + This property is declared in QGraphicsItem. + + By default, this property is true. + + \sa QGraphicsItem::isEnabled(), QGraphicsItem::setEnabled(), enabledChanged() +*/ + +/*! + \fn QGraphicsObject::enabledChanged() + + This signal gets emitted whenever the item get's enabled or disabled. + + \sa enabled +*/ + +/*! + \property QGraphicsObject::visible + \brief whether the item is visible or not + + This property is declared in QGraphicsItem. + + By default, this property is true. + + \sa QGraphicsItem::isVisible(), QGraphicsItem::setVisible(), visibleChanged() +*/ + +/*! + \fn QGraphicsObject::visibleChanged() + + This signal gets emitted whenever the visibility of the item changes + + \sa visible +*/ + + + +/*! \class QAbstractGraphicsShapeItem \brief The QAbstractGraphicsShapeItem class provides a common base for all path items. @@ -8148,17 +8282,6 @@ public: }; -QGraphicsObject::QGraphicsObject(QGraphicsItem *parent) - : QGraphicsItem(parent) -{ -} - -QGraphicsObject::QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene) - : QGraphicsItem(dd, parent, scene) -{ -} - - /*! Constructs a QGraphicsTextItem, using \a text as the default plain text. \a parent is passed to QGraphicsItem's constructor. diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index 69aab20..a5ccef2 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -63,6 +63,7 @@ class QBrush; class QCursor; class QFocusEvent; class QGraphicsItemGroup; +class QGraphicsObject; class QGraphicsSceneContextMenuEvent; class QGraphicsSceneDragDropEvent; class QGraphicsSceneEvent; @@ -159,6 +160,9 @@ public: bool isWidget() const; bool isWindow() const; + QGraphicsObject *toGraphicsObject(); + const QGraphicsObject *toGraphicsObject() const; + QGraphicsItemGroup *group() const; void setGroup(QGraphicsItemGroup *group); @@ -484,6 +488,31 @@ inline QRectF QGraphicsItem::mapRectFromParent(qreal ax, qreal ay, qreal w, qrea inline QRectF QGraphicsItem::mapRectFromScene(qreal ax, qreal ay, qreal w, qreal h) const { return mapRectFromScene(QRectF(ax, ay, w, h)); } + +class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem +{ + Q_OBJECT + Q_INTERFACES(QGraphicsItem) + Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged) + Q_PROPERTY(QPointF pos READ pos WRITE setPos NOTIFY positionChanged) + Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) + Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) +public: + QGraphicsObject(QGraphicsItem *parent = 0); + +Q_SIGNALS: + void opacityChanged(); + void visibleChanged(); + void enabledChanged(); + void positionChanged(); + +protected: + QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene); +private: + friend class QGraphicsItem; +}; + + class QAbstractGraphicsShapeItemPrivate; class Q_GUI_EXPORT QAbstractGraphicsShapeItem : public QGraphicsItem { @@ -832,20 +861,6 @@ private: inline void QGraphicsPixmapItem::setOffset(qreal ax, qreal ay) { setOffset(QPointF(ax, ay)); } -class Q_GUI_EXPORT QGraphicsObject : public QObject, public QGraphicsItem -{ - Q_OBJECT - Q_INTERFACES(QGraphicsItem) - Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity) - Q_PROPERTY(QPointF pos READ pos WRITE setPos) - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) - Q_PROPERTY(bool visible READ isVisible WRITE setVisible) -public: - QGraphicsObject(QGraphicsItem *parent = 0); -protected: - QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene); -}; - class QGraphicsTextItemPrivate; class QTextDocument; class QTextCursor; diff --git a/src/gui/graphicsview/qgraphicsitem_p.h b/src/gui/graphicsview/qgraphicsitem_p.h index 5626867..0e6658c 100644 --- a/src/gui/graphicsview/qgraphicsitem_p.h +++ b/src/gui/graphicsview/qgraphicsitem_p.h @@ -149,6 +149,7 @@ public: dirtySceneTransform(1), geometryChanged(0), inDestructor(0), + isObject(0), globalStackingOrder(-1), q_ptr(0) { @@ -405,7 +406,8 @@ public: quint32 dirtySceneTransform : 1; quint32 geometryChanged : 1; quint32 inDestructor : 1; - quint32 unused : 15; // feel free to use + quint32 isObject : 1; + quint32 unused : 14; // feel free to use // Optional stacking order int globalStackingOrder; diff --git a/src/gui/graphicsview/qgraphicswidget.cpp b/src/gui/graphicsview/qgraphicswidget.cpp index 84434db..419277d 100644 --- a/src/gui/graphicsview/qgraphicswidget.cpp +++ b/src/gui/graphicsview/qgraphicswidget.cpp @@ -170,87 +170,6 @@ QT_BEGIN_NAMESPACE */ /*! - \property QGraphicsWidget::enabled - \brief whether the item is enabled or not - - This property is declared in QGraphicsItem. - - By default, this property is true. - - \sa QGraphicsItem::isEnabled(), QGraphicsItem::setEnabled() -*/ - -/*! - \property QGraphicsWidget::visible - \brief whether the item is visible or not - - This property is declared in QGraphicsItem. - - By default, this property is true. - - \sa QGraphicsItem::isVisible(), QGraphicsItem::setVisible(), show(), - hide() -*/ - -/*! - \property QGraphicsWidget::opacity - \brief the opacity of the widget -*/ - -/*! - \property QGraphicsWidget::pos - \brief the position of the widget -*/ - -/*! - \property QGraphicsWidget::xRotation - \since 4.6 - \brief the rotation angle in degrees around the X axis -*/ - -/*! - \property QGraphicsWidget::yRotation - \since 4.6 - \brief the rotation angle in degrees around the Y axis -*/ - -/*! - \property QGraphicsWidget::zRotation - \since 4.6 - \brief the rotation angle in degrees around the Z axis -*/ - -/*! - \property QGraphicsWidget::xScale - \since 4.6 - \brief the scale factor on the X axis. -*/ - -/*! - \property QGraphicsWidget::yScale - \since 4.6 - \brief the scale factor on the Y axis. -*/ - -/*! - \property QGraphicsWidget::horizontalShear - \since 4.6 - \brief the horizontal shear. -*/ - -/*! - \property QGraphicsWidget::verticalShear - \since 4.6 - \brief the vertical shear. -*/ - -/*! - \property QGraphicsWidget::transformOrigin - \since 4.6 - \brief the transformation origin for the transformation properties. -*/ - -/*! Constructs a QGraphicsWidget instance. The optional \a parent argument is passed to QGraphicsItem's constructor. The optional \a wFlags argument specifies the widget's window flags (e.g., whether the widget should be a |