#include <math.h>
#define FRAME_Z_VALUE 1000
-#define ANCHOR_RADIUS 10
+#define ANCHOR_RADIUS 3
#define PI 3.14159265359
//=======================================================================
{
if( myAnchorMap.isEmpty() )
{
- for( int aType = Top; aType <= TopMost; aType++ )
+ for( int aType = TopMost; aType <= BottomRight; aType++ )
{
UnscaledGraphicsEllipseItem* anAnchorItem = new UnscaledGraphicsEllipseItem( this );
- //anAnchorItem->setFlag( QGraphicsItem::ItemIgnoresTransformations, true );
Qt::GlobalColor aColor = Qt::white;
if( aType == TopMost )
QPointF aPoint2 = myAnchorMap[ Bottom ]->getBasePoint();
QPointF aPoint3 = myAnchorMap[ Left ]->getBasePoint();
QPointF aPoint4 = myAnchorMap[ Right ]->getBasePoint();
- return ( aPoint1 + aPoint2 + aPoint3 + aPoint4 ) /4.;
+ return ( aPoint1 + aPoint2 + aPoint3 + aPoint4 ) / 4.;
}
//================================================================
QRectF aRect = myPrsImage->boundingRect();
QMap<int, QPointF> anAnchorPointMap;
+ anAnchorPointMap[ TopMost ] = ( aRect.topLeft() + aRect.topRight() ) / 2;
anAnchorPointMap[ Top ] = ( aRect.topLeft() + aRect.topRight() ) / 2;
anAnchorPointMap[ Bottom ] = ( aRect.bottomLeft() + aRect.bottomRight() ) / 2;
anAnchorPointMap[ Left ] = ( aRect.topLeft() + aRect.bottomLeft() ) / 2;
anAnchorPointMap[ BottomLeft ] = aRect.bottomLeft();
anAnchorPointMap[ BottomRight ] = aRect.bottomRight();
- // tmp
- anAnchorPointMap[ TopMost ] = ( aRect.topLeft() + aRect.topRight() ) / 2 -
- QPointF( 0, 4 * ANCHOR_RADIUS );
-
qreal ar = ANCHOR_RADIUS;
QMapIterator<int, QPointF> anIter( anAnchorPointMap );
while( anIter.hasNext() )
QRectF anAnchorRect( anAnchorPoint - QPointF( ar, ar ), QSizeF( ar * 2, ar * 2 ) );
myAnchorMap[ anAnchorType ]->setRect( anAnchorRect );
myAnchorMap[ anAnchorType ]->setBasePoint( anAnchorPoint );
+
+ if( anAnchorType == TopMost )
+ myAnchorMap[ anAnchorType ]->setOffset( QPointF( 0, -6 * ANCHOR_RADIUS ) );
}
}
setVisible( anIsSelected );
}
+//================================================================
+// Function : setRotationAngle
+// Purpose :
+//================================================================
+void GraphicsView_PrsImageFrame::setRotationAngle( const double theRotationAngle )
+{
+ AnchorMapIterator anIter( myAnchorMap );
+ while( anIter.hasNext() )
+ if( UnscaledGraphicsEllipseItem* anAnchorItem = anIter.next().value() )
+ anAnchorItem->setRotationAngle( theRotationAngle );
+}
+
//================================================================
// Function : getResizeCursor
// Purpose :
// Purpose : Constructor
//=======================================================================
GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::UnscaledGraphicsEllipseItem( QGraphicsItem* theParent )
-: QGraphicsEllipseItem( theParent )
+: QGraphicsEllipseItem( theParent ),
+ myRotationAngle( 0.0 ),
+ myScale( 1.0 )
{
}
{
}
+//================================================================
+// Function : boundingRect
+// Purpose :
+//================================================================
+QRectF GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::boundingRect() const
+{
+ QRectF aRect = QGraphicsEllipseItem::boundingRect();
+
+ if( fabs( myScale ) < 1e-10 )
+ return aRect;
+
+ QPointF aCenter = aRect.center();
+ double aWidth = aRect.width() / myScale;
+ double aHeight = aRect.height() / myScale;
+
+ double anOffsetX = myOffset.x() / myScale;
+ double anOffsetY = myOffset.y() / myScale;
+
+ aRect = QRectF( aCenter.x() - aWidth / 2 + anOffsetX,
+ aCenter.y() - aHeight / 2 + anOffsetY,
+ aWidth, aHeight );
+ return aRect;
+}
+
//================================================================
// Function : GenerateTranslationOnlyTransform
// Purpose :
const QStyleOptionGraphicsItem* theOption,
QWidget* theWidget )
{
- //thePainter->save();
- //thePainter->setTransform( GenerateTranslationOnlyTransform( thePainter->transform(),
- // myBasePoint ) );
+ QTransform aTransform = thePainter->transform();
+ aTransform.rotate( -myRotationAngle ); // exclude rotation from matrix
+ myScale = aTransform.m11(); // same as m22(), viewer specific
+
+ // draw a connection line (mainly, for top-most anchor)
+ thePainter->drawLine( myBasePoint, boundingRect().center() );
+
+ thePainter->save();
+ thePainter->setTransform( GenerateTranslationOnlyTransform( thePainter->transform(),
+ myBasePoint ) );
+
+ double anAngle = myRotationAngle * PI / 180.;
+ double aDX = myOffset.x() * cos( anAngle ) - myOffset.y() * sin( anAngle );
+ double aDY = myOffset.x() * sin( anAngle ) + myOffset.y() * cos( anAngle );
+ thePainter->translate( aDX, aDY );
+
QGraphicsEllipseItem::paint( thePainter, theOption, theWidget );
- //thePainter->restore();
+ thePainter->restore();
}
public:
class UnscaledGraphicsEllipseItem;
- enum AnchorType { Undefined = 0, Top, Bottom, Left, Right,
- TopLeft, TopRight, BottomLeft, BottomRight,
- TopMost };
+ enum AnchorType { Undefined = 0, TopMost, Top, Bottom, Left, Right,
+ TopLeft, TopRight, BottomLeft, BottomRight };
typedef QMap <int, UnscaledGraphicsEllipseItem*> AnchorMap;
typedef QMapIterator<int, UnscaledGraphicsEllipseItem*> AnchorMapIterator;
void computeAnchorItems();
void updateAnchorItems();
+ void setRotationAngle( const double theRotationAngle );
+
protected:
QCursor* getVerCursor() const { return myVerCursor; }
QCursor* getHorCursor() const { return myHorCursor; }
void setBasePoint( const QPointF& thePoint ) { myBasePoint = thePoint; }
const QPointF& getBasePoint() const { return myBasePoint; }
+ void setOffset( const QPointF& theOffset ) { myOffset = theOffset; }
+ const QPointF& getOffset() const { return myOffset; }
+
+ void setRotationAngle( const double theAngle ) { myRotationAngle = theAngle; }
+
public:
+ virtual QRectF boundingRect() const;
virtual void paint( QPainter*, const QStyleOptionGraphicsItem*, QWidget* );
private:
QPointF myBasePoint;
+ QPointF myOffset;
+
+ double myRotationAngle;
+ double myScale;
};
#endif