From c298a43b2f24331dc8b07ac8aa1b816bce2d3d7b Mon Sep 17 00:00:00 2001 From: ruglory Date: Wed, 22 Apr 2009 02:48:03 +0000 Subject: [PATCH] Round text changes radius and angle when is dragged by mouse instead of moving the center git-svn-id: https://svn.code.sf.net/p/qlscribe/svn/trunk@147 cac9541e-1b8d-4bfa-827e-589bba606050 --- src/qlightroundtextitem.cpp | 35 ++++++++++++++++++++++++++++++----- src/qlightroundtextitem.h | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) 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;