From 44c44e844040c00db5a535c28d83bf56c61aebb3 Mon Sep 17 00:00:00 2001 From: ouv Date: Fri, 5 Jul 2013 11:10:27 +0000 Subject: [PATCH] Drawing a connection line for the TopMost anchor. --- .../GraphicsView_PrsImageFrame.cxx | 52 ++++++++++++++----- src/GraphicsView/GraphicsView_PrsImageFrame.h | 3 ++ 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx index 2ffb80911..d550632f9 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.cxx +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.cxx @@ -153,9 +153,9 @@ bool GraphicsView_PrsImageFrame::checkHighlight( double theX, double theY, QCurs while( anIter.hasNext() ) { int aType = anIter.next().key(); - if( QGraphicsEllipseItem* anAnchorItem = anIter.value() ) + if( UnscaledGraphicsEllipseItem* anAnchorItem = anIter.value() ) { - QRectF aRect = anAnchorItem->sceneBoundingRect(); + QRectF aRect = anAnchorItem->sceneHighlightRect(); if( aRect.contains( QPointF( theX, theY ) ) ) { if( aType >= Top && aType <= BottomRight ) @@ -196,7 +196,7 @@ bool GraphicsView_PrsImageFrame::startPulling( const QPointF& thePoint ) int aType = anIter.next().key(); if( UnscaledGraphicsEllipseItem* anAnchorItem = anIter.value() ) { - QRectF aRect = anAnchorItem->sceneBoundingRect(); + QRectF aRect = anAnchorItem->sceneHighlightRect(); if( aRect.contains( thePoint ) ) { myPullingAnchor = aType; @@ -479,10 +479,10 @@ void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem:: } //================================================================ -// Function : boundingRect +// Function : highlightRect // Purpose : //================================================================ -QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() const +QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::highlightRect() const { QRectF aRect = QGraphicsEllipseItem::boundingRect(); @@ -507,12 +507,29 @@ QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() c aRect = QRectF( aCenter.x() - aWidth / 2 + anOffsetX, aCenter.y() - aHeight / 2 + anOffsetY, aWidth, aHeight ); + return aRect; +} - // to do - //QRectF aBaseRect( myBasePoint, QSizeF( 1, 1 ) ); - //aRect |= aBaseRect; +//================================================================ +// Function : sceneHighlightRect +// Purpose : +//================================================================ +QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::sceneHighlightRect() const +{ + if( QGraphicsItem* aParentItem = parentItem() ) + return aParentItem->sceneTransform().mapRect( highlightRect() ); + return sceneBoundingRect(); +} - return aRect; +//================================================================ +// Function : boundingRect +// Purpose : +//================================================================ +QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() const +{ + QRectF aHighlightRect = highlightRect(); + QRectF aBaseRect( myBasePoint, QSizeF( 1, 1 ) ); + return aHighlightRect | aBaseRect; } //================================================================ @@ -541,7 +558,7 @@ void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::paint( QWidget* theWidget ) { // draw a connection line (mainly, for top-most anchor) - //thePainter->drawLine( myBasePoint, boundingRect().center() ); + thePainter->drawLine( myBasePoint, highlightRect().center() ); thePainter->save(); thePainter->setTransform( GenerateTranslationOnlyTransform( thePainter->transform(), @@ -563,8 +580,15 @@ void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::paint( thePainter->restore(); // for debug - //thePainter->save(); - //thePainter->setPen( QPen( Qt::magenta ) ); - //thePainter->drawRect( boundingRect() ); - //thePainter->restore(); + /* + thePainter->save(); + thePainter->setPen( QPen( Qt::magenta ) ); + thePainter->drawRect( boundingRect() ); + thePainter->restore(); + + thePainter->save(); + thePainter->setPen( QPen( Qt::blue ) ); + thePainter->drawRect( highlightRect() ); + thePainter->restore(); + */ } diff --git a/src/GraphicsView/GraphicsView_PrsImageFrame.h b/src/GraphicsView/GraphicsView_PrsImageFrame.h index e5d42ec72..a6aecd689 100644 --- a/src/GraphicsView/GraphicsView_PrsImageFrame.h +++ b/src/GraphicsView/GraphicsView_PrsImageFrame.h @@ -127,6 +127,9 @@ public: void setScaling( const double theScaleX, const double theScaleY ); void setRotationAngle( const double theRotationAngle ); + QRectF highlightRect() const; + QRectF sceneHighlightRect() const; + public: virtual QRectF boundingRect() const; virtual void paint( QPainter*, const QStyleOptionGraphicsItem*, QWidget* ); -- 2.39.2