]> SALOME platform Git repositories - modules/gui.git/blob - src/GraphicsView/GraphicsView_Viewer.cxx
Salome HOME
Patch for non-restricted zoom-in.
[modules/gui.git] / src / GraphicsView / GraphicsView_Viewer.cxx
1 // Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "GraphicsView_Viewer.h"
21
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"
28
29 #include <SUIT_ViewManager.h>
30
31 #include <ImageComposer_Image.h>
32
33 #include <QApplication>
34 #include <QColorDialog>
35 #include <QGraphicsSceneMouseEvent>
36 #include <QGraphicsSceneWheelEvent>
37 #include <QKeyEvent>
38 #include <QMenu>
39
40 // testing ImageViewer
41 /*
42 #include "GraphicsView_PrsImage.h"
43 #include "GraphicsView_PrsPropDlg.h"
44 #include <QFileDialog>
45 */
46
47 //=======================================================================
48 // Name    : GraphicsView_Viewer
49 // Purpose : Constructor
50 //=======================================================================
51 GraphicsView_Viewer::GraphicsView_Viewer( const QString& title, QWidget* widget )
52 : SUIT_ViewModel(),
53   mySelector( 0 ),
54   myTransformer( 0 ),
55   myWidget( widget ),
56   myIsInitialized( false )
57 {
58 }
59
60 //=======================================================================
61 // Name    : GraphicsView_Viewer
62 // Purpose : Destructor
63 //=======================================================================
64 GraphicsView_Viewer::~GraphicsView_Viewer()
65 {
66   delete mySelector;
67 }
68
69 GraphicsView_ViewFrame* GraphicsView_Viewer::createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget )
70 {
71   return new GraphicsView_ViewFrame( theDesktop, this, theWidget );
72 }
73
74 //================================================================
75 // Function : createView
76 // Purpose  : 
77 //================================================================
78 SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop )
79 {
80   GraphicsView_ViewFrame* aViewFrame = createViewFrame( theDesktop, myWidget );
81
82   connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ),
83            this, SLOT( onKeyEvent( QKeyEvent* ) ) );
84
85   connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ),
86            this, SLOT( onKeyEvent( QKeyEvent* ) ) );
87
88   connect( aViewFrame, SIGNAL( mousePressed( QGraphicsSceneMouseEvent* ) ),
89            this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
90
91   connect( aViewFrame, SIGNAL( mouseMoving( QGraphicsSceneMouseEvent* ) ),
92            this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
93
94   connect( aViewFrame, SIGNAL( mouseReleased( QGraphicsSceneMouseEvent* ) ),
95            this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
96
97   connect( aViewFrame, SIGNAL( wheeling( QGraphicsSceneWheelEvent* ) ),
98            this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
99
100   connect( aViewFrame, SIGNAL( sketchingFinished( QPainterPath ) ),
101            this, SLOT( onSketchingFinished( QPainterPath ) ) );
102
103   return aViewFrame;
104 }
105
106 //================================================================
107 // Function : contextMenuPopup
108 // Purpose  : 
109 //================================================================
110 void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup )
111 {
112   if( thePopup->actions().count() > 0 )
113     thePopup->addSeparator();
114
115   // testing ImageViewer
116   /*
117   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
118   {
119     int aNbSelected = aViewPort->nbSelected();
120     if( aNbSelected == 0 )
121     {
122       thePopup->addAction( tr( "ADD_IMAGE" ), this, SLOT( onAddImage() ) );
123       thePopup->addSeparator();
124
125       thePopup->addAction( tr( "TEST_FUSE_OPERATOR" ), this, SLOT( onTestFuseOperator() ) );
126       thePopup->addAction( tr( "TEST_CROP_OPERATOR" ), this, SLOT( onTestCropOperatorPrepare() ) );
127     }
128     else
129     {
130       thePopup->addAction( tr( "BRING_TO_FRONT" ), this, SLOT( onBringToFront() ) );
131       thePopup->addAction( tr( "SEND_TO_BACK" ), this, SLOT( onSendToBack() ) );
132       thePopup->addAction( tr( "BRING_FORWARD" ), this, SLOT( onBringForward() ) );
133       thePopup->addAction( tr( "SEND_BACKWARD" ), this, SLOT( onSendBackward() ) );
134       thePopup->addSeparator();
135
136       if( aNbSelected == 1 )
137       {
138         thePopup->addAction( tr( "PROPERTIES" ), this, SLOT( onPrsProperties() ) );
139         thePopup->addSeparator();
140       }
141
142       thePopup->addAction( tr( "REMOVE_IMAGES" ), this, SLOT( onRemoveImages() ) );
143     }
144     thePopup->addSeparator();
145   }
146   */
147
148   thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) );
149 }
150
151 //================================================================
152 // Function : getSelector
153 // Purpose  : 
154 //================================================================
155 GraphicsView_Selector* GraphicsView_Viewer::getSelector()
156 {
157   if( !mySelector )
158   {
159     mySelector = new GraphicsView_Selector( this );
160     if( mySelector )
161     {
162       connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ),
163                this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) );
164       connect( mySelector, SIGNAL( selSelectionCancel() ),
165                this, SLOT( onSelectionCancel() ) );
166     }
167   }
168   return mySelector;
169 }
170
171 //================================================================
172 // Function : getActiveView
173 // Purpose  : 
174 //================================================================
175 GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const
176 {
177   if( SUIT_ViewManager* aViewManager = getViewManager() )
178     return dynamic_cast<GraphicsView_ViewFrame*>( aViewManager->getActiveView() );
179   return NULL;
180 }
181
182 //================================================================
183 // Function : getActiveViewPort
184 // Purpose  : 
185 //================================================================
186 GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const
187 {
188   if( GraphicsView_ViewFrame* aViewFrame = getActiveView() )
189     return aViewFrame->getViewPort();
190   return NULL;
191 }
192
193 //================================================================
194 // Function : getActiveScene
195 // Purpose  : 
196 //================================================================
197 GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const
198 {
199   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
200     return dynamic_cast<GraphicsView_Scene*>( aViewPort->scene() );
201   return NULL;
202 }
203
204 //================================================================
205 // Function : activateTransform
206 // Purpose  : 
207 //================================================================
208 void GraphicsView_Viewer::activateTransform( int theType )
209 {
210   if( theType == NoTransform ) // finish current transform
211   {
212     if ( myTransformer )
213     {
214       onTransformationFinished();
215       delete myTransformer;
216       myTransformer = 0;
217     }
218   }
219   else // activate new transform
220   {
221     activateTransform( NoTransform );
222     myTransformer = createTransformer( theType );
223     onTransformationStarted();
224     myTransformer->exec();
225   }
226 }
227
228 //================================================================
229 // Function : setIsInitialized
230 // Purpose  : 
231 //================================================================
232 void GraphicsView_Viewer::setIsInitialized( bool theFlag )
233 {
234   myIsInitialized = theFlag;
235 }
236
237 //================================================================
238 // Function : createTransformer
239 // Purpose  : 
240 //================================================================
241 GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType )
242 {
243   return new GraphicsView_ViewTransformer( this, theType );
244 }
245
246 //================================================================
247 // Function : onTransformationStarted
248 // Purpose  : 
249 //================================================================
250 void GraphicsView_Viewer::onTransformationStarted()
251 {
252   if( GraphicsView_Selector* aSelector = getSelector() )
253   {
254     aSelector->undetectAll();
255     aSelector->lock( true ); // disable selection
256   }
257
258   // watch events: any mouse/key event outside the
259   // viewport will be considered as the end of transform
260   if( myTransformer )
261     qApp->installEventFilter( this );
262 }
263
264 //================================================================
265 // Function : onTransformationFinished
266 // Purpose  : 
267 //================================================================
268 void GraphicsView_Viewer::onTransformationFinished()
269 {
270   if( GraphicsView_Selector* aSelector = getSelector() )
271     aSelector->lock( false ); // enable selection
272
273   // stop watching events
274   if( myTransformer )
275     qApp->removeEventFilter( this );
276 }
277
278 //================================================================
279 // Function : onKeyEvent
280 // Purpose  : 
281 //================================================================
282 void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e )
283 {
284   switch( e->type() )
285   {
286     case QEvent::KeyPress:
287       handleKeyPress( e );
288       break;
289     case QEvent::KeyRelease:
290       handleKeyRelease( e );
291       break;
292     default: break;
293   }
294 }
295
296 //================================================================
297 // Function : onMouseEvent
298 // Purpose  : 
299 //================================================================
300 void GraphicsView_Viewer::onMouseEvent( QGraphicsSceneMouseEvent* e )
301 {
302   switch( e->type() )
303   {
304     case QEvent::GraphicsSceneMousePress:
305       handleMousePress( e );
306       break;
307     case QEvent::GraphicsSceneMouseMove:
308       handleMouseMove( e );
309       break;
310     case QEvent::GraphicsSceneMouseRelease:
311       handleMouseRelease( e );
312       break;
313     default: break;
314   }
315 }
316
317 //================================================================
318 // Function : onWheelEvent
319 // Purpose  : 
320 //================================================================
321 void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e )
322 {
323   switch( e->type() )
324   {
325     case QEvent::GraphicsSceneWheel:
326       handleWheel( e );
327       break;
328     default: break;
329   }
330 }
331
332 //================================================================
333 // Function : handleKeyPress
334 // Purpose  : 
335 //================================================================
336 void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e )
337 {
338   if( e->key() == Qt::Key_Escape )
339   {
340     // Cancel current operation
341     bool anIsCancelled = false;
342     if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
343     {
344       anIsCancelled = aViewPort->cancelCurrentOperation();
345
346       // Unselect all objects (if there is no operation to cancel)
347       if( !anIsCancelled )
348       {
349         aViewPort->finishSelectByRect();
350         aViewPort->clearSelected();
351       }
352     }
353
354     // Emit unselection signal
355     if( !anIsCancelled )
356       if( GraphicsView_Selector* aSelector = getSelector() )
357         aSelector->unselectAll();
358   }
359 }
360
361 //================================================================
362 // Function : handleKeyRelease
363 // Purpose  : 
364 //================================================================
365 void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* e )
366 {
367 }
368
369 //================================================================
370 // Function : handleMousePress
371 // Purpose  : 
372 //================================================================
373 void GraphicsView_Viewer::handleMousePress( QGraphicsSceneMouseEvent* e )
374 {
375   // test accel for transforms
376   if ( e->modifiers() & GraphicsView_ViewTransformer::accelKey() )
377   {
378     Qt::MouseButton bs = e->button();
379     if ( bs == GraphicsView_ViewTransformer::zoomButton() )
380       activateTransform( Zoom );
381     else if ( bs == GraphicsView_ViewTransformer::panButton() )
382       activateTransform( Pan );
383   }
384   else // checking for other operations before selection in release event
385   {
386     if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
387     {
388       bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
389       if( e->button() == Qt::LeftButton &&
390           aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Sketching ) &&
391           aViewPort->isPrepareToSketch() )
392       {
393         // Use 'append' flag for sketching by arbitrary path
394         aViewPort->startSketching( e->scenePos(), append );
395       }
396       else if( e->button() == Qt::LeftButton &&
397                aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
398                !aViewPort->isSelectByRect() && 
399                !aViewPort->isDragging() &&
400                aViewPort->startPulling( e->scenePos() ) )
401       {
402         // Try to start pulling if rectangular selection is performed
403         aViewPort->finishSelectByRect();
404       }
405       else if( e->button() == Qt::LeftButton &&
406                !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) &&
407                !aViewPort->getHighlightedObject() )
408       {
409         // Start rectangular selection if pulling was not started
410         QPoint p = aViewPort->mapFromScene( e->scenePos() );
411         aViewPort->startSelectByRect( p.x(), p.y() );
412       }
413       else if( e->button() != Qt::MidButton && !append &&
414                aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateSelection ) &&
415                aViewPort->nbSelected() < 2 )
416       {
417         // Do not perform 'immediate selection' if the multiple objects are already selected
418         getSelector()->select( QRectF(), append );
419       }
420       else if( e->button() == Qt::RightButton &&
421                aViewPort->hasInteractionFlag( GraphicsView_ViewPort::ImmediateContextMenu ) &&
422                aViewPort->nbSelected() < 1 )
423       {
424         // If the 'immediate context menu' mode is enabled,
425         // try to perform selection before invoking context menu
426         getSelector()->select( QRectF(), append );
427       }
428     }
429   }
430 }
431
432 //================================================================
433 // Function : handleMouseMove
434 // Purpose  : 
435 //================================================================
436 void GraphicsView_Viewer::handleMouseMove( QGraphicsSceneMouseEvent* e )
437 {
438   GraphicsView_ViewPort* aViewPort = getActiveViewPort();
439
440   // highlight for selection
441   bool anIsDragged = ( e->buttons() & ( Qt::LeftButton | Qt::MidButton | Qt::RightButton ) );
442   bool anIsPrepareToSketch = aViewPort && aViewPort->isPrepareToSketch();
443   if ( !anIsDragged && !anIsPrepareToSketch )
444   {
445     if ( getSelector() )
446       getSelector()->detect( e->scenePos().x(), e->scenePos().y() );
447   }
448
449   // try to activate other operations
450   if( aViewPort )
451   {
452     if( aViewPort->isPulling() )
453     {
454       aViewPort->drawPulling( e->scenePos() );
455     }
456     else if( aViewPort->isSketching() )
457     {
458       aViewPort->drawSketching( e->scenePos() );
459     }
460     else if( e->button() == Qt::LeftButton &&
461              aViewPort->hasInteractionFlag( GraphicsView_ViewPort::Pulling ) &&
462              !aViewPort->isSelectByRect() &&
463              !aViewPort->isDragging() &&
464              aViewPort->startPulling( e->scenePos() ) )
465     {
466       aViewPort->finishSelectByRect();
467     }
468     else if( !aViewPort->getHighlightedObject() )
469     {
470       QPoint p = aViewPort->mapFromScene( e->scenePos() );
471       aViewPort->drawSelectByRect( p.x(), p.y() );
472     }
473   }
474 }
475
476 //================================================================
477 // Function : handleMouseRelease
478 // Purpose  : 
479 //================================================================
480 void GraphicsView_Viewer::handleMouseRelease( QGraphicsSceneMouseEvent* e )
481 {
482   // selection
483   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
484   {
485     if( e->button() == Qt::LeftButton &&
486         !( aViewPort->currentBlock() & GraphicsView_ViewPort::BS_Selection ) )
487     {
488       if ( getSelector() )
489       {
490         bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
491         getSelector()->select( QRectF(), append );
492       }
493     }
494   }
495
496   // try to finish active operations
497   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
498   {
499     if( aViewPort->isPulling() )
500     {
501       aViewPort->finishPulling( true );
502     }
503     else if( aViewPort->isSketching() )
504     {
505       aViewPort->finishSketching( true );
506     }
507     else if( !aViewPort->getHighlightedObject() )
508     {
509       QRect aSelRect = aViewPort->selectionRect();
510       aViewPort->finishSelectByRect();
511       if ( getSelector() && !aSelRect.isNull() )
512       {            
513         bool append = bool ( e->modifiers() & GraphicsView_Selector::getAppendKey() );
514         QRectF aRect = aViewPort->mapToScene( aSelRect ).boundingRect();
515         getSelector()->select( aRect, append );
516       }
517     }
518   }
519 }
520
521 //================================================================
522 // Function : handleWheel
523 // Purpose  : 
524 //================================================================
525 void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e )
526 {
527   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
528   {
529     if( aViewPort->hasInteractionFlag( GraphicsView_ViewPort::WheelScaling ) )
530     {
531       bool anIsScaleUp = e->delta() > 0;
532       bool anIsCtrl = e->modifiers() & Qt::ControlModifier;
533
534       bool anIsScaleChanged = false;
535       for( aViewPort->initSelected(); aViewPort->moreSelected(); aViewPort->nextSelected() )
536         if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
537           anIsScaleChanged = anObject->updateScale( anIsScaleUp, anIsCtrl ) || anIsScaleChanged;
538
539       if( anIsScaleChanged )
540       {
541         emit wheelScaleChanged();
542         aViewPort->onBoundingRectChanged();
543       }
544     }
545   }
546 }
547
548 //================================================================
549 // Function : onSketchingFinished
550 // Purpose  : 
551 //================================================================
552 void GraphicsView_Viewer::onSketchingFinished( QPainterPath thePath )
553 {
554   // testing ImageViewer
555   //onTestCropOperatorPerform( thePath );
556 }
557
558 //================================================================
559 // Function : onSelectionDone
560 // Purpose  : 
561 //================================================================
562 void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus )
563 {
564   emit selectionChanged( theStatus );
565 }
566
567 //================================================================
568 // Function : onChangeBgColor
569 // Purpose  : 
570 //================================================================
571 void GraphicsView_Viewer::onChangeBgColor()
572 {
573   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
574   {
575     QColor aColor = aViewPort->isForegroundEnabled() ?
576       aViewPort->foregroundColor() : aViewPort->backgroundColor();
577     aColor = QColorDialog::getColor( aColor, aViewPort );       
578     if ( aColor.isValid() )
579     {
580       if( aViewPort->isForegroundEnabled() )
581       {
582         aViewPort->setForegroundColor( aColor );
583         aViewPort->updateForeground();
584       }
585       else
586         aViewPort->setBackgroundColor( aColor );
587     }
588   }
589 }
590
591 //================================================================
592 // Function : onSelectionCancel
593 // Purpose  : 
594 //================================================================
595 void GraphicsView_Viewer::onSelectionCancel()
596 {
597   emit selectionChanged( GVSCS_Invalid );
598 }
599
600 /*
601 //================================================================
602 // Function : onAddImage
603 // Purpose  : 
604 //================================================================
605 void GraphicsView_Viewer::onAddImage()
606 {
607   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
608   {
609     QString aFileName = QFileDialog::getOpenFileName();
610     if( aFileName.isEmpty() )
611       return;
612
613     GraphicsView_PrsImage* aPrs = new GraphicsView_PrsImage();
614
615     QImage anImage( aFileName );
616     aPrs->setImage( anImage );
617
618     aPrs->compute();
619
620     aViewPort->addItem( aPrs );
621     aViewPort->fitAll();
622   }
623 }
624
625 //================================================================
626 // Function : onRemoveImages
627 // Purpose  : 
628 //================================================================
629 void GraphicsView_Viewer::onRemoveImages()
630 {
631   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
632   {
633     GraphicsView_ObjectListIterator anIter( aViewPort->getSelectedObjects() );
634     while( anIter.hasNext() )
635     {
636       if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anIter.next() ) )
637       {
638         aViewPort->removeItem( aPrs );
639         delete aPrs;
640       }
641     }
642   }
643 }
644
645 //================================================================
646 // Function : onBringToFront
647 // Purpose  : 
648 //================================================================
649 void GraphicsView_Viewer::onBringToFront()
650 {
651   processQueueOperation( BringToFront );
652 }
653
654 //================================================================
655 // Function : onSendToBack
656 // Purpose  : 
657 //================================================================
658 void GraphicsView_Viewer::onSendToBack()
659 {
660   processQueueOperation( SendToBack );
661 }
662
663 //================================================================
664 // Function : onBringForward
665 // Purpose  : 
666 //================================================================
667 void GraphicsView_Viewer::onBringForward()
668 {
669   processQueueOperation( BringForward );
670 }
671
672 //================================================================
673 // Function : onSendBackward
674 // Purpose  : 
675 //================================================================
676 void GraphicsView_Viewer::onSendBackward()
677 {
678   processQueueOperation( SendBackward );
679 }
680
681 //================================================================
682 // Function : processQueueOperation
683 // Purpose  : 
684 //================================================================
685 void GraphicsView_Viewer::processQueueOperation( const QueueOperation theOperation )
686 {
687   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
688   {
689     const GraphicsView_ObjectList& aSelectedList = aViewPort->getSelectedObjects();
690
691     GraphicsView_ObjectList aSortedList;
692
693     GraphicsView_ObjectList aList = aViewPort->getObjects();
694     GraphicsView_ObjectListIterator anIter( aList );
695     while( anIter.hasNext() )
696     {
697       if( GraphicsView_Object* anObject = anIter.next() )
698       {
699         if( !anObject->hasSpecificZValue() )
700         {
701           double aZValue = anObject->zValue();
702           GraphicsView_ObjectList::iterator anIter1, anIter1End = aSortedList.end();
703           for( anIter1 = aSortedList.begin(); anIter1 != anIter1End; anIter1++ )
704             if( GraphicsView_Object* anObjectRef = *anIter1 )
705               if( !anObjectRef->hasSpecificZValue() && anObjectRef->zValue() > aZValue )
706                 break;
707           aSortedList.insert( anIter1, anObject );
708         }
709       }
710     }
711
712     QList<int> anIndicesToMove;
713
714     int anIndex = 0;
715     anIter = aSortedList;
716     while( anIter.hasNext() )
717     {
718       if( GraphicsView_Object* anObject = anIter.next() )
719         if( aSelectedList.contains( anObject ) )
720           anIndicesToMove.append( anIndex );
721       anIndex++;
722     }
723
724     bool anIsReverse = theOperation == BringToFront || theOperation == BringForward;
725     QListIterator<int> anIndicesIter( anIndicesToMove );
726     if( anIsReverse )
727       anIndicesIter.toBack();
728
729     int aShiftForMultiple = 0;
730     int anObjectCount = aSortedList.count();
731     while( anIsReverse ? anIndicesIter.hasPrevious() : anIndicesIter.hasNext() )
732     {
733       int anIndex = anIsReverse ? anIndicesIter.previous() : anIndicesIter.next();
734       int aNewIndex = anIndex;
735       switch( theOperation )
736       {
737         case BringToFront: aNewIndex = anObjectCount - 1 - aShiftForMultiple; break;
738         case SendToBack:   aNewIndex = aShiftForMultiple; break;
739         case BringForward: aNewIndex = anIndex + 1; break;
740         case SendBackward: aNewIndex = anIndex - 1; break;
741       }
742       aShiftForMultiple++;
743
744       if( aNewIndex < 0 || aNewIndex > anObjectCount - 1 )
745         break;
746
747       aSortedList.move( anIndex, aNewIndex );
748     }
749
750     double aZValue = 1.0;
751     anIter = aSortedList;
752     while( anIter.hasNext() )
753     {
754       if( GraphicsView_Object* anObject = anIter.next() )
755       {
756         anObject->setZValue( aZValue );
757         aZValue += 1.0;
758       }
759     }
760   }
761 }
762
763 //================================================================
764 // Function : onPrsProperties
765 // Purpose  : 
766 //================================================================
767 void GraphicsView_Viewer::onPrsProperties()
768 {
769   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
770   {
771     aViewPort->initSelected();
772     if( GraphicsView_Object* anObject = aViewPort->selectedObject() )
773     {
774       if( GraphicsView_PrsImage* aPrs = dynamic_cast<GraphicsView_PrsImage*>( anObject ) )
775       {
776         double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
777         aPrs->getPosition( aPosX, aPosY );
778         aPrs->getScaling( aScaleX, aScaleY );
779         aPrs->getRotationAngle( aRotationAngle );
780
781         double aZValue = aPrs->zValue();
782         double anOpacity = aPrs->opacity();
783
784         bool anIsLockAspectRatio = aPrs->getIsLockAspectRatio();
785         bool anIsSmoothTransformation = aPrs->getIsSmoothTransformation();
786
787         GraphicsView_PrsPropDlg aDlg( aViewPort );
788         aDlg.setData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
789                       aZValue, anOpacity, anIsLockAspectRatio,
790                       anIsSmoothTransformation );
791         if( aDlg.exec() )
792         {
793           aDlg.getData( aPosX, aPosY, aScaleX, aScaleY, aRotationAngle,
794                         aZValue, anOpacity, anIsLockAspectRatio,
795                         anIsSmoothTransformation );
796
797           aPrs->setPosition( aPosX, aPosY );
798           aPrs->setScaling( aScaleX, aScaleY );
799           aPrs->setRotationAngle( aRotationAngle );
800
801           aPrs->setZValue( aZValue );
802           aPrs->setOpacity( anOpacity );
803
804           aPrs->setIsLockAspectRatio( anIsLockAspectRatio );
805           aPrs->setIsSmoothTransformation( anIsSmoothTransformation );
806
807           aPrs->compute();
808         }
809       }
810     }
811   }
812 }
813
814 //================================================================
815 // Function : onTestFuseOperator
816 // Purpose  : 
817 //================================================================
818 void GraphicsView_Viewer::onTestFuseOperator()
819 {
820   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
821   {
822     GraphicsView_ObjectList aList = aViewPort->getObjects();
823     if( aList.count() < 3 )
824       return;
825
826     GraphicsView_PrsImage* anObj1 = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
827     GraphicsView_PrsImage* anObj2 = dynamic_cast<GraphicsView_PrsImage*>( aList[2] );
828
829     ImageComposer_Image anImage1;
830     anImage1 = anObj1->getImage();
831     anImage1.setTransform( anObj1->getTransform() );
832
833     ImageComposer_Image anImage2;
834     anImage2 = anObj2->getImage();
835     anImage2.setTransform( anObj2->getTransform() );
836
837     ImageComposer_Image aResult = anImage1 | anImage2;
838     GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
839     aResPrs->setImage( aResult );
840
841     double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
842     anObj1->getPosition( aPosX, aPosY );
843     anObj1->getScaling( aScaleX, aScaleY );
844     anObj1->getRotationAngle( aRotationAngle );
845
846     aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
847     aResPrs->setScaling( aScaleX, aScaleY );
848     aResPrs->setRotationAngle( aRotationAngle );
849
850     aResPrs->compute();
851
852     aViewPort->addItem( aResPrs );
853     aViewPort->removeItem( anObj1 );
854     aViewPort->removeItem( anObj2 );
855   }
856 }
857
858 //================================================================
859 // Function : onTestCropOperatorPrepare
860 // Purpose  : 
861 //================================================================
862 void GraphicsView_Viewer::onTestCropOperatorPrepare()
863 {
864   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
865     aViewPort->prepareToSketch( true );
866 }
867
868 //================================================================
869 // Function : onTestCropOperatorPerform
870 // Purpose  : 
871 //================================================================
872 void GraphicsView_Viewer::onTestCropOperatorPerform( QPainterPath thePath )
873 {
874   if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() )
875   {
876     GraphicsView_ObjectList aList = aViewPort->getObjects();
877     if( aList.count() < 1 )
878       return;
879
880     GraphicsView_PrsImage* anObj = dynamic_cast<GraphicsView_PrsImage*>( aList[0] );
881
882     ImageComposer_Image anImage;
883     anImage = anObj->getImage();
884     anImage.setTransform( anObj->getTransform() );
885
886     ImageComposer_Image aResult = anImage & thePath;
887     GraphicsView_PrsImage* aResPrs = new GraphicsView_PrsImage();
888     aResPrs->setImage( aResult );
889
890     double aPosX, aPosY, aScaleX, aScaleY, aRotationAngle;
891     anObj->getPosition( aPosX, aPosY );
892     anObj->getScaling( aScaleX, aScaleY );
893     anObj->getRotationAngle( aRotationAngle );
894
895     aResPrs->setPosition( aResult.transform().dx(), aResult.transform().dy() );
896     aResPrs->setScaling( aScaleX, aScaleY );
897     aResPrs->setRotationAngle( aRotationAngle );
898
899     aResPrs->compute();
900
901     aViewPort->addItem( aResPrs );
902     aViewPort->removeItem( anObj );
903   }
904 }
905 */