this, SLOT( wheelEvent( QGraphicsSceneWheelEvent* ) ) );
connect( myViewPort, SIGNAL( vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ),
this, SLOT( contextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) );
+
+ connect( myViewPort, SIGNAL( vpSketchingFinished( QPainterPath ) ),
+ this, SIGNAL( sketchingFinished( QPainterPath ) ) );
}
//=======================================================================
void mouseDoubleClicked( QGraphicsSceneMouseEvent* );
void wheeling( QGraphicsSceneWheelEvent* );
+ void sketchingFinished( QPainterPath );
+
private:
void createActions();
int createToolBar();
#include <math.h>
+#define FOREGROUND_Z_VALUE -2
+#define GRID_Z_VALUE -1
+#define SKETCH_Z_VALUE 3000
+
int GraphicsView_ViewPort::nCounter = 0;
QCursor* GraphicsView_ViewPort::defCursor = 0;
QCursor* GraphicsView_ViewPort::handCursor = 0;
QCursor* GraphicsView_ViewPort::panCursor = 0;
QCursor* GraphicsView_ViewPort::panglCursor = 0;
QCursor* GraphicsView_ViewPort::zoomCursor = 0;
+QCursor* GraphicsView_ViewPort::sketchCursor = 0;
//=======================================================================
// Name : GraphicsView_ViewPort::NameLabel
SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr();
zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) );
+
+ sketchCursor = new QCursor( Qt::CrossCursor );
}
//================================================================
//================================================================
void GraphicsView_ViewPort::destroyCursors()
{
- delete defCursor; defCursor = 0;
- delete handCursor; handCursor = 0;
- delete panCursor; panCursor = 0;
- delete panglCursor; panglCursor = 0;
- delete zoomCursor; zoomCursor = 0;
+ delete defCursor; defCursor = 0;
+ delete handCursor; handCursor = 0;
+ delete panCursor; panCursor = 0;
+ delete panglCursor; panglCursor = 0;
+ delete zoomCursor; zoomCursor = 0;
+ delete sketchCursor; sketchCursor = 0;
}
//=======================================================================
mySelectionIterator( 0 ),
myRectBand( 0 ),
myAreSelectionPointsInitialized( false ),
+ mySketchingItem( 0 ),
+ myIsPrepareToSketch( false ),
+ myIsSketching( false ),
+ myIsSketchingByPath( false ),
myIsDragging( false ),
myIsDragPositionInitialized( false ),
myIsPulling( false ),
//setInteractionFlag( TraceBoundingRect );
//setInteractionFlag( DraggingByMiddleButton );
//setInteractionFlag( ImmediateContextMenu );
- setInteractionFlag( ImmediateSelection );
+ setInteractionFlag( ImmediateSelection ); // testing ImageViewer
+ setInteractionFlag( Sketching ); // testing ImageViewer
// background
setBackgroundBrush( QBrush( Qt::white ) );
{
if( !myForegroundItem )
myForegroundItem = myScene->addRect( QRectF(), QPen(), QBrush( Qt::white ) );
- myForegroundItem->setZValue( -2 );
+ myForegroundItem->setZValue( FOREGROUND_Z_VALUE );
QPointF aPoint = QPointF();
QRectF aRect( aPoint, myForegroundSize );
{
if( !myGridItem )
myGridItem = myScene->addPath( QPainterPath() );
- myGridItem->setZValue( -1 );
+ myGridItem->setZValue( GRID_Z_VALUE );
double aWidth = myForegroundSize.width();
double aHeight = myForegroundSize.height();
return aRect;
}
+//================================================================
+// Function : prepareToSketch
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::prepareToSketch( bool theStatus )
+{
+ myIsPrepareToSketch = theStatus;
+ if( theStatus )
+ setCursor( *getSketchCursor() );
+}
+
+//================================================================
+// Function : isPrepareToSketch
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::isPrepareToSketch()
+{
+ return myIsPrepareToSketch;
+}
+
+//================================================================
+// Function : startSketching
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::startSketching( const QPointF& thePoint,
+ bool theIsPath )
+{
+ prepareToSketch( false );
+
+ if( !mySketchingItem )
+ {
+ mySketchingItem = new QGraphicsPathItem();
+ mySketchingItem->setZValue( SKETCH_Z_VALUE );
+
+ QPen aPen = mySketchingItem->pen();
+ aPen.setStyle( Qt::DotLine );
+ mySketchingItem->setPen( aPen );
+
+ addItem( mySketchingItem );
+ }
+
+ mySketchingPoint = thePoint;
+
+ QPainterPath aPath;
+ aPath.moveTo( mySketchingPoint );
+ mySketchingItem->setPath( aPath );
+ mySketchingItem->setVisible( true );
+
+ myIsSketching = true;
+ myIsSketchingByPath = theIsPath;
+}
+
+//================================================================
+// Function : drawSketching
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::drawSketching( const QPointF& thePoint )
+{
+ bool anIsPath = false;
+ if( mySketchingItem && isSketching( &anIsPath ) )
+ {
+ QPainterPath aPath = mySketchingItem->path();
+ if( anIsPath ) // arbitrary path
+ aPath.lineTo( thePoint );
+ else // rectangle
+ {
+ // make a valid rectangle
+ double x1 = mySketchingPoint.x(), y1 = mySketchingPoint.y();
+ double x2 = thePoint.x(), y2 = thePoint.y();
+ QPointF aPoint1( qMin( x1, x2 ), qMin( y1, y2 ) );
+ QPointF aPoint2( qMax( x1, x2 ), qMax( y1, y2 ) );
+ QRectF aRect( aPoint1, aPoint2 );
+
+ aPath = QPainterPath();
+ aPath.addRect( aRect );
+ }
+ mySketchingItem->setPath( aPath );
+ }
+}
+
+//================================================================
+// Function : finishSketching
+// Purpose :
+//================================================================
+void GraphicsView_ViewPort::finishSketching( bool theStatus )
+{
+ prepareToSketch( false ); // just in case
+
+ mySketchingItem->setVisible( false );
+ myIsSketching = false;
+
+ setCursor( *getDefaultCursor() );
+
+ if( theStatus )
+ {
+ QPainterPath aPath = mySketchingItem->path();
+ emit vpSketchingFinished( aPath );
+ }
+}
+
+//================================================================
+// Function : isSketching
+// Purpose :
+//================================================================
+bool GraphicsView_ViewPort::isSketching( bool* theIsPath ) const
+{
+ if( theIsPath )
+ *theIsPath = myIsSketchingByPath;
+ return myIsSketching;
+}
+
//================================================================
// Function : dragObjects
// Purpose :
if( hasInteractionFlag( EditFlags ) && nbSelected() )
for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
if( GraphicsView_Object* anObject = selectedObject() )
- anIsHandled = anObject->handleMousePress( e );
+ anIsHandled = anObject->handleMouseMove( e );
if( !anIsHandled && !isPulling() && myIsDragging )
dragObjects( e );
if( hasInteractionFlag( EditFlags ) && nbSelected() )
for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
if( GraphicsView_Object* anObject = selectedObject() )
- anIsHandled = anObject->handleMousePress( e );
+ anIsHandled = anObject->handleMouseRelease( e );
if( !anIsHandled && !isPulling() && myIsDragging )
{
DraggingByMiddleButton = 0x0010,
ImmediateContextMenu = 0x0020,
ImmediateSelection = 0x0040,
+ Sketching = 0x0080
};
Q_DECLARE_FLAGS( InteractionFlags, InteractionFlag )
bool isSelectByRect() const;
QRect selectionRect();
+ // sketching
+ void prepareToSketch( bool theStatus );
+ bool isPrepareToSketch();
+ void startSketching( const QPointF& thePoint,
+ bool theIsPath );
+ void drawSketching( const QPointF& thePoint );
+ void finishSketching( bool theStatus );
+ bool isSketching( bool* theIsPath = 0 ) const;
+
// dragging
bool isDragging() { return myIsDragging; }
static QCursor* getPanCursor() { return panCursor; }
static QCursor* getPanglCursor() { return panglCursor; }
static QCursor* getZoomCursor() { return zoomCursor; }
+ static QCursor* getSketchCursor() { return sketchCursor; }
public slots:
void onBoundingRectChanged();
void vpWheelEvent( QGraphicsSceneWheelEvent* );
void vpContextMenuEvent( QGraphicsSceneContextMenuEvent* );
+ void vpSketchingFinished( QPainterPath );
+
void vpObjectBeforeMoving();
void vpObjectAfterMoving( bool );
static QCursor* panCursor;
static QCursor* panglCursor;
static QCursor* zoomCursor;
+ static QCursor* sketchCursor;
private:
// scene
QPoint myLastSelectionPoint;
bool myAreSelectionPointsInitialized;
+ // sketching
+ QGraphicsPathItem* mySketchingItem;
+ QPointF mySketchingPoint;
+ bool myIsPrepareToSketch;
+ bool myIsSketching;
+ bool myIsSketchingByPath;
+
// dragging
int myIsDragging;
QPointF myDragPosition;
connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
+ connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ),
+ this, SLOT( onSketchingFinished( QPainterPath ) ) );
+
return aViewFrame;
}
thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) );
thePopup->addSeparator();
- thePopup->addAction( tr( "TEST_IMAGE_COMPOSITION" ), this, SLOT( onTestImageComposition() ) );
+ thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) );
+ thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) );
}
else
{
{
bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
if( e->button() == Qt::LeftButton &&
+ aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) &&
+ aViewPort->isPrepareToSketch() )
+ {
+ // Use 'append' flag for sketching by arbitrary path
+ aViewPort->startSketching( e->scenePos(), append );
+ }
+ else if( e->button() == Qt::LeftButton &&
aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
!aViewPort->isSelectByRect() &&
!aViewPort->isDragging() &&
QPoint p = aViewPort->mapFromScene( e->scenePos() );
aViewPort->startSelectByRect( p.x(), p.y() );
}
- else if( !append &&
- e->button() != Qt::MidButton &&
+ else if( e->button() != Qt::MidButton && !append &&
aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) &&
aViewPort->nbSelected() < 2 )
{
{
// If the 'immediate context menu' mode is enabled,
// try to perform selection before invoking context menu
- //bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
getSelector()->select( QRectF(), append );
}
}
//================================================================
void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
{
+ GraphicsView_ViewPort* aViewPort = getActiveViewPort();
+
// highlight for selection
- bool dragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
- if ( !dragged )
+ bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
+ bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch();
+ if ( !anIsDragged && !anIsPrepareToSketch )
{
if ( getSelector() )
getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
}
// try to activate other operations
- if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ if( aViewPort )
{
if( aViewPort->isPulling() )
{
aViewPort->drawPulling( e->scenePos() );
}
+ else if( aViewPort->isSketching() )
+ {
+ aViewPort->drawSketching( e->scenePos() );
+ }
else if( e->button() == Qt::LeftButton &&
aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
!aViewPort->isSelectByRect() &&
{
aViewPort->finishPulling( true );
}
+ else if( aViewPort->isSketching() )
+ {
+ aViewPort->finishSketching( true );
+ }
else if( !aViewPort->getHighlightedObject() )
{
QRect aSelRect = aViewPort->selectionRect();
}
}
+//================================================================
+// Function : onSketchingFinished
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onSketchingFinished( QPainterPath thePath )
+{
+ // testing ImageViewer
+ onTestCropOperatorPerform( thePath );
+}
+
//================================================================
// Function : onSelectionDone
// Purpose :
}
//================================================================
-// Function : onTestImageComposition
+// Function : onTestFuseOperator
// Purpose :
//================================================================
-void GraphicsView_Viewer::onTestImageComposition()
+void GraphicsView_Viewer::onTestFuseOperator()
{
if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
{
GraphicsView_ObjectList aList = aViewPort->getObjects();
- int aCount = aList.count();
+ if( aList.count() < 3 )
+ return;
+
GraphicsView_PrsImage* anObj1 = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
GraphicsView_PrsImage* anObj2 = dynamic_cast<GraphicsView_PrsImage*>( aList[2] );
aViewPort->removeItem( anObj2 );
}
}
+
+//================================================================
+// Function : onTestCropOperatorPrepare
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onTestCropOperatorPrepare()
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ aViewPort->prepareToSketch( true );
+}
+
+//================================================================
+// Function : onTestCropOperatorPerform
+// Purpose :
+//================================================================
+void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath )
+{
+ if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
+ {
+ GraphicsView_ObjectList aList = aViewPort->getObjects();
+ if( aList.count() < 1 )
+ return;
+
+ GraphicsView_PrsImage* anObj = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
+
+ ImageComposer_Image anImage;
+ anImage = anObj->getImage();
+ anImage.setTransform( anObj->getTransform() );
+
+ ImageComposer_Image aResult = anImage & thePath;
+ GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
+ aResPrs->setImage( aResult );
+
+ double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
+ anObj->getPosition( aPosX, aPosY );
+ anObj->getScaling( aScaleX, aScaleY );
+ anObj->getRotationAngle( aRotationAngle );
+
+ aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
+ aResPrs->setScaling( aScaleX, aScaleY );
+ aResPrs->setRotationAngle( aRotationAngle );
+
+ aResPrs->compute();
+
+ aViewPort->addItem( aResPrs );
+ aViewPort->removeItem( anObj );
+ }
+}
#include <SUIT_ViewModel.h>
+#include <QPainterPath>
+
class QGraphicsSceneMouseEvent;
class QGraphicsSceneWheelEvent;
class QKeyEvent;
virtual void onMouseEvent( QGraphicsSceneMouseEvent* );
virtual void onWheelEvent( QGraphicsSceneWheelEvent* );
+ virtual void onSketchingFinished( QPainterPath );
+
virtual void onSelectionDone( GV_SelectionChangeStatus );
virtual void onSelectionCancel();
virtual void onChangeBgColor();
// testing ImageViewer
- void onTestImageComposition();
void onAddImage();
void onRemoveImages();
void onBringToFront();
void onBringForward();
void onSendBackward();
void onPrsProperties();
+ void onTestFuseOperator();
+ void onTestCropOperatorPrepare();
+ void onTestCropOperatorPerform( QPainterPath thePath );
private:
void handleKeyPress( QKeyEvent* );