#include "GraphicsView.h"
+#include "GraphicsView_Defs.h"
+
#include <QGraphicsItemGroup>
class GraphicsView_ViewPort;
virtual QRectF getPullingRect() const { return getRect(); }
virtual bool portContains( const QPointF& ) { return false; }
virtual bool startPulling( const QPointF& ) { return false; }
- virtual void pull( const QPointF&, GraphicsView_Object* ) {}
- virtual void finishPulling() {}
+ virtual void pull( const QPointF&,
+ GraphicsView_Object*,
+ const GraphicsView_ObjectList& ) {}
+ virtual void finishPulling( const GraphicsView_ObjectList& ) {}
virtual bool isPulling() { return false; }
virtual bool handleMousePress( QGraphicsSceneMouseEvent* ) { return false; }
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QPainter>
-
-#include <gp_Vec2d.hxx>
+#include <QVector2D>
#include <math.h>
+#define EPSILON 1e-6
#define PI 3.14159265359
//=======================================================================
// Purpose :
//================================================================
void GraphicsView_PrsImage::processResize( const int theAnchor,
- const QPointF& thePoint1,
- const QPointF& thePoint2 )
+ const double theDX,
+ const double theDY )
{
- if( thePoint1 == thePoint2 )
+ if( fabs( theDX ) < EPSILON && fabs( theDY ) < EPSILON )
return;
if( !myPreviewPixmapItem->isVisible() )
enablePreview( true );
- QPixmap aCurrentPixmap = myPixmapItem->pixmap();
- int aWidth = aCurrentPixmap.width();
- int aHeight = aCurrentPixmap.height();
-
- double aDX = thePoint2.x() - thePoint1.x();
- double aDY = thePoint2.y() - thePoint1.y();
-
double anAngle = -1 * myRotationAngle * PI / 180.;
- gp_Pnt2d aPnt1( thePoint1.x(), thePoint1.y() );
- gp_Pnt2d aPnt2( thePoint2.x(), thePoint2.y() );
- gp_Vec2d aVec( aPnt1, aPnt2 );
- gp_Vec2d aVecHor( 10, 0 );
+ QVector2D aVec( theDX, theDY );
+ QVector2D aVecHor( 10, 0 );
- double aDist = aPnt1.Distance( aPnt2 );
- double anAngle1 = aVec.Angle( aVecHor );
+ double aDist = sqrt( theDX * theDX + theDY * theDY );
+ double anAngle1 = computeAngle( aVec, aVecHor );
double anAngle2 = anAngle1 - anAngle;
double aSizeDX = aDist * cos( anAngle2 );
aSizeShift = QPointF( aSizeDX, 0 );
break;
case GraphicsView_PrsImageFrame::TopLeft:
- aPosShift = QPointF( aDX, aDY );
+ aPosShift = QPointF( theDX, theDY );
aSizeShift = QPointF( -aSizeDX, -aSizeDY );
break;
case GraphicsView_PrsImageFrame::TopRight:
break;
}
- aWidth += (int)aSizeShift.x();
- aHeight += (int)aSizeShift.y();
- if( aWidth < 10 || aHeight < 10 ) // tmp
+ QPixmap aCurrentPixmap = myPixmapItem->pixmap();
+ int aWidth = aCurrentPixmap.width();
+ int aHeight = aCurrentPixmap.height();
+
+ int aNewWidth = aWidth + (int)aSizeShift.x();
+ int aNewHeight = aHeight + (int)aSizeShift.y();
+ if( aNewWidth < 10 || aNewHeight < 10 ) // tmp
return;
- QPixmap aPixmap = myPixmap.scaled( aWidth, aHeight );
+ QPixmap aPixmap = myPixmap.scaled( aNewWidth, aNewHeight );
myPreviewPixmapItem->setPixmap( aPixmap );
myPreviewPixmapItem->setPos( pos() + aPosShift );
}
//================================================================
-// Function : processRotate
+// Function : computeRotationAngle
// Purpose :
//================================================================
-void GraphicsView_PrsImage::processRotate( const QPointF& thePoint1,
- const QPointF& thePoint2 )
+double GraphicsView_PrsImage::computeRotationAngle( const QPointF& thePoint1,
+ const QPointF& thePoint2 ) const
{
- if( thePoint1 == thePoint2 )
- return;
-
- if( !myPreviewPixmapItem->isVisible() )
- enablePreview( true );
-
QRectF aRect = getRect();
QPointF aCenter = aRect.center();
- gp_Pnt2d aPnt0( aCenter.x(), aCenter.y() );
- gp_Pnt2d aPnt1( thePoint1.x(), thePoint1.y() );
- gp_Pnt2d aPnt2( thePoint2.x(), thePoint2.y() );
-
- gp_Vec2d aVec1( aPnt0, aPnt1 );
- gp_Vec2d aVec2( aPnt0, aPnt2 );
+ QVector2D aVec1( thePoint1 - aCenter );
+ QVector2D aVec2( thePoint2 - aCenter );
- double anAngle = aVec1.Angle( aVec2 );
+ double anAngle = computeAngle( aVec1, aVec2 );
double anAngleDeg = anAngle / PI * 180.;
+ return anAngleDeg;
+}
+
+//================================================================
+// Function : processRotate
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::processRotate( const double theAngle )
+{
+ if( fabs( theAngle ) < EPSILON )
+ return;
- myPreviewRotationAngle = myRotationAngle + anAngleDeg;
+ if( !myPreviewPixmapItem->isVisible() )
+ enablePreview( true );
+
+ myPreviewRotationAngle = myRotationAngle + theAngle;
setRotationAroundCenter( myPreviewPixmapItem, myPreviewRotationAngle );
}
else
myPreviewPixmapItem->setVisible( false );
}
+
+//================================================================
+// Function : computeAngle
+// Purpose :
+//================================================================
+double GraphicsView_PrsImage::computeAngle( const QVector2D& theVector1,
+ const QVector2D& theVector2 )
+{
+ if( theVector1.isNull() || theVector2.isNull() )
+ return 0.0;
+
+ double aDotProduct = QVector2D::dotProduct( theVector1, theVector2 );
+ double aCos = aDotProduct / theVector1.length() / theVector2.length();
+
+ double aCrossProduct = theVector1.x() * theVector2.y() - theVector1.y() * theVector2.x();
+
+ double anAngle = acos( aCos );
+ if( aCrossProduct < 0 )
+ anAngle *= -1;
+
+ return anAngle;
+}
protected:
void processResize( const int theAnchor,
- const QPointF& thePoint1,
- const QPointF& thePoint2 );
+ const double theDX,
+ const double theDY );
void finishResize();
- void processRotate( const QPointF& thePoint1,
- const QPointF& thePoint2 );
+ double computeRotationAngle( const QPointF& thePoint1,
+ const QPointF& thePoint2 ) const;
+
+ void processRotate( const double theAngle );
void finishRotate();
protected:
void enablePreview( const bool theState );
+ static double computeAngle( const QVector2D& theVector1,
+ const QVector2D& theVector2 );
+
protected:
QPixmap myPixmap;
#include <QCursor>
#include <QPainter>
+#include <math.h>
+
+#define PI 3.14159265359
+
#define ANCHOR_RADIUS 10
//=======================================================================
// Function : pull
// Purpose :
//================================================================
-void GraphicsView_PrsImageFrame::pull( const QPointF& thePoint, GraphicsView_Object* )
+void GraphicsView_PrsImageFrame::pull( const QPointF& thePoint,
+ GraphicsView_Object* theLockedObject, // unused
+ const GraphicsView_ObjectList& theSyncObjects )
{
if( !myPrsImage )
return;
+ if( thePoint == myPullingPoint )
+ return;
+
+ double aDX = thePoint.x() - myPullingPoint.x();
+ double aDY = thePoint.y() - myPullingPoint.y();
+
+ double aDAngle = myPrsImage->computeRotationAngle( myPullingPoint, thePoint );
+
if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
- myPrsImage->processResize( myPullingAnchor, myPullingPoint, thePoint );
+ myPrsImage->processResize( myPullingAnchor, aDX, aDY );
else if( myPullingAnchor == TopMost )
- myPrsImage->processRotate( myPullingPoint, thePoint );
+ myPrsImage->processRotate( aDAngle );
+
+ QRectF aRect = myPrsImage->getRect();
+ double anAngle = 0;
+ myPrsImage->getRotationAngle( anAngle );
+
+ GraphicsView_ObjectListIterator anIter( theSyncObjects );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_PrsImage* aPrsImage = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
+ {
+ if( aPrsImage != myPrsImage )
+ {
+ if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
+ {
+ QRectF aRectRef = aPrsImage->getRect();
+ double anAngleRef = 0;
+ aPrsImage->getRotationAngle( anAngleRef );
+
+ double aDXRef = aDX * aRectRef.width() / aRect.width();
+ double aDYRef = aDY * aRectRef.height() / aRect.height();
+
+ double anAngleDiff = ( anAngleRef - anAngle ) * PI / 180.;
+ double aDXRefTrans = aDXRef * cos( anAngleDiff ) - aDYRef * sin( anAngleDiff );
+ double aDYRefTrans = aDXRef * sin( anAngleDiff ) + aDYRef * cos( anAngleDiff );
+
+ aPrsImage->processResize( myPullingAnchor, aDXRefTrans, aDYRefTrans );
+ }
+ else if( myPullingAnchor == TopMost )
+ aPrsImage->processRotate( aDAngle );
+ }
+ }
+ }
}
//================================================================
// Function : finishPulling
// Purpose :
//================================================================
-void GraphicsView_PrsImageFrame::finishPulling()
+void GraphicsView_PrsImageFrame::finishPulling( const GraphicsView_ObjectList& theSyncObjects )
{
if( !myPrsImage )
return;
myPrsImage->finishResize();
else if( myPullingAnchor == TopMost )
myPrsImage->finishRotate();
+
+ GraphicsView_ObjectListIterator anIter( theSyncObjects );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_PrsImage* aPrsImage = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
+ {
+ if( aPrsImage != myPrsImage )
+ {
+ if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
+ aPrsImage->finishResize();
+ else if( myPullingAnchor == TopMost )
+ aPrsImage->finishRotate();
+ }
+ }
+ }
}
//================================================================
virtual QRectF getPullingRect() const;
virtual bool portContains( const QPointF& ) { return false; } // useless
virtual bool startPulling( const QPointF& );
- virtual void pull( const QPointF&, GraphicsView_Object* );
- virtual void finishPulling();
+ virtual void pull( const QPointF&,
+ GraphicsView_Object*,
+ const GraphicsView_ObjectList& );
+ virtual void finishPulling( const GraphicsView_ObjectList& );
virtual bool isPulling() { return myIsPulling; }
virtual QPointF centerPoint();
}
}
- myPullingObject->pull( thePoint, aLockedObject );
+ myPullingObject->pull( thePoint, aLockedObject, getSelectedObjects() );
}
//================================================================
void GraphicsView_ViewPort::finishPulling()
{
myIsPulling = false;
- myPullingObject->finishPulling();
+ myPullingObject->finishPulling( getSelectedObjects() );
setCursor( *getDefaultCursor() );
}
GraphicsView_msg_en.qm \
GraphicsView_msg_fr.qm
-libGraphicsView_la_CPPFLAGS = $(QT_INCLUDES) $(CAS_CPPFLAGS) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx
-libGraphicsView_la_LDFLAGS = $(QT_MT_LIBS) $(CAS_KERNEL)
+libGraphicsView_la_CPPFLAGS = $(QT_INCLUDES) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx
+libGraphicsView_la_LDFLAGS = $(QT_MT_LIBS)
libGraphicsView_la_LIBADD = ../SUIT/libsuit.la