diff --git a/src/qlightroundtextitem.cpp b/src/qlightroundtextitem.cpp index f5fa013..df13699 100644 --- a/src/qlightroundtextitem.cpp +++ b/src/qlightroundtextitem.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -231,14 +232,38 @@ void QLightRoundTextItem::paint( QPainter *painter, const QStyleOptionGraphicsIt } } -QVariant QLightRoundTextItem::itemChange( GraphicsItemChange change, const QVariant & value ) +inline +double distance( const QPointF &p1, const QPointF &p2 ) { - if( scene() && change == ItemPositionHasChanged ) - static_cast( scene() )->itemMoved(); - - return value; + QPointF d = p1 - p2; + return sqrt( d.x() * d.x() + d.y() * d.y() ); } +inline +double angle( const QPointF &p1, const QPointF &p2 ) +{ + QPointF d = p1 - p2; + return atan2( d.y(), d.x() ) * 180.0 / 3.14159; +} + +void QLightRoundTextItem::mouseMoveEvent( QGraphicsSceneMouseEvent *event ) +{ + if( event->buttons() & Qt::LeftButton ) { + double dradi = distance( scenePos(), event->lastScenePos() ) - distance( scenePos(), event->scenePos() ); + double dangle = ::angle( scenePos(), event->lastScenePos() ) - ::angle( scenePos(), event->scenePos() ); + + prepareGeometryChange(); + m_radius -= dradi; + m_angle -= dangle; + if( m_angle > 360.0 ) m_angle -= 360.0; + if( m_angle < 0.0 ) m_angle += 360.0; + + static_cast( scene() )->itemMoved(); + } else + event->ignore(); +} + + RegisterController< QShapeControllerRoundText > regControllerRoundText; QString QShapeControllerRoundText::name() const diff --git a/src/qlightroundtextitem.h b/src/qlightroundtextitem.h index 69d9688..5c3000c 100644 --- a/src/qlightroundtextitem.h +++ b/src/qlightroundtextitem.h @@ -55,7 +55,7 @@ public: virtual int type() const { return Type; } protected: - virtual QVariant itemChange ( GraphicsItemChange change, const QVariant & value ); + virtual void mouseMoveEvent( QGraphicsSceneMouseEvent *event ); private: QFont m_font;