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>
42 // testing ImageViewer
44 #include "GraphicsView_PrsImage.h"
45 #include "GraphicsView_PrsPropDlg.h"
46 #include <QFileDialog>
49 //=======================================================================
50 // Name : GraphicsView_Viewer
51 // Purpose : Constructor
52 //=======================================================================
53 GraphicsView_Viewer::GraphicsView_Viewer( const QString& title, QWidget* widget )
58 myIsInitialized( false )
62 //=======================================================================
63 // Name : GraphicsView_Viewer
64 // Purpose : Destructor
65 //=======================================================================
66 GraphicsView_Viewer::~GraphicsView_Viewer()
71 //================================================================
72 // Function : createView
74 //================================================================
75 SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
77 GraphicsView_ViewFrame* aViewFrame = new GraphicsView_ViewFrame( theDesktop, this, myWidget );
79 connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
80 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
82 connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ),
83 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
85 connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
86 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
88 connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
89 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
91 connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
92 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
94 connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
95 this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
97 connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ),
98 this, SLOT( onSketchingFinished( QPainterPath ) ) );
103 //================================================================
104 // Function : contextMenuPopup
106 //================================================================
107 void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup )
109 if( thePopup->actions().count() > 0 )
110 thePopup->addSeparator();
112 // testing ImageViewer
114 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
116 int aNbSelected = aViewPort->nbSelected();
117 if( aNbSelected == 0 )
119 thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) );
120 thePopup->addSeparator();
122 thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) );
123 thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) );
127 thePopup->addAction( tr( "BRING_TO_FRONT" ), this, SLOT( onBringToFront() ) );
128 thePopup->addAction( tr( "SEND_TO_BACK" ), this, SLOT( onSendToBack() ) );
129 thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) );
130 thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) );
131 thePopup->addSeparator();
133 if( aNbSelected == 1 )
135 thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) );
136 thePopup->addSeparator();
139 thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) );
141 thePopup->addSeparator();
145 thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
148 //================================================================
149 // Function : getSelector
151 //================================================================
152 GraphicsView_Selector* GraphicsView_Viewer::getSelector()
156 mySelector = new GraphicsView_Selector( this );
159 connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ),
160 this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) );
161 connect( mySelector, SIGNAL( selSelectionCancel() ),
162 this, SLOT( onSelectionCancel() ) );
168 //================================================================
169 // Function : getActiveView
171 //================================================================
172 GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const
174 if( SUIT_ViewManager* aViewManager = getViewManager() )
175 return dynamic_cast<GraphicsView_ViewFrame*>( aViewManager->getActiveView() );
179 //================================================================
180 // Function : getActiveViewPort
182 //================================================================
183 GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const
185 if( GraphicsView_ViewFrame* aViewFrame = getActiveView() )
186 return aViewFrame->getViewPort();
190 //================================================================
191 // Function : getActiveScene
193 //================================================================
194 GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const
196 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
197 return dynamic_cast<GraphicsView_Scene*>( aViewPort->scene() );
201 //================================================================
202 // Function : activateTransform
204 //================================================================
205 void GraphicsView_Viewer::activateTransform( int theType )
207 if( theType == NoTransform ) // finish current transform
211 onTransformationFinished();
212 delete myTransformer;
216 else // activate new transform
218 activateTransform( NoTransform );
219 myTransformer = createTransformer( theType );
220 onTransformationStarted();
221 myTransformer->exec();
225 //================================================================
226 // Function : setIsInitialized
228 //================================================================
229 void GraphicsView_Viewer::setIsInitialized( bool theFlag )
231 myIsInitialized = theFlag;
234 //================================================================
235 // Function : createTransformer
237 //================================================================
238 GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType )
240 return new GraphicsView_ViewTransformer( this, theType );
243 //================================================================
244 // Function : onTransformationStarted
246 //================================================================
247 void GraphicsView_Viewer::onTransformationStarted()
249 if( GraphicsView_Selector* aSelector = getSelector() )
251 aSelector->undetectAll();
252 aSelector->lock( true ); // disable selection
255 // watch events: any mouse/key event outside the
256 // viewport will be considered as the end of transform
258 qApp->installEventFilter( this );
261 //================================================================
262 // Function : onTransformationFinished
264 //================================================================
265 void GraphicsView_Viewer::onTransformationFinished()
267 if( GraphicsView_Selector* aSelector = getSelector() )
268 aSelector->lock( false ); // enable selection
270 // stop watching events
272 qApp->removeEventFilter( this );
275 //================================================================
276 // Function : onKeyEvent
278 //================================================================
279 void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e )
283 case QEvent::KeyPress:
286 case QEvent::KeyRelease:
287 handleKeyRelease( e );
293 //================================================================
294 // Function : onMouseEvent
296 //================================================================
297 void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
301 case QEvent::GraphicsSceneMousePress:
302 handleMousePress( e );
304 case QEvent::GraphicsSceneMouseMove:
305 handleMouseMove( e );
307 case QEvent::GraphicsSceneMouseRelease:
308 handleMouseRelease( e );
314 //================================================================
315 // Function : onWheelEvent
317 //================================================================
318 void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
322 case QEvent::GraphicsSceneWheel:
329 //================================================================
330 // Function : handleKeyPress
332 //================================================================
333 void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e )
335 if( e->key() == Qt::Key_Escape )
337 // Cancel current operation
338 bool anIsCancelled = false;
339 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
341 anIsCancelled = aViewPort->cancelCurrentOperation();
343 // Unselect all objects (if there is no operation to cancel)
346 aViewPort->finishSelectByRect();
347 aViewPort->clearSelected();
351 // Emit unselection signal
353 if( GraphicsView_Selector* aSelector = getSelector() )
354 aSelector->unselectAll();
358 //================================================================
359 // Function : handleKeyRelease
361 //================================================================
362 void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* e )
366 //================================================================
367 // Function : handleMousePress
369 //================================================================
370 void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
372 // test accel for transforms
373 if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
375 Qt::MouseButton bs = e->button();
376 if ( bs == GraphicsView_ViewTransformer::zoomButton() )
377 activateTransform( Zoom );
378 else if ( bs == GraphicsView_ViewTransformer::panButton() )
379 activateTransform( Pan );
381 else // checking for other operations before selection in release event
383 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
385 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
386 if( e->button() == Qt::LeftButton &&
387 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) &&
388 aViewPort->isPrepareToSketch() )
390 // Use 'append' flag for sketching by arbitrary path
391 aViewPort->startSketching( e->scenePos(), append );
393 else if( e->button() == Qt::LeftButton &&
394 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
395 !aViewPort->isSelectByRect() &&
396 !aViewPort->isDragging() &&
397 aViewPort->startPulling( e->scenePos() ) )
399 // Try to start pulling if rectangular selection is performed
400 aViewPort->finishSelectByRect();
402 else if( e->button() == Qt::LeftButton &&
403 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
404 !aViewPort->getHighlightedObject() )
406 // Start rectangular selection if pulling was not started
407 QPoint p = aViewPort->mapFromScene( e->scenePos() );
408 aViewPort->startSelectByRect( p.x(), p.y() );
410 else if( e->button() != Qt::MidButton && !append &&
411 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) &&
412 aViewPort->nbSelected() < 2 )
414 // Do not perform 'immediate selection' if the multiple objects are already selected
415 getSelector()->select( QRectF(), append );
417 else if( e->button() == Qt::RightButton &&
418 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) &&
419 aViewPort->nbSelected() < 1 )
421 // If the 'immediate context menu' mode is enabled,
422 // try to perform selection before invoking context menu
423 getSelector()->select( QRectF(), append );
429 //================================================================
430 // Function : handleMouseMove
432 //================================================================
433 void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
435 GraphicsView_ViewPort* aViewPort = getActiveViewPort();
437 // highlight for selection
438 bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
439 bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch();
440 if ( !anIsDragged && !anIsPrepareToSketch )
443 getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
446 // try to activate other operations
449 if( aViewPort->isPulling() )
451 aViewPort->drawPulling( e->scenePos() );
453 else if( aViewPort->isSketching() )
455 aViewPort->drawSketching( e->scenePos() );
457 else if( e->button() == Qt::LeftButton &&
458 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
459 !aViewPort->isSelectByRect() &&
460 !aViewPort->isDragging() &&
461 aViewPort->startPulling( e->scenePos() ) )
463 aViewPort->finishSelectByRect();
465 else if( !aViewPort->getHighlightedObject() )
467 QPoint p = aViewPort->mapFromScene( e->scenePos() );
468 aViewPort->drawSelectByRect( p.x(), p.y() );
473 //================================================================
474 // Function : handleMouseRelease
476 //================================================================
477 void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
480 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
482 if( e->button() == Qt::LeftButton &&
483 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
487 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
488 getSelector()->select( QRectF(), append );
493 // try to finish active operations
494 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
496 if( aViewPort->isPulling() )
498 aViewPort->finishPulling( true );
500 else if( aViewPort->isSketching() )
502 aViewPort->finishSketching( true );
504 else if( !aViewPort->getHighlightedObject() )
506 QRect aSelRect = aViewPort->selectionRect();
507 aViewPort->finishSelectByRect();
508 if ( getSelector() && !aSelRect.isNull() )
510 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
511 QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect();
512 getSelector()->select( aRect, append );
518 //================================================================
519 // Function : handleWheel
521 //================================================================
522 void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
524 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
526 if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling ) )
528 const double d = 1.05;
529 double q = pow( d, e->delta()/120 );
530 QGraphicsView::ViewportAnchor old_anchor = aViewPort->transformationAnchor();
531 aViewPort->setTransformationAnchor( QGraphicsView::AnchorUnderMouse );
532 aViewPort->scale( q, q );
533 aViewPort->setTransformationAnchor( old_anchor );
536 if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) )
538 bool anIsScaleUp = e->delta() > 0;
539 bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
541 bool anIsScaleChanged = false;
542 for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
543 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
544 anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
546 if( anIsScaleChanged )
548 emit wheelScaleChanged();
549 aViewPort->onBoundingRectChanged();
555 //================================================================
556 // Function : onSketchingFinished
558 //================================================================
559 void GraphicsView_Viewer::onSketchingFinished( QPainterPath thePath )
561 // testing ImageViewer
562 //onTestCropOperatorPerform( thePath );
565 //================================================================
566 // Function : onSelectionDone
568 //================================================================
569 void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
571 emit selectionChanged( theStatus );
574 //================================================================
575 // Function : onChangeBgColor
577 //================================================================
578 void GraphicsView_Viewer::onChangeBgColor()
580 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
582 QColor aColor = aViewPort->isForegroundEnabled() ?
583 aViewPort->foregroundColor() : aViewPort->backgroundColor();
584 aColor = QColorDialog::getColor( aColor, aViewPort );
585 if ( aColor.isValid() )
587 if( aViewPort->isForegroundEnabled() )
589 aViewPort->setForegroundColor( aColor );
590 aViewPort->updateForeground();
593 aViewPort->setBackgroundColor( aColor );
598 //================================================================
599 // Function : onSelectionCancel
601 //================================================================
602 void GraphicsView_Viewer::onSelectionCancel()
604 emit selectionChanged( GVSCS_Invalid );
608 //================================================================
609 // Function : onAddImage
611 //================================================================
612 void GraphicsView_Viewer::onAddImage()
614 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
616 QString aFileName = QFileDialog::getOpenFileName();
617 if( aFileName.isEmpty() )
620 GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage();
622 QImage anImage( aFileName );
623 aPrs->setImage( anImage );
627 aViewPort->addItem( aPrs );
632 //================================================================
633 // Function : onRemoveImages
635 //================================================================
636 void GraphicsView_Viewer::onRemoveImages()
638 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
640 GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() );
641 while( anIter.hasNext() )
643 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
645 aViewPort->removeItem( aPrs );
652 //================================================================
653 // Function : onBringToFront
655 //================================================================
656 void GraphicsView_Viewer::onBringToFront()
658 processQueueOperation( BringToFront );
661 //================================================================
662 // Function : onSendToBack
664 //================================================================
665 void GraphicsView_Viewer::onSendToBack()
667 processQueueOperation( SendToBack );
670 //================================================================
671 // Function : onBringForward
673 //================================================================
674 void GraphicsView_Viewer::onBringForward()
676 processQueueOperation( BringForward );
679 //================================================================
680 // Function : onSendBackward
682 //================================================================
683 void GraphicsView_Viewer::onSendBackward()
685 processQueueOperation( SendBackward );
688 //================================================================
689 // Function : processQueueOperation
691 //================================================================
692 void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation )
694 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
696 const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects();
698 GraphicsView_ObjectList aSortedList;
700 GraphicsView_ObjectList aList = aViewPort->getObjects();
701 GraphicsView_ObjectListIterator anIter( aList );
702 while( anIter.hasNext() )
704 if( GraphicsView_Object* anObject = anIter.next() )
706 if( !anObject->hasSpecificZValue() )
708 double aZValue = anObject->zValue();
709 GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end();
710 for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ )
711 if( GraphicsView_Object* anObjectRef = *anIter1 )
712 if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue )
714 aSortedList.insert( anIter1, anObject );
719 QList<int> anIndicesToMove;
722 anIter = aSortedList;
723 while( anIter.hasNext() )
725 if( GraphicsView_Object* anObject = anIter.next() )
726 if( aSelectedList.contains( anObject ) )
727 anIndicesToMove.append( anIndex );
731 bool anIsReverse = theOperation == BringToFront || theOperation == BringForward;
732 QListIterator<int> anIndicesIter( anIndicesToMove );
734 anIndicesIter.toBack();
736 int aShiftForMultiple = 0;
737 int anObjectCount = aSortedList.count();
738 while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() )
740 int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next();
741 int aNewIndex = anIndex;
742 switch( theOperation )
744 case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break;
745 case SendToBack: aNewIndex = aShiftForMultiple; break;
746 case BringForward: aNewIndex = anIndex + 1; break;
747 case SendBackward: aNewIndex = anIndex - 1; break;
751 if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 )
754 aSortedList.move( anIndex, aNewIndex );
757 double aZValue = 1.0;
758 anIter = aSortedList;
759 while( anIter.hasNext() )
761 if( GraphicsView_Object* anObject = anIter.next() )
763 anObject->setZValue( aZValue );
770 //================================================================
771 // Function : onPrsProperties
773 //================================================================
774 void GraphicsView_Viewer::onPrsProperties()
776 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
778 aViewPort->initSelected();
779 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
781 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
783 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
784 aPrs->getPosition( aPosX, aPosY );
785 aPrs->getScaling( aScaleX, aScaleY );
786 aPrs->getRotationAngle( aRotationAngle );
788 double aZValue = aPrs->zValue();
789 double anOpacity = aPrs->opacity();
791 bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio();
792 bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation();
794 GraphicsView_PrsPropDlg aDlg( aViewPort );
795 aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
796 aZValue, anOpacity, anIsLockAspectRatio,
797 anIsSmoothTransformation );
800 aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
801 aZValue, anOpacity, anIsLockAspectRatio,
802 anIsSmoothTransformation );
804 aPrs->setPosition( aPosX, aPosY );
805 aPrs->setScaling( aScaleX, aScaleY );
806 aPrs->setRotationAngle( aRotationAngle );
808 aPrs->setZValue( aZValue );
809 aPrs->setOpacity( anOpacity );
811 aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
812 aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
821 //================================================================
822 // Function : onTestFuseOperator
824 //================================================================
825 void GraphicsView_Viewer::onTestFuseOperator()
827 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
829 GraphicsView_ObjectList aList = aViewPort->getObjects();
830 if( aList.count() < 3 )
833 GraphicsView_PrsImage* anObj1 = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
834 GraphicsView_PrsImage* anObj2 = dynamic_cast<GraphicsView_PrsImage*>( aList[2] );
836 ImageComposer_Image anImage1;
837 anImage1 = anObj1->getImage();
838 anImage1.setTransform( anObj1->getTransform() );
840 ImageComposer_Image anImage2;
841 anImage2 = anObj2->getImage();
842 anImage2.setTransform( anObj2->getTransform() );
844 ImageComposer_Image aResult = anImage1 | anImage2;
845 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
846 aResPrs->setImage( aResult );
848 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
849 anObj1->getPosition( aPosX, aPosY );
850 anObj1->getScaling( aScaleX, aScaleY );
851 anObj1->getRotationAngle( aRotationAngle );
853 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
854 aResPrs->setScaling( aScaleX, aScaleY );
855 aResPrs->setRotationAngle( aRotationAngle );
859 aViewPort->addItem( aResPrs );
860 aViewPort->removeItem( anObj1 );
861 aViewPort->removeItem( anObj2 );
865 //================================================================
866 // Function : onTestCropOperatorPrepare
868 //================================================================
869 void GraphicsView_Viewer::onTestCropOperatorPrepare()
871 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
872 aViewPort->prepareToSketch( true );
875 //================================================================
876 // Function : onTestCropOperatorPerform
878 //================================================================
879 void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath )
881 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
883 GraphicsView_ObjectList aList = aViewPort->getObjects();
884 if( aList.count() < 1 )
887 GraphicsView_PrsImage* anObj = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
889 ImageComposer_Image anImage;
890 anImage = anObj->getImage();
891 anImage.setTransform( anObj->getTransform() );
893 ImageComposer_Image aResult = anImage & thePath;
894 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
895 aResPrs->setImage( aResult );
897 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
898 anObj->getPosition( aPosX, aPosY );
899 anObj->getScaling( aScaleX, aScaleY );
900 anObj->getRotationAngle( aRotationAngle );
902 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
903 aResPrs->setScaling( aScaleX, aScaleY );
904 aResPrs->setRotationAngle( aRotationAngle );
908 aViewPort->addItem( aResPrs );
909 aViewPort->removeItem( anObj );