diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.cpp | 47 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicsitem.h | 13 | ||||
-rw-r--r-- | src/gui/graphicsview/qgraphicswidget.h | 1 |
3 files changed, 49 insertions, 12 deletions
diff --git a/src/gui/graphicsview/qgraphicsitem.cpp b/src/gui/graphicsview/qgraphicsitem.cpp index 6d87c36..3622c82 100644 --- a/src/gui/graphicsview/qgraphicsitem.cpp +++ b/src/gui/graphicsview/qgraphicsitem.cpp @@ -1789,6 +1789,9 @@ void QGraphicsItemPrivate::setVisibleHelper(bool newVisible, bool explicitly, bo // Deliver post-change notification. q_ptr->itemChange(QGraphicsItem::ItemVisibleHasChanged, newVisibleVariant); + + if (isObject) + emit static_cast<QGraphicsObject *>(q_ptr)->visibleChanged(); } /*! @@ -1821,9 +1824,6 @@ 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(); } /*! @@ -1912,6 +1912,9 @@ void QGraphicsItemPrivate::setEnabledHelper(bool newEnabled, bool explicitly, bo // Deliver post-change notification. q_ptr->itemChange(QGraphicsItem::ItemEnabledHasChanged, newEnabledVariant); + + if (isObject) + emit static_cast<QGraphicsObject *>(q_ptr)->enabledChanged(); } /*! @@ -1945,9 +1948,6 @@ 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(); } /*! @@ -2110,6 +2110,7 @@ void QGraphicsItem::setOpacity(qreal opacity) /*maybeDirtyClipPath=*/false, /*force=*/false, /*ignoreOpacity=*/true); + if (d_ptr->isObject) emit static_cast<QGraphicsObject *>(this)->opacityChanged(); } @@ -2520,6 +2521,17 @@ QPointF QGraphicsItem::pos() const \sa y() */ +/* + Set's the x coordinate of the item's position. Equivalent to + calling setPos(x, y()). + + \sa x(), setPos() +*/ +void QGraphicsItem::setX(qreal x) +{ + d_ptr->setPosHelper(QPointF(x, d_ptr->pos.y())); +} + /*! \fn QGraphicsItem::y() const @@ -2528,6 +2540,17 @@ QPointF QGraphicsItem::pos() const \sa x() */ +/* + Set's the y coordinate of the item's position. Equivalent to + calling setPos(x(), y). + + \sa x(), setPos() +*/ +void QGraphicsItem::setY(qreal y) +{ + d_ptr->setPosHelper(QPointF(d_ptr->pos.x(), y)); +} + /*! Returns the item's position in scene coordinates. This is equivalent to calling \c mapToScene(0, 0). @@ -2551,11 +2574,16 @@ void QGraphicsItemPrivate::setPosHelper(const QPointF &pos) updateCachedClipPathFromSetPosHelper(pos); if (scene) q->prepareGeometryChange(); + QPointF oldPos = this->pos; this->pos = pos; dirtySceneTransform = 1; inSetPosHelper = 0; - if (isObject) - emit static_cast<QGraphicsObject *>(q)->positionChanged(); + if (isObject) { + if (pos.x() != oldPos.x()) + emit static_cast<QGraphicsObject *>(q_ptr)->xChanged(); + if (pos.y() != oldPos.y()) + emit static_cast<QGraphicsObject *>(q_ptr)->yChanged(); + } } /*! @@ -3535,6 +3563,9 @@ void QGraphicsItem::setZValue(qreal z) } itemChange(ItemZValueHasChanged, newZVariant); + + if (d_ptr->isObject) + emit static_cast<QGraphicsObject *>(this)->zChanged(); } /*! diff --git a/src/gui/graphicsview/qgraphicsitem.h b/src/gui/graphicsview/qgraphicsitem.h index a5ccef2..a69eced 100644 --- a/src/gui/graphicsview/qgraphicsitem.h +++ b/src/gui/graphicsview/qgraphicsitem.h @@ -227,7 +227,9 @@ public: // Positioning in scene coordinates QPointF pos() const; inline qreal x() const { return pos().x(); } + void setX(qreal x); inline qreal y() const { return pos().y(); } + void setY(qreal y); QPointF scenePos() const; void setPos(const QPointF &pos); inline void setPos(qreal x, qreal y); @@ -492,11 +494,13 @@ inline QRectF QGraphicsItem::mapRectFromScene(qreal ax, qreal ay, qreal w, qreal 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(QPointF pos READ pos WRITE setPos) Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled NOTIFY enabledChanged) Q_PROPERTY(bool visible READ isVisible WRITE setVisible NOTIFY visibleChanged) + Q_PROPERTY(qreal x READ x WRITE setX NOTIFY xChanged) + Q_PROPERTY(qreal y READ y WRITE setY NOTIFY yChanged) + Q_PROPERTY(qreal z READ zValue WRITE setZValue NOTIFY zChanged) public: QGraphicsObject(QGraphicsItem *parent = 0); @@ -504,12 +508,15 @@ Q_SIGNALS: void opacityChanged(); void visibleChanged(); void enabledChanged(); - void positionChanged(); + void xChanged(); + void yChanged(); + void zChanged(); protected: QGraphicsObject(QGraphicsItemPrivate &dd, QGraphicsItem *parent, QGraphicsScene *scene); private: friend class QGraphicsItem; + friend class QGraphicsItemPrivate; }; diff --git a/src/gui/graphicsview/qgraphicswidget.h b/src/gui/graphicsview/qgraphicswidget.h index e19513d..337490c 100644 --- a/src/gui/graphicsview/qgraphicswidget.h +++ b/src/gui/graphicsview/qgraphicswidget.h @@ -69,7 +69,6 @@ class QGraphicsWidgetPrivate; class Q_GUI_EXPORT QGraphicsWidget : public QGraphicsObject, public QGraphicsLayoutItem { Q_OBJECT - Q_INTERFACES(QGraphicsLayoutItem) Q_PROPERTY(QPalette palette READ palette WRITE setPalette) Q_PROPERTY(QFont font READ font WRITE setFont) Q_PROPERTY(Qt::LayoutDirection layoutDirection READ layoutDirection WRITE setLayoutDirection RESET unsetLayoutDirection) |