1 // Copyright (C) 2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "GraphicsView_Viewer.h"
22 #include "GraphicsView_Object.h"
23 #include "GraphicsView_Selector.h"
24 #include "GraphicsView_Scene.h"
25 #include "GraphicsView_ViewFrame.h"
26 #include "GraphicsView_ViewPort.h"
27 #include "GraphicsView_ViewTransformer.h"
29 #include <SUIT_ViewManager.h>
31 #include <ImageComposer_Image.h>
33 #include <QApplication>
34 #include <QColorDialog>
35 #include <QGraphicsSceneMouseEvent>
36 #include <QGraphicsSceneWheelEvent>
40 // testing ImageViewer
42 #include "GraphicsView_PrsImage.h"
43 #include "GraphicsView_PrsPropDlg.h"
44 #include <QFileDialog>
47 //=======================================================================
48 // Name : GraphicsView_Viewer
49 // Purpose : Constructor
50 //=======================================================================
51 GraphicsView_Viewer::GraphicsView_Viewer( const QString& title )
55 myIsInitialized( false )
59 //=======================================================================
60 // Name : GraphicsView_Viewer
61 // Purpose : Destructor
62 //=======================================================================
63 GraphicsView_Viewer::~GraphicsView_Viewer()
68 //================================================================
69 // Function : createView
71 //================================================================
72 SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
74 GraphicsView_ViewFrame* aViewFrame = new GraphicsView_ViewFrame( theDesktop, this );
76 connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
77 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
79 connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ),
80 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
82 connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
83 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
85 connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
86 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
88 connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
89 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
91 connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
92 this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
94 connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ),
95 this, SLOT( onSketchingFinished( QPainterPath ) ) );
100 //================================================================
101 // Function : contextMenuPopup
103 //================================================================
104 void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup )
106 if( thePopup->actions().count() > 0 )
107 thePopup->addSeparator();
109 // testing ImageViewer
111 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
113 int aNbSelected = aViewPort->nbSelected();
114 if( aNbSelected == 0 )
116 thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) );
117 thePopup->addSeparator();
119 thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) );
120 thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) );
124 thePopup->addAction( tr( "BRING_TO_FRONT" ), this, SLOT( onBringToFront() ) );
125 thePopup->addAction( tr( "SEND_TO_BACK" ), this, SLOT( onSendToBack() ) );
126 thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) );
127 thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) );
128 thePopup->addSeparator();
130 if( aNbSelected == 1 )
132 thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) );
133 thePopup->addSeparator();
136 thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) );
138 thePopup->addSeparator();
142 thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
145 //================================================================
146 // Function : getSelector
148 //================================================================
149 GraphicsView_Selector* GraphicsView_Viewer::getSelector()
153 mySelector = new GraphicsView_Selector( this );
156 connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ),
157 this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) );
158 connect( mySelector, SIGNAL( selSelectionCancel() ),
159 this, SLOT( onSelectionCancel() ) );
165 //================================================================
166 // Function : getActiveView
168 //================================================================
169 GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const
171 if( SUIT_ViewManager* aViewManager = getViewManager() )
172 return dynamic_cast<GraphicsView_ViewFrame*>( aViewManager->getActiveView() );
176 //================================================================
177 // Function : getActiveViewPort
179 //================================================================
180 GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const
182 if( GraphicsView_ViewFrame* aViewFrame = getActiveView() )
183 return aViewFrame->getViewPort();
187 //================================================================
188 // Function : getActiveScene
190 //================================================================
191 GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const
193 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
194 return dynamic_cast<GraphicsView_Scene*>( aViewPort->scene() );
198 //================================================================
199 // Function : activateTransform
201 //================================================================
202 void GraphicsView_Viewer::activateTransform( int theType )
204 if( theType == NoTransform ) // finish current transform
208 onTransformationFinished();
209 delete myTransformer;
213 else // activate new transform
215 activateTransform( NoTransform );
216 myTransformer = createTransformer( theType );
217 onTransformationStarted();
218 myTransformer->exec();
222 //================================================================
223 // Function : setIsInitialized
225 //================================================================
226 void GraphicsView_Viewer::setIsInitialized( bool theFlag )
228 myIsInitialized = theFlag;
231 //================================================================
232 // Function : createTransformer
234 //================================================================
235 GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType )
237 return new GraphicsView_ViewTransformer( this, theType );
240 //================================================================
241 // Function : onTransformationStarted
243 //================================================================
244 void GraphicsView_Viewer::onTransformationStarted()
246 if( GraphicsView_Selector* aSelector = getSelector() )
248 aSelector->undetectAll();
249 aSelector->lock( true ); // disable selection
252 // watch events: any mouse/key event outside the
253 // viewport will be considered as the end of transform
255 qApp->installEventFilter( this );
258 //================================================================
259 // Function : onTransformationFinished
261 //================================================================
262 void GraphicsView_Viewer::onTransformationFinished()
264 if( GraphicsView_Selector* aSelector = getSelector() )
265 aSelector->lock( false ); // enable selection
267 // stop watching events
269 qApp->removeEventFilter( this );
272 //================================================================
273 // Function : onKeyEvent
275 //================================================================
276 void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e )
280 case QEvent::KeyPress:
283 case QEvent::KeyRelease:
284 handleKeyRelease( e );
290 //================================================================
291 // Function : onMouseEvent
293 //================================================================
294 void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
298 case QEvent::GraphicsSceneMousePress:
299 handleMousePress( e );
301 case QEvent::GraphicsSceneMouseMove:
302 handleMouseMove( e );
304 case QEvent::GraphicsSceneMouseRelease:
305 handleMouseRelease( e );
311 //================================================================
312 // Function : onWheelEvent
314 //================================================================
315 void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
319 case QEvent::GraphicsSceneWheel:
326 //================================================================
327 // Function : handleKeyPress
329 //================================================================
330 void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e )
332 if( e->key() == Qt::Key_Escape )
334 // Cancel current operation
335 bool anIsCancelled = false;
336 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
338 anIsCancelled = aViewPort->cancelCurrentOperation();
340 // Unselect all objects (if there is no operation to cancel)
343 aViewPort->finishSelectByRect();
344 aViewPort->clearSelected();
348 // Emit unselection signal
350 if( GraphicsView_Selector* aSelector = getSelector() )
351 aSelector->unselectAll();
355 //================================================================
356 // Function : handleKeyRelease
358 //================================================================
359 void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* e )
363 //================================================================
364 // Function : handleMousePress
366 //================================================================
367 void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
369 // test accel for transforms
370 if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
372 Qt::MouseButton bs = e->button();
373 if ( bs == GraphicsView_ViewTransformer::zoomButton() )
374 activateTransform( Zoom );
375 else if ( bs == GraphicsView_ViewTransformer::panButton() )
376 activateTransform( Pan );
378 else // checking for other operations before selection in release event
380 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
382 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
383 if( e->button() == Qt::LeftButton &&
384 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) &&
385 aViewPort->isPrepareToSketch() )
387 // Use 'append' flag for sketching by arbitrary path
388 aViewPort->startSketching( e->scenePos(), append );
390 else if( e->button() == Qt::LeftButton &&
391 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
392 !aViewPort->isSelectByRect() &&
393 !aViewPort->isDragging() &&
394 aViewPort->startPulling( e->scenePos() ) )
396 // Try to start pulling if rectangular selection is performed
397 aViewPort->finishSelectByRect();
399 else if( e->button() == Qt::LeftButton &&
400 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
401 !aViewPort->getHighlightedObject() )
403 // Start rectangular selection if pulling was not started
404 QPoint p = aViewPort->mapFromScene( e->scenePos() );
405 aViewPort->startSelectByRect( p.x(), p.y() );
407 else if( e->button() != Qt::MidButton && !append &&
408 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) &&
409 aViewPort->nbSelected() < 2 )
411 // Do not perform 'immediate selection' if the multiple objects are already selected
412 getSelector()->select( QRectF(), append );
414 else if( e->button() == Qt::RightButton &&
415 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) &&
416 aViewPort->nbSelected() < 1 )
418 // If the 'immediate context menu' mode is enabled,
419 // try to perform selection before invoking context menu
420 getSelector()->select( QRectF(), append );
426 //================================================================
427 // Function : handleMouseMove
429 //================================================================
430 void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
432 GraphicsView_ViewPort* aViewPort = getActiveViewPort();
434 // highlight for selection
435 bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
436 bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch();
437 if ( !anIsDragged && !anIsPrepareToSketch )
440 getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
443 // try to activate other operations
446 if( aViewPort->isPulling() )
448 aViewPort->drawPulling( e->scenePos() );
450 else if( aViewPort->isSketching() )
452 aViewPort->drawSketching( e->scenePos() );
454 else if( e->button() == Qt::LeftButton &&
455 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
456 !aViewPort->isSelectByRect() &&
457 !aViewPort->isDragging() &&
458 aViewPort->startPulling( e->scenePos() ) )
460 aViewPort->finishSelectByRect();
462 else if( !aViewPort->getHighlightedObject() )
464 QPoint p = aViewPort->mapFromScene( e->scenePos() );
465 aViewPort->drawSelectByRect( p.x(), p.y() );
470 //================================================================
471 // Function : handleMouseRelease
473 //================================================================
474 void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
477 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
479 if( e->button() == Qt::LeftButton &&
480 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
484 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
485 getSelector()->select( QRectF(), append );
490 // try to finish active operations
491 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
493 if( aViewPort->isPulling() )
495 aViewPort->finishPulling( true );
497 else if( aViewPort->isSketching() )
499 aViewPort->finishSketching( true );
501 else if( !aViewPort->getHighlightedObject() )
503 QRect aSelRect = aViewPort->selectionRect();
504 aViewPort->finishSelectByRect();
505 if ( getSelector() && !aSelRect.isNull() )
507 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
508 QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect();
509 getSelector()->select( aRect, append );
515 //================================================================
516 // Function : handleWheel
518 //================================================================
519 void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
521 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
523 if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) )
525 bool anIsScaleUp = e->delta() > 0;
526 bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
528 bool anIsScaleChanged = false;
529 for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
530 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
531 anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
533 if( anIsScaleChanged )
535 emit wheelScaleChanged();
536 aViewPort->onBoundingRectChanged();
542 //================================================================
543 // Function : onSketchingFinished
545 //================================================================
546 void GraphicsView_Viewer::onSketchingFinished( QPainterPath thePath )
548 // testing ImageViewer
549 //onTestCropOperatorPerform( thePath );
552 //================================================================
553 // Function : onSelectionDone
555 //================================================================
556 void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
558 emit selectionChanged( theStatus );
561 //================================================================
562 // Function : onChangeBgColor
564 //================================================================
565 void GraphicsView_Viewer::onChangeBgColor()
567 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
569 QColor aColor = aViewPort->isForegroundEnabled() ?
570 aViewPort->foregroundColor() : aViewPort->backgroundColor();
571 aColor = QColorDialog::getColor( aColor, aViewPort );
572 if ( aColor.isValid() )
574 if( aViewPort->isForegroundEnabled() )
576 aViewPort->setForegroundColor( aColor );
577 aViewPort->updateForeground();
580 aViewPort->setBackgroundColor( aColor );
585 //================================================================
586 // Function : onSelectionCancel
588 //================================================================
589 void GraphicsView_Viewer::onSelectionCancel()
591 emit selectionChanged( GVSCS_Invalid );
595 //================================================================
596 // Function : onAddImage
598 //================================================================
599 void GraphicsView_Viewer::onAddImage()
601 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
603 QString aFileName = QFileDialog::getOpenFileName();
604 if( aFileName.isEmpty() )
607 GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage();
609 QImage anImage( aFileName );
610 aPrs->setImage( anImage );
614 aViewPort->addItem( aPrs );
619 //================================================================
620 // Function : onRemoveImages
622 //================================================================
623 void GraphicsView_Viewer::onRemoveImages()
625 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
627 GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() );
628 while( anIter.hasNext() )
630 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
632 aViewPort->removeItem( aPrs );
639 //================================================================
640 // Function : onBringToFront
642 //================================================================
643 void GraphicsView_Viewer::onBringToFront()
645 processQueueOperation( BringToFront );
648 //================================================================
649 // Function : onSendToBack
651 //================================================================
652 void GraphicsView_Viewer::onSendToBack()
654 processQueueOperation( SendToBack );
657 //================================================================
658 // Function : onBringForward
660 //================================================================
661 void GraphicsView_Viewer::onBringForward()
663 processQueueOperation( BringForward );
666 //================================================================
667 // Function : onSendBackward
669 //================================================================
670 void GraphicsView_Viewer::onSendBackward()
672 processQueueOperation( SendBackward );
675 //================================================================
676 // Function : processQueueOperation
678 //================================================================
679 void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation )
681 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
683 const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects();
685 GraphicsView_ObjectList aSortedList;
687 GraphicsView_ObjectList aList = aViewPort->getObjects();
688 GraphicsView_ObjectListIterator anIter( aList );
689 while( anIter.hasNext() )
691 if( GraphicsView_Object* anObject = anIter.next() )
693 if( !anObject->hasSpecificZValue() )
695 double aZValue = anObject->zValue();
696 GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end();
697 for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ )
698 if( GraphicsView_Object* anObjectRef = *anIter1 )
699 if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue )
701 aSortedList.insert( anIter1, anObject );
706 QList<int> anIndicesToMove;
709 anIter = aSortedList;
710 while( anIter.hasNext() )
712 if( GraphicsView_Object* anObject = anIter.next() )
713 if( aSelectedList.contains( anObject ) )
714 anIndicesToMove.append( anIndex );
718 bool anIsReverse = theOperation == BringToFront || theOperation == BringForward;
719 QListIterator<int> anIndicesIter( anIndicesToMove );
721 anIndicesIter.toBack();
723 int aShiftForMultiple = 0;
724 int anObjectCount = aSortedList.count();
725 while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() )
727 int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next();
728 int aNewIndex = anIndex;
729 switch( theOperation )
731 case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break;
732 case SendToBack: aNewIndex = aShiftForMultiple; break;
733 case BringForward: aNewIndex = anIndex + 1; break;
734 case SendBackward: aNewIndex = anIndex - 1; break;
738 if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 )
741 aSortedList.move( anIndex, aNewIndex );
744 double aZValue = 1.0;
745 anIter = aSortedList;
746 while( anIter.hasNext() )
748 if( GraphicsView_Object* anObject = anIter.next() )
750 anObject->setZValue( aZValue );
757 //================================================================
758 // Function : onPrsProperties
760 //================================================================
761 void GraphicsView_Viewer::onPrsProperties()
763 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
765 aViewPort->initSelected();
766 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
768 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
770 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
771 aPrs->getPosition( aPosX, aPosY );
772 aPrs->getScaling( aScaleX, aScaleY );
773 aPrs->getRotationAngle( aRotationAngle );
775 double aZValue = aPrs->zValue();
776 double anOpacity = aPrs->opacity();
778 bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio();
779 bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation();
781 GraphicsView_PrsPropDlg aDlg( aViewPort );
782 aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
783 aZValue, anOpacity, anIsLockAspectRatio,
784 anIsSmoothTransformation );
787 aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
788 aZValue, anOpacity, anIsLockAspectRatio,
789 anIsSmoothTransformation );
791 aPrs->setPosition( aPosX, aPosY );
792 aPrs->setScaling( aScaleX, aScaleY );
793 aPrs->setRotationAngle( aRotationAngle );
795 aPrs->setZValue( aZValue );
796 aPrs->setOpacity( anOpacity );
798 aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
799 aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
808 //================================================================
809 // Function : onTestFuseOperator
811 //================================================================
812 void GraphicsView_Viewer::onTestFuseOperator()
814 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
816 GraphicsView_ObjectList aList = aViewPort->getObjects();
817 if( aList.count() < 3 )
820 GraphicsView_PrsImage* anObj1 = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
821 GraphicsView_PrsImage* anObj2 = dynamic_cast<GraphicsView_PrsImage*>( aList[2] );
823 ImageComposer_Image anImage1;
824 anImage1 = anObj1->getImage();
825 anImage1.setTransform( anObj1->getTransform() );
827 ImageComposer_Image anImage2;
828 anImage2 = anObj2->getImage();
829 anImage2.setTransform( anObj2->getTransform() );
831 ImageComposer_Image aResult = anImage1 | anImage2;
832 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
833 aResPrs->setImage( aResult );
835 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
836 anObj1->getPosition( aPosX, aPosY );
837 anObj1->getScaling( aScaleX, aScaleY );
838 anObj1->getRotationAngle( aRotationAngle );
840 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
841 aResPrs->setScaling( aScaleX, aScaleY );
842 aResPrs->setRotationAngle( aRotationAngle );
846 aViewPort->addItem( aResPrs );
847 aViewPort->removeItem( anObj1 );
848 aViewPort->removeItem( anObj2 );
852 //================================================================
853 // Function : onTestCropOperatorPrepare
855 //================================================================
856 void GraphicsView_Viewer::onTestCropOperatorPrepare()
858 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
859 aViewPort->prepareToSketch( true );
862 //================================================================
863 // Function : onTestCropOperatorPerform
865 //================================================================
866 void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath )
868 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
870 GraphicsView_ObjectList aList = aViewPort->getObjects();
871 if( aList.count() < 1 )
874 GraphicsView_PrsImage* anObj = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
876 ImageComposer_Image anImage;
877 anImage = anObj->getImage();
878 anImage.setTransform( anObj->getTransform() );
880 ImageComposer_Image aResult = anImage & thePath;
881 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
882 aResPrs->setImage( aResult );
884 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
885 anObj->getPosition( aPosX, aPosY );
886 anObj->getScaling( aScaleX, aScaleY );
887 anObj->getRotationAngle( aRotationAngle );
889 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
890 aResPrs->setScaling( aScaleX, aScaleY );
891 aResPrs->setRotationAngle( aRotationAngle );
895 aViewPort->addItem( aResPrs );
896 aViewPort->removeItem( anObj );