#include "GraphicsView_Object.h"
#include "GraphicsView_Scene.h"
+#include "GraphicsView_ViewPort.h"
//=======================================================================
// Name : GraphicsView_Object
myPriority( 0 ),
myIsOnTop( false ),
myIsHighlighted( false ),
- myIsSelected( false )
+ myIsSelected( false ),
+ myIsMoving( false )
{
+ myHighlightCursor = new QCursor( Qt::OpenHandCursor );
}
//=======================================================================
//=======================================================================
GraphicsView_Object::~GraphicsView_Object()
{
+ if( myHighlightCursor )
+ {
+ delete myHighlightCursor;
+ myHighlightCursor = 0;
+ }
+}
+
+//================================================================
+// Function : addTo
+// Purpose :
+//================================================================
+void GraphicsView_Object::addTo( GraphicsView_ViewPort* theViewPort )
+{
+ if( QGraphicsScene* aScene = theViewPort->scene() )
+ aScene->addItem( this );
+}
+
+//================================================================
+// Function : removeFrom
+// Purpose :
+//================================================================
+void GraphicsView_Object::removeFrom( GraphicsView_ViewPort* theViewPort )
+{
+ if( QGraphicsScene* aScene = theViewPort->scene() )
+ aScene->removeItem( this );
}
//================================================================
// Function : checkHighlight
// Purpose :
//================================================================
-bool GraphicsView_Object::checkHighlight( double theX, double theY ) const
+bool GraphicsView_Object::checkHighlight( double theX, double theY, QCursor& theCursor ) const
{
- return getRect().contains( theX, theY );
+ return !getRect().isNull() && getRect().contains( theX, theY );
}
//================================================================
//================================================================
bool GraphicsView_Object::highlight( double theX, double theY )
{
+ QCursor aCursor;
if( myIsHighlighted = isVisible() )
- myIsHighlighted = checkHighlight( theX, theY );
+ myIsHighlighted = checkHighlight( theX, theY, aCursor );
return myIsHighlighted;
}
//================================================================
bool GraphicsView_Object::select( double theX, double theY, const QRectF& theRect )
{
+ QCursor aCursor;
if( myIsSelected = isVisible() )
{
if( !theRect.isNull() )
myIsSelected = theRect.contains( getRect() );
else
- myIsSelected = checkHighlight( theX, theY );
+ myIsSelected = checkHighlight( theX, theY, aCursor );
}
return myIsSelected;
}
//================================================================
void GraphicsView_Object::move( double theDX, double theDY, bool theIsAtOnce )
{
- moveBy( theDX, theDY );
if( theIsAtOnce )
+ {
finishMove();
+ return;
+ }
+
+ myIsMoving = true;
+ moveBy( theDX, theDY );
}
//================================================================
//================================================================
bool GraphicsView_Object::finishMove()
{
+ myIsMoving = false;
if( GraphicsView_Scene* aScene = dynamic_cast<GraphicsView_Scene*>( scene() ) )
aScene->processRectChanged();
return true;
}
+
+//================================================================
+// Function : centerPoint
+// Purpose :
+//================================================================
+QPointF GraphicsView_Object::centerPoint()
+{
+ QRectF aRect = getRect();
+ double aCenterX = aRect.width() / 2.;
+ double aCenterY = aRect.height() / 2.;
+ return QPointF( aCenterX, aCenterY );
+}
+
+//================================================================
+// Function : setRotationAroundCenter
+// Purpose :
+//================================================================
+void GraphicsView_Object::setRotationAroundCenter( QGraphicsItem* theItem, double theAngle )
+{
+ if( !theItem )
+ return;
+
+ QRectF aRect = theItem->boundingRect();
+ double aCenterX = aRect.width() / 2.;
+ double aCenterY = aRect.height() / 2.;
+ if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( theItem ) )
+ {
+ aCenterX = anObject->centerPoint().x();
+ aCenterY = anObject->centerPoint().y();
+ }
+ else if( QGraphicsPixmapItem* aPixmapItem = dynamic_cast<QGraphicsPixmapItem*>( theItem ) )
+ {
+ QPoint aPoint = aPixmapItem->pixmap().rect().center();
+ aCenterX = aPoint.x();
+ aCenterY = aPoint.y();
+ }
+
+ QTransform aTransform;
+ aTransform.translate( aCenterX, aCenterY );
+ aTransform.rotate( theAngle );
+ aTransform.translate( -aCenterX, -aCenterY );
+ theItem->setTransform( aTransform, false );
+}
#include <QGraphicsItemGroup>
+class GraphicsView_ViewPort;
+
/*
Class : GraphicsView_Object
Description : Base class for all objects displayed at the scene
virtual void compute() = 0;
+ virtual void addTo( GraphicsView_ViewPort* theViewPort );
+ virtual void removeFrom( GraphicsView_ViewPort* theViewPort );
+
const QString& getName() const { return myName; }
virtual void setName( const QString& theName );
virtual QRectF getRect() const;
+ virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const;
+
virtual bool highlight( double theX, double theY );
virtual void unhighlight();
virtual bool isHighlighted() const { return myIsHighlighted; }
virtual void move( double theDX, double theDY, bool theIsAtOnce = false );
virtual bool finishMove();
+ virtual bool isMoving() const { return myIsMoving; }
virtual bool isMovingByXAllowed( double theDX ) { return true; }
virtual bool isMovingByYAllowed( double theDY ) { return true; }
virtual bool handleMouseMove( QGraphicsSceneMouseEvent* ) { return false; }
virtual bool handleMouseRelease( QGraphicsSceneMouseEvent* ) { return false; }
+ virtual QPointF centerPoint();
+
+public:
+ static void setRotationAroundCenter( QGraphicsItem* theItem, double theAngle );
+
protected:
- virtual bool checkHighlight( double theX, double theY ) const;
+ QCursor* getHighlightCursor() const { return myHighlightCursor; }
protected:
QString myName;
bool myIsHighlighted;
bool myIsSelected;
+
+ bool myIsMoving;
+
+private:
+ QCursor* myHighlightCursor;
};
#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "GraphicsView_PrsImage.h"
+
+#include "GraphicsView_PrsImageFrame.h"
+#include "GraphicsView_ViewPort.h"
+
+#include <QCursor>
+#include <QGraphicsScene>
+#include <QGraphicsView>
+#include <QPainter>
+
+#include <gp_Vec2d.hxx>
+
+#include <math.h>
+
+#define PI 3.14159265359
+
+//=======================================================================
+// name : GraphicsView_PrsImage
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_PrsImage::GraphicsView_PrsImage()
+: GraphicsView_Object(),
+ myPixmapItem( 0 ),
+ myPreviewPixmapItem( 0 ),
+ myImageFrame( 0 ),
+ myScaleX( 1.0 ),
+ myScaleY( 1.0 ),
+ myRotationAngle( 0.0 ),
+ myPreviewRotationAngle( 0.0 )
+{
+}
+
+//=======================================================================
+// name : GraphicsView_PrsImage
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_PrsImage::~GraphicsView_PrsImage()
+{
+ if( myPreviewPixmapItem )
+ {
+ delete myPreviewPixmapItem;
+ myPreviewPixmapItem = 0;
+ }
+
+ if( myImageFrame )
+ {
+ delete myImageFrame;
+ myImageFrame = 0;
+ }
+
+ QListIterator<QGraphicsItem*> aChildIter( children() );
+ while( aChildIter.hasNext() )
+ {
+ if( QGraphicsItem* aChild = aChildIter.next() )
+ {
+ removeFromGroup( aChild );
+ if( QGraphicsScene* aScene = aChild->scene() )
+ aScene->removeItem( aChild );
+ delete aChild;
+ aChild = 0;
+ }
+ }
+}
+
+//================================================================
+// Function : setImage
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::setImage( const QImage& theImage )
+{
+ myPixmap = QPixmap::fromImage( theImage );
+}
+
+//================================================================
+// Function : getImage
+// Purpose :
+//================================================================
+QImage GraphicsView_PrsImage::getImage() const
+{
+ QImage anImage = myPixmap.toImage();
+ return anImage;
+}
+
+//================================================================
+// Function : getTransformation
+// Purpose :
+//================================================================
+QTransform GraphicsView_PrsImage::getTransform() const
+{
+ double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
+ getPosition( aPosX, aPosY );
+ getScaling( aScaleX, aScaleY );
+ getRotationAngle( aRotationAngle );
+
+ QTransform aTransform;
+ aTransform.translate( aPosX, aPosY );
+ aTransform.scale( aScaleX, aScaleY );
+ aTransform.rotate( aRotationAngle );
+ return aTransform;
+}
+
+//================================================================
+// Function : setPosition
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::setPosition( const double thePosX, const double thePosY )
+{
+ setPos( thePosX, thePosY );
+}
+
+//================================================================
+// Function : getPosition
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::getPosition( double& thePosX, double& thePosY ) const
+{
+ thePosX = pos().x();
+ thePosY = pos().y();
+}
+
+//================================================================
+// Function : setScaling
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::setScaling( const double theScaleX, const double theScaleY )
+{
+ myScaleX = theScaleX;
+ myScaleY = theScaleY;
+}
+
+//================================================================
+// Function : getScaling
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::getScaling( double& theScaleX, double& theScaleY ) const
+{
+ theScaleX = myScaleX;
+ theScaleY = myScaleY;
+}
+
+//================================================================
+// Function : setRotationAngle
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::setRotationAngle( const double theRotationAngle )
+{
+ myRotationAngle = theRotationAngle;
+}
+
+//================================================================
+// Function : getRotationAngle
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::getRotationAngle( double& theRotationAngle ) const
+{
+ theRotationAngle = myRotationAngle;
+}
+
+//================================================================
+// Function : boundingRect
+// Purpose :
+//================================================================
+QRectF GraphicsView_PrsImage::boundingRect() const
+{
+ return myPixmapItem->boundingRect();
+}
+
+//================================================================
+// Function : compute
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::compute()
+{
+ if( !myPixmapItem )
+ {
+ myPixmapItem = new QGraphicsPixmapItem( this );
+ addToGroup( myPixmapItem );
+ }
+ if( !myPreviewPixmapItem )
+ {
+ myPreviewPixmapItem = new QGraphicsPixmapItem();
+ //addToGroup( myPreviewPixmapItem ); // don't add
+ }
+ if( !myImageFrame )
+ {
+ myImageFrame = new GraphicsView_PrsImageFrame();
+ myImageFrame->setPrsImage( this );
+ }
+
+ setZValue( 0 );
+
+ QSize aSourceSize = myPixmap.size();
+ QSize aScaledSize( aSourceSize.width() * myScaleX,
+ aSourceSize.height() * myScaleY );
+
+ QPixmap aPixmap = myPixmap.scaled( aScaledSize );
+ myPixmapItem->setPixmap( aPixmap );
+
+ myPreviewPixmapItem->setPixmap( aPixmap );
+ myPreviewPixmapItem->setVisible( false );
+
+ setRotationAroundCenter( this, myRotationAngle );
+
+ myImageFrame->compute();
+}
+
+//================================================================
+// Function : addTo
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::addTo( GraphicsView_ViewPort* theViewPort )
+{
+ GraphicsView_Object::addTo( theViewPort );
+ theViewPort->addItem( myImageFrame );
+ theViewPort->addItem( myPreviewPixmapItem );
+}
+
+//================================================================
+// Function : removeFrom
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::removeFrom( GraphicsView_ViewPort* theViewPort )
+{
+ GraphicsView_Object::removeFrom( theViewPort );
+ theViewPort->removeItem( myImageFrame );
+ theViewPort->removeItem( myPreviewPixmapItem );
+}
+
+//================================================================
+// Function : checkHighlight
+// Purpose :
+//================================================================
+bool GraphicsView_PrsImage::checkHighlight( double theX, double theY, QCursor& theCursor ) const
+{
+ QRect aRect = myPixmapItem->boundingRect().toRect();
+ QPolygon aPolygon = sceneTransform().mapToPolygon( aRect );
+ if( aPolygon.containsPoint( QPoint( theX, theY ), Qt::OddEvenFill ) )
+ {
+ theCursor = *getHighlightCursor();
+ return true;
+ }
+ return false;
+}
+
+//================================================================
+// Function : highlight
+// Purpose :
+//================================================================
+bool GraphicsView_PrsImage::highlight( double theX, double theY )
+{
+ bool anIsHighlighted = GraphicsView_Object::highlight( theX, theY );
+ return anIsHighlighted;
+}
+
+//================================================================
+// Function : unhighlight
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::unhighlight()
+{
+ GraphicsView_Object::unhighlight();
+}
+
+//================================================================
+// Function : select
+// Purpose :
+//================================================================
+bool GraphicsView_PrsImage::select( double theX, double theY, const QRectF& theRect )
+{
+ bool anIsSelected = GraphicsView_Object::select( theX, theY, theRect );
+ myImageFrame->updateAnchorItems();
+ return anIsSelected;
+}
+
+//================================================================
+// Function : unselect
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::unselect()
+{
+ GraphicsView_Object::unselect();
+ myImageFrame->updateAnchorItems();
+}
+
+//================================================================
+// Function : setSelected
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::setSelected( bool theState )
+{
+ GraphicsView_Object::setSelected( theState );
+ myImageFrame->updateAnchorItems();
+}
+
+//================================================================
+// Function : move
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::move( double theDX, double theDY, bool theIsAtOnce )
+{
+ if( theIsAtOnce )
+ {
+ finishMove();
+ return;
+ }
+
+ if( !myIsMoving )
+ enablePreview( true );
+
+ myIsMoving = true;
+ myPreviewPixmapItem->moveBy( theDX, theDY );
+}
+
+//================================================================
+// Function : finishMove
+// Purpose :
+//================================================================
+bool GraphicsView_PrsImage::finishMove()
+{
+ if( myIsMoving )
+ {
+ setPos( myPreviewPixmapItem->pos() );
+ myImageFrame->setPos( pos() );
+
+ enablePreview( false );
+ }
+ return GraphicsView_Object::finishMove();
+}
+
+//================================================================
+// Function : centerPoint
+// Purpose :
+//================================================================
+QPointF GraphicsView_PrsImage::centerPoint()
+{
+ QPointF aPoint = myPixmapItem->boundingRect().center();
+ return aPoint;
+}
+
+//================================================================
+// Function : processResize
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::processResize( const int theAnchor,
+ const QPointF& thePoint1,
+ const QPointF& thePoint2 )
+{
+ if( thePoint1 == thePoint2 )
+ 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 );
+
+ double aDist = aPnt1.Distance( aPnt2 );
+ double anAngle1 = aVec.Angle( aVecHor );
+ double anAngle2 = anAngle1 - anAngle;
+
+ double aSizeDX = aDist * cos( anAngle2 );
+ double aSizeDY = -aDist * sin( anAngle2 );
+
+ QPointF aPosShift;
+ QPointF aSizeShift;
+ switch( theAnchor )
+ {
+ case GraphicsView_PrsImageFrame::Top:
+ aPosShift = QPointF( aSizeDY * sin( anAngle ), aSizeDY * cos( anAngle ) );
+ aSizeShift = QPointF( 0, -aSizeDY );
+ break;
+ case GraphicsView_PrsImageFrame::Bottom:
+ aPosShift = QPointF( 0, 0 );
+ aSizeShift = QPointF( 0, aSizeDY );
+ break;
+ case GraphicsView_PrsImageFrame::Left:
+ aPosShift = QPointF( aSizeDX * cos( anAngle ), -aSizeDX * sin( anAngle ) );
+ aSizeShift = QPointF( -aSizeDX, 0 );
+ break;
+ case GraphicsView_PrsImageFrame::Right:
+ aPosShift = QPointF( 0, 0 );
+ aSizeShift = QPointF( aSizeDX, 0 );
+ break;
+ case GraphicsView_PrsImageFrame::TopLeft:
+ aPosShift = QPointF( aDX, aDY );
+ aSizeShift = QPointF( -aSizeDX, -aSizeDY );
+ break;
+ case GraphicsView_PrsImageFrame::TopRight:
+ aPosShift = QPointF( aSizeDY * sin( anAngle ), aSizeDY * cos( anAngle ) );
+ aSizeShift = QPointF( aSizeDX, -aSizeDY );
+ break;
+ case GraphicsView_PrsImageFrame::BottomLeft:
+ aPosShift = QPointF( aSizeDX * cos( anAngle ), -aSizeDX * sin( anAngle ) );
+ aSizeShift = QPointF( -aSizeDX, aSizeDY );
+ break;
+ case GraphicsView_PrsImageFrame::BottomRight:
+ aPosShift = QPointF( 0, 0 );
+ aSizeShift = QPointF( aSizeDX, aSizeDY );
+ break;
+ }
+
+ aWidth += (int)aSizeShift.x();
+ aHeight += (int)aSizeShift.y();
+ if( aWidth < 10 || aHeight < 10 ) // tmp
+ return;
+
+ QPixmap aPixmap = myPixmap.scaled( aWidth, aHeight );
+ myPreviewPixmapItem->setPixmap( aPixmap );
+
+ myPreviewPixmapItem->setPos( pos() + aPosShift );
+}
+
+//================================================================
+// Function : finishResize
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::finishResize()
+{
+ QSize aSourceSize = myPixmap.size();
+ QSize aScaledSize = myPreviewPixmapItem->pixmap().size();
+
+ myScaleX = ( (double)aScaledSize.width() ) / ( (double)aSourceSize.width() );
+ myScaleY = ( (double)aScaledSize.height() ) / ( (double)aSourceSize.height() );
+
+ QPointF aSceneCenter = myPixmapItem->sceneBoundingRect().center();
+ QPointF aPreviewSceneCenter = myPreviewPixmapItem->sceneBoundingRect().center();
+
+ QPointF aCenter = myPixmapItem->pixmap().rect().center();
+ QPointF aPreviewCenter = myPreviewPixmapItem->pixmap().rect().center();
+
+ QPointF aCenterShift = aSceneCenter - aCenter;
+ QPointF aPreviewCenterShift = aPreviewSceneCenter - aPreviewCenter;
+
+ QPointF aPosShift = myPreviewPixmapItem->pos() - pos();
+ QPointF aShift = aPreviewCenterShift - aCenterShift - aPosShift;
+
+ myPixmapItem->setPixmap( myPreviewPixmapItem->pixmap() );
+ myImageFrame->computeAnchorItems();
+
+ setPos( myPreviewPixmapItem->pos() + aShift );
+ setRotationAroundCenter( this, myRotationAngle );
+
+ myImageFrame->setPos( myPreviewPixmapItem->pos() + aShift );
+ setRotationAroundCenter( myImageFrame, myRotationAngle );
+
+ enablePreview( false );
+}
+
+//================================================================
+// Function : processRotate
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::processRotate( const QPointF& thePoint1,
+ const QPointF& thePoint2 )
+{
+ 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 );
+
+ double anAngle = aVec1.Angle( aVec2 );
+ double anAngleDeg = anAngle / PI * 180.;
+
+ myPreviewRotationAngle = myRotationAngle + anAngleDeg;
+ setRotationAroundCenter( myPreviewPixmapItem, myPreviewRotationAngle );
+}
+
+//================================================================
+// Function : finishRotate
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::finishRotate()
+{
+ myRotationAngle = myPreviewRotationAngle;
+ setRotationAroundCenter( this, myRotationAngle );
+ setRotationAroundCenter( myImageFrame, myRotationAngle );
+
+ enablePreview( false );
+}
+
+//================================================================
+// Function : enablePreview
+// Purpose :
+//================================================================
+void GraphicsView_PrsImage::enablePreview( const bool theState )
+{
+ if( theState )
+ {
+ myPreviewPixmapItem->setZValue( 100 );
+ myPreviewPixmapItem->setOpacity( opacity() / 2. );
+
+ myPreviewPixmapItem->setPos( pos() );
+ setRotationAroundCenter( myPreviewPixmapItem, myRotationAngle );
+ myPreviewRotationAngle = myRotationAngle;
+
+ myPreviewPixmapItem->setVisible( true );
+ }
+ else
+ myPreviewPixmapItem->setVisible( false );
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef GRAPHICSVIEW_PRSIMAGE_H
+#define GRAPHICSVIEW_PRSIMAGE_H
+
+#include "GraphicsView.h"
+
+#include "GraphicsView_Object.h"
+
+class GraphicsView_PrsImageFrame;
+
+/*
+ Class : GraphicsView_PrsImage
+ Description : Presentation for image object
+*/
+class GRAPHICSVIEW_API GraphicsView_PrsImage : public GraphicsView_Object
+{
+public:
+ GraphicsView_PrsImage();
+ virtual ~GraphicsView_PrsImage();
+
+public:
+ void setImage( const QImage& theImage );
+ QImage getImage() const;
+
+ QTransform getTransform() const;
+
+ void setPosition( const double thePosX, const double thePosY );
+ void getPosition( double& thePosX, double& thePosY ) const;
+
+ void setScaling( const double theScaleX, const double theScaleY );
+ void getScaling( double& theScaleX, double& theScaleY ) const;
+
+ void setRotationAngle( const double theRotationAngle );
+ void getRotationAngle( double& theRotationAngle ) const;
+
+public:
+ // from QGraphicsItem
+ virtual QRectF boundingRect() const;
+
+ // from GraphicsView_Object
+ virtual void compute();
+
+ virtual void addTo( GraphicsView_ViewPort* theViewPort );
+ virtual void removeFrom( GraphicsView_ViewPort* theViewPort );
+
+ virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const;
+
+ virtual bool highlight( double theX, double theY );
+ virtual void unhighlight();
+
+ virtual bool select( double theX, double theY, const QRectF& theRect );
+ virtual void unselect();
+ virtual void setSelected( bool theState );
+
+ virtual void move( double theDX, double theDY, bool theIsAtOnce = false );
+ virtual bool finishMove();
+
+ virtual QPointF centerPoint();
+
+protected:
+ void processResize( const int theAnchor,
+ const QPointF& thePoint1,
+ const QPointF& thePoint2 );
+ void finishResize();
+
+ void processRotate( const QPointF& thePoint1,
+ const QPointF& thePoint2 );
+ void finishRotate();
+
+protected:
+ void enablePreview( const bool theState );
+
+protected:
+ QPixmap myPixmap;
+
+ QGraphicsPixmapItem* myPixmapItem;
+ QGraphicsPixmapItem* myPreviewPixmapItem;
+
+ GraphicsView_PrsImageFrame* myImageFrame;
+
+ double myScaleX;
+ double myScaleY;
+
+ double myRotationAngle;
+ double myPreviewRotationAngle;
+
+private:
+ friend class GraphicsView_PrsImageFrame;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "GraphicsView_PrsImageFrame.h"
+
+#include "GraphicsView_PrsImage.h"
+
+#include <SUIT_ResourceMgr.h>
+#include <SUIT_Session.h>
+
+#include <QCursor>
+#include <QPainter>
+
+#define ANCHOR_RADIUS 10
+
+//=======================================================================
+// name : GraphicsView_PrsImageFrame
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_PrsImageFrame::GraphicsView_PrsImageFrame()
+: GraphicsView_Object(),
+ myPrsImage( 0 ),
+ myIsPulling( false ),
+ myPullingAnchor( Undefined )
+{
+ myVerCursor = new QCursor( Qt::SizeVerCursor );
+ myHorCursor = new QCursor( Qt::SizeHorCursor );
+ myBDiagCursor = new QCursor( Qt::SizeBDiagCursor );
+ myFDiagCursor = new QCursor( Qt::SizeFDiagCursor );
+
+ SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr();
+ myRotateCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", QObject::tr( "ICON_GV_ROTATE" ) ) );
+}
+
+//=======================================================================
+// name : GraphicsView_PrsImageFrame
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_PrsImageFrame::~GraphicsView_PrsImageFrame()
+{
+ if( myVerCursor )
+ {
+ delete myVerCursor;
+ myVerCursor = 0;
+ }
+ if( myHorCursor )
+ {
+ delete myHorCursor;
+ myHorCursor = 0;
+ }
+ if( myBDiagCursor )
+ {
+ delete myBDiagCursor;
+ myBDiagCursor = 0;
+ }
+ if( myFDiagCursor )
+ {
+ delete myFDiagCursor;
+ myFDiagCursor = 0;
+ }
+ if( myRotateCursor )
+ {
+ delete myRotateCursor;
+ myRotateCursor = 0;
+ }
+}
+
+//================================================================
+// Function : boundingRect
+// Purpose :
+//================================================================
+QRectF GraphicsView_PrsImageFrame::boundingRect() const
+{
+ QRectF aRect;
+ AnchorMapIterator anIter( myAnchorMap );
+ while( anIter.hasNext() )
+ {
+ if( QGraphicsEllipseItem* anAnchorItem = anIter.next().value() )
+ {
+ QRectF anAnchorRect = anAnchorItem->boundingRect();
+ if( !anAnchorRect.isNull() )
+ {
+ if( aRect.isNull() )
+ aRect = anAnchorRect;
+ else
+ aRect |= anAnchorRect;
+ }
+ }
+ }
+ return aRect;
+}
+
+//================================================================
+// Function : compute
+// Purpose :
+//================================================================
+void GraphicsView_PrsImageFrame::compute()
+{
+ if( myAnchorMap.isEmpty() )
+ {
+ for( int aType = Top; aType <= TopMost; aType++ )
+ {
+ UnscaledGraphicsEllipseItem* anAnchorItem = new UnscaledGraphicsEllipseItem( this );
+ //anAnchorItem->setFlag( QGraphicsItem::ItemIgnoresTransformations, true );
+
+ Qt::GlobalColor aColor = Qt::white;
+ if( aType == TopMost )
+ aColor = Qt::green;
+ anAnchorItem->setBrush( QBrush( aColor ) );
+
+ myAnchorMap.insert( aType, anAnchorItem );
+
+ addToGroup( anAnchorItem );
+ }
+ }
+
+ setZValue( 1000 );
+
+ computeAnchorItems();
+ updateAnchorItems();
+}
+
+//================================================================
+// Function : checkHighlight
+// Purpose :
+//================================================================
+bool GraphicsView_PrsImageFrame::checkHighlight( double theX, double theY, QCursor& theCursor ) const
+{
+ AnchorMapIterator anIter( myAnchorMap );
+ while( anIter.hasNext() )
+ {
+ int aType = anIter.next().key();
+ if( QGraphicsEllipseItem* anAnchorItem = anIter.value() )
+ {
+ QRectF aRect = anAnchorItem->sceneBoundingRect();
+ if( aRect.contains( QPointF( theX, theY ) ) )
+ {
+ if( aType >= Top && aType <= BottomRight )
+ {
+ if( QCursor* aCursor = getResizeCursor( aType ) )
+ theCursor = *aCursor;
+ }
+ else if( aType == TopMost )
+ theCursor = *getRotateCursor();
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+//================================================================
+// Function : getPullingRect
+// Purpose :
+//================================================================
+QRectF GraphicsView_PrsImageFrame::getPullingRect() const
+{
+ return getRect();
+}
+
+//================================================================
+// Function : startPulling
+// Purpose :
+//================================================================
+bool GraphicsView_PrsImageFrame::startPulling( const QPointF& thePoint )
+{
+ if( !isVisible() )
+ return false;
+
+ AnchorMapIterator anIter( myAnchorMap );
+ while( anIter.hasNext() )
+ {
+ int aType = anIter.next().key();
+ if( UnscaledGraphicsEllipseItem* anAnchorItem = anIter.value() )
+ {
+ QRectF aRect = anAnchorItem->sceneBoundingRect();
+ if( aRect.contains( thePoint ) )
+ {
+ myPullingAnchor = aType;
+ myPullingPoint = sceneTransform().map( anAnchorItem->getBasePoint() );
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+//================================================================
+// Function : pull
+// Purpose :
+//================================================================
+void GraphicsView_PrsImageFrame::pull( const QPointF& thePoint, GraphicsView_Object* )
+{
+ if( !myPrsImage )
+ return;
+
+ if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
+ myPrsImage->processResize( myPullingAnchor, myPullingPoint, thePoint );
+ else if( myPullingAnchor == TopMost )
+ myPrsImage->processRotate( myPullingPoint, thePoint );
+}
+
+//================================================================
+// Function : finishPulling
+// Purpose :
+//================================================================
+void GraphicsView_PrsImageFrame::finishPulling()
+{
+ if( !myPrsImage )
+ return;
+
+ if( myPullingAnchor >= Top && myPullingAnchor <= BottomRight )
+ myPrsImage->finishResize();
+ else if( myPullingAnchor == TopMost )
+ myPrsImage->finishRotate();
+}
+
+//================================================================
+// Function : centerPoint
+// Purpose :
+//================================================================
+QPointF GraphicsView_PrsImageFrame::centerPoint()
+{
+ QPointF aPoint1 = myAnchorMap[ Top ]->getBasePoint();
+ QPointF aPoint2 = myAnchorMap[ Bottom ]->getBasePoint();
+ QPointF aPoint3 = myAnchorMap[ Left ]->getBasePoint();
+ QPointF aPoint4 = myAnchorMap[ Right ]->getBasePoint();
+ return ( aPoint1 + aPoint2 + aPoint3 + aPoint4 ) /4.;
+}
+
+//================================================================
+// Function : setPrsImage
+// Purpose :
+//================================================================
+void GraphicsView_PrsImageFrame::setPrsImage( GraphicsView_PrsImage* thePrsImage )
+{
+ myPrsImage = thePrsImage;
+}
+
+//================================================================
+// Function : computeAnchorItems
+// Purpose :
+//================================================================
+void GraphicsView_PrsImageFrame::computeAnchorItems()
+{
+ if( !myPrsImage )
+ return;
+
+ QRectF aRect = myPrsImage->boundingRect();
+
+ QMap<int, QPointF> anAnchorPointMap;
+ anAnchorPointMap[ Top ] = ( aRect.topLeft() + aRect.topRight() ) / 2;
+ anAnchorPointMap[ Bottom ] = ( aRect.bottomLeft() + aRect.bottomRight() ) / 2;
+ anAnchorPointMap[ Left ] = ( aRect.topLeft() + aRect.bottomLeft() ) / 2;
+ anAnchorPointMap[ Right ] = ( aRect.topRight() + aRect.bottomRight() ) / 2;
+ anAnchorPointMap[ TopLeft ] = aRect.topLeft();
+ anAnchorPointMap[ TopRight ] = aRect.topRight();
+ 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() )
+ {
+ int anAnchorType = anIter.next().key();
+ const QPointF& anAnchorPoint = anIter.value();
+
+ QRectF anAnchorRect( anAnchorPoint - QPointF( ar, ar ), QSizeF( ar * 2, ar * 2 ) );
+ myAnchorMap[ anAnchorType ]->setRect( anAnchorRect );
+ myAnchorMap[ anAnchorType ]->setBasePoint( anAnchorPoint );
+ }
+}
+
+//================================================================
+// Function : updateAnchorItems
+// Purpose :
+//================================================================
+void GraphicsView_PrsImageFrame::updateAnchorItems()
+{
+ if( !myPrsImage )
+ return;
+
+ bool anIsSelected = myPrsImage->isSelected();
+ if( anIsSelected )
+ {
+ double aPosX, aPosY, aRotationAngle;
+ myPrsImage->getPosition( aPosX, aPosY );
+ myPrsImage->getRotationAngle( aRotationAngle );
+
+ setPos( aPosX, aPosY );
+ setRotationAroundCenter( this, aRotationAngle );
+ }
+ setVisible( anIsSelected );
+}
+
+//================================================================
+// Function : getResizeCursor
+// Purpose :
+//================================================================
+QCursor* GraphicsView_PrsImageFrame::getResizeCursor( const int theAnchor ) const
+{
+ if( !myPrsImage )
+ return 0;
+
+ double aRotationAngle = 0;
+ myPrsImage->getRotationAngle( aRotationAngle );
+
+ int anAngle = (int)aRotationAngle;
+ anAngle = anAngle % 360;
+ anAngle += 360; // to avoid negative values
+ anAngle = anAngle % 360; // 0 <= anAngle <= 359
+
+ int aShift = 0;
+ switch( theAnchor )
+ {
+ case Top: aShift = 0; break;
+ case TopRight: aShift = 45; break;
+ case Right: aShift = 90; break;
+ case BottomRight: aShift = 135; break;
+ case Bottom: aShift = 180; break;
+ case BottomLeft: aShift = 225; break;
+ case Left: aShift = 270; break;
+ case TopLeft: aShift = 315; break;
+ }
+ anAngle += aShift;
+ anAngle = anAngle % 360;
+
+ // 360 = 8 sectors of 45 degrees
+ if( anAngle <= 22 || anAngle >= 338 )
+ return getVerCursor();
+ if( anAngle >= 23 && anAngle <= 67 )
+ return getBDiagCursor();
+ if( anAngle >= 68 && anAngle <= 112 )
+ return getHorCursor();
+ if( anAngle >= 113 && anAngle <= 157 )
+ return getFDiagCursor();
+ if( anAngle >= 158 && anAngle <= 202 )
+ return getVerCursor();
+ if( anAngle >= 203 && anAngle <= 247 )
+ return getBDiagCursor();
+ if( anAngle >= 248 && anAngle <= 292 )
+ return getHorCursor();
+ if( anAngle >= 293 && anAngle <= 337 )
+ return getFDiagCursor();
+ return 0;
+}
+
+//=======================================================================
+// name : GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem
+// Purpose : Constructor
+//=======================================================================
+GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::UnscaledGraphicsEllipseItem( QGraphicsItem* theParent )
+: QGraphicsEllipseItem( theParent )
+{
+}
+
+//=======================================================================
+// name : GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem
+// Purpose : Destructor
+//=======================================================================
+GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::~UnscaledGraphicsEllipseItem()
+{
+}
+
+//================================================================
+// Function : GenerateTranslationOnlyTransform
+// Purpose :
+//================================================================
+static QTransform GenerateTranslationOnlyTransform( const QTransform &theOriginalTransform,
+ const QPointF &theTargetPoint )
+{
+ qreal dx = theOriginalTransform.m11() * theTargetPoint.x() - theTargetPoint.x() +
+ theOriginalTransform.m21() * theTargetPoint.y() +
+ theOriginalTransform.m31();
+ qreal dy = theOriginalTransform.m22() * theTargetPoint.y() - theTargetPoint.y() +
+ theOriginalTransform.m12() * theTargetPoint.x() +
+ theOriginalTransform.m32();
+ return QTransform::fromTranslate( dx, dy );
+}
+
+//================================================================
+// Function : paint
+// Purpose :
+//================================================================
+void GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem::paint(
+ QPainter* thePainter,
+ const QStyleOptionGraphicsItem* theOption,
+ QWidget* theWidget )
+{
+ //thePainter->save();
+ //thePainter->setTransform( GenerateTranslationOnlyTransform( thePainter->transform(),
+ // myBasePoint ) );
+ QGraphicsEllipseItem::paint( thePainter, theOption, theWidget );
+ //thePainter->restore();
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef GRAPHICSVIEW_PRSIMAGEFRAME_H
+#define GRAPHICSVIEW_PRSIMAGEFRAME_H
+
+#include "GraphicsView.h"
+
+#include "GraphicsView_Object.h"
+
+#include <QGraphicsEllipseItem>
+
+class GraphicsView_PrsImage;
+
+/*
+ Class : GraphicsView_PrsImageFrame
+ Description : Presentation for image frame object
+*/
+class GRAPHICSVIEW_API GraphicsView_PrsImageFrame : public GraphicsView_Object
+{
+public:
+ class UnscaledGraphicsEllipseItem;
+
+ enum AnchorType { Undefined = 0, Top, Bottom, Left, Right,
+ TopLeft, TopRight, BottomLeft, BottomRight,
+ TopMost };
+
+ typedef QMap <int, UnscaledGraphicsEllipseItem*> AnchorMap;
+ typedef QMapIterator<int, UnscaledGraphicsEllipseItem*> AnchorMapIterator;
+
+public:
+ GraphicsView_PrsImageFrame();
+ virtual ~GraphicsView_PrsImageFrame();
+
+public:
+ // from QGraphicsItem
+ virtual QRectF boundingRect() const;
+
+ // from GraphicsView_Object
+ virtual void compute();
+
+ virtual bool isMovable() const { return false; }
+
+ virtual bool checkHighlight( double theX, double theY, QCursor& theCursor ) const;
+
+ 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 bool isPulling() { return myIsPulling; }
+
+ virtual QPointF centerPoint();
+
+public:
+ void setPrsImage( GraphicsView_PrsImage* );
+
+ void computeAnchorItems();
+ void updateAnchorItems();
+
+protected:
+ QCursor* getVerCursor() const { return myVerCursor; }
+ QCursor* getHorCursor() const { return myHorCursor; }
+ QCursor* getBDiagCursor() const { return myBDiagCursor; }
+ QCursor* getFDiagCursor() const { return myFDiagCursor; }
+ QCursor* getRotateCursor() const { return myRotateCursor; }
+
+ QCursor* getResizeCursor( const int theAnchor ) const;
+
+protected:
+ GraphicsView_PrsImage* myPrsImage;
+
+ bool myIsPulling;
+ int myPullingAnchor;
+ QPointF myPullingPoint;
+
+ AnchorMap myAnchorMap;
+
+private:
+ QCursor* myVerCursor;
+ QCursor* myHorCursor;
+ QCursor* myBDiagCursor;
+ QCursor* myFDiagCursor;
+ QCursor* myRotateCursor;
+};
+
+/*
+ Class : UnscaledGraphicsEllipseItem
+ Description : Class for unscaled ellipse item
+*/
+class GraphicsView_PrsImageFrame::UnscaledGraphicsEllipseItem : public QGraphicsEllipseItem
+{
+public:
+ UnscaledGraphicsEllipseItem( QGraphicsItem* );
+ virtual ~UnscaledGraphicsEllipseItem();
+
+public:
+ void setBasePoint( const QPointF& thePoint ) { myBasePoint = thePoint; }
+ const QPointF& getBasePoint() const { return myBasePoint; }
+
+public:
+ virtual void paint( QPainter*, const QStyleOptionGraphicsItem*, QWidget* );
+
+private:
+ QPointF myBasePoint;
+};
+
+#endif
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#include "GraphicsView_PrsPropDlg.h"
+
+#include <QtxDoubleSpinBox.h>
+
+#include <QGroupBox>
+#include <QLabel>
+#include <QLayout>
+
+//================================================================
+// Function : GraphicsView_PrsPropDlg
+// Purpose :
+//================================================================
+GraphicsView_PrsPropDlg::GraphicsView_PrsPropDlg( QWidget* theParent )
+: QtxDialog( theParent, true, true, QtxDialog::OKCancel )
+{
+ setWindowTitle( tr( "PROPERTIES" ) );
+
+ QFrame* aMainFrame = mainFrame();
+
+ QGroupBox* aPropGroup = new QGroupBox( aMainFrame );
+
+ QLabel* aPositionXLabel = new QLabel( tr( "POSITION_X" ), aPropGroup );
+ myPositionX = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup );
+
+ QLabel* aPositionYLabel = new QLabel( tr( "POSITION_Y" ), aPropGroup );
+ myPositionY = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup );
+
+ QLabel* aScalingXLabel = new QLabel( tr( "SCALING_X" ), aPropGroup );
+ myScalingX = new QtxDoubleSpinBox( 1e-6, 1e6, 1, aPropGroup );
+
+ QLabel* aScalingYLabel = new QLabel( tr( "SCALING_Y" ), aPropGroup );
+ myScalingY = new QtxDoubleSpinBox( 1e-6, 1e6, 1, aPropGroup );
+
+ QLabel* aRotationAngleLabel = new QLabel( tr( "ROTATION_ANGLE" ), aPropGroup );
+ myRotationAngle = new QtxDoubleSpinBox( -1e6, 1e6, 1, aPropGroup );
+
+ QGridLayout* aPropLayout = new QGridLayout( aPropGroup );
+ aPropLayout->setMargin( 5 );
+ aPropLayout->setSpacing( 5 );
+ aPropLayout->addWidget( aPositionXLabel, 0, 0 );
+ aPropLayout->addWidget( myPositionX, 0, 1 );
+ aPropLayout->addWidget( aPositionYLabel, 1, 0 );
+ aPropLayout->addWidget( myPositionY, 1, 1 );
+ aPropLayout->addWidget( aScalingXLabel, 2, 0 );
+ aPropLayout->addWidget( myScalingX, 2, 1 );
+ aPropLayout->addWidget( aScalingYLabel, 3, 0 );
+ aPropLayout->addWidget( myScalingY, 3, 1 );
+ aPropLayout->addWidget( aRotationAngleLabel, 4, 0 );
+ aPropLayout->addWidget( myRotationAngle, 4, 1 );
+ aPropLayout->setColumnStretch( 1, 1 );
+
+ QVBoxLayout* aMainLayout = new QVBoxLayout( aMainFrame );
+ aMainLayout->setMargin( 5 );
+ aMainLayout->setSpacing( 5 );
+ aMainLayout->addWidget( aPropGroup );
+
+ setButtonPosition( Center, OK );
+ setButtonPosition( Center, Cancel );
+ setMinimumWidth( 300 );
+}
+
+//================================================================
+// Function : ~GraphicsView_PrsPropDlg
+// Purpose :
+//================================================================
+GraphicsView_PrsPropDlg::~GraphicsView_PrsPropDlg()
+{
+}
+
+//=============================================================================
+// Function : setData
+// Purpose :
+//=============================================================================
+void GraphicsView_PrsPropDlg::setData( const double thePositionX,
+ const double thePositionY,
+ const double theScalingX,
+ const double theScalingY,
+ const double theRotationAngle )
+{
+ myPositionX->setValue( thePositionX );
+ myPositionY->setValue( thePositionY );
+ myScalingX->setValue( theScalingX );
+ myScalingY->setValue( theScalingY );
+ myRotationAngle->setValue( theRotationAngle );
+}
+
+//=============================================================================
+// Function : getData
+// Purpose :
+//=============================================================================
+void GraphicsView_PrsPropDlg::getData( double& thePositionX,
+ double& thePositionY,
+ double& theScalingX,
+ double& theScalingY,
+ double& theRotationAngle ) const
+{
+ thePositionX = myPositionX->value();
+ thePositionY = myPositionY->value();
+ theScalingX = myScalingX->value();
+ theScalingY = myScalingY->value();
+ theRotationAngle = myRotationAngle->value();
+}
--- /dev/null
+// Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+#ifndef GRAPHICSVIEW_PRSPROPDLG_H
+#define GRAPHICSVIEW_PRSPROPDLG_H
+
+#include "GraphicsView.h"
+
+#include <QtxDialog.h>
+
+class QtxDoubleSpinBox;
+
+/*
+ Class : GraphicsView_PrsPropDlg
+ Description : Dialog for managing presentation properties
+*/
+class GRAPHICSVIEW_API GraphicsView_PrsPropDlg : public QtxDialog
+{
+ Q_OBJECT
+
+public:
+ GraphicsView_PrsPropDlg( QWidget* = 0 );
+ virtual ~GraphicsView_PrsPropDlg();
+
+public:
+ void setData( const double thePositionX,
+ const double thePositionY,
+ const double theScalingX,
+ const double theScalingY,
+ const double theRotationAngle );
+
+ void getData( double& thePositionX,
+ double& thePositionY,
+ double& theScalingX,
+ double& theScalingY,
+ double& theRotationAngle ) const;
+
+private:
+ QtxDoubleSpinBox* myPositionX;
+ QtxDoubleSpinBox* myPositionY;
+ QtxDoubleSpinBox* myScalingX;
+ QtxDoubleSpinBox* myScalingY;
+ QtxDoubleSpinBox* myRotationAngle;
+};
+
+#endif
#include <QGraphicsRectItem>
#include <QGraphicsSceneWheelEvent>
-//#define VIEWER_DEBUG
+#define VIEWER_DEBUG // testing ImageViewer
//=======================================================================
// Name : GraphicsView_Scene
connect( this, SIGNAL( sceneRectChanged( const QRectF& ) ),
this, SLOT( onSceneRectChanged( const QRectF& ) ) );
+
+ QGraphicsEllipseItem* aCenterItem = new QGraphicsEllipseItem( 0, 0, 5, 5 );
+ aCenterItem->setBrush( QBrush( Qt::red ) );
+ addItem( aCenterItem );
#endif
+
+ setSceneRect( -500, -500, 3000, 3000 ); // testing ImageViewer
}
//=======================================================================
myIsDragging( false ),
myIsDragPositionInitialized( false ),
myIsPulling( false ),
- myPullingObject( 0 )
+ myPullingObject( 0 ),
+ myStoredCursor( Qt::ArrowCursor )
{
// scene
myScene = new GraphicsView_Scene( this );
mySceneGap = 20;
myFitAllGap = 40;
- myIsTraceBoundingRectEnabled = true;
+ myIsTraceBoundingRectEnabled = false; // testing ImageViewer
// interaction flags
myInteractionFlags = AllFlags;
}
}
myObjects.insert( anIter, anObject );
+ anObject->addTo( this );
}
- myScene->addItem( theItem );
+ else
+ myScene->addItem( theItem );
onBoundingRectChanged();
}
myHighlightedObject = 0;
mySelectedObjects.removeAll( anObject );
myObjects.removeAll( anObject );
+ anObject->removeFrom( this );
}
- myScene->removeItem( theItem );
+ else
+ myScene->removeItem( theItem );
onBoundingRectChanged();
}
GraphicsView_Object* aPreviousHighlightedObject = myHighlightedObject;
GraphicsView_Object* aHighlightedObject = 0;
- GraphicsView_ObjectList aList = getObjects( true );
+ QCursor aCursor;
+
+ GraphicsView_ObjectList aList = getObjects( false );
GraphicsView_ObjectListIterator anIter( aList );
anIter.toBack(); // objects with higher priority have to be checked earlier
while( anIter.hasPrevious() )
{
if( anObject->isVisible() && anObject->isSelectable() )
{
- QRectF aRect = anObject->getRect();
- if( !aRect.isNull() && aRect.contains( theX, theY ) )
+ if( anObject->checkHighlight( theX, theY, aCursor ) )
{
anIsOnObject = true;
anIsHighlighted = anObject->highlight( theX, theY );
}
}
+ setCursor( aCursor );
+
if( !anIsOnObject )
{
anIter = aList;
{
myIsPulling = true;
myPullingObject = anObject;
- setCursor( *getHandCursor() );
+ //setCursor( *getHandCursor() ); // testing ImageViewer
return true;
}
}
getHighlightedObject()->isMovable() &&
!( anAccel || e->button() == Qt::RightButton ) ) ||
( nbSelected() && !anAccel && e->button() == Qt::MidButton ) )
- myIsDragging = true;
+ {
+ myIsDragging = true;
+ myStoredCursor = cursor();
+ setCursor( Qt::ClosedHandCursor );
+ }
}
break;
}
myIsDragging = false;
myDragPosition = QPointF();
+ setCursor( myStoredCursor );
emit vpObjectAfterMoving( anIsMoved );
}
// pulling
bool myIsPulling;
GraphicsView_Object* myPullingObject;
+
+ // cursor
+ QCursor myStoredCursor;
};
#endif
#include <QKeyEvent>
#include <QMenu>
+// testing ImageViewer
+#include "GraphicsView_PrsImage.h"
+#include "GraphicsView_PrsPropDlg.h"
+#include <QFileDialog>
+
//=======================================================================
// Name : GraphicsView_Viewer
// Purpose : Constructor
if( thePopup->actions().count() > 0 )
thePopup->addSeparator();
+ // testing ImageViewer
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ int aNbSelected = aViewPort->nbSelected();
+ if( aNbSelected == 0 )
+ {
+ thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) );
+ thePopup->addSeparator();
+
+ thePopup->addAction( tr( "TEST_IMAGE_COMPOSITION" ), this, SLOT( onTestImageComposition() ) );
+ }
+ else
+ {
+ if( aNbSelected == 1 )
+ {
+ thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) );
+ thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) );
+ thePopup->addSeparator();
+ thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) );
+ thePopup->addSeparator();
+ }
+ thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) );
+ }
+ thePopup->addSeparator();
+ }
+
thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
}
{
emit selectionChanged( GVSCS_Invalid );
}
+
+//================================================================
+// Function : onAddImage
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onAddImage()
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ QString aFileName = QFileDialog::getOpenFileName();
+ if( aFileName.isEmpty() )
+ return;
+
+ GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage();
+
+ QImage anImage( aFileName );
+ aPrs->setImage( anImage );
+
+ aPrs->compute();
+
+ aViewPort->addItem( aPrs );
+ aViewPort->fitAll();
+ }
+}
+
+//================================================================
+// Function : onRemoveImages
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onRemoveImages()
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
+ {
+ if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
+ {
+ if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
+ {
+ aViewPort->removeItem( aPrs );
+ delete aPrs;
+ }
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : onBringForward
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onBringForward()
+{
+ // to do
+}
+
+//================================================================
+// Function : onSendBackward
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onSendBackward()
+{
+ // to do
+}
+
+//================================================================
+// Function : onPrsProperties
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onPrsProperties()
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ aViewPort->initSelected();
+ if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
+ {
+ if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
+ {
+ double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
+ aPrs->getPosition( aPosX, aPosY );
+ aPrs->getScaling( aScaleX, aScaleY );
+ aPrs->getRotationAngle( aRotationAngle );
+
+ GraphicsView_PrsPropDlg aDlg( aViewPort );
+ aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle );
+ if( aDlg.exec() )
+ {
+ aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle );
+ aPrs->setPosition( aPosX, aPosY );
+ aPrs->setScaling( aScaleX, aScaleY );
+ aPrs->setRotationAngle( aRotationAngle );
+ aPrs->compute();
+ }
+ }
+ }
+ }
+}
+
+//================================================================
+// Function : onTestImageComposition
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onTestImageComposition()
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ GraphicsView_ObjectList aList = aViewPort->getObjects();
+ GraphicsView_ObjectListIterator anIter( aList );
+ while( anIter.hasNext() )
+ {
+ if( GraphicsView_Object* anObject = anIter.next() )
+ {
+ if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
+ {
+ QImage anImage = aPrs->getImage();
+ QTransform aTransform = aPrs->getTransform();
+ // ...
+ }
+ }
+ }
+ }
+}
virtual void onChangeBgColor();
+ // testing ImageViewer
+ void onAddImage();
+ void onRemoveImages();
+ void onBringForward();
+ void onSendBackward();
+ void onPrsProperties();
+ void onTestImageComposition();
+
private:
void handleKeyPress( QKeyEvent* );
void handleKeyRelease( QKeyEvent* );
salomeinclude_HEADERS = \
GraphicsView_Defs.h \
-GraphicsView_Geom.h \
GraphicsView.h \
GraphicsView_Object.h \
GraphicsView_Scene.h \
GraphicsView_ViewFrame.h \
GraphicsView_ViewManager.h \
GraphicsView_ViewPort.h \
-GraphicsView_ViewTransformer.h
+GraphicsView_ViewTransformer.h \
+GraphicsView_PrsImage.h \
+GraphicsView_PrsImageFrame.h \
+GraphicsView_PrsPropDlg.h
dist_libGraphicsView_la_SOURCES = \
GraphicsView_Object.cxx \
GraphicsView_ViewFrame.cxx \
GraphicsView_ViewManager.cxx \
GraphicsView_ViewPort.cxx \
-GraphicsView_ViewTransformer.cxx
+GraphicsView_ViewTransformer.cxx \
+GraphicsView_PrsImage.cxx \
+GraphicsView_PrsImageFrame.cxx \
+GraphicsView_PrsPropDlg.cxx
MOC_FILES = \
GraphicsView_ViewManager_moc.cxx \
GraphicsView_ViewFrame_moc.cxx \
GraphicsView_Selector_moc.cxx \
GraphicsView_ViewPort_moc.cxx \
-GraphicsView_Scene_moc.cxx
+GraphicsView_Scene_moc.cxx \
+GraphicsView_PrsPropDlg_moc.cxx
nodist_libGraphicsView_la_SOURCES = $(MOC_FILES)
resources/graphics_view_glpan.png \
resources/graphics_view_pan.png \
resources/graphics_view_reset.png \
+resources/graphics_view_rotate.png \
resources/graphics_view_zoom.png
nodist_salomeres_DATA = \
GraphicsView_msg_en.qm \
GraphicsView_msg_fr.qm
-libGraphicsView_la_CPPFLAGS = $(QT_INCLUDES) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx
-libGraphicsView_la_LDFLAGS = $(QT_MT_LIBS)
+libGraphicsView_la_CPPFLAGS = $(QT_INCLUDES) $(CAS_CPPFLAGS) -I$(srcdir)/../SUIT -I$(srcdir)/../Qtx
+libGraphicsView_la_LDFLAGS = $(QT_MT_LIBS) $(CAS_KERNEL)
libGraphicsView_la_LIBADD = ../SUIT/libsuit.la
<source>ICON_GV_FITAREA</source>
<translation>graphics_view_fitarea.png</translation>
</message>
+ <message>
+ <source>ICON_GV_ROTATE</source>
+ <translation>graphics_view_rotate.png</translation>
+ </message>
</context>
</TS>
<source>CHANGE_BGCOLOR</source>
<translation>Change background...</translation>
</message>
+ <message>
+ <source>ADD_IMAGE</source>
+ <translation>Add image</translation>
+ </message>
+ <message>
+ <source>REMOVE_IMAGES</source>
+ <translation>Remove image(s)</translation>
+ </message>
+ <message>
+ <source>BRING_FORWARD</source>
+ <translation>Bring forward</translation>
+ </message>
+ <message>
+ <source>SEND_BACKWARD</source>
+ <translation>Send backward</translation>
+ </message>
+ <message>
+ <source>PROPERTIES</source>
+ <translation>Properties</translation>
+ </message>
+ <message>
+ <source>TEST_IMAGE_COMPOSITION</source>
+ <translation>Test image composition</translation>
+ </message>
</context>
<context>
<name>GraphicsView_ViewManager</name>
<translation>Graphics scene:%M - viewer:%V</translation>
</message>
</context>
+ <context>
+ <name>GraphicsView_PrsPropDlg</name>
+ <message>
+ <source>PROPERTIES</source>
+ <translation>Properties</translation>
+ </message>
+ <message>
+ <source>POSITION_X</source>
+ <translation>Position X</translation>
+ </message>
+ <message>
+ <source>POSITION_Y</source>
+ <translation>Position Y</translation>
+ </message>
+ <message>
+ <source>SCALING_X</source>
+ <translation>Scaling X</translation>
+ </message>
+ <message>
+ <source>SCALING_Y</source>
+ <translation>Scaling Y</translation>
+ </message>
+ <message>
+ <source>ROTATION_ANGLE</source>
+ <translation>Rotation angle</translation>
+ </message>
+ </context>
</TS>