1 // Copyright (C) 2013-2023 CEA, EDF, 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 GraphicsView_ViewFrame* GraphicsView_Viewer::createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget )
73 return new GraphicsView_ViewFrame( theDesktop, this, theWidget );
76 //================================================================
77 // Function : createView
79 //================================================================
80 SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
82 GraphicsView_ViewFrame* aViewFrame = createViewFrame( theDesktop, myWidget );
84 connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
85 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
87 connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ),
88 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
90 connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
91 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
93 connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
94 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
96 connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
97 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
99 connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
100 this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
102 connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ),
103 this, SLOT( onSketchingFinished( QPainterPath ) ) );
108 //================================================================
109 // Function : contextMenuPopup
111 //================================================================
112 void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup )
114 if( thePopup->actions().count() > 0 )
115 thePopup->addSeparator();
117 // testing ImageViewer
119 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
121 int aNbSelected = aViewPort->nbSelected();
122 if( aNbSelected == 0 )
124 thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) );
125 thePopup->addSeparator();
127 thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) );
128 thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) );
132 thePopup->addAction( tr( "BRING_TO_FRONT" ), this, SLOT( onBringToFront() ) );
133 thePopup->addAction( tr( "SEND_TO_BACK" ), this, SLOT( onSendToBack() ) );
134 thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) );
135 thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) );
136 thePopup->addSeparator();
138 if( aNbSelected == 1 )
140 thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) );
141 thePopup->addSeparator();
144 thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) );
146 thePopup->addSeparator();
150 thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
153 //================================================================
154 // Function : getSelector
156 //================================================================
157 GraphicsView_Selector* GraphicsView_Viewer::getSelector()
161 mySelector = new GraphicsView_Selector( this );
164 connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ),
165 this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) );
166 connect( mySelector, SIGNAL( selSelectionCancel() ),
167 this, SLOT( onSelectionCancel() ) );
173 //================================================================
174 // Function : getActiveView
176 //================================================================
177 GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const
179 if( SUIT_ViewManager* aViewManager = getViewManager() )
180 return dynamic_cast<GraphicsView_ViewFrame*>( aViewManager->getActiveView() );
184 //================================================================
185 // Function : getActiveViewPort
187 //================================================================
188 GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const
190 if( GraphicsView_ViewFrame* aViewFrame = getActiveView() )
191 return aViewFrame->getViewPort();
195 //================================================================
196 // Function : getActiveScene
198 //================================================================
199 GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const
201 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
202 return dynamic_cast<GraphicsView_Scene*>( aViewPort->scene() );
206 //================================================================
207 // Function : activateTransform
209 //================================================================
210 void GraphicsView_Viewer::activateTransform( int theType )
212 if( theType == NoTransform ) // finish current transform
216 onTransformationFinished();
217 delete myTransformer;
221 else // activate new transform
223 activateTransform( NoTransform );
224 myTransformer = createTransformer( theType );
225 onTransformationStarted();
226 myTransformer->exec();
230 //================================================================
231 // Function : setIsInitialized
233 //================================================================
234 void GraphicsView_Viewer::setIsInitialized( bool theFlag )
236 myIsInitialized = theFlag;
239 //================================================================
240 // Function : createTransformer
242 //================================================================
243 GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType )
245 return new GraphicsView_ViewTransformer( this, theType );
248 //================================================================
249 // Function : onTransformationStarted
251 //================================================================
252 void GraphicsView_Viewer::onTransformationStarted()
254 if( GraphicsView_Selector* aSelector = getSelector() )
256 aSelector->undetectAll();
257 aSelector->lock( true ); // disable selection
260 // watch events: any mouse/key event outside the
261 // viewport will be considered as the end of transform
263 qApp->installEventFilter( this );
266 //================================================================
267 // Function : onTransformationFinished
269 //================================================================
270 void GraphicsView_Viewer::onTransformationFinished()
272 if( GraphicsView_Selector* aSelector = getSelector() )
273 aSelector->lock( false ); // enable selection
275 // stop watching events
277 qApp->removeEventFilter( this );
280 //================================================================
281 // Function : onKeyEvent
283 //================================================================
284 void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e )
288 case QEvent::KeyPress:
291 case QEvent::KeyRelease:
292 handleKeyRelease( e );
298 //================================================================
299 // Function : onMouseEvent
301 //================================================================
302 void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
306 case QEvent::GraphicsSceneMousePress:
307 handleMousePress( e );
309 case QEvent::GraphicsSceneMouseMove:
310 handleMouseMove( e );
312 case QEvent::GraphicsSceneMouseRelease:
313 handleMouseRelease( e );
319 //================================================================
320 // Function : onWheelEvent
322 //================================================================
323 void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
327 case QEvent::GraphicsSceneWheel:
334 //================================================================
335 // Function : handleKeyPress
337 //================================================================
338 void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e )
340 if( e->key() == Qt::Key_Escape )
342 // Cancel current operation
343 bool anIsCancelled = false;
344 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
346 anIsCancelled = aViewPort->cancelCurrentOperation();
348 // Unselect all objects (if there is no operation to cancel)
351 aViewPort->finishSelectByRect();
352 aViewPort->clearSelected();
356 // Emit unselection signal
358 if( GraphicsView_Selector* aSelector = getSelector() )
359 aSelector->unselectAll();
363 //================================================================
364 // Function : handleKeyRelease
366 //================================================================
367 void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* /*e*/ ) //!< TODO: unused variable
371 //================================================================
372 // Function : handleMousePress
374 //================================================================
375 void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
377 // test accel for transforms
378 if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
380 Qt::MouseButton bs = e->button();
381 if ( (int)bs == GraphicsView_ViewTransformer::zoomButton() ) // todo Qt::MouseButton is unsigned int: comparison of int with uint
382 activateTransform( Zoom );
383 else if ( (int)bs == GraphicsView_ViewTransformer::panButton() ) // todo Qt::MouseButton is unsigned int: comparison of int with uint
384 activateTransform( Pan );
386 else // checking for other operations before selection in release event
388 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
390 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
391 if( e->button() == Qt::LeftButton &&
392 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) &&
393 aViewPort->isPrepareToSketch() )
395 // Use 'append' flag for sketching by arbitrary path
396 aViewPort->startSketching( e->scenePos(), append );
398 else if( e->button() == Qt::LeftButton &&
399 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
400 !aViewPort->isSelectByRect() &&
401 !aViewPort->isDragging() &&
402 aViewPort->startPulling( e->scenePos() ) )
404 // Try to start pulling if rectangular selection is performed
405 aViewPort->finishSelectByRect();
407 else if( e->button() == Qt::LeftButton &&
408 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
409 !aViewPort->getHighlightedObject() &&
410 ( ( !aViewPort->isDraggingSelectedByLeftButton() ) ||
411 ( aViewPort->isDraggingSelectedByLeftButton() && aViewPort->nbSelected() == 0 ) ) )
413 // Start rectangular selection if pulling was not started
414 QPoint p = aViewPort->mapFromScene( e->scenePos() );
415 aViewPort->startSelectByRect( p.x(), p.y() );
417 else if( e->button() != Qt::MidButton && !append &&
418 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) &&
419 aViewPort->nbSelected() < 2 )
421 // Do not perform 'immediate selection' if the multiple objects are already selected
422 getSelector()->select( QRectF(), append );
424 else if( e->button() == Qt::RightButton &&
425 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) &&
426 aViewPort->nbSelected() < 1 )
428 // If the 'immediate context menu' mode is enabled,
429 // try to perform selection before invoking context menu
430 getSelector()->select( QRectF(), append );
436 //================================================================
437 // Function : handleMouseMove
439 //================================================================
440 void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
442 GraphicsView_ViewPort* aViewPort = getActiveViewPort();
444 // highlight for selection
445 bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
446 bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch();
447 if ( !anIsDragged && !anIsPrepareToSketch )
450 getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
453 // try to activate other operations
456 if( aViewPort->isPulling() )
458 aViewPort->drawPulling( e->scenePos() );
460 else if( aViewPort->isSketching() )
462 aViewPort->drawSketching( e->scenePos() );
464 else if( e->button() == Qt::LeftButton &&
465 aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
466 !aViewPort->isSelectByRect() &&
467 !aViewPort->isDragging() &&
468 aViewPort->startPulling( e->scenePos() ) )
470 aViewPort->finishSelectByRect();
472 else if( !aViewPort->getHighlightedObject() )
474 QPoint p = aViewPort->mapFromScene( e->scenePos() );
475 aViewPort->drawSelectByRect( p.x(), p.y() );
480 //================================================================
481 // Function : handleMouseRelease
483 //================================================================
484 void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
487 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
489 if( e->button() == Qt::LeftButton &&
490 !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
494 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
495 getSelector()->select( QRectF(), append );
500 // try to finish active operations
501 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
503 if( aViewPort->isPulling() )
505 aViewPort->finishPulling( true );
507 else if( aViewPort->isSketching() )
509 aViewPort->finishSketching( true );
511 else if( !aViewPort->getHighlightedObject() )
513 QRect aSelRect = aViewPort->selectionRect();
514 aViewPort->finishSelectByRect();
515 if ( getSelector() && !aSelRect.isNull() )
517 bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
518 QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect();
519 getSelector()->select( aRect, append );
525 //================================================================
526 // Function : handleWheel
528 //================================================================
529 void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
531 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
533 if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::GlobalWheelScaling ) )
535 const double d = 1.05;
536 double q = pow( d, e->delta()/120 );
537 QGraphicsView::ViewportAnchor old_anchor = aViewPort->transformationAnchor();
538 aViewPort->setTransformationAnchor( QGraphicsView::AnchorUnderMouse );
539 aViewPort->scale( q, q );
540 aViewPort->setTransformationAnchor( old_anchor );
543 if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) )
545 bool anIsScaleUp = e->delta() > 0;
546 bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
548 bool anIsScaleChanged = false;
549 for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
550 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
551 anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
553 if( anIsScaleChanged )
555 emit wheelScaleChanged();
556 aViewPort->onBoundingRectChanged();
562 //================================================================
563 // Function : onSketchingFinished
565 //================================================================
566 void GraphicsView_Viewer::onSketchingFinished( QPainterPath /*thePath*/ )
568 // testing ImageViewer
569 //onTestCropOperatorPerform( thePath );
572 //================================================================
573 // Function : onSelectionDone
575 //================================================================
576 void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
578 emit selectionChanged( theStatus );
581 //================================================================
582 // Function : onChangeBgColor
584 //================================================================
585 void GraphicsView_Viewer::onChangeBgColor()
587 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
589 QColor aColor = aViewPort->isForegroundEnabled() ?
590 aViewPort->foregroundColor() : aViewPort->backgroundColor();
591 aColor = QColorDialog::getColor( aColor, aViewPort );
592 if ( aColor.isValid() )
594 if( aViewPort->isForegroundEnabled() )
596 aViewPort->setForegroundColor( aColor );
597 aViewPort->updateForeground();
600 aViewPort->setBackgroundColor( aColor );
605 //================================================================
606 // Function : onSelectionCancel
608 //================================================================
609 void GraphicsView_Viewer::onSelectionCancel()
611 emit selectionChanged( GVSCS_Invalid );
615 //================================================================
616 // Function : onAddImage
618 //================================================================
619 void GraphicsView_Viewer::onAddImage()
621 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
623 QString aFileName = QFileDialog::getOpenFileName();
624 if( aFileName.isEmpty() )
627 GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage();
629 QImage anImage( aFileName );
630 aPrs->setImage( anImage );
634 aViewPort->addItem( aPrs );
639 //================================================================
640 // Function : onRemoveImages
642 //================================================================
643 void GraphicsView_Viewer::onRemoveImages()
645 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
647 GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() );
648 while( anIter.hasNext() )
650 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
652 aViewPort->removeItem( aPrs );
659 //================================================================
660 // Function : onBringToFront
662 //================================================================
663 void GraphicsView_Viewer::onBringToFront()
665 processQueueOperation( BringToFront );
668 //================================================================
669 // Function : onSendToBack
671 //================================================================
672 void GraphicsView_Viewer::onSendToBack()
674 processQueueOperation( SendToBack );
677 //================================================================
678 // Function : onBringForward
680 //================================================================
681 void GraphicsView_Viewer::onBringForward()
683 processQueueOperation( BringForward );
686 //================================================================
687 // Function : onSendBackward
689 //================================================================
690 void GraphicsView_Viewer::onSendBackward()
692 processQueueOperation( SendBackward );
695 //================================================================
696 // Function : processQueueOperation
698 //================================================================
699 void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation )
701 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
703 const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects();
705 GraphicsView_ObjectList aSortedList;
707 GraphicsView_ObjectList aList = aViewPort->getObjects();
708 GraphicsView_ObjectListIterator anIter( aList );
709 while( anIter.hasNext() )
711 if( GraphicsView_Object* anObject = anIter.next() )
713 if( !anObject->hasSpecificZValue() )
715 double aZValue = anObject->zValue();
716 GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end();
717 for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ )
718 if( GraphicsView_Object* anObjectRef = *anIter1 )
719 if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue )
721 aSortedList.insert( anIter1, anObject );
726 QList<int> anIndicesToMove;
729 anIter = aSortedList;
730 while( anIter.hasNext() )
732 if( GraphicsView_Object* anObject = anIter.next() )
733 if( aSelectedList.contains( anObject ) )
734 anIndicesToMove.append( anIndex );
738 bool anIsReverse = theOperation == BringToFront || theOperation == BringForward;
739 QListIterator<int> anIndicesIter( anIndicesToMove );
741 anIndicesIter.toBack();
743 int aShiftForMultiple = 0;
744 int anObjectCount = aSortedList.count();
745 while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() )
747 int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next();
748 int aNewIndex = anIndex;
749 switch( theOperation )
751 case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break;
752 case SendToBack: aNewIndex = aShiftForMultiple; break;
753 case BringForward: aNewIndex = anIndex + 1; break;
754 case SendBackward: aNewIndex = anIndex - 1; break;
758 if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 )
761 aSortedList.move( anIndex, aNewIndex );
764 double aZValue = 1.0;
765 anIter = aSortedList;
766 while( anIter.hasNext() )
768 if( GraphicsView_Object* anObject = anIter.next() )
770 anObject->setZValue( aZValue );
777 //================================================================
778 // Function : onPrsProperties
780 //================================================================
781 void GraphicsView_Viewer::onPrsProperties()
783 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
785 aViewPort->initSelected();
786 if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
788 if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
790 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
791 aPrs->getPosition( aPosX, aPosY );
792 aPrs->getScaling( aScaleX, aScaleY );
793 aPrs->getRotationAngle( aRotationAngle );
795 double aZValue = aPrs->zValue();
796 double anOpacity = aPrs->opacity();
798 bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio();
799 bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation();
801 GraphicsView_PrsPropDlg aDlg( aViewPort );
802 aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
803 aZValue, anOpacity, anIsLockAspectRatio,
804 anIsSmoothTransformation );
807 aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
808 aZValue, anOpacity, anIsLockAspectRatio,
809 anIsSmoothTransformation );
811 aPrs->setPosition( aPosX, aPosY );
812 aPrs->setScaling( aScaleX, aScaleY );
813 aPrs->setRotationAngle( aRotationAngle );
815 aPrs->setZValue( aZValue );
816 aPrs->setOpacity( anOpacity );
818 aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
819 aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
828 //================================================================
829 // Function : onTestFuseOperator
831 //================================================================
832 void GraphicsView_Viewer::onTestFuseOperator()
834 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
836 GraphicsView_ObjectList aList = aViewPort->getObjects();
837 if( aList.count() < 3 )
840 GraphicsView_PrsImage* anObj1 = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
841 GraphicsView_PrsImage* anObj2 = dynamic_cast<GraphicsView_PrsImage*>( aList[2] );
843 ImageComposer_Image anImage1;
844 anImage1 = anObj1->getImage();
845 anImage1.setTransform( anObj1->getTransform() );
847 ImageComposer_Image anImage2;
848 anImage2 = anObj2->getImage();
849 anImage2.setTransform( anObj2->getTransform() );
851 ImageComposer_Image aResult = anImage1 | anImage2;
852 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
853 aResPrs->setImage( aResult );
855 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
856 anObj1->getPosition( aPosX, aPosY );
857 anObj1->getScaling( aScaleX, aScaleY );
858 anObj1->getRotationAngle( aRotationAngle );
860 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
861 aResPrs->setScaling( aScaleX, aScaleY );
862 aResPrs->setRotationAngle( aRotationAngle );
866 aViewPort->addItem( aResPrs );
867 aViewPort->removeItem( anObj1 );
868 aViewPort->removeItem( anObj2 );
872 //================================================================
873 // Function : onTestCropOperatorPrepare
875 //================================================================
876 void GraphicsView_Viewer::onTestCropOperatorPrepare()
878 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
879 aViewPort->prepareToSketch( true );
882 //================================================================
883 // Function : onTestCropOperatorPerform
885 //================================================================
886 void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath )
888 if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
890 GraphicsView_ObjectList aList = aViewPort->getObjects();
891 if( aList.count() < 1 )
894 GraphicsView_PrsImage* anObj = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
896 ImageComposer_Image anImage;
897 anImage = anObj->getImage();
898 anImage.setTransform( anObj->getTransform() );
900 ImageComposer_Image aResult = anImage & thePath;
901 GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
902 aResPrs->setImage( aResult );
904 double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
905 anObj->getPosition( aPosX, aPosY );
906 anObj->getScaling( aScaleX, aScaleY );
907 anObj->getRotationAngle( aRotationAngle );
909 aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
910 aResPrs->setScaling( aScaleX, aScaleY );
911 aResPrs->setRotationAngle( aRotationAngle );
915 aViewPort->addItem( aResPrs );
916 aViewPort->removeItem( anObj );