1 // Copyright (C) 2013-2023 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( 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 printer.setOutputFormat(QPrinter::PdfFormat);
484 printer.setOutputFileName(fileName);
486 if (!painter.begin(&printer))
489 QRect view( 0, 0, printer.pageRect().width(), printer.paperRect().height() );
490 QRectF bounds = myScene->itemsBoundingRect();
492 if( !view.isEmpty() && !bounds.isEmpty() )
494 float SCALE = 0.5;//qMin( view.width()/bounds.width(), view.height()/bounds.height() );
495 painter.setViewport( view );
496 painter.scale( SCALE, SCALE );
498 myScene->render( &painter, QRectF( view ), bounds );
505 //================================================================
506 // Function : setSceneGap
508 //================================================================
509 void GraphicsView_ViewPort::setSceneGap( double theSceneGap )
511 mySceneGap = theSceneGap;
512 onBoundingRectChanged();
515 //================================================================
516 // Function : setFitAllGap
518 //================================================================
519 void GraphicsView_ViewPort::setFitAllGap( double theFitAllGap )
521 myFitAllGap = theFitAllGap;
524 //================================================================
525 // Function : interactionFlags
527 //================================================================
528 int GraphicsView_ViewPort::interactionFlags() const
530 return myInteractionFlags;
533 //================================================================
534 // Function : hasInteractionFlag
536 //================================================================
537 bool GraphicsView_ViewPort::hasInteractionFlag( InteractionFlag theFlag )
539 return ( interactionFlags() & theFlag ) == theFlag;
542 //================================================================
543 // Function : setInteractionFlag
545 //================================================================
546 void GraphicsView_ViewPort::setInteractionFlag( InteractionFlag theFlag,
550 setInteractionFlags( myInteractionFlags | theFlag );
552 setInteractionFlags( myInteractionFlags & ~theFlag );
555 //================================================================
556 // Function : setInteractionFlags
558 //================================================================
559 void GraphicsView_ViewPort::setInteractionFlags( InteractionFlags theFlags )
561 myInteractionFlags = theFlags;
564 //================================================================
565 // Function : setViewLabelPosition
567 //================================================================
568 void GraphicsView_ViewPort::setViewLabelPosition( ViewLabelPosition thePosition,
571 if( theIsForced && !myViewLabel )
572 myViewLabel = new ViewLabel( viewport() );
577 if( thePosition == VLP_None )
579 myViewLabel->setVisible( false );
583 if( myViewLabelLayout )
584 delete myViewLabelLayout;
586 myViewLabelLayout = new QGridLayout( viewport() );
587 myViewLabelLayout->setMargin( 10 );
588 myViewLabelLayout->setSpacing( 0 );
590 int aRow = 0, aColumn = 0;
591 switch( thePosition )
593 case VLP_TopLeft: aRow = 0; aColumn = 0; break;
594 case VLP_TopRight: aRow = 0; aColumn = 1; break;
595 case VLP_BottomLeft: aRow = 1; aColumn = 0; break;
596 case VLP_BottomRight: aRow = 1; aColumn = 1; break;
600 myViewLabelLayout->addWidget( myViewLabel, aRow, aColumn );
601 myViewLabelLayout->setRowStretch( 1 - aRow, 1 );
602 myViewLabelLayout->setColumnStretch( 1 - aColumn, 1 );
604 myViewLabel->setVisible( true );
607 //================================================================
608 // Function : setViewLabelText
610 //================================================================
611 void GraphicsView_ViewPort::setViewLabelText( const QString& theText )
614 myViewLabel->setText( theText );
617 //================================================================
618 // Function : setMousePositionEnabled
620 //================================================================
621 void GraphicsView_ViewPort::setMousePositionEnabled( bool theState )
623 myIsMousePositionEnabled = theState;
627 setViewLabelPosition( VLP_BottomLeft, true );
629 int aMouseX = 0, aMouseY = 0;
630 setViewLabelText( QString( "(%1, %2)" ).arg( aMouseX ).arg( aMouseY ) );
633 setViewLabelPosition( VLP_None );
636 //================================================================
637 // Function : backgroundColor
639 //================================================================
640 QColor GraphicsView_ViewPort::backgroundColor() const
642 return backgroundBrush().color();
645 //================================================================
646 // Function : setBackgroundColor
648 //================================================================
649 void GraphicsView_ViewPort::setBackgroundColor( const QColor& theColor )
651 setBackgroundBrush( QBrush( theColor ) );
654 //================================================================
655 // Function : setForegroundEnabled
657 //================================================================
658 void GraphicsView_ViewPort::setForegroundEnabled( bool theState )
660 myIsForegroundEnabled = theState;
663 //================================================================
664 // Function : setForegroundSize
666 //================================================================
667 void GraphicsView_ViewPort::setForegroundSize( const QSizeF& theSize )
669 myForegroundSize = theSize;
672 //================================================================
673 // Function : setForegroundMargin
675 //================================================================
676 void GraphicsView_ViewPort::setForegroundMargin( double theMargin )
678 myForegroundMargin = theMargin;
681 //================================================================
682 // Function : setForegroundColor
684 //================================================================
685 void GraphicsView_ViewPort::setForegroundColor( const QColor& theColor )
687 myForegroundColor = theColor;
690 //================================================================
691 // Function : setForegroundFrameColor
693 //================================================================
694 void GraphicsView_ViewPort::setForegroundFrameColor( const QColor& theColor )
696 myForegroundFrameColor = theColor;
699 //================================================================
700 // Function : setForegroundFrameLineWidth
702 //================================================================
703 void GraphicsView_ViewPort::setForegroundFrameLineWidth( double theLineWidth )
705 myForegroundFrameLineWidth = theLineWidth;
708 //================================================================
709 // Function : updateForeground
711 //================================================================
712 void GraphicsView_ViewPort::updateForeground()
714 if( myIsForegroundEnabled )
716 if( !myForegroundItem )
717 myForegroundItem = myScene->addRect( QRectF(), QPen(), QBrush( Qt::white ) );
718 myForegroundItem->setZValue( FOREGROUND_Z_VALUE );
720 QPointF aPoint = QPointF();
721 QRectF aRect( aPoint, myForegroundSize );
722 aRect.adjust( -myForegroundMargin, -myForegroundMargin,
723 myForegroundMargin, myForegroundMargin );
724 myForegroundItem->setRect( aRect );
726 QBrush aBrush = myForegroundItem->brush();
727 aBrush.setColor( myForegroundColor );
728 myForegroundItem->setBrush( aBrush );
730 QPen aPen = myForegroundItem->pen();
731 aPen.setColor( myForegroundFrameColor );
732 aPen.setWidthF( myForegroundFrameLineWidth );
733 myForegroundItem->setPen( aPen );
735 myForegroundItem->setVisible( true );
737 myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) );
741 if( myForegroundItem )
742 myForegroundItem->setVisible( false );
745 updateGrid(); // foreground size could be changed
748 //================================================================
749 // Function : setGridEnabled
751 //================================================================
752 void GraphicsView_ViewPort::setGridEnabled( bool theState )
754 myIsGridEnabled = theState;
757 //================================================================
758 // Function : setGridCellSize
760 //================================================================
761 void GraphicsView_ViewPort::setGridCellSize( int theCellSize )
763 myGridCellSize = theCellSize;
766 //================================================================
767 // Function : setGridLineStyle
769 //================================================================
770 void GraphicsView_ViewPort::setGridLineStyle( int theLineStyle )
772 myGridLineStyle = theLineStyle;
775 //================================================================
776 // Function : setGridLineColor
778 //================================================================
779 void GraphicsView_ViewPort::setGridLineColor( const QColor& theLineColor )
781 myGridLineColor = theLineColor;
784 //================================================================
785 // Function : updateGrid
787 //================================================================
788 void GraphicsView_ViewPort::updateGrid()
790 if( myIsGridEnabled )
793 myGridItem = myScene->addPath( QPainterPath() );
794 myGridItem->setZValue( GRID_Z_VALUE );
796 double aWidth = myForegroundSize.width();
797 double aHeight = myForegroundSize.height();
799 int aGridNbX = int( aWidth / myGridCellSize ) + 1;
800 int aGridNbY = int( aHeight / myGridCellSize ) + 1;
804 for( anIndex = 0; anIndex < aGridNbX; anIndex++ )
806 double x = myGridCellSize * (double)anIndex;
807 aPath.moveTo( x, 0 );
808 aPath.lineTo( x, aHeight );
810 for( anIndex = 0; anIndex < aGridNbY; anIndex++ )
812 double y = myGridCellSize * (double)anIndex;
813 aPath.moveTo( 0, y );
814 aPath.lineTo( aWidth, y );
816 myGridItem->setPath( aPath );
818 QPen aPen = myGridItem->pen();
819 aPen.setStyle( (Qt::PenStyle)myGridLineStyle );
820 aPen.setColor( myGridLineColor );
821 myGridItem->setPen( aPen );
823 myGridItem->setVisible( true );
828 myGridItem->setVisible( false );
832 //================================================================
835 //================================================================
836 void GraphicsView_ViewPort::reset()
841 //================================================================
844 //================================================================
845 void GraphicsView_ViewPort::pan( double theDX, double theDY )
847 myIsTransforming = true;
850 myViewLabel->setAcceptMoveEvents( false );
852 if( QScrollBar* aHBar = horizontalScrollBar() )
854 if( isUnlimitedPanning() )
856 int aNewValue = aHBar->value() - theDX;
857 if( aNewValue < aHBar->minimum() )
858 aHBar->setMinimum( aNewValue );
859 if( aNewValue > aHBar->maximum() )
860 aHBar->setMaximum( aNewValue );
862 aHBar->setValue( aHBar->value() - theDX );
864 if( QScrollBar* aVBar = verticalScrollBar() )
866 if( isUnlimitedPanning() )
868 int aNewValue = aVBar->value() + theDY;
869 if( aNewValue < aVBar->minimum() )
870 aVBar->setMinimum( aNewValue );
871 if( aNewValue > aVBar->maximum() )
872 aVBar->setMaximum( aNewValue );
874 aVBar->setValue( aVBar->value() + theDY );
878 myViewLabel->setAcceptMoveEvents( true );
880 myIsTransforming = false;
885 //================================================================
886 // Function : setCenter
888 //================================================================
889 void GraphicsView_ViewPort::setCenter( double theX, double theY )
891 myIsTransforming = true;
893 setTransform( myCurrentTransform );
894 centerOn( theX, theY );
896 myIsTransforming = false;
901 //================================================================
904 //================================================================
905 void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, double theY2 )
907 myIsTransforming = true;
909 double aDX = theX2 - theX1;
910 double aDY = theY2 - theY1;
911 double aZoom = sqrt( aDX * aDX + aDY * aDY ) / 100 + 1;
912 aZoom = ( aDX > 0 ) ? aZoom : 1 / aZoom;
914 QTransform aTransform = transform();
915 aTransform.scale( aZoom, aZoom );
916 double aM11 = aTransform.m11();
917 double aM22 = aTransform.m22();
920 QGraphicsView::ViewportAnchor old_anchor = transformationAnchor();
921 setTransformationAnchor( QGraphicsView::AnchorUnderMouse );
923 // increasing of diagonal coefficients (>300) leads to a crash sometimes
924 // at the values of 100 some primitives are drawn incorrectly
925 if( myZoomCoeff < 0 || qMax( aM11, aM22 ) < myZoomCoeff )
926 setTransform( aTransform );
928 myIsTransforming = false;
932 setTransformationAnchor( old_anchor );
935 //================================================================
936 // Function : fitRect
938 //================================================================
939 void GraphicsView_ViewPort::fitRect( const QRectF& theRect )
941 myIsTransforming = true;
943 fitInView( theRect, Qt::KeepAspectRatio );
945 myIsTransforming = false;
950 //================================================================
951 // Function : fitSelect
953 //================================================================
954 void GraphicsView_ViewPort::fitSelect()
956 myIsTransforming = true;
959 for( initSelected(); moreSelected(); nextSelected() )
961 if( GraphicsView_Object* aMovingObject = selectedObject() )
963 QRectF aRect = aMovingObject->getRect();
964 if( aGlobalRect.isNull() )
967 aGlobalRect |= aRect;
971 if( !aGlobalRect.isNull() )
973 double aGap = qMax( aGlobalRect.width(), aGlobalRect.height() ) / 5;
974 aGlobalRect.adjust( -aGap, -aGap, aGap, aGap );
975 fitInView( aGlobalRect, Qt::KeepAspectRatio );
978 myIsTransforming = false;
983 //================================================================
986 //================================================================
987 void GraphicsView_ViewPort::fitAll( bool theKeepScale )
989 myIsTransforming = true;
992 myCurrentTransform = transform();
994 double aGap = myFitAllGap;
995 QRectF aRect = objectsBoundingRect( true );
996 fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio );
998 myIsTransforming = false;
1003 //================================================================
1004 // Function : fitWidth
1006 //================================================================
1007 void GraphicsView_ViewPort::fitWidth()
1009 myIsTransforming = true;
1011 double aGap = myFitAllGap;
1012 QRectF aRect = objectsBoundingRect( true );
1014 double aTop = aRect.top();
1015 double aLeft = aRect.left();
1016 double aMargin = 10;
1018 aRect.setY( aRect.center().y() );
1019 aRect.setHeight( aMargin );
1021 fitInView( aRect.adjusted( -aGap, -aGap, aGap, aGap ), Qt::KeepAspectRatio );
1022 ensureVisible( aLeft, aTop, aMargin, aMargin, 0, aGap );
1024 myIsTransforming = false;
1029 //================================================================
1030 // Function : applyTransform
1032 //================================================================
1033 void GraphicsView_ViewPort::applyTransform()
1035 GraphicsView_ObjectListIterator anIter( getObjects() );
1036 while( anIter.hasNext() )
1037 if( GraphicsView_Object* anObject = anIter.next() )
1038 anObject->setViewTransform( transform() );
1041 //================================================================
1042 // Function : setZoomCoeff
1044 //================================================================
1045 void GraphicsView_ViewPort::setZoomCoeff( const int& theZoomCoeff )
1047 myZoomCoeff = theZoomCoeff;
1050 //================================================================
1051 // Function : setUnlimitedPanning
1053 //================================================================
1054 void GraphicsView_ViewPort::setUnlimitedPanning( const bool& theValue )
1056 if ( myUnlimitedPanning == theValue )
1059 myUnlimitedPanning = theValue;
1061 if( myUnlimitedPanning )
1063 myHBarPolicy = horizontalScrollBarPolicy();
1064 myVBarPolicy = verticalScrollBarPolicy();
1066 setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
1067 setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn );
1071 setHorizontalScrollBarPolicy( myHBarPolicy );
1072 setVerticalScrollBarPolicy( myVBarPolicy );
1076 //================================================================
1077 // Function : currentBlock
1079 //================================================================
1080 GraphicsView_ViewPort::BlockStatus GraphicsView_ViewPort::currentBlock()
1082 if( isDragging() && !myDragPosition.isNull() )
1083 return BlockStatus( BS_Selection );
1085 if( myAreSelectionPointsInitialized && ( myFirstSelectionPoint != myLastSelectionPoint ) )
1086 return BlockStatus( BS_Selection );
1089 return BlockStatus( BS_Selection );
1094 //================================================================
1095 // Function : highlight
1097 //================================================================
1098 void GraphicsView_ViewPort::highlight( double theX, double theY )
1100 myIsHighlighting = true;
1101 myHighlightX = theX;
1102 myHighlightY = theY;
1104 bool anIsHighlighted = false;
1105 bool anIsOnObject = false;
1107 GraphicsView_Object* aHighlightedObject = 0;
1111 GraphicsView_ObjectList aList = getObjects( SortByZLevel );
1112 GraphicsView_ObjectListIterator anIter( aList );
1113 anIter.toBack(); // objects with higher priority have to be checked earlier
1114 while( anIter.hasPrevious() )
1116 if( GraphicsView_Object* anObject = anIter.previous() )
1118 if( anObject->isVisible() && anObject->isSelectable() )
1120 if( anObject->checkHighlight( theX, theY, aCursor ) )
1122 anIsOnObject = true;
1123 anIsHighlighted = anObject->highlight( theX, theY );
1126 if( anIsHighlighted )
1128 aHighlightedObject = anObject;
1135 setCursor( aCursor );
1140 while( anIter.hasNext() )
1141 if( GraphicsView_Object* anObject = anIter.next() )
1142 anObject->unhighlight();
1144 myHighlightedObject = 0;
1147 else if( !myHighlightedObject && anIsHighlighted )
1149 myHighlightedObject = aHighlightedObject;
1151 else if( myHighlightedObject && !anIsHighlighted )
1153 myHighlightedObject->unhighlight();
1154 myHighlightedObject = 0;
1156 else if( myHighlightedObject && anIsHighlighted )
1158 myHighlightedObject->highlight( theX, theY );
1159 if( myHighlightedObject != aHighlightedObject )
1161 myHighlightedObject->unhighlight();
1162 myHighlightedObject = aHighlightedObject;
1167 //================================================================
1168 // Function : clearHighlighted
1170 //================================================================
1171 void GraphicsView_ViewPort::clearHighlighted()
1173 if( myHighlightedObject )
1175 myHighlightedObject->unhighlight();
1176 myHighlightedObject = 0;
1180 //================================================================
1181 // Function : select
1183 //================================================================
1184 int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend )
1186 if( !myIsHighlighting )
1187 return GVSS_NoChanged;
1189 GV_SelectionStatus aStatus = GVSS_Invalid;
1190 if( theRect.isNull() ) // point selection
1192 if( myHighlightedObject )
1194 if( mySelectedObjects.count() == 1 &&
1195 mySelectedObjects.first() == myHighlightedObject )
1196 aStatus = GVSS_LocalChanged;
1200 GraphicsView_ObjectListIterator anIter( mySelectedObjects );
1201 while( anIter.hasNext() )
1202 if( GraphicsView_Object* anObject = anIter.next() )
1203 if( myHighlightedObject != anObject )
1204 anObject->unselect();
1206 if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid )
1207 aStatus = GVSS_GlobalChanged;
1208 mySelectedObjects.clear();
1210 else if( myHighlightedObject->isSelected() && aStatus != GVSS_LocalChanged )
1212 mySelectedObjects.removeAll( myHighlightedObject );
1213 myHighlightedObject->unselect();
1215 if( !mySelectedObjects.isEmpty() && aStatus == GVSS_Invalid )
1216 aStatus = GVSS_GlobalChanged;
1221 if( myHighlightedObject->select( myHighlightX, myHighlightY, QRectF() ) &&
1222 mySelectedObjects.indexOf( myHighlightedObject ) == -1 )
1224 mySelectedObjects.append( myHighlightedObject );
1225 if( aStatus == GVSS_Invalid )
1226 aStatus = GVSS_GlobalChanged;
1228 else if( aStatus == GVSS_LocalChanged )
1229 aStatus = GVSS_GlobalChanged;
1234 if( !myHighlightedObject )
1238 GraphicsView_ObjectListIterator anIter( mySelectedObjects );
1239 while( anIter.hasNext() )
1240 if( GraphicsView_Object* anObject = anIter.next() )
1241 if( myHighlightedObject != anObject )
1242 anObject->unselect();
1244 if( !mySelectedObjects.isEmpty() )
1245 aStatus = GVSS_GlobalChanged;
1246 mySelectedObjects.clear();
1251 return GVSS_NoChanged;
1253 else // rectangle selection
1255 aStatus = GVSS_NoChanged;
1259 if( !mySelectedObjects.isEmpty() )
1260 aStatus = GVSS_GlobalChanged;
1262 GraphicsView_ObjectListIterator anIter( mySelectedObjects );
1263 while( anIter.hasNext() )
1264 if( GraphicsView_Object* anObject = anIter.next() )
1265 if( myHighlightedObject != anObject )
1266 anObject->unselect();
1267 mySelectedObjects.clear();
1270 QListIterator<QGraphicsItem*> anIter( items() );
1271 while( anIter.hasNext() )
1273 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
1275 if( anObject->isVisible() && anObject->isSelectable() )
1277 bool anIsSelected = false;
1278 QRectF aRect = anObject->getRect();
1279 if( theRect.contains( aRect ) && myIsHighlighting )
1280 anIsSelected = anObject->select( myHighlightX, myHighlightY, theRect );
1282 if( anIsSelected && mySelectedObjects.indexOf( anObject ) == -1 )
1284 mySelectedObjects.append( anObject );
1285 aStatus = GVSS_GlobalChanged;
1294 //================================================================
1295 // Function : clearSelected
1297 //================================================================
1298 void GraphicsView_ViewPort::clearSelected()
1300 GraphicsView_ObjectListIterator anIter( mySelectedObjects );
1301 while( anIter.hasNext() )
1302 if( GraphicsView_Object* anObject = anIter.next() )
1303 anObject->unselect();
1304 mySelectedObjects.clear();
1307 //================================================================
1308 // Function : setSelected
1310 //================================================================
1311 void GraphicsView_ViewPort::setSelected( GraphicsView_Object* theObject )
1315 theObject->setSelected( true );
1316 mySelectedObjects.append( theObject );
1320 //================================================================
1321 // Function : nbSelected
1323 //================================================================
1324 int GraphicsView_ViewPort::nbSelected() const
1326 return mySelectedObjects.count();
1329 //================================================================
1330 // Function : initSelected
1332 //================================================================
1333 void GraphicsView_ViewPort::initSelected()
1335 mySelectionIterator = 0;
1338 //================================================================
1339 // Function : moreSelected
1341 //================================================================
1342 bool GraphicsView_ViewPort::moreSelected()
1344 return mySelectionIterator < nbSelected();
1347 //================================================================
1348 // Function : nextSelected
1350 //================================================================
1351 bool GraphicsView_ViewPort::nextSelected()
1353 if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() )
1355 mySelectionIterator++;
1361 //================================================================
1362 // Function : selectedObject
1364 //================================================================
1365 GraphicsView_Object* GraphicsView_ViewPort::selectedObject()
1367 if( mySelectionIterator >= 0 && mySelectionIterator < nbSelected() )
1368 return mySelectedObjects[ mySelectionIterator ];
1372 //================================================================
1373 // Function : startSelectByRect
1375 //================================================================
1376 void GraphicsView_ViewPort::startSelectByRect( int x, int y )
1378 if( !myAreSelectionPointsInitialized )
1380 myFirstSelectionPoint = QPoint( x, y );
1381 myLastSelectionPoint = QPoint( x, y );
1382 myAreSelectionPointsInitialized = true;
1387 myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
1389 palette.setColor( myRectBand->foregroundRole(), Qt::white );
1390 myRectBand->setPalette( palette );
1395 //================================================================
1396 // Function : drawSelectByRect
1398 //================================================================
1399 void GraphicsView_ViewPort::drawSelectByRect( int x, int y )
1401 if( myAreSelectionPointsInitialized )
1405 myLastSelectionPoint.setX( x );
1406 myLastSelectionPoint.setY( y );
1408 QRect aRect = selectionRect();
1409 myRectBand->setGeometry( aRect );
1410 myRectBand->setVisible( aRect.isValid() );
1414 //================================================================
1415 // Function : isSelectByRect
1417 //================================================================
1418 bool GraphicsView_ViewPort::isSelectByRect() const
1420 return myAreSelectionPointsInitialized;
1423 //================================================================
1424 // Function : finishSelectByRect
1426 //================================================================
1427 void GraphicsView_ViewPort::finishSelectByRect()
1429 if( myAreSelectionPointsInitialized )
1438 myAreSelectionPointsInitialized = false;
1442 //================================================================
1443 // Function : selectionRect
1445 //================================================================
1446 QRect GraphicsView_ViewPort::selectionRect()
1449 if( myAreSelectionPointsInitialized )
1451 aRect.setLeft( qMin( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) );
1452 aRect.setTop( qMin( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) );
1453 aRect.setRight( qMax( myFirstSelectionPoint.x(), myLastSelectionPoint.x() ) );
1454 aRect.setBottom( qMax( myFirstSelectionPoint.y(), myLastSelectionPoint.y() ) );
1459 //================================================================
1460 // Function : prepareToSketch
1462 //================================================================
1463 void GraphicsView_ViewPort::prepareToSketch( bool theStatus )
1465 myIsPrepareToSketch = theStatus;
1467 setCursor( *getSketchCursor() );
1470 //================================================================
1471 // Function : isPrepareToSketch
1473 //================================================================
1474 bool GraphicsView_ViewPort::isPrepareToSketch()
1476 return myIsPrepareToSketch;
1479 //================================================================
1480 // Function : startSketching
1482 //================================================================
1483 void GraphicsView_ViewPort::startSketching( const QPointF& thePoint,
1486 prepareToSketch( false );
1488 if( !mySketchingItem )
1490 mySketchingItem = new QGraphicsPathItem();
1491 mySketchingItem->setZValue( SKETCH_Z_VALUE );
1493 QPen aPen = mySketchingItem->pen();
1494 aPen.setStyle( Qt::DotLine );
1495 mySketchingItem->setPen( aPen );
1497 addItem( mySketchingItem );
1500 mySketchingPoint = thePoint;
1503 aPath.moveTo( mySketchingPoint );
1504 mySketchingItem->setPath( aPath );
1505 mySketchingItem->setVisible( true );
1507 myIsSketching = true;
1508 myIsSketchingByPath = theIsPath;
1511 //================================================================
1512 // Function : drawSketching
1514 //================================================================
1515 void GraphicsView_ViewPort::drawSketching( const QPointF& thePoint )
1517 bool anIsPath = false;
1518 if( mySketchingItem && isSketching( &anIsPath ) )
1520 QPainterPath aPath = mySketchingItem->path();
1521 if( anIsPath ) // arbitrary path
1522 aPath.lineTo( thePoint );
1525 // make a valid rectangle
1526 double x1 = mySketchingPoint.x(), y1 = mySketchingPoint.y();
1527 double x2 = thePoint.x(), y2 = thePoint.y();
1528 QPointF aPoint1( qMin( x1, x2 ), qMin( y1, y2 ) );
1529 QPointF aPoint2( qMax( x1, x2 ), qMax( y1, y2 ) );
1530 QRectF aRect( aPoint1, aPoint2 );
1532 aPath = QPainterPath();
1533 aPath.addRect( aRect );
1535 mySketchingItem->setPath( aPath );
1539 //================================================================
1540 // Function : finishSketching
1542 //================================================================
1543 void GraphicsView_ViewPort::finishSketching( bool theStatus )
1545 prepareToSketch( false );
1547 mySketchingItem->setVisible( false );
1548 myIsSketching = false;
1550 setCursor( *getDefaultCursor() );
1554 QPainterPath aPath = mySketchingItem->path();
1555 emit vpSketchingFinished( aPath );
1559 //================================================================
1560 // Function : isSketching
1562 //================================================================
1563 bool GraphicsView_ViewPort::isSketching( bool* theIsPath ) const
1566 *theIsPath = myIsSketchingByPath;
1567 return myIsSketching;
1570 //================================================================
1571 // Function : setDraggingSelectedByLeftButton
1573 //================================================================
1574 void GraphicsView_ViewPort::setDraggingSelectedByLeftButton( const bool& theValue )
1576 myDraggingSelectedByLeftButton = theValue;
1579 //================================================================
1580 // Function : dragObjects
1582 //================================================================
1583 void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e )
1585 GraphicsView_Object* anObject = getHighlightedObject();
1587 if( myDragPosition.isNull() )
1589 myDragPosition = e->scenePos();
1593 GraphicsView_ObjectList anObjectsToMove;
1594 if( anObject && anObject->isMovable() && ( e->buttons() & Qt::LeftButton ) )
1596 if( anObject->isSelected() )
1598 for( initSelected(); moreSelected(); nextSelected() )
1599 if( GraphicsView_Object* aMovingObject = selectedObject() )
1600 if( aMovingObject->isMovable() )
1601 anObjectsToMove.append( aMovingObject );
1604 anObjectsToMove.append( anObject );
1606 else if( ( ( hasInteractionFlag( DraggingByMiddleButton ) && ( e->buttons() & Qt::MidButton ) ) ||
1607 ( isDraggingSelectedByLeftButton() && ( e->buttons() & Qt::LeftButton ) ) ) &&
1610 for( initSelected(); moreSelected(); nextSelected() )
1611 if( GraphicsView_Object* aMovingObject = selectedObject() )
1612 if( aMovingObject->isMovable() )
1613 anObjectsToMove.append( aMovingObject );
1616 if( anObjectsToMove.isEmpty() )
1619 double aDX = e->scenePos().x() - myDragPosition.x();
1620 double aDY = e->scenePos().y() - myDragPosition.y();
1622 bool anIsMovingByXAllowed = true, anIsMovingByYAllowed = true;
1623 GraphicsView_ObjectListIterator anIter( anObjectsToMove );
1624 while( anIter.hasNext() )
1625 if( GraphicsView_Object* aMovingObject = anIter.next() )
1627 if( !aMovingObject->isMovingByXAllowed( aDX ) )
1628 anIsMovingByXAllowed = false;
1629 if( !aMovingObject->isMovingByYAllowed( aDY ) )
1630 anIsMovingByYAllowed = false;
1633 if( !anIsMovingByXAllowed && !anIsMovingByYAllowed )
1634 return; // myDragPosition shouldn't be changed
1636 if( !anIsMovingByXAllowed )
1639 if( !anIsMovingByYAllowed )
1642 anIter = anObjectsToMove;
1643 while( anIter.hasNext() )
1644 if( GraphicsView_Object* aMovingObject = anIter.next() )
1645 aMovingObject->move( aDX, aDY );
1647 if( anIsMovingByXAllowed )
1648 myDragPosition.setX( e->scenePos().x() );
1650 if( anIsMovingByYAllowed )
1651 myDragPosition.setY( e->scenePos().y() );
1654 //================================================================
1655 // Function : startPulling
1657 //================================================================
1658 bool GraphicsView_ViewPort::startPulling( const QPointF& thePoint )
1660 QListIterator<QGraphicsItem*> anIter( items() );
1661 while( anIter.hasNext() )
1663 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
1665 QRectF aRect = anObject->getPullingRect();
1666 if( aRect.contains( thePoint ) && anObject->startPulling( thePoint ) )
1669 myPullingObject = anObject;
1670 //setCursor( *getHandCursor() ); // testing ImageViewer
1678 //================================================================
1679 // Function : drawPulling
1681 //================================================================
1682 void GraphicsView_ViewPort::drawPulling( const QPointF& thePoint )
1684 GraphicsView_Object* aLockedObject = 0;
1686 QListIterator<QGraphicsItem*> anIter( items() );
1687 while( anIter.hasNext() )
1689 if( GraphicsView_Object* anObject = dynamic_cast<GraphicsView_Object*>( anIter.next() ) )
1691 if( !anObject->isVisible() )
1694 QRectF aRect = anObject->getPullingRect();
1695 if( aRect.contains( thePoint ) && anObject->portContains( thePoint ) )
1697 aLockedObject = anObject;
1703 myPullingObject->pull( thePoint, aLockedObject, getSelectedObjects() );
1706 //================================================================
1707 // Function : finishPulling
1709 //================================================================
1710 void GraphicsView_ViewPort::finishPulling( bool theStatus )
1712 myIsPulling = false;
1713 myPullingObject->finishPulling( theStatus, getSelectedObjects() );
1714 setCursor( *getDefaultCursor() );
1717 //================================================================
1718 // Function : cancelCurrentOperation
1720 //================================================================
1721 bool GraphicsView_ViewPort::cancelCurrentOperation()
1723 myIsHighlighting = false;
1727 for( initSelected(); moreSelected(); nextSelected() )
1728 if( GraphicsView_Object* aMovingObject = selectedObject() )
1729 aMovingObject->finishMove( false );
1731 if( GraphicsView_Object* aMovingObject = getHighlightedObject() )
1732 aMovingObject->finishMove( false );
1734 myIsDragging = false;
1735 myDragPosition = QPointF();
1736 //setCursor( myStoredCursor );
1737 setCursor( *getDefaultCursor() );
1744 finishPulling( false );
1748 if( isSketching() || isPrepareToSketch() )
1750 finishSketching( false );
1757 //================================================================
1758 // Function : onBoundingRectChanged
1760 //================================================================
1761 void GraphicsView_ViewPort::onBoundingRectChanged()
1763 if( hasInteractionFlag( TraceBoundingRect ) )
1765 QRectF aRect = objectsBoundingRect( true );
1766 myScene->setSceneRect( aRect.adjusted( -mySceneGap, -mySceneGap, mySceneGap, mySceneGap ) );
1770 //================================================================
1771 // Function : onKeyEvent
1773 //================================================================
1774 void GraphicsView_ViewPort::onKeyEvent( QKeyEvent* e )
1776 emit vpKeyEvent( e );
1779 //================================================================
1780 // Function : onMouseEvent
1782 //================================================================
1783 void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e )
1785 emit vpMouseEvent( e );
1787 bool anIsHandled = false;
1790 case QEvent::GraphicsSceneMousePress:
1792 if( hasInteractionFlag( EditFlags ) && nbSelected() )
1793 for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
1794 if( GraphicsView_Object* anObject = selectedObject() )
1795 anIsHandled = anObject->handleMousePress( e );
1797 if( !anIsHandled && hasInteractionFlag( Dragging ) )
1799 bool anAccel = e->modifiers() & GraphicsView_ViewTransformer::accelKey();
1800 if( ( getHighlightedObject() &&
1801 getHighlightedObject()->isMovable() &&
1802 !( anAccel || e->button() != Qt::LeftButton ) ) ||
1803 ( ( ( hasInteractionFlag( DraggingByMiddleButton ) && e->button() == Qt::MidButton ) ||
1804 ( isDraggingSelectedByLeftButton() && e->button() == Qt::LeftButton ) ) &&
1805 nbSelected() && !anAccel ) )
1807 myIsDragging = true;
1808 myStoredCursor = cursor();
1809 setCursor( Qt::ClosedHandCursor );
1814 case QEvent::GraphicsSceneMouseMove:
1816 if( hasInteractionFlag( EditFlags ) && nbSelected() )
1817 for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
1818 if( GraphicsView_Object* anObject = selectedObject() )
1819 anIsHandled = anObject->handleMouseMove( e );
1821 if( !anIsHandled && !isPulling() && myIsDragging )
1825 case QEvent::GraphicsSceneMouseRelease:
1827 if( hasInteractionFlag( EditFlags ) && nbSelected() )
1828 for( initSelected(); moreSelected() && !anIsHandled; nextSelected() )
1829 if( GraphicsView_Object* anObject = selectedObject() )
1830 anIsHandled = anObject->handleMouseRelease( e );
1832 if( !anIsHandled && !isPulling() && myIsDragging )
1834 emit vpObjectBeforeMoving();
1836 bool anIsMoved = false;
1837 for( initSelected(); moreSelected(); nextSelected() )
1838 if( GraphicsView_Object* aMovingObject = selectedObject() )
1839 anIsMoved = aMovingObject->finishMove( true ) || anIsMoved;
1841 if( GraphicsView_Object* aMovingObject = getHighlightedObject() )
1842 anIsMoved = aMovingObject->finishMove( true ) || anIsMoved;
1844 myIsDragging = false;
1845 myDragPosition = QPointF();
1846 setCursor( myStoredCursor );
1848 emit vpObjectAfterMoving( anIsMoved );
1852 case QEvent::GraphicsSceneMouseDoubleClick:
1853 break; // do nothing, just emit the signal
1858 if( myIsMousePositionEnabled )
1860 int aMouseX = (int)e->scenePos().x();
1861 int aMouseY = (int)e->scenePos().y();
1862 setViewLabelText( QString( "(%1, %2)" ).arg( aMouseX ).arg( aMouseY ) );
1866 //================================================================
1867 // Function : onWheelEvent
1869 //================================================================
1870 void GraphicsView_ViewPort::onWheelEvent( QGraphicsSceneWheelEvent* e )
1872 emit vpWheelEvent( e );
1875 //================================================================
1876 // Function : onContextMenuEvent
1878 //================================================================
1879 void GraphicsView_ViewPort::onContextMenuEvent( QGraphicsSceneContextMenuEvent* e )
1881 emit vpContextMenuEvent( e );
1884 //================================================================
1885 // Function : scrollContentsBy
1887 //================================================================
1888 void GraphicsView_ViewPort::scrollContentsBy( int theDX, int theDY )
1891 myViewLabel->setAcceptMoveEvents( false );
1893 QGraphicsView::scrollContentsBy( theDX, theDY );
1896 myViewLabel->setAcceptMoveEvents( true );