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 //================================================================
70 // Function : createView
72 //================================================================
73 SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
75 GraphicsView_ViewFrame* aViewFrame = new GraphicsView_ViewFrame( theDesktop, this, myWidget );
77 connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
78 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
80 connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ),
81 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
83 connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
84 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
86 connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
87 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
89 connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
90 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
92 connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
93 this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
95 connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ),
96 this, SLOT( onSketchingFinished( QPainterPath ) ) );
101 //================================================================
102 // Function : contextMenuPopup
104 //================================================================
105 void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup )
107 if( thePopup->actions().count() > 0 )
108 thePopup->addSeparator();
110 // testing ImageViewer
112 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
114 int aNbSelected = aViewPort->nbSelected();
115 if( aNbSelected == 0 )
117 thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) );
118 thePopup->addSeparator();
120 thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) );
121 thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) );
125 thePopup->addAction( tr( "BRING_TO_FRONT" ), this, SLOT( onBringToFront() ) );
126 thePopup->addAction( tr( "SEND_TO_BACK" ), this, SLOT( onSendToBack() ) );
127 thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) );
128 thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) );
129 thePopup->addSeparator();
131 if( aNbSelected == 1 )
133 thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) );
134 thePopup->addSeparator();
137 thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) );
139 thePopup->addSeparator();
143 thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
146 //================================================================
147 // Function : getSelector
149 //================================================================
150 GraphicsView_Selector* GraphicsView_Viewer::getSelector()
154 mySelector = new GraphicsView_Selector( this );
157 connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ),
158 this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) );
159 connect( mySelector, SIGNAL( selSelectionCancel() ),
160 this, SLOT( onSelectionCancel() ) );
166 //================================================================
167 // Function : getActiveView
169 //================================================================
170 GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const
172 if( SUIT_ViewManager* aViewManager = getViewManager() )
173 return dynamic_cast<GraphicsView_ViewFrame*>( aViewManager->getActiveView() );
177 //================================================================
178 // Function : getActiveViewPort
180 //================================================================
181 GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const
183 if( GraphicsView_ViewFrame* aViewFrame = getActiveView() )
184 return aViewFrame->getViewPort();
188 //================================================================
189 // Function : getActiveScene
191 //================================================================
192 GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const
194 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
195 return dynamic_cast<GraphicsView_Scene*>( aViewPort->scene() );
199 //================================================================
200 // Function : activateTransform
202 //================================================================
203 void GraphicsView_Viewer::activateTransform( int theType )
205 if( theType == NoTransform ) // finish current transform
209 onTransformationFinished();
210 delete myTransformer;
214 else // activate new transform
216 activateTransform( NoTransform );
217 myTransformer = createTransformer( theType );
218 onTransformationStarted();
219 myTransformer->exec();
223 //================================================================
224 // Function : setIsInitialized
226 //================================================================
227 void GraphicsView_Viewer::setIsInitialized( bool theFlag )
229 myIsInitialized = theFlag;
232 //================================================================
233 // Function : createTransformer
235 //================================================================
236 GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType )
238 return new GraphicsView_ViewTransformer( this, theType );
241 //================================================================
242 // Function : onTransformationStarted
244 //================================================================
245 void GraphicsView_Viewer::onTransformationStarted()
247 if( GraphicsView_Selector* aSelector = getSelector() )
249 aSelector->undetectAll();
250 aSelector->lock( true ); // disable selection
253 // watch events: any mouse/key event outside the
254 // viewport will be considered as the end of transform
256 qApp->installEventFilter( this );
259 //================================================================
260 // Function : onTransformationFinished
262 //================================================================
263 void GraphicsView_Viewer::onTransformationFinished()
265 if( GraphicsView_Selector* aSelector = getSelector() )
266 aSelector->lock( false ); // enable selection
268 // stop watching events
270 qApp->removeEventFilter( this );
273 //================================================================
274 // Function : onKeyEvent
276 //================================================================
277 void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e )
281 case QEvent::KeyPress:
284 case QEvent::KeyRelease:
285 handleKeyRelease( e );
291 //================================================================
292 // Function : onMouseEvent
294 //================================================================
295 void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
299 case QEvent::GraphicsSceneMousePress:
300 handleMousePress( e );
302 case QEvent::GraphicsSceneMouseMove:
303 handleMouseMove( e );
305 case QEvent::GraphicsSceneMouseRelease:
306 handleMouseRelease( e );
312 //================================================================
313 // Function : onWheelEvent
315 //================================================================
316 void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
320 case QEvent::GraphicsSceneWheel:
327 //================================================================
328 // Function : handleKeyPress
330 //================================================================
331 void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e )
333 if( e->key() == Qt::Key_Escape )
335 // Cancel current operation
336 bool anIsCancelled = false;
337 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
339 anIsCancelled = aViewPort->cancelCurrentOperation();
341 // Unselect all objects (if there is no operation to cancel)
344 aViewPort->finishSelectByRect();
345 aViewPort->clearSelected();
349 // Emit unselection signal
351 if( GraphicsView_Selector* aSelector = getSelector() )
352 aSelector->unselectAll();
356 //================================================================
357 // Function : handleKeyRelease
359 //================================================================
360 void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* e )
364 //================================================================
365 // Function : handleMousePress
367 //================================================================
368 void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
370 // test accel for transforms
371 if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
373 Qt::MouseButton bs = e->button();
374 if ( bs == GraphicsView_ViewTransformer::zoomButton() )
375 activateTransform( Zoom );
376 else if ( bs == GraphicsView_ViewTransformer::panButton() )
377 activateTransform( Pan );
379 else // checking for other operations before selection in release event
381 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
383 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
384 if( e->button() == Qt::LeftButton &&
385 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) &&
386 aViewPort->isPrepareToSketch() )
388 // Use 'append' flag for sketching by arbitrary path
389 aViewPort->startSketching( e->scenePos(), append );
391 else if( e->button() == Qt::LeftButton &&
392 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
393 !aViewPort->isSelectByRect() &&
394 !aViewPort->isDragging() &&
395 aViewPort->startPulling( e->scenePos() ) )
397 // Try to start pulling if rectangular selection is performed
398 aViewPort->finishSelectByRect();
400 else if( e->button() == Qt::LeftButton &&
401 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
402 !aViewPort->getHighlightedObject() )
404 // Start rectangular selection if pulling was not started
405 QPoint p = aViewPort->mapFromScene( e->scenePos() );
406 aViewPort->startSelectByRect( p.x(), p.y() );
408 else if( e->button() != Qt::MidButton && !append &&
409 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) &&
410 aViewPort->nbSelected() < 2 )
412 // Do not perform 'immediate selection' if the multiple objects are already selected
413 getSelector()->select( QRectF(), append );
415 else if( e->button() == Qt::RightButton &&
416 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) &&
417 aViewPort->nbSelected() < 1 )
419 // If the 'immediate context menu' mode is enabled,
420 // try to perform selection before invoking context menu
421 getSelector()->select( QRectF(), append );
427 //================================================================
428 // Function : handleMouseMove
430 //================================================================
431 void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
433 GraphicsView_ViewPort* aViewPort = getActiveViewPort();
435 // highlight for selection
436 bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
437 bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch();
438 if ( !anIsDragged && !anIsPrepareToSketch )
441 getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
444 // try to activate other operations
447 if( aViewPort->isPulling() )
449 aViewPort->drawPulling( e->scenePos() );
451 else if( aViewPort->isSketching() )
453 aViewPort->drawSketching( e->scenePos() );
455 else if( e->button() == Qt::LeftButton &&
456 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
457 !aViewPort->isSelectByRect() &&
458 !aViewPort->isDragging() &&
459 aViewPort->startPulling( e->scenePos() ) )
461 aViewPort->finishSelectByRect();
463 else if( !aViewPort->getHighlightedObject() )
465 QPoint p = aViewPort->mapFromScene( e->scenePos() );
466 aViewPort->drawSelectByRect( p.x(), p.y() );
471 //================================================================
472 // Function : handleMouseRelease
474 //================================================================
475 void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
478 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
480 if( e->button() == Qt::LeftButton &&
481 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
485 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
486 getSelector()->select( QRectF(), append );
491 // try to finish active operations
492 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
494 if( aViewPort->isPulling() )
496 aViewPort->finishPulling( true );
498 else if( aViewPort->isSketching() )
500 aViewPort->finishSketching( true );
502 else if( !aViewPort->getHighlightedObject() )
504 QRect aSelRect = aViewPort->selectionRect();
505 aViewPort->finishSelectByRect();
506 if ( getSelector() && !aSelRect.isNull() )
508 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
509 QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect();
510 getSelector()->select( aRect, append );
516 //================================================================
517 // Function : handleWheel
519 //================================================================
520 void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
522 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
524 if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling ) )
526 const double d = 1.05;
527 double q = pow( d, e->delta()/120 );
528 QGraphicsView::ViewportAnchor old_anchor = aViewPort->transformationAnchor();
529 aViewPort->setTransformationAnchor( QGraphicsView::AnchorUnderMouse );
530 aViewPort->scale( q, q );
531 aViewPort->setTransformationAnchor( old_anchor );
534 if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) )
536 bool anIsScaleUp = e->delta() > 0;
537 bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
539 bool anIsScaleChanged = false;
540 for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
541 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
542 anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
544 if( anIsScaleChanged )
546 emit wheelScaleChanged();
547 aViewPort->onBoundingRectChanged();
553 //================================================================
554 // Function : onSketchingFinished
556 //================================================================
557 void GraphicsView_Viewer::onSketchingFinished( QPainterPath thePath )
559 // testing ImageViewer
560 //onTestCropOperatorPerform( thePath );
563 //================================================================
564 // Function : onSelectionDone
566 //================================================================
567 void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
569 emit selectionChanged( theStatus );
572 //================================================================
573 // Function : onChangeBgColor
575 //================================================================
576 void GraphicsView_Viewer::onChangeBgColor()
578 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
580 QColor aColor = aViewPort->isForegroundEnabled() ?
581 aViewPort->foregroundColor() : aViewPort->backgroundColor();
582 aColor = QColorDialog::getColor( aColor, aViewPort );
583 if ( aColor.isValid() )
585 if( aViewPort->isForegroundEnabled() )
587 aViewPort->setForegroundColor( aColor );
588 aViewPort->updateForeground();
591 aViewPort->setBackgroundColor( aColor );
596 //================================================================
597 // Function : onSelectionCancel
599 //================================================================
600 void GraphicsView_Viewer::onSelectionCancel()
602 emit selectionChanged( GVSCS_Invalid );
606 //================================================================
607 // Function : onAddImage
609 //================================================================
610 void GraphicsView_Viewer::onAddImage()
612 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
614 QString aFileName = QFileDialog::getOpenFileName();
615 if( aFileName.isEmpty() )
618 GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage();
620 QImage anImage( aFileName );
621 aPrs->setImage( anImage );
625 aViewPort->addItem( aPrs );
630 //================================================================
631 // Function : onRemoveImages
633 //================================================================
634 void GraphicsView_Viewer::onRemoveImages()
636 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
638 GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() );
639 while( anIter.hasNext() )
641 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
643 aViewPort->removeItem( aPrs );
650 //================================================================
651 // Function : onBringToFront
653 //================================================================
654 void GraphicsView_Viewer::onBringToFront()
656 processQueueOperation( BringToFront );
659 //================================================================
660 // Function : onSendToBack
662 //================================================================
663 void GraphicsView_Viewer::onSendToBack()
665 processQueueOperation( SendToBack );
668 //================================================================
669 // Function : onBringForward
671 //================================================================
672 void GraphicsView_Viewer::onBringForward()
674 processQueueOperation( BringForward );
677 //================================================================
678 // Function : onSendBackward
680 //================================================================
681 void GraphicsView_Viewer::onSendBackward()
683 processQueueOperation( SendBackward );
686 //================================================================
687 // Function : processQueueOperation
689 //================================================================
690 void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation )
692 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
694 const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects();
696 GraphicsView_ObjectList aSortedList;
698 GraphicsView_ObjectList aList = aViewPort->getObjects();
699 GraphicsView_ObjectListIterator anIter( aList );
700 while( anIter.hasNext() )
702 if( GraphicsView_Object* anObject = anIter.next() )
704 if( !anObject->hasSpecificZValue() )
706 double aZValue = anObject->zValue();
707 GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end();
708 for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ )
709 if( GraphicsView_Object* anObjectRef = *anIter1 )
710 if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue )
712 aSortedList.insert( anIter1, anObject );
717 QList<int> anIndicesToMove;
720 anIter = aSortedList;
721 while( anIter.hasNext() )
723 if( GraphicsView_Object* anObject = anIter.next() )
724 if( aSelectedList.contains( anObject ) )
725 anIndicesToMove.append( anIndex );
729 bool anIsReverse = theOperation == BringToFront || theOperation == BringForward;
730 QListIterator<int> anIndicesIter( anIndicesToMove );
732 anIndicesIter.toBack();
734 int aShiftForMultiple = 0;
735 int anObjectCount = aSortedList.count();
736 while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() )
738 int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next();
739 int aNewIndex = anIndex;
740 switch( theOperation )
742 case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break;
743 case SendToBack: aNewIndex = aShiftForMultiple; break;
744 case BringForward: aNewIndex = anIndex + 1; break;
745 case SendBackward: aNewIndex = anIndex - 1; break;
749 if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 )
752 aSortedList.move( anIndex, aNewIndex );
755 double aZValue = 1.0;
756 anIter = aSortedList;
757 while( anIter.hasNext() )
759 if( GraphicsView_Object* anObject = anIter.next() )
761 anObject->setZValue( aZValue );
768 //================================================================
769 // Function : onPrsProperties
771 //================================================================
772 void GraphicsView_Viewer::onPrsProperties()
774 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
776 aViewPort->initSelected();
777 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
779 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
781 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
782 aPrs->getPosition( aPosX, aPosY );
783 aPrs->getScaling( aScaleX, aScaleY );
784 aPrs->getRotationAngle( aRotationAngle );
786 double aZValue = aPrs->zValue();
787 double anOpacity = aPrs->opacity();
789 bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio();
790 bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation();
792 GraphicsView_PrsPropDlg aDlg( aViewPort );
793 aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
794 aZValue, anOpacity, anIsLockAspectRatio,
795 anIsSmoothTransformation );
798 aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
799 aZValue, anOpacity, anIsLockAspectRatio,
800 anIsSmoothTransformation );
802 aPrs->setPosition( aPosX, aPosY );
803 aPrs->setScaling( aScaleX, aScaleY );
804 aPrs->setRotationAngle( aRotationAngle );
806 aPrs->setZValue( aZValue );
807 aPrs->setOpacity( anOpacity );
809 aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
810 aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
819 //================================================================
820 // Function : onTestFuseOperator
822 //================================================================
823 void GraphicsView_Viewer::onTestFuseOperator()
825 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
827 GraphicsView_ObjectList aList = aViewPort->getObjects();
828 if( aList.count() < 3 )
831 GraphicsView_PrsImage* anObj1 = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
832 GraphicsView_PrsImage* anObj2 = dynamic_cast<GraphicsView_PrsImage*>( aList[2] );
834 ImageComposer_Image anImage1;
835 anImage1 = anObj1->getImage();
836 anImage1.setTransform( anObj1->getTransform() );
838 ImageComposer_Image anImage2;
839 anImage2 = anObj2->getImage();
840 anImage2.setTransform( anObj2->getTransform() );
842 ImageComposer_Image aResult = anImage1 | anImage2;
843 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
844 aResPrs->setImage( aResult );
846 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
847 anObj1->getPosition( aPosX, aPosY );
848 anObj1->getScaling( aScaleX, aScaleY );
849 anObj1->getRotationAngle( aRotationAngle );
851 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
852 aResPrs->setScaling( aScaleX, aScaleY );
853 aResPrs->setRotationAngle( aRotationAngle );
857 aViewPort->addItem( aResPrs );
858 aViewPort->removeItem( anObj1 );
859 aViewPort->removeItem( anObj2 );
863 //================================================================
864 // Function : onTestCropOperatorPrepare
866 //================================================================
867 void GraphicsView_Viewer::onTestCropOperatorPrepare()
869 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
870 aViewPort->prepareToSketch( true );
873 //================================================================
874 // Function : onTestCropOperatorPerform
876 //================================================================
877 void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath )
879 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
881 GraphicsView_ObjectList aList = aViewPort->getObjects();
882 if( aList.count() < 1 )
885 GraphicsView_PrsImage* anObj = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
887 ImageComposer_Image anImage;
888 anImage = anObj->getImage();
889 anImage.setTransform( anObj->getTransform() );
891 ImageComposer_Image aResult = anImage & thePath;
892 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
893 aResPrs->setImage( aResult );
895 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
896 anObj->getPosition( aPosX, aPosY );
897 anObj->getScaling( aScaleX, aScaleY );
898 anObj->getRotationAngle( aRotationAngle );
900 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
901 aResPrs->setScaling( aScaleX, aScaleY );
902 aResPrs->setRotationAngle( aRotationAngle );
906 aViewPort->addItem( aResPrs );
907 aViewPort->removeItem( anObj );