1 // Copyright (C) 2013-2016 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, or (at your option) any later version.
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, QWidget* widget )
56 myIsInitialized( false )
60 //=======================================================================
61 // Name : GraphicsView_Viewer
62 // Purpose : Destructor
63 //=======================================================================
64 GraphicsView_Viewer::~GraphicsView_Viewer()
69 GraphicsView_ViewFrame* GraphicsView_Viewer::createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget )
71 return new GraphicsView_ViewFrame( theDesktop, this, theWidget );
74 //================================================================
75 // Function : createView
77 //================================================================
78 SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
80 GraphicsView_ViewFrame* aViewFrame = createViewFrame( theDesktop, myWidget );
82 connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
83 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
85 connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ),
86 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
88 connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
89 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
91 connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
92 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
94 connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
95 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
97 connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
98 this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
100 connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ),
101 this, SLOT( onSketchingFinished( QPainterPath ) ) );
106 //================================================================
107 // Function : contextMenuPopup
109 //================================================================
110 void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup )
112 if( thePopup->actions().count() > 0 )
113 thePopup->addSeparator();
115 // testing ImageViewer
117 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
119 int aNbSelected = aViewPort->nbSelected();
120 if( aNbSelected == 0 )
122 thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) );
123 thePopup->addSeparator();
125 thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) );
126 thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) );
130 thePopup->addAction( tr( "BRING_TO_FRONT" ), this, SLOT( onBringToFront() ) );
131 thePopup->addAction( tr( "SEND_TO_BACK" ), this, SLOT( onSendToBack() ) );
132 thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) );
133 thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) );
134 thePopup->addSeparator();
136 if( aNbSelected == 1 )
138 thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) );
139 thePopup->addSeparator();
142 thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) );
144 thePopup->addSeparator();
148 thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
151 //================================================================
152 // Function : getSelector
154 //================================================================
155 GraphicsView_Selector* GraphicsView_Viewer::getSelector()
159 mySelector = new GraphicsView_Selector( this );
162 connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ),
163 this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) );
164 connect( mySelector, SIGNAL( selSelectionCancel() ),
165 this, SLOT( onSelectionCancel() ) );
171 //================================================================
172 // Function : getActiveView
174 //================================================================
175 GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const
177 if( SUIT_ViewManager* aViewManager = getViewManager() )
178 return dynamic_cast<GraphicsView_ViewFrame*>( aViewManager->getActiveView() );
182 //================================================================
183 // Function : getActiveViewPort
185 //================================================================
186 GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const
188 if( GraphicsView_ViewFrame* aViewFrame = getActiveView() )
189 return aViewFrame->getViewPort();
193 //================================================================
194 // Function : getActiveScene
196 //================================================================
197 GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const
199 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
200 return dynamic_cast<GraphicsView_Scene*>( aViewPort->scene() );
204 //================================================================
205 // Function : activateTransform
207 //================================================================
208 void GraphicsView_Viewer::activateTransform( int theType )
210 if( theType == NoTransform ) // finish current transform
214 onTransformationFinished();
215 delete myTransformer;
219 else // activate new transform
221 activateTransform( NoTransform );
222 myTransformer = createTransformer( theType );
223 onTransformationStarted();
224 myTransformer->exec();
228 //================================================================
229 // Function : setIsInitialized
231 //================================================================
232 void GraphicsView_Viewer::setIsInitialized( bool theFlag )
234 myIsInitialized = theFlag;
237 //================================================================
238 // Function : createTransformer
240 //================================================================
241 GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType )
243 return new GraphicsView_ViewTransformer( this, theType );
246 //================================================================
247 // Function : onTransformationStarted
249 //================================================================
250 void GraphicsView_Viewer::onTransformationStarted()
252 if( GraphicsView_Selector* aSelector = getSelector() )
254 aSelector->undetectAll();
255 aSelector->lock( true ); // disable selection
258 // watch events: any mouse/key event outside the
259 // viewport will be considered as the end of transform
261 qApp->installEventFilter( this );
264 //================================================================
265 // Function : onTransformationFinished
267 //================================================================
268 void GraphicsView_Viewer::onTransformationFinished()
270 if( GraphicsView_Selector* aSelector = getSelector() )
271 aSelector->lock( false ); // enable selection
273 // stop watching events
275 qApp->removeEventFilter( this );
278 //================================================================
279 // Function : onKeyEvent
281 //================================================================
282 void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e )
286 case QEvent::KeyPress:
289 case QEvent::KeyRelease:
290 handleKeyRelease( e );
296 //================================================================
297 // Function : onMouseEvent
299 //================================================================
300 void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
304 case QEvent::GraphicsSceneMousePress:
305 handleMousePress( e );
307 case QEvent::GraphicsSceneMouseMove:
308 handleMouseMove( e );
310 case QEvent::GraphicsSceneMouseRelease:
311 handleMouseRelease( e );
317 //================================================================
318 // Function : onWheelEvent
320 //================================================================
321 void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
325 case QEvent::GraphicsSceneWheel:
332 //================================================================
333 // Function : handleKeyPress
335 //================================================================
336 void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e )
338 if( e->key() == Qt::Key_Escape )
340 // Cancel current operation
341 bool anIsCancelled = false;
342 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
344 anIsCancelled = aViewPort->cancelCurrentOperation();
346 // Unselect all objects (if there is no operation to cancel)
349 aViewPort->finishSelectByRect();
350 aViewPort->clearSelected();
354 // Emit unselection signal
356 if( GraphicsView_Selector* aSelector = getSelector() )
357 aSelector->unselectAll();
361 //================================================================
362 // Function : handleKeyRelease
364 //================================================================
365 void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* e )
369 //================================================================
370 // Function : handleMousePress
372 //================================================================
373 void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
375 // test accel for transforms
376 if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
378 Qt::MouseButton bs = e->button();
379 if ( bs == GraphicsView_ViewTransformer::zoomButton() )
380 activateTransform( Zoom );
381 else if ( bs == GraphicsView_ViewTransformer::panButton() )
382 activateTransform( Pan );
384 else // checking for other operations before selection in release event
386 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
388 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
389 if( e->button() == Qt::LeftButton &&
390 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) &&
391 aViewPort->isPrepareToSketch() )
393 // Use 'append' flag for sketching by arbitrary path
394 aViewPort->startSketching( e->scenePos(), append );
396 else if( e->button() == Qt::LeftButton &&
397 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
398 !aViewPort->isSelectByRect() &&
399 !aViewPort->isDragging() &&
400 aViewPort->startPulling( e->scenePos() ) )
402 // Try to start pulling if rectangular selection is performed
403 aViewPort->finishSelectByRect();
405 else if( e->button() == Qt::LeftButton &&
406 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
407 !aViewPort->getHighlightedObject() )
409 // Start rectangular selection if pulling was not started
410 QPoint p = aViewPort->mapFromScene( e->scenePos() );
411 aViewPort->startSelectByRect( p.x(), p.y() );
413 else if( e->button() != Qt::MidButton && !append &&
414 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) &&
415 aViewPort->nbSelected() < 2 )
417 // Do not perform 'immediate selection' if the multiple objects are already selected
418 getSelector()->select( QRectF(), append );
420 else if( e->button() == Qt::RightButton &&
421 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) &&
422 aViewPort->nbSelected() < 1 )
424 // If the 'immediate context menu' mode is enabled,
425 // try to perform selection before invoking context menu
426 getSelector()->select( QRectF(), append );
432 //================================================================
433 // Function : handleMouseMove
435 //================================================================
436 void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
438 GraphicsView_ViewPort* aViewPort = getActiveViewPort();
440 // highlight for selection
441 bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
442 bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch();
443 if ( !anIsDragged && !anIsPrepareToSketch )
446 getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
449 // try to activate other operations
452 if( aViewPort->isPulling() )
454 aViewPort->drawPulling( e->scenePos() );
456 else if( aViewPort->isSketching() )
458 aViewPort->drawSketching( e->scenePos() );
460 else if( e->button() == Qt::LeftButton &&
461 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
462 !aViewPort->isSelectByRect() &&
463 !aViewPort->isDragging() &&
464 aViewPort->startPulling( e->scenePos() ) )
466 aViewPort->finishSelectByRect();
468 else if( !aViewPort->getHighlightedObject() )
470 QPoint p = aViewPort->mapFromScene( e->scenePos() );
471 aViewPort->drawSelectByRect( p.x(), p.y() );
476 //================================================================
477 // Function : handleMouseRelease
479 //================================================================
480 void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
483 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
485 if( e->button() == Qt::LeftButton &&
486 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
490 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
491 getSelector()->select( QRectF(), append );
496 // try to finish active operations
497 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
499 if( aViewPort->isPulling() )
501 aViewPort->finishPulling( true );
503 else if( aViewPort->isSketching() )
505 aViewPort->finishSketching( true );
507 else if( !aViewPort->getHighlightedObject() )
509 QRect aSelRect = aViewPort->selectionRect();
510 aViewPort->finishSelectByRect();
511 if ( getSelector() && !aSelRect.isNull() )
513 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
514 QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect();
515 getSelector()->select( aRect, append );
521 //================================================================
522 // Function : handleWheel
524 //================================================================
525 void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
527 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
529 if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) )
531 bool anIsScaleUp = e->delta() > 0;
532 bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
534 bool anIsScaleChanged = false;
535 for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
536 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
537 anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
539 if( anIsScaleChanged )
541 emit wheelScaleChanged();
542 aViewPort->onBoundingRectChanged();
548 //================================================================
549 // Function : onSketchingFinished
551 //================================================================
552 void GraphicsView_Viewer::onSketchingFinished( QPainterPath thePath )
554 // testing ImageViewer
555 //onTestCropOperatorPerform( thePath );
558 //================================================================
559 // Function : onSelectionDone
561 //================================================================
562 void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
564 emit selectionChanged( theStatus );
567 //================================================================
568 // Function : onChangeBgColor
570 //================================================================
571 void GraphicsView_Viewer::onChangeBgColor()
573 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
575 QColor aColor = aViewPort->isForegroundEnabled() ?
576 aViewPort->foregroundColor() : aViewPort->backgroundColor();
577 aColor = QColorDialog::getColor( aColor, aViewPort );
578 if ( aColor.isValid() )
580 if( aViewPort->isForegroundEnabled() )
582 aViewPort->setForegroundColor( aColor );
583 aViewPort->updateForeground();
586 aViewPort->setBackgroundColor( aColor );
591 //================================================================
592 // Function : onSelectionCancel
594 //================================================================
595 void GraphicsView_Viewer::onSelectionCancel()
597 emit selectionChanged( GVSCS_Invalid );
601 //================================================================
602 // Function : onAddImage
604 //================================================================
605 void GraphicsView_Viewer::onAddImage()
607 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
609 QString aFileName = QFileDialog::getOpenFileName();
610 if( aFileName.isEmpty() )
613 GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage();
615 QImage anImage( aFileName );
616 aPrs->setImage( anImage );
620 aViewPort->addItem( aPrs );
625 //================================================================
626 // Function : onRemoveImages
628 //================================================================
629 void GraphicsView_Viewer::onRemoveImages()
631 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
633 GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() );
634 while( anIter.hasNext() )
636 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
638 aViewPort->removeItem( aPrs );
645 //================================================================
646 // Function : onBringToFront
648 //================================================================
649 void GraphicsView_Viewer::onBringToFront()
651 processQueueOperation( BringToFront );
654 //================================================================
655 // Function : onSendToBack
657 //================================================================
658 void GraphicsView_Viewer::onSendToBack()
660 processQueueOperation( SendToBack );
663 //================================================================
664 // Function : onBringForward
666 //================================================================
667 void GraphicsView_Viewer::onBringForward()
669 processQueueOperation( BringForward );
672 //================================================================
673 // Function : onSendBackward
675 //================================================================
676 void GraphicsView_Viewer::onSendBackward()
678 processQueueOperation( SendBackward );
681 //================================================================
682 // Function : processQueueOperation
684 //================================================================
685 void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation )
687 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
689 const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects();
691 GraphicsView_ObjectList aSortedList;
693 GraphicsView_ObjectList aList = aViewPort->getObjects();
694 GraphicsView_ObjectListIterator anIter( aList );
695 while( anIter.hasNext() )
697 if( GraphicsView_Object* anObject = anIter.next() )
699 if( !anObject->hasSpecificZValue() )
701 double aZValue = anObject->zValue();
702 GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end();
703 for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ )
704 if( GraphicsView_Object* anObjectRef = *anIter1 )
705 if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue )
707 aSortedList.insert( anIter1, anObject );
712 QList<int> anIndicesToMove;
715 anIter = aSortedList;
716 while( anIter.hasNext() )
718 if( GraphicsView_Object* anObject = anIter.next() )
719 if( aSelectedList.contains( anObject ) )
720 anIndicesToMove.append( anIndex );
724 bool anIsReverse = theOperation == BringToFront || theOperation == BringForward;
725 QListIterator<int> anIndicesIter( anIndicesToMove );
727 anIndicesIter.toBack();
729 int aShiftForMultiple = 0;
730 int anObjectCount = aSortedList.count();
731 while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() )
733 int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next();
734 int aNewIndex = anIndex;
735 switch( theOperation )
737 case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break;
738 case SendToBack: aNewIndex = aShiftForMultiple; break;
739 case BringForward: aNewIndex = anIndex + 1; break;
740 case SendBackward: aNewIndex = anIndex - 1; break;
744 if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 )
747 aSortedList.move( anIndex, aNewIndex );
750 double aZValue = 1.0;
751 anIter = aSortedList;
752 while( anIter.hasNext() )
754 if( GraphicsView_Object* anObject = anIter.next() )
756 anObject->setZValue( aZValue );
763 //================================================================
764 // Function : onPrsProperties
766 //================================================================
767 void GraphicsView_Viewer::onPrsProperties()
769 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
771 aViewPort->initSelected();
772 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
774 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
776 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
777 aPrs->getPosition( aPosX, aPosY );
778 aPrs->getScaling( aScaleX, aScaleY );
779 aPrs->getRotationAngle( aRotationAngle );
781 double aZValue = aPrs->zValue();
782 double anOpacity = aPrs->opacity();
784 bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio();
785 bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation();
787 GraphicsView_PrsPropDlg aDlg( aViewPort );
788 aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
789 aZValue, anOpacity, anIsLockAspectRatio,
790 anIsSmoothTransformation );
793 aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
794 aZValue, anOpacity, anIsLockAspectRatio,
795 anIsSmoothTransformation );
797 aPrs->setPosition( aPosX, aPosY );
798 aPrs->setScaling( aScaleX, aScaleY );
799 aPrs->setRotationAngle( aRotationAngle );
801 aPrs->setZValue( aZValue );
802 aPrs->setOpacity( anOpacity );
804 aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
805 aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
814 //================================================================
815 // Function : onTestFuseOperator
817 //================================================================
818 void GraphicsView_Viewer::onTestFuseOperator()
820 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
822 GraphicsView_ObjectList aList = aViewPort->getObjects();
823 if( aList.count() < 3 )
826 GraphicsView_PrsImage* anObj1 = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
827 GraphicsView_PrsImage* anObj2 = dynamic_cast<GraphicsView_PrsImage*>( aList[2] );
829 ImageComposer_Image anImage1;
830 anImage1 = anObj1->getImage();
831 anImage1.setTransform( anObj1->getTransform() );
833 ImageComposer_Image anImage2;
834 anImage2 = anObj2->getImage();
835 anImage2.setTransform( anObj2->getTransform() );
837 ImageComposer_Image aResult = anImage1 | anImage2;
838 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
839 aResPrs->setImage( aResult );
841 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
842 anObj1->getPosition( aPosX, aPosY );
843 anObj1->getScaling( aScaleX, aScaleY );
844 anObj1->getRotationAngle( aRotationAngle );
846 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
847 aResPrs->setScaling( aScaleX, aScaleY );
848 aResPrs->setRotationAngle( aRotationAngle );
852 aViewPort->addItem( aResPrs );
853 aViewPort->removeItem( anObj1 );
854 aViewPort->removeItem( anObj2 );
858 //================================================================
859 // Function : onTestCropOperatorPrepare
861 //================================================================
862 void GraphicsView_Viewer::onTestCropOperatorPrepare()
864 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
865 aViewPort->prepareToSketch( true );
868 //================================================================
869 // Function : onTestCropOperatorPerform
871 //================================================================
872 void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath )
874 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
876 GraphicsView_ObjectList aList = aViewPort->getObjects();
877 if( aList.count() < 1 )
880 GraphicsView_PrsImage* anObj = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
882 ImageComposer_Image anImage;
883 anImage = anObj->getImage();
884 anImage.setTransform( anObj->getTransform() );
886 ImageComposer_Image aResult = anImage & thePath;
887 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
888 aResPrs->setImage( aResult );
890 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
891 anObj->getPosition( aPosX, aPosY );
892 anObj->getScaling( aScaleX, aScaleY );
893 anObj->getRotationAngle( aRotationAngle );
895 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
896 aResPrs->setScaling( aScaleX, aScaleY );
897 aResPrs->setRotationAngle( aRotationAngle );
901 aViewPort->addItem( aResPrs );
902 aViewPort->removeItem( anObj );