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::WheelScaling ) )
526 bool anIsScaleUp = e->delta() > 0;
527 bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
529 bool anIsScaleChanged = false;
530 for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
531 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
532 anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
534 if( anIsScaleChanged )
536 emit wheelScaleChanged();
537 aViewPort->onBoundingRectChanged();
543 //================================================================
544 // Function : onSketchingFinished
546 //================================================================
547 void GraphicsView_Viewer::onSketchingFinished( QPainterPath thePath )
549 // testing ImageViewer
550 //onTestCropOperatorPerform( thePath );
553 //================================================================
554 // Function : onSelectionDone
556 //================================================================
557 void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
559 emit selectionChanged( theStatus );
562 //================================================================
563 // Function : onChangeBgColor
565 //================================================================
566 void GraphicsView_Viewer::onChangeBgColor()
568 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
570 QColor aColor = aViewPort->isForegroundEnabled() ?
571 aViewPort->foregroundColor() : aViewPort->backgroundColor();
572 aColor = QColorDialog::getColor( aColor, aViewPort );
573 if ( aColor.isValid() )
575 if( aViewPort->isForegroundEnabled() )
577 aViewPort->setForegroundColor( aColor );
578 aViewPort->updateForeground();
581 aViewPort->setBackgroundColor( aColor );
586 //================================================================
587 // Function : onSelectionCancel
589 //================================================================
590 void GraphicsView_Viewer::onSelectionCancel()
592 emit selectionChanged( GVSCS_Invalid );
596 //================================================================
597 // Function : onAddImage
599 //================================================================
600 void GraphicsView_Viewer::onAddImage()
602 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
604 QString aFileName = QFileDialog::getOpenFileName();
605 if( aFileName.isEmpty() )
608 GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage();
610 QImage anImage( aFileName );
611 aPrs->setImage( anImage );
615 aViewPort->addItem( aPrs );
620 //================================================================
621 // Function : onRemoveImages
623 //================================================================
624 void GraphicsView_Viewer::onRemoveImages()
626 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
628 GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() );
629 while( anIter.hasNext() )
631 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
633 aViewPort->removeItem( aPrs );
640 //================================================================
641 // Function : onBringToFront
643 //================================================================
644 void GraphicsView_Viewer::onBringToFront()
646 processQueueOperation( BringToFront );
649 //================================================================
650 // Function : onSendToBack
652 //================================================================
653 void GraphicsView_Viewer::onSendToBack()
655 processQueueOperation( SendToBack );
658 //================================================================
659 // Function : onBringForward
661 //================================================================
662 void GraphicsView_Viewer::onBringForward()
664 processQueueOperation( BringForward );
667 //================================================================
668 // Function : onSendBackward
670 //================================================================
671 void GraphicsView_Viewer::onSendBackward()
673 processQueueOperation( SendBackward );
676 //================================================================
677 // Function : processQueueOperation
679 //================================================================
680 void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation )
682 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
684 const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects();
686 GraphicsView_ObjectList aSortedList;
688 GraphicsView_ObjectList aList = aViewPort->getObjects();
689 GraphicsView_ObjectListIterator anIter( aList );
690 while( anIter.hasNext() )
692 if( GraphicsView_Object* anObject = anIter.next() )
694 if( !anObject->hasSpecificZValue() )
696 double aZValue = anObject->zValue();
697 GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end();
698 for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ )
699 if( GraphicsView_Object* anObjectRef = *anIter1 )
700 if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue )
702 aSortedList.insert( anIter1, anObject );
707 QList<int> anIndicesToMove;
710 anIter = aSortedList;
711 while( anIter.hasNext() )
713 if( GraphicsView_Object* anObject = anIter.next() )
714 if( aSelectedList.contains( anObject ) )
715 anIndicesToMove.append( anIndex );
719 bool anIsReverse = theOperation == BringToFront || theOperation == BringForward;
720 QListIterator<int> anIndicesIter( anIndicesToMove );
722 anIndicesIter.toBack();
724 int aShiftForMultiple = 0;
725 int anObjectCount = aSortedList.count();
726 while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() )
728 int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next();
729 int aNewIndex = anIndex;
730 switch( theOperation )
732 case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break;
733 case SendToBack: aNewIndex = aShiftForMultiple; break;
734 case BringForward: aNewIndex = anIndex + 1; break;
735 case SendBackward: aNewIndex = anIndex - 1; break;
739 if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 )
742 aSortedList.move( anIndex, aNewIndex );
745 double aZValue = 1.0;
746 anIter = aSortedList;
747 while( anIter.hasNext() )
749 if( GraphicsView_Object* anObject = anIter.next() )
751 anObject->setZValue( aZValue );
758 //================================================================
759 // Function : onPrsProperties
761 //================================================================
762 void GraphicsView_Viewer::onPrsProperties()
764 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
766 aViewPort->initSelected();
767 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
769 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
771 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
772 aPrs->getPosition( aPosX, aPosY );
773 aPrs->getScaling( aScaleX, aScaleY );
774 aPrs->getRotationAngle( aRotationAngle );
776 double aZValue = aPrs->zValue();
777 double anOpacity = aPrs->opacity();
779 bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio();
780 bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation();
782 GraphicsView_PrsPropDlg aDlg( aViewPort );
783 aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
784 aZValue, anOpacity, anIsLockAspectRatio,
785 anIsSmoothTransformation );
788 aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
789 aZValue, anOpacity, anIsLockAspectRatio,
790 anIsSmoothTransformation );
792 aPrs->setPosition( aPosX, aPosY );
793 aPrs->setScaling( aScaleX, aScaleY );
794 aPrs->setRotationAngle( aRotationAngle );
796 aPrs->setZValue( aZValue );
797 aPrs->setOpacity( anOpacity );
799 aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
800 aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
809 //================================================================
810 // Function : onTestFuseOperator
812 //================================================================
813 void GraphicsView_Viewer::onTestFuseOperator()
815 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
817 GraphicsView_ObjectList aList = aViewPort->getObjects();
818 if( aList.count() < 3 )
821 GraphicsView_PrsImage* anObj1 = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
822 GraphicsView_PrsImage* anObj2 = dynamic_cast<GraphicsView_PrsImage*>( aList[2] );
824 ImageComposer_Image anImage1;
825 anImage1 = anObj1->getImage();
826 anImage1.setTransform( anObj1->getTransform() );
828 ImageComposer_Image anImage2;
829 anImage2 = anObj2->getImage();
830 anImage2.setTransform( anObj2->getTransform() );
832 ImageComposer_Image aResult = anImage1 | anImage2;
833 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
834 aResPrs->setImage( aResult );
836 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
837 anObj1->getPosition( aPosX, aPosY );
838 anObj1->getScaling( aScaleX, aScaleY );
839 anObj1->getRotationAngle( aRotationAngle );
841 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
842 aResPrs->setScaling( aScaleX, aScaleY );
843 aResPrs->setRotationAngle( aRotationAngle );
847 aViewPort->addItem( aResPrs );
848 aViewPort->removeItem( anObj1 );
849 aViewPort->removeItem( anObj2 );
853 //================================================================
854 // Function : onTestCropOperatorPrepare
856 //================================================================
857 void GraphicsView_Viewer::onTestCropOperatorPrepare()
859 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
860 aViewPort->prepareToSketch( true );
863 //================================================================
864 // Function : onTestCropOperatorPerform
866 //================================================================
867 void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath )
869 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
871 GraphicsView_ObjectList aList = aViewPort->getObjects();
872 if( aList.count() < 1 )
875 GraphicsView_PrsImage* anObj = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
877 ImageComposer_Image anImage;
878 anImage = anObj->getImage();
879 anImage.setTransform( anObj->getTransform() );
881 ImageComposer_Image aResult = anImage & thePath;
882 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
883 aResPrs->setImage( aResult );
885 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
886 anObj->getPosition( aPosX, aPosY );
887 anObj->getScaling( aScaleX, aScaleY );
888 anObj->getRotationAngle( aRotationAngle );
890 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
891 aResPrs->setScaling( aScaleX, aScaleY );
892 aResPrs->setRotationAngle( aRotationAngle );
896 aViewPort->addItem( aResPrs );
897 aViewPort->removeItem( anObj );