1 // Copyright (C) 2013-2019 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_ViewPort.h"
22 #include "GraphicsView_Object.h"
23 #include "GraphicsView_Scene.h"
24 #include "GraphicsView_ViewTransformer.h"
26 #include "SUIT_ResourceMgr.h"
27 #include "SUIT_Session.h"
30 #include <QGraphicsSceneMouseEvent>
31 #include <QGridLayout>
35 #include <QRubberBand>
42 #define FOREGROUND_Z_VALUE -2
43 #define GRID_Z_VALUE -1
44 #define SKETCH_Z_VALUE 3000
46 int GraphicsView_ViewPort::nCounter = 0;
47 QCursor* GraphicsView_ViewPort::defCursor = 0;
48 QCursor* GraphicsView_ViewPort::handCursor = 0;
49 QCursor* GraphicsView_ViewPort::panCursor = 0;
50 QCursor* GraphicsView_ViewPort::panglCursor = 0;
51 QCursor* GraphicsView_ViewPort::zoomCursor = 0;
52 QCursor* GraphicsView_ViewPort::sketchCursor = 0;
54 //=======================================================================
55 // Name : GraphicsView_ViewPort::ViewLabel
56 // Purpose : Wrapper for label, which can ignore move events sent from
57 // QGraphicsView::scrollContentsBy() method, which,
58 // in its turn, called from GraphicsView_ViewPort::pan()
59 //=======================================================================
60 class GraphicsView_ViewPort::ViewLabel : public QLabel
63 ViewLabel( QWidget* theParent )
64 : QLabel( theParent ),
65 myAcceptMoveEvents( false )
70 void setAcceptMoveEvents( bool theFlag )
72 myAcceptMoveEvents = theFlag;
76 virtual void moveEvent( QMoveEvent* theEvent )
78 if( myAcceptMoveEvents )
79 QLabel::moveEvent( theEvent );
80 else // return the label to the initial position
82 myAcceptMoveEvents = true;
83 move( theEvent->oldPos() );
84 myAcceptMoveEvents = false;
89 bool myAcceptMoveEvents;
92 //================================================================
93 // Function : createCursors
95 //================================================================
96 void GraphicsView_ViewPort::createCursors ()
98 defCursor = new QCursor( Qt::ArrowCursor );
99 handCursor = new QCursor( Qt::PointingHandCursor );
100 panCursor = new QCursor( Qt::SizeAllCursor );
101 panglCursor = new QCursor( Qt::CrossCursor );
103 SUIT_ResourceMgr* rmgr = SUIT_Session::session()->resourceMgr();
104 zoomCursor = new QCursor( rmgr->loadPixmap( "GraphicsView", tr( "ICON_GV_CURSOR_ZOOM" ) ) );
106 sketchCursor = new QCursor( Qt::CrossCursor );
109 //================================================================
110 // Function : destroyCursors
112 //================================================================
113 void GraphicsView_ViewPort::destroyCursors()
115 delete defCursor; defCursor = 0;
116 delete handCursor; handCursor = 0;
117 delete panCursor; panCursor = 0;
118 delete panglCursor; panglCursor = 0;
119 delete zoomCursor; zoomCursor = 0;
120 delete sketchCursor; sketchCursor = 0;
123 //=======================================================================
124 // Name : GraphicsView_ViewPort
125 // Purpose : Constructor
126 //=======================================================================
127 GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent )
128 : QGraphicsView( theParent ),
129 myInteractionFlags( 0 ),
131 myViewLabelPosition( VLP_None ),
132 myViewLabelLayout( 0 ),
133 myIsMousePositionEnabled( false ),
134 myForegroundItem( 0 ),
136 myIsTransforming( false ),
137 myUnlimitedPanning( false ),
138 myHighlightedObject( 0 ),
141 myIsHighlighting( false ),
142 mySelectionIterator( 0 ),
144 myAreSelectionPointsInitialized( false ),
145 mySketchingItem( 0 ),
146 myIsPrepareToSketch( false ),
147 myIsSketching( false ),
148 myIsSketchingByPath( false ),
149 myIsDragging( false ),
150 myIsDragPositionInitialized( false ),
151 myDraggingSelectedByLeftButton( false ),
152 myIsPulling( false ),
153 myPullingObject( 0 ),
154 myStoredCursor( Qt::ArrowCursor ),
158 myScene = new GraphicsView_Scene( this );
165 setInteractionFlags( EditFlags );
166 //setInteractionFlag( TraceBoundingRect );
167 //setInteractionFlag( DraggingByMiddleButton );
168 //setInteractionFlag( ImmediateContextMenu );
169 //setInteractionFlag( ImmediateSelection );
170 //setInteractionFlag( Sketching );
173 setBackgroundBrush( QBrush( Qt::white ) );
176 myIsForegroundEnabled = false;
177 myForegroundSize = QSizeF( 100, 30 );
178 myForegroundMargin = 0.0;
179 myForegroundColor = Qt::white;
180 myForegroundFrameColor = Qt::black;
181 myForegroundFrameLineWidth = 1.0;
184 myIsGridEnabled = false;
185 myGridCellSize = 100;
186 myGridLineStyle = Qt::DotLine;
187 myGridLineColor = Qt::darkGray;
189 // default index method (BspTreeIndex) leads to
190 // crashes in QGraphicsView::paintEvent() method
191 myScene->setItemIndexMethod( QGraphicsScene::NoIndex );
193 // render hints (default - TextAntialiasing only)
194 setRenderHints( QPainter::Antialiasing |
195 QPainter::TextAntialiasing |
196 QPainter::SmoothPixmapTransform |
197 QPainter::HighQualityAntialiasing );
199 myHBarPolicy = horizontalScrollBarPolicy();
200 myVBarPolicy = verticalScrollBarPolicy();
202 connect( myScene, SIGNAL( gsKeyEvent( QKeyEvent* ) ),
203 this, SLOT( onKeyEvent( QKeyEvent* ) ) );
204 connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ),
205 this, SLOT( onMouseEvent( QGraphicsSceneMouseEvent* ) ) );
206 connect( myScene, SIGNAL( gsWheelEvent( QGraphicsSceneWheelEvent* ) ),
207 this, SLOT( onWheelEvent( QGraphicsSceneWheelEvent* ) ) );
208 connect( myScene, SIGNAL( gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ),
209 this, SLOT( onContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) );
211 connect( myScene, SIGNAL( gsBoundingRectChanged() ),
212 this, SLOT( onBoundingRectChanged() ) );
217 //=======================================================================
218 // Name : GraphicsView_ViewPort
219 // Purpose : Destructor
220 //=======================================================================
221 GraphicsView_ViewPort::~GraphicsView_ViewPort()
232 //================================================================
233 // Function : initialize
235 //================================================================
236 void GraphicsView_ViewPort::initialize()
238 if ( nCounter++ == 0 )
241 setMouseTracking( true );
242 setFocusPolicy( Qt::StrongFocus );
245 //================================================================
246 // Function : cleanup
248 //================================================================
249 void GraphicsView_ViewPort::cleanup()
251 if ( --nCounter == 0 )
255 //================================================================
256 // Function : addItem
258 //================================================================
259 void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem )
261 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( theItem ) )
263 int aPriority = anObject->getPriority();
264 GraphicsView_ObjectList::iterator anIter, anIterEnd = myObjects.end();
265 for( anIter = myObjects.begin(); anIter != anIterEnd; anIter++ )
267 if( GraphicsView_Object* anObjectRef = *anIter )
269 if( anObjectRef->getPriority() > aPriority )
273 myObjects.insert( anIter, anObject );
274 anObject->setViewTransform( transform() );
275 anObject->addTo( this );
278 myScene->addItem( theItem );
279 onBoundingRectChanged();
282 //================================================================
283 // Function : isItemAdded
285 //================================================================
286 bool GraphicsView_ViewPort::isItemAdded( QGraphicsItem* theItem )
288 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( theItem ) )
290 for( GraphicsView_ObjectList::iterator anIter = myObjects.begin(); anIter != myObjects.end(); anIter++ )
291 if( theItem == *anIter )
295 for( int i = 0; i < myScene->items().size(); i++ )
296 if( theItem == myScene->items().at(i) )
302 //================================================================
303 // Function : removeItem
305 //================================================================
306 void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem )
308 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( theItem ) )
310 if( myHighlightedObject == anObject )
311 myHighlightedObject = 0;
312 mySelectedObjects.removeAll( anObject );
313 myObjects.removeAll( anObject );
314 anObject->removeFrom( this );
317 myScene->removeItem( theItem );
318 onBoundingRectChanged();
321 void GraphicsView_ViewPort::clearItems()
323 myHighlightedObject = 0;
324 mySelectedObjects.clear();
327 onBoundingRectChanged();
330 //================================================================
331 // Function : getObjects
333 //================================================================
334 GraphicsView_ObjectList GraphicsView_ViewPort::getObjects( SortType theSortType ) const
336 if( theSortType == SelectedFirst )
338 // to append selected objects after their non-selected siblings with similar priority
339 int aCurrentPriority = -1;
340 GraphicsView_ObjectList aSelectedObjects;
341 GraphicsView_ObjectList aTopmostObjects;
343 GraphicsView_ObjectList aList;
344 GraphicsView_ObjectListIterator anIter( myObjects );
345 while( anIter.hasNext() )
347 if( GraphicsView_Object* anObject = anIter.next() )
349 if( anObject->isOnTop() )
351 aTopmostObjects.append( anObject );
355 int aPriority = anObject->getPriority();
356 if( aPriority > aCurrentPriority )
358 if( !aSelectedObjects.isEmpty() )
360 aList.append( aSelectedObjects );
361 aSelectedObjects.clear();
363 aCurrentPriority = aPriority;
366 if( anObject->isSelected() )
367 aSelectedObjects.append( anObject );
369 aList.append( anObject );
373 // for selected objects with highest priority,
374 // which were not pushed to the result list yet
375 if( !aSelectedObjects.isEmpty() )
377 aList.append( aSelectedObjects );
378 aSelectedObjects.clear();
381 aList.append( aTopmostObjects );
386 if( theSortType == SortByZLevel ) // double loop, needs to be optimized
388 GraphicsView_ObjectList aList;
390 GraphicsView_ObjectListIterator anIter( myObjects );
391 while( anIter.hasNext() )
393 if( GraphicsView_Object* anObject = anIter.next() )
395 double aZValue = anObject->zValue();
396 GraphicsView_ObjectList::iterator anIter1, anIter1End = aList.end();
397 for( anIter1 = aList.begin(); anIter1 != anIter1End; anIter1++ )
398 if( GraphicsView_Object* anObjectRef = *anIter1 )
399 if( anObjectRef->zValue() > aZValue )
401 aList.insert( anIter1, anObject );
407 return myObjects; // theSortType == NoSorting
410 //================================================================
411 // Function : objectsBoundingRect
413 //================================================================
414 QRectF GraphicsView_ViewPort::objectsBoundingRect( bool theOnlyVisible ) const
417 QListIterator<QGraphicsItem*> anIter( items() );
418 while( anIter.hasNext() )
420 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
422 if( theOnlyVisible && !anObject->isVisible() )
425 QRectF anObjectRect = anObject->getRect();
426 if( !anObjectRect.isNull() )
429 aRect = anObject->getRect();
431 aRect |= anObject->getRect();
438 //================================================================
439 // Function : dumpView
441 //================================================================
442 QImage GraphicsView_ViewPort::dumpView( bool theWholeScene,
445 if( !theWholeScene ) // just grab the view contents
447 QPixmap aPixmap = QPixmap::grabWindow( viewport()->winId() );
448 return aPixmap.toImage();
451 // get a bounding rect of all presented objects
452 // (itemsBoundingRect() method is unsuitable)
453 QRectF aRect = objectsBoundingRect();
457 QRectF aTargetRect( 0, 0, aRect.width(), aRect.height() );
458 if( theSize.isValid() )
460 double aRatioX = theSize.width() / aTargetRect.width();
461 double aRatioY = theSize.height() / aTargetRect.height();
462 double aRatio = qMin( aRatioX, aRatioY );
463 aTargetRect.setWidth( aTargetRect.width() * aRatio );
464 aTargetRect.setHeight( aTargetRect.height() * aRatio );
467 // render the scene to an image
468 QImage anImage( aTargetRect.toRect().size(), QImage::Format_RGB32 );
469 QPainter aPainter( &anImage );
470 aPainter.setRenderHints( renderHints() );
472 myScene->render( &aPainter, aTargetRect, aRect );
477 bool GraphicsView_ViewPort::dumpViewToFormat(const QString& fileName, const QString& format)
479 if( format!="PS" && format!="EPS" )
482 QPrinter printer(QPrinter::ScreenResolution);
483 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
484 printer.setOutputFormat(QPrinter::PostScriptFormat);
486 printer.setOutputFormat(QPrinter::PdfFormat);
488 printer.setOutputFileName(fileName);
490 if (!painter.begin(&printer))
493 QRect view( 0, 0, printer.pageRect().width(), printer.paperRect().height() );
494 QRectF bounds = myScene->itemsBoundingRect();
496 if( !view.isEmpty() && !bounds.isEmpty() )
498 float SCALE = 0.5;//qMin( view.width()/bounds.width(), view.height()/bounds.height() );
499 painter.setViewport( view );
500 painter.scale( SCALE, SCALE );
502 myScene->render( &painter, QRectF( view ), bounds );
509 //================================================================
510 // Function : setSceneGap
512 //================================================================
513 void GraphicsView_ViewPort::setSceneGap( double theSceneGap )
515 mySceneGap = theSceneGap;
516 onBoundingRectChanged();
519 //================================================================
520 // Function : setFitAllGap
522 //================================================================
523 void GraphicsView_ViewPort::setFitAllGap( double theFitAllGap )
525 myFitAllGap = theFitAllGap;
528 //================================================================
529 // Function : interactionFlags
531 //================================================================
532 int GraphicsView_ViewPort::interactionFlags() const
534 return myInteractionFlags;
537 //================================================================
538 // Function : hasInteractionFlag
540 //================================================================
541 bool GraphicsView_ViewPort::hasInteractionFlag( InteractionFlag theFlag )
543 return ( interactionFlags() & theFlag ) == theFlag;
546 //================================================================
547 // Function : setInteractionFlag
549 //================================================================
550 void GraphicsView_ViewPort::setInteractionFlag( InteractionFlag theFlag,
554 setInteractionFlags( myInteractionFlags | theFlag );
556 setInteractionFlags( myInteractionFlags & ~theFlag );
559 //================================================================
560 // Function : setInteractionFlags
562 //================================================================
563 void GraphicsView_ViewPort::setInteractionFlags( InteractionFlags theFlags )
565 myInteractionFlags = theFlags;
568 //================================================================
569 // Function : setViewLabelPosition
571 //================================================================
572 void GraphicsView_ViewPort::setViewLabelPosition( ViewLabelPosition thePosition,
575 if( theIsForced && !myViewLabel )
576 myViewLabel = new ViewLabel( viewport() );
581 if( thePosition == VLP_None )
583 myViewLabel->setVisible( false );
587 if( myViewLabelLayout )
588 delete myViewLabelLayout;
590 myViewLabelLayout = new QGridLayout( viewport() );
591 myViewLabelLayout->setMargin( 10 );
592 myViewLabelLayout->setSpacing( 0 );
594 int aRow = 0, aColumn = 0;
595 switch( thePosition )
597 case VLP_TopLeft: aRow = 0; aColumn = 0; break;
598 case VLP_TopRight: aRow = 0; aColumn = 1; break;
599 case VLP_BottomLeft: aRow = 1; aColumn = 0; break;
600 case VLP_BottomRight: aRow = 1; aColumn = 1; break;
604 myViewLabelLayout->addWidget( myViewLabel, aRow, aColumn );
605 myViewLabelLayout->setRowStretch( 1 - aRow, 1 );
606 myViewLabelLayout->setColumnStretch( 1 - aColumn, 1 );
608 myViewLabel->setVisible( true );
611 //================================================================
612 // Function : setViewLabelText
614 //================================================================
615 void GraphicsView_ViewPort::setViewLabelText( const QString& theText )
618 myViewLabel->setText( theText );
621 //================================================================
622 // Function : setMousePositionEnabled
624 //================================================================
625 void GraphicsView_ViewPort::setMousePositionEnabled( bool theState )
627 myIsMousePositionEnabled = theState;
631 setViewLabelPosition( VLP_BottomLeft, true );
633 int aMouseX = 0, aMouseY = 0;
634 setViewLabelText( QString( "(%1, %2)" ).arg( aMouseX ).arg( aMouseY ) );
637 setViewLabelPosition( VLP_None );
640 //================================================================
641 // Function : backgroundColor
643 //================================================================
644 QColor GraphicsView_ViewPort::backgroundColor() const
646 return backgroundBrush().color();
649 //================================================================
650 // Function : setBackgroundColor
652 //================================================================
653 void GraphicsView_ViewPort::setBackgroundColor( const QColor& theColor )
655 setBackgroundBrush( QBrush( theColor ) );
658 //================================================================
659 // Function : setForegroundEnabled
661 //================================================================
662 void GraphicsView_ViewPort::setForegroundEnabled( bool theState )
664 myIsForegroundEnabled = theState;
667 //================================================================
668 // Function : setForegroundSize
670 //================================================================
671 void GraphicsView_ViewPort::setForegroundSize( const QSizeF& theSize )
673 myForegroundSize = theSize;
676 //================================================================
677 // Function : setForegroundMargin
679 //================================================================
680 void GraphicsView_ViewPort::setForegroundMargin( double theMargin )
682 myForegroundMargin = theMargin;
685 //================================================================
686 // Function : setForegroundColor
688 //================================================================
689 void GraphicsView_ViewPort::setForegroundColor( const QColor& theColor )
691 myForegroundColor = theColor;
694 //================================================================
695 // Function : setForegroundFrameColor
697 //================================================================
698 void GraphicsView_ViewPort::setForegroundFrameColor( const QColor& theColor )
700 myForegroundFrameColor = theColor;
703 //================================================================
704 // Function : setForegroundFrameLineWidth
706 //================================================================
707 void GraphicsView_ViewPort::setForegroundFrameLineWidth( double theLineWidth )
709 myForegroundFrameLineWidth = theLineWidth;
712 //================================================================
713 // Function : updateForeground
715 //================================================================
716 void GraphicsView_ViewPort::updateForeground()
718 if( myIsForegroundEnabled )
720 if( !myForegroundItem )
721 myForegroundItem = myScene->addRect( QRectF(), QPen(), QBrush( Qt::white ) );
722 myForegroundItem->setZValue( FOREGROUND_Z_VALUE );
724 QPointF aPoint = QPointF();
725 QRectF aRect( aPoint, myForegroundSize );
726 aRect.adjust( -myForegroundMargin, -myForegroundMargin,
727 myForegroundMargin, myForegroundMargin );
728 myForegroundItem->setRect( aRect );
730 QBrush aBrush = myForegroundItem->brush();
731 aBrush.setColor( myForegroundColor );
732 myForegroundItem->setBrush( aBrush );
734 QPen aPen = myForegroundItem->pen();
735 aPen.setColor( myForegroundFrameColor );
736 aPen.setWidthF( myForegroundFrameLineWidth );
737 myForegroundItem->setPen( aPen );
739 myForegroundItem->setVisible( true );
741 myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) );
745 if( myForegroundItem )
746 myForegroundItem->setVisible( false );
749 updateGrid(); // foreground size could be changed
752 //================================================================
753 // Function : setGridEnabled
755 //================================================================
756 void GraphicsView_ViewPort::setGridEnabled( bool theState )
758 myIsGridEnabled = theState;
761 //================================================================
762 // Function : setGridCellSize
764 //================================================================
765 void GraphicsView_ViewPort::setGridCellSize( int theCellSize )
767 myGridCellSize = theCellSize;
770 //================================================================
771 // Function : setGridLineStyle
773 //================================================================
774 void GraphicsView_ViewPort::setGridLineStyle( int theLineStyle )
776 myGridLineStyle = theLineStyle;
779 //================================================================
780 // Function : setGridLineColor
782 //================================================================
783 void GraphicsView_ViewPort::setGridLineColor( const QColor& theLineColor )
785 myGridLineColor = theLineColor;
788 //================================================================
789 // Function : updateGrid
791 //================================================================
792 void GraphicsView_ViewPort::updateGrid()
794 if( myIsGridEnabled )
797 myGridItem = myScene->addPath( QPainterPath() );
798 myGridItem->setZValue( GRID_Z_VALUE );
800 double aWidth = myForegroundSize.width();
801 double aHeight = myForegroundSize.height();
803 int aGridNbX = int( aWidth / myGridCellSize ) + 1;
804 int aGridNbY = int( aHeight / myGridCellSize ) + 1;
808 for( anIndex = 0; anIndex < aGridNbX; anIndex++ )
810 double x = myGridCellSize * (double)anIndex;
811 aPath.moveTo( x, 0 );
812 aPath.lineTo( x, aHeight );
814 for( anIndex = 0; anIndex < aGridNbY; anIndex++ )
816 double y = myGridCellSize * (double)anIndex;
817 aPath.moveTo( 0, y );
818 aPath.lineTo( aWidth, y );
820 myGridItem->setPath( aPath );
822 QPen aPen = myGridItem->pen();
823 aPen.setStyle( (Qt::PenStyle)myGridLineStyle );
824 aPen.setColor( myGridLineColor );
825 myGridItem->setPen( aPen );
827 myGridItem->setVisible( true );
832 myGridItem->setVisible( false );
836 //================================================================
839 //================================================================
840 void GraphicsView_ViewPort::reset()
845 //================================================================
848 //================================================================
849 void GraphicsView_ViewPort::pan( double theDX, double theDY )
851 myIsTransforming = true;
854 myViewLabel->setAcceptMoveEvents( false );
856 if( QScrollBar* aHBar = horizontalScrollBar() )
858 if( isUnlimitedPanning() )
860 int aNewValue = aHBar->value() - theDX;
861 if( aNewValue < aHBar->minimum() )
862 aHBar->setMinimum( aNewValue );
863 if( aNewValue > aHBar->maximum() )
864 aHBar->setMaximum( aNewValue );
866 aHBar->setValue( aHBar->value() - theDX );
868 if( QScrollBar* aVBar = verticalScrollBar() )
870 if( isUnlimitedPanning() )
872 int aNewValue = aVBar->value() + theDY;
873 if( aNewValue < aVBar->minimum() )
874 aVBar->setMinimum( aNewValue );
875 if( aNewValue > aVBar->maximum() )
876 aVBar->setMaximum( aNewValue );
878 aVBar->setValue( aVBar->value() + theDY );
882 myViewLabel->setAcceptMoveEvents( true );
884 myIsTransforming = false;
889 //================================================================
890 // Function : setCenter
892 //================================================================
893 void GraphicsView_ViewPort::setCenter( double theX, double theY )
895 myIsTransforming = true;
897 setTransform( myCurrentTransform );
898 centerOn( theX, theY );
900 myIsTransforming = false;
905 //================================================================
908 //================================================================
909 void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, double theY2 )
911 myIsTransforming = true;
913 double aDX = theX2 - theX1;
914 double aDY = theY2 - theY1;
915 double aZoom = sqrt( aDX * aDX + aDY * aDY ) / 100 + 1;
916 aZoom = ( aDX > 0 ) ? aZoom : 1 / aZoom;
918 QTransform aTransform = transform();
919 aTransform.scale( aZoom, aZoom );
920 double aM11 = aTransform.m11();
921 double aM22 = aTransform.m22();
924 QGraphicsView::ViewportAnchor old_anchor = transformationAnchor();
925 setTransformationAnchor( QGraphicsView::AnchorUnderMouse );
927 // increasing of diagonal coefficients (>300) leads to a crash sometimes
928 // at the values of 100 some primitives are drawn incorrectly
929 if( myZoomCoeff < 0 || qMax( aM11, aM22 ) < myZoomCoeff )
930 setTransform( aTransform );
932 myIsTransforming = false;
936 setTransformationAnchor( old_anchor );
939 //================================================================
940 // Function : fitRect
942 //================================================================
943 void GraphicsView_ViewPort::fitRect( const QRectF& theRect )
945 myIsTransforming = true;
947 fitInView( theRect, Qt::KeepAspectRatio );
949 myIsTransforming = false;
954 //================================================================
955 // Function : fitSelect
957 //================================================================
958 void GraphicsView_ViewPort::fitSelect()
960 myIsTransforming = true;
963 for( initSelected(); moreSelected(); nextSelected() )
965 if( GraphicsView_Object* aMovingObject = selectedObject() )
967 QRectF aRect = aMovingObject->getRect();
968 if( aGlobalRect.isNull() )
971 aGlobalRect |= aRect;
975 if( !aGlobalRect.isNull() )
977 double aGap = qMax( aGlobalRect.width(), aGlobalRect.height() ) / 5;
978 aGlobalRect.adjust( -aGap, -aGap, aGap, aGap );
979 fitInView( aGlobalRect, Qt::KeepAspectRatio );
982 myIsTransforming = false;
987 //================================================================
990 //================================================================
991 void GraphicsView_ViewPort::fitAll( bool theKeepScale )
993 myIsTransforming = true;
996 myCurrentTransform = transform();
998 double aGap = myFitAllGap;
999 QRectF aRect = objectsBoundingRect( true );
1000 fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio );
1002 myIsTransforming = false;
1007 //================================================================
1008 // Function : fitWidth
1010 //================================================================
1011 void GraphicsView_ViewPort::fitWidth()
1013 myIsTransforming = true;
1015 double aGap = myFitAllGap;
1016 QRectF aRect = objectsBoundingRect( true );
1018 double aTop = aRect.top();
1019 double aLeft = aRect.left();
1020 double aMargin = 10;
1022 aRect.setY( aRect.center().y() );
1023 aRect.setHeight( aMargin );
1025 fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio );
1026 ensureVisible( aLeft, aTop, aMargin, aMargin, 0, aGap );
1028 myIsTransforming = false;
1033 //================================================================
1034 // Function : applyTransform
1036 //================================================================
1037 void GraphicsView_ViewPort::applyTransform()
1039 GraphicsView_ObjectListIterator anIter( getObjects() );
1040 while( anIter.hasNext() )
1041 if( GraphicsView_Object* anObject = anIter.next() )
1042 anObject->setViewTransform( transform() );
1045 //================================================================
1046 // Function : setZoomCoeff
1048 //================================================================
1049 void GraphicsView_ViewPort::setZoomCoeff( const int& theZoomCoeff )
1051 myZoomCoeff = theZoomCoeff;
1054 //================================================================
1055 // Function : setUnlimitedPanning
1057 //================================================================
1058 void GraphicsView_ViewPort::setUnlimitedPanning( const bool& theValue )
1060 if ( myUnlimitedPanning == theValue )
1063 myUnlimitedPanning = theValue;
1065 if( myUnlimitedPanning )
1067 myHBarPolicy = horizontalScrollBarPolicy();
1068 myVBarPolicy = verticalScrollBarPolicy();
1070 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
1071 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
1075 setHorizontalScrollBarPolicy( myHBarPolicy );
1076 setVerticalScrollBarPolicy( myVBarPolicy );
1080 //================================================================
1081 // Function : currentBlock
1083 //================================================================
1084 GraphicsView_ViewPort::BlockStatus GraphicsView_ViewPort::currentBlock()
1086 if( isDragging() && !myDragPosition.isNull() )
1087 return BlockStatus( BS_Selection );
1089 if( myAreSelectionPointsInitialized && ( myFirstSelectionPoint != myLastSelectionPoint ) )
1090 return BlockStatus( BS_Selection );
1093 return BlockStatus( BS_Selection );
1098 //================================================================
1099 // Function : highlight
1101 //================================================================
1102 void GraphicsView_ViewPort::highlight( double theX, double theY )
1104 myIsHighlighting = true;
1105 myHighlightX = theX;
1106 myHighlightY = theY;
1108 bool anIsHighlighted = false;
1109 bool anIsOnObject = false;
1111 GraphicsView_Object* aPreviousHighlightedObject = myHighlightedObject;
1112 GraphicsView_Object* aHighlightedObject = 0;
1116 GraphicsView_ObjectList aList = getObjects( SortByZLevel );
1117 GraphicsView_ObjectListIterator anIter( aList );
1118 anIter.toBack(); // objects with higher priority have to be checked earlier
1119 while( anIter.hasPrevious() )
1121 if( GraphicsView_Object* anObject = anIter.previous() )
1123 if( anObject->isVisible() && anObject->isSelectable() )
1125 if( anObject->checkHighlight( theX, theY, aCursor ) )
1127 anIsOnObject = true;
1128 anIsHighlighted = anObject->highlight( theX, theY );
1131 if( anIsHighlighted )
1133 aHighlightedObject = anObject;
1140 setCursor( aCursor );
1145 while( anIter.hasNext() )
1146 if( GraphicsView_Object* anObject = anIter.next() )
1147 anObject->unhighlight();
1149 myHighlightedObject = 0;
1152 else if( !myHighlightedObject && anIsHighlighted )
1154 myHighlightedObject = aHighlightedObject;
1156 else if( myHighlightedObject && !anIsHighlighted )
1158 myHighlightedObject->unhighlight();
1159 myHighlightedObject = 0;
1161 else if( myHighlightedObject && anIsHighlighted )
1163 myHighlightedObject->highlight( theX, theY );
1164 if( myHighlightedObject != aHighlightedObject )
1166 myHighlightedObject->unhighlight();
1167 myHighlightedObject = aHighlightedObject;
1172 //================================================================
1173 // Function : clearHighlighted
1175 //================================================================
1176 void GraphicsView_ViewPort::clearHighlighted()
1178 if( myHighlightedObject )
1180 myHighlightedObject->unhighlight();
1181 myHighlightedObject = 0;
1185 //================================================================
1186 // Function : select
1188 //================================================================
1189 int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend )
1191 if( !myIsHighlighting )
1192 return GVSS_NoChanged;
1194 GV_SelectionStatus aStatus = GVSS_Invalid;
1195 if( theRect.isNull() ) // point selection
1197 if( myHighlightedObject )
1199 if( mySelectedObjects.count() == 1 &&
1200 mySelectedObjects.first() == myHighlightedObject )
1201 aStatus = GVSS_LocalChanged;
1205 GraphicsView_ObjectListIterator anIter( mySelectedObjects );
1206 while( anIter.hasNext() )
1207 if( GraphicsView_Object* anObject = anIter.next() )
1208 if( myHighlightedObject != anObject )
1209 anObject->unselect();
1211 if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid )
1212 aStatus = GVSS_GlobalChanged;
1213 mySelectedObjects.clear();
1215 else if( myHighlightedObject->isSelected() && aStatus != GVSS_LocalChanged )
1217 mySelectedObjects.removeAll( myHighlightedObject );
1218 myHighlightedObject->unselect();
1220 if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid )
1221 aStatus = GVSS_GlobalChanged;
1226 if( myHighlightedObject->select( myHighlightX, myHighlightY, QRectF() ) &&
1227 mySelectedObjects.indexOf( myHighlightedObject ) == -1 )
1229 mySelectedObjects.append( myHighlightedObject );
1230 if( aStatus == GVSS_Invalid )
1231 aStatus = GVSS_GlobalChanged;
1233 else if( aStatus == GVSS_LocalChanged )
1234 aStatus = GVSS_GlobalChanged;
1239 if( !myHighlightedObject )
1243 GraphicsView_ObjectListIterator anIter( mySelectedObjects );
1244 while( anIter.hasNext() )
1245 if( GraphicsView_Object* anObject = anIter.next() )
1246 if( myHighlightedObject != anObject )
1247 anObject->unselect();
1249 if( !mySelectedObjects.isEmpty() )
1250 aStatus = GVSS_GlobalChanged;
1251 mySelectedObjects.clear();
1256 return GVSS_NoChanged;
1258 else // rectangle selection
1260 aStatus = GVSS_NoChanged;
1262 bool updateAll = false;
1265 if( !mySelectedObjects.isEmpty() )
1266 aStatus = GVSS_GlobalChanged;
1268 GraphicsView_ObjectListIterator anIter( mySelectedObjects );
1269 while( anIter.hasNext() )
1270 if( GraphicsView_Object* anObject = anIter.next() )
1271 if( myHighlightedObject != anObject )
1272 anObject->unselect();
1273 mySelectedObjects.clear();
1276 QListIterator<QGraphicsItem*> anIter( items() );
1277 while( anIter.hasNext() )
1279 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
1281 if( anObject->isVisible() && anObject->isSelectable() )
1283 bool anIsSelected = false;
1284 QRectF aRect = anObject->getRect();
1285 if( theRect.contains( aRect ) && myIsHighlighting )
1286 anIsSelected = anObject->select( myHighlightX, myHighlightY, theRect );
1288 if( anIsSelected && mySelectedObjects.indexOf( anObject ) == -1 )
1290 mySelectedObjects.append( anObject );
1291 aStatus = GVSS_GlobalChanged;
1300 //================================================================
1301 // Function : clearSelected
1303 //================================================================
1304 void GraphicsView_ViewPort::clearSelected()
1306 GraphicsView_ObjectListIterator anIter( mySelectedObjects );
1307 while( anIter.hasNext() )
1308 if( GraphicsView_Object* anObject = anIter.next() )
1309 anObject->unselect();
1310 mySelectedObjects.clear();
1313 //================================================================
1314 // Function : setSelected
1316 //================================================================
1317 void GraphicsView_ViewPort::setSelected( GraphicsView_Object* theObject )
1321 theObject->setSelected( true );
1322 mySelectedObjects.append( theObject );
1326 //================================================================
1327 // Function : nbSelected
1329 //================================================================
1330 int GraphicsView_ViewPort::nbSelected() const
1332 return mySelectedObjects.count();
1335 //================================================================
1336 // Function : initSelected
1338 //================================================================
1339 void GraphicsView_ViewPort::initSelected()
1341 mySelectionIterator = 0;
1344 //================================================================
1345 // Function : moreSelected
1347 //================================================================
1348 bool GraphicsView_ViewPort::moreSelected()
1350 return mySelectionIterator < nbSelected();
1353 //================================================================
1354 // Function : nextSelected
1356 //================================================================
1357 bool GraphicsView_ViewPort::nextSelected()
1359 if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() )
1361 mySelectionIterator++;
1367 //================================================================
1368 // Function : selectedObject
1370 //================================================================
1371 GraphicsView_Object* GraphicsView_ViewPort::selectedObject()
1373 if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() )
1374 return mySelectedObjects[ mySelectionIterator ];
1378 //================================================================
1379 // Function : startSelectByRect
1381 //================================================================
1382 void GraphicsView_ViewPort::startSelectByRect( int x, int y )
1384 if( !myAreSelectionPointsInitialized )
1386 myFirstSelectionPoint = QPoint( x, y );
1387 myLastSelectionPoint = QPoint( x, y );
1388 myAreSelectionPointsInitialized = true;
1393 myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
1395 palette.setColor( myRectBand->foregroundRole(), Qt::white );
1396 myRectBand->setPalette( palette );
1401 //================================================================
1402 // Function : drawSelectByRect
1404 //================================================================
1405 void GraphicsView_ViewPort::drawSelectByRect( int x, int y )
1407 if( myAreSelectionPointsInitialized )
1411 myLastSelectionPoint.setX( x );
1412 myLastSelectionPoint.setY( y );
1414 QRect aRect = selectionRect();
1415 myRectBand->setGeometry( aRect );
1416 myRectBand->setVisible( aRect.isValid() );
1420 //================================================================
1421 // Function : isSelectByRect
1423 //================================================================
1424 bool GraphicsView_ViewPort::isSelectByRect() const
1426 return myAreSelectionPointsInitialized;
1429 //================================================================
1430 // Function : finishSelectByRect
1432 //================================================================
1433 void GraphicsView_ViewPort::finishSelectByRect()
1435 if( myAreSelectionPointsInitialized )
1444 myAreSelectionPointsInitialized = false;
1448 //================================================================
1449 // Function : selectionRect
1451 //================================================================
1452 QRect GraphicsView_ViewPort::selectionRect()
1455 if( myAreSelectionPointsInitialized )
1457 aRect.setLeft( qMin( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) );
1458 aRect.setTop( qMin( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) );
1459 aRect.setRight( qMax( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) );
1460 aRect.setBottom( qMax( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) );
1465 //================================================================
1466 // Function : prepareToSketch
1468 //================================================================
1469 void GraphicsView_ViewPort::prepareToSketch( bool theStatus )
1471 myIsPrepareToSketch = theStatus;
1473 setCursor( *getSketchCursor() );
1476 //================================================================
1477 // Function : isPrepareToSketch
1479 //================================================================
1480 bool GraphicsView_ViewPort::isPrepareToSketch()
1482 return myIsPrepareToSketch;
1485 //================================================================
1486 // Function : startSketching
1488 //================================================================
1489 void GraphicsView_ViewPort::startSketching( const QPointF& thePoint,
1492 prepareToSketch( false );
1494 if( !mySketchingItem )
1496 mySketchingItem = new QGraphicsPathItem();
1497 mySketchingItem->setZValue( SKETCH_Z_VALUE );
1499 QPen aPen = mySketchingItem->pen();
1500 aPen.setStyle( Qt::DotLine );
1501 mySketchingItem->setPen( aPen );
1503 addItem( mySketchingItem );
1506 mySketchingPoint = thePoint;
1509 aPath.moveTo( mySketchingPoint );
1510 mySketchingItem->setPath( aPath );
1511 mySketchingItem->setVisible( true );
1513 myIsSketching = true;
1514 myIsSketchingByPath = theIsPath;
1517 //================================================================
1518 // Function : drawSketching
1520 //================================================================
1521 void GraphicsView_ViewPort::drawSketching( const QPointF& thePoint )
1523 bool anIsPath = false;
1524 if( mySketchingItem && isSketching( &anIsPath ) )
1526 QPainterPath aPath = mySketchingItem->path();
1527 if( anIsPath ) // arbitrary path
1528 aPath.lineTo( thePoint );
1531 // make a valid rectangle
1532 double x1 = mySketchingPoint.x(), y1 = mySketchingPoint.y();
1533 double x2 = thePoint.x(), y2 = thePoint.y();
1534 QPointF aPoint1( qMin( x1, x2 ), qMin( y1, y2 ) );
1535 QPointF aPoint2( qMax( x1, x2 ), qMax( y1, y2 ) );
1536 QRectF aRect( aPoint1, aPoint2 );
1538 aPath = QPainterPath();
1539 aPath.addRect( aRect );
1541 mySketchingItem->setPath( aPath );
1545 //================================================================
1546 // Function : finishSketching
1548 //================================================================
1549 void GraphicsView_ViewPort::finishSketching( bool theStatus )
1551 prepareToSketch( false );
1553 mySketchingItem->setVisible( false );
1554 myIsSketching = false;
1556 setCursor( *getDefaultCursor() );
1560 QPainterPath aPath = mySketchingItem->path();
1561 emit vpSketchingFinished( aPath );
1565 //================================================================
1566 // Function : isSketching
1568 //================================================================
1569 bool GraphicsView_ViewPort::isSketching( bool* theIsPath ) const
1572 *theIsPath = myIsSketchingByPath;
1573 return myIsSketching;
1576 //================================================================
1577 // Function : setDraggingSelectedByLeftButton
1579 //================================================================
1580 void GraphicsView_ViewPort::setDraggingSelectedByLeftButton( const bool& theValue )
1582 myDraggingSelectedByLeftButton = theValue;
1585 //================================================================
1586 // Function : dragObjects
1588 //================================================================
1589 void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e )
1591 GraphicsView_Object* anObject = getHighlightedObject();
1593 if( myDragPosition.isNull() )
1595 myDragPosition = e->scenePos();
1599 GraphicsView_ObjectList anObjectsToMove;
1600 if( anObject && anObject->isMovable() && ( e->buttons() & Qt::LeftButton ) )
1602 if( anObject->isSelected() )
1604 for( initSelected(); moreSelected(); nextSelected() )
1605 if( GraphicsView_Object* aMovingObject = selectedObject() )
1606 if( aMovingObject->isMovable() )
1607 anObjectsToMove.append( aMovingObject );
1610 anObjectsToMove.append( anObject );
1612 else if( ( hasInteractionFlag( DraggingByMiddleButton ) && ( e->buttons() & Qt::MidButton ) ||
1613 isDraggingSelectedByLeftButton() && ( e->buttons() & Qt::LeftButton ) ) &&
1616 for( initSelected(); moreSelected(); nextSelected() )
1617 if( GraphicsView_Object* aMovingObject = selectedObject() )
1618 if( aMovingObject->isMovable() )
1619 anObjectsToMove.append( aMovingObject );
1622 if( anObjectsToMove.isEmpty() )
1625 double aDX = e->scenePos().x() - myDragPosition.x();
1626 double aDY = e->scenePos().y() - myDragPosition.y();
1628 bool anIsMovingByXAllowed = true, anIsMovingByYAllowed = true;
1629 GraphicsView_ObjectListIterator anIter( anObjectsToMove );
1630 while( anIter.hasNext() )
1631 if( GraphicsView_Object* aMovingObject = anIter.next() )
1633 if( !aMovingObject->isMovingByXAllowed( aDX ) )
1634 anIsMovingByXAllowed = false;
1635 if( !aMovingObject->isMovingByYAllowed( aDY ) )
1636 anIsMovingByYAllowed = false;
1639 if( !anIsMovingByXAllowed && !anIsMovingByYAllowed )
1640 return; // myDragPosition shouldn't be changed
1642 if( !anIsMovingByXAllowed )
1645 if( !anIsMovingByYAllowed )
1648 anIter = anObjectsToMove;
1649 while( anIter.hasNext() )
1650 if( GraphicsView_Object* aMovingObject = anIter.next() )
1651 aMovingObject->move( aDX, aDY );
1653 if( anIsMovingByXAllowed )
1654 myDragPosition.setX( e->scenePos().x() );
1656 if( anIsMovingByYAllowed )
1657 myDragPosition.setY( e->scenePos().y() );
1660 //================================================================
1661 // Function : startPulling
1663 //================================================================
1664 bool GraphicsView_ViewPort::startPulling( const QPointF& thePoint )
1666 QListIterator<QGraphicsItem*> anIter( items() );
1667 while( anIter.hasNext() )
1669 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
1671 QRectF aRect = anObject->getPullingRect();
1672 if( aRect.contains( thePoint ) && anObject->startPulling( thePoint ) )
1675 myPullingObject = anObject;
1676 //setCursor( *getHandCursor() ); // testing ImageViewer
1684 //================================================================
1685 // Function : drawPulling
1687 //================================================================
1688 void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint )
1690 GraphicsView_Object* aLockedObject = 0;
1692 QListIterator<QGraphicsItem*> anIter( items() );
1693 while( anIter.hasNext() )
1695 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
1697 if( !anObject->isVisible() )
1700 QRectF aRect = anObject->getPullingRect();
1701 if( aRect.contains( thePoint ) && anObject->portContains( thePoint ) )
1703 aLockedObject = anObject;
1709 myPullingObject->pull( thePoint, aLockedObject, getSelectedObjects() );
1712 //================================================================
1713 // Function : finishPulling
1715 //================================================================
1716 void GraphicsView_ViewPort::finishPulling( bool theStatus )
1718 myIsPulling = false;
1719 myPullingObject->finishPulling( theStatus, getSelectedObjects() );
1720 setCursor( *getDefaultCursor() );
1723 //================================================================
1724 // Function : cancelCurrentOperation
1726 //================================================================
1727 bool GraphicsView_ViewPort::cancelCurrentOperation()
1729 myIsHighlighting = false;
1733 for( initSelected(); moreSelected(); nextSelected() )
1734 if( GraphicsView_Object* aMovingObject = selectedObject() )
1735 aMovingObject->finishMove( false );
1737 if( GraphicsView_Object* aMovingObject = getHighlightedObject() )
1738 aMovingObject->finishMove( false );
1740 myIsDragging = false;
1741 myDragPosition = QPointF();
1742 //setCursor( myStoredCursor );
1743 setCursor( *getDefaultCursor() );
1750 finishPulling( false );
1754 if( isSketching() || isPrepareToSketch() )
1756 finishSketching( false );
1763 //================================================================
1764 // Function : onBoundingRectChanged
1766 //================================================================
1767 void GraphicsView_ViewPort::onBoundingRectChanged()
1769 if( hasInteractionFlag( TraceBoundingRect ) )
1771 QRectF aRect = objectsBoundingRect( true );
1772 myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) );
1776 //================================================================
1777 // Function : onKeyEvent
1779 //================================================================
1780 void GraphicsView_ViewPort::onKeyEvent( QKeyEvent* e )
1782 emit vpKeyEvent( e );
1785 //================================================================
1786 // Function : onMouseEvent
1788 //================================================================
1789 void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e )
1791 emit vpMouseEvent( e );
1793 bool anIsHandled = false;
1796 case QEvent::GraphicsSceneMousePress:
1798 if( hasInteractionFlag( EditFlags ) && nbSelected() )
1799 for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
1800 if( GraphicsView_Object* anObject = selectedObject() )
1801 anIsHandled = anObject->handleMousePress( e );
1803 if( !anIsHandled && hasInteractionFlag( Dragging ) )
1805 bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey();
1806 if( ( getHighlightedObject() &&
1807 getHighlightedObject()->isMovable() &&
1808 !( anAccel || e->button() != Qt::LeftButton ) ) ||
1809 ( ( hasInteractionFlag( DraggingByMiddleButton ) && e->button() == Qt::MidButton ||
1810 isDraggingSelectedByLeftButton() && e->button() == Qt::LeftButton ) &&
1811 nbSelected() && !anAccel ) )
1813 myIsDragging = true;
1814 myStoredCursor = cursor();
1815 setCursor( Qt::ClosedHandCursor );
1820 case QEvent::GraphicsSceneMouseMove:
1822 if( hasInteractionFlag( EditFlags ) && nbSelected() )
1823 for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
1824 if( GraphicsView_Object* anObject = selectedObject() )
1825 anIsHandled = anObject->handleMouseMove( e );
1827 if( !anIsHandled && !isPulling() && myIsDragging )
1831 case QEvent::GraphicsSceneMouseRelease:
1833 if( hasInteractionFlag( EditFlags ) && nbSelected() )
1834 for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
1835 if( GraphicsView_Object* anObject = selectedObject() )
1836 anIsHandled = anObject->handleMouseRelease( e );
1838 if( !anIsHandled && !isPulling() && myIsDragging )
1840 emit vpObjectBeforeMoving();
1842 bool anIsMoved = false;
1843 for( initSelected(); moreSelected(); nextSelected() )
1844 if( GraphicsView_Object* aMovingObject = selectedObject() )
1845 anIsMoved = aMovingObject->finishMove( true ) || anIsMoved;
1847 if( GraphicsView_Object* aMovingObject = getHighlightedObject() )
1848 anIsMoved = aMovingObject->finishMove( true ) || anIsMoved;
1850 myIsDragging = false;
1851 myDragPosition = QPointF();
1852 setCursor( myStoredCursor );
1854 emit vpObjectAfterMoving( anIsMoved );
1858 case QEvent::GraphicsSceneMouseDoubleClick:
1859 break; // do nothing, just emit the signal
1864 if( myIsMousePositionEnabled )
1866 int aMouseX = (int)e->scenePos().x();
1867 int aMouseY = (int)e->scenePos().y();
1868 setViewLabelText( QString( "(%1, %2)" ).arg( aMouseX ).arg( aMouseY ) );
1872 //================================================================
1873 // Function : onWheelEvent
1875 //================================================================
1876 void GraphicsView_ViewPort::onWheelEvent( QGraphicsSceneWheelEvent* e )
1878 emit vpWheelEvent( e );
1881 //================================================================
1882 // Function : onContextMenuEvent
1884 //================================================================
1885 void GraphicsView_ViewPort::onContextMenuEvent( QGraphicsSceneContextMenuEvent* e )
1887 emit vpContextMenuEvent( e );
1890 //================================================================
1891 // Function : scrollContentsBy
1893 //================================================================
1894 void GraphicsView_ViewPort::scrollContentsBy( int theDX, int theDY )
1897 myViewLabel->setAcceptMoveEvents( false );
1899 QGraphicsView::scrollContentsBy( theDX, theDY );
1902 myViewLabel->setAcceptMoveEvents( true );