X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGraphicsView%2FGraphicsView_ViewPort.cxx;h=2d0cbc40c56871d6854f3ff3a1d947d0d391cade;hb=refs%2Ftags%2FV9_11_0;hp=93e75b461dba58878b061181b951015a6478b8ea;hpb=7630c6fc03d9dbf6e68d0b6e95188afd5352fff1;p=modules%2Fgui.git diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 93e75b461..2d0cbc40c 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2013-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2013-2023 CEA, EDF, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -134,6 +134,7 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myForegroundItem( 0 ), myGridItem( 0 ), myIsTransforming( false ), + myUnlimitedPanning( false ), myHighlightedObject( 0 ), myHighlightX( 0 ), myHighlightY( 0 ), @@ -147,6 +148,7 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myIsSketchingByPath( false ), myIsDragging( false ), myIsDragPositionInitialized( false ), + myDraggingSelectedByLeftButton( false ), myIsPulling( false ), myPullingObject( 0 ), myStoredCursor( Qt::ArrowCursor ), @@ -194,6 +196,9 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) QPainter::SmoothPixmapTransform | QPainter::HighQualityAntialiasing ); + myHBarPolicy = horizontalScrollBarPolicy(); + myVBarPolicy = verticalScrollBarPolicy(); + connect( myScene, SIGNAL( gsKeyEvent( QKeyEvent* ) ), this, SLOT( onKeyEvent( QKeyEvent* ) ) ); connect( myScene, SIGNAL( gsMouseEvent( QGraphicsSceneMouseEvent* ) ), @@ -280,7 +285,7 @@ void GraphicsView_ViewPort::addItem( QGraphicsItem* theItem ) //================================================================ bool GraphicsView_ViewPort::isItemAdded( QGraphicsItem* theItem ) { - if( GraphicsView_Object* anObject = dynamic_cast( theItem ) ) + if( dynamic_cast( theItem ) ) { for( GraphicsView_ObjectList::iterator anIter = myObjects.begin(); anIter != myObjects.end(); anIter++ ) if( theItem == *anIter ) @@ -469,10 +474,13 @@ QImage GraphicsView_ViewPort::dumpView( bool theWholeScene, return anImage; } -bool GraphicsView_ViewPort::dumpViewToPSFormat(const QString& fileName) +bool GraphicsView_ViewPort::dumpViewToFormat(const QString& fileName, const QString& format) { + if( format!="PS" && format!="EPS" ) + return false; + QPrinter printer(QPrinter::ScreenResolution); - printer.setOutputFormat(QPrinter::PostScriptFormat); + printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); QPainter painter; if (!painter.begin(&printer)) @@ -842,9 +850,29 @@ void GraphicsView_ViewPort::pan( double theDX, double theDY ) myViewLabel->setAcceptMoveEvents( false ); if( QScrollBar* aHBar = horizontalScrollBar() ) + { + if( isUnlimitedPanning() ) + { + int aNewValue = aHBar->value() - theDX; + if( aNewValue < aHBar->minimum() ) + aHBar->setMinimum( aNewValue ); + if( aNewValue > aHBar->maximum() ) + aHBar->setMaximum( aNewValue ); + } aHBar->setValue( aHBar->value() - theDX ); + } if( QScrollBar* aVBar = verticalScrollBar() ) + { + if( isUnlimitedPanning() ) + { + int aNewValue = aVBar->value() + theDY; + if( aNewValue < aVBar->minimum() ) + aVBar->setMinimum( aNewValue ); + if( aNewValue > aVBar->maximum() ) + aVBar->setMaximum( aNewValue ); + } aVBar->setValue( aVBar->value() + theDY ); + } if( myViewLabel ) myViewLabel->setAcceptMoveEvents( true ); @@ -887,6 +915,11 @@ void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, doub aTransform.scale( aZoom, aZoom ); double aM11 = aTransform.m11(); double aM22 = aTransform.m22(); + + + QGraphicsView::ViewportAnchor old_anchor = transformationAnchor(); + setTransformationAnchor( QGraphicsView::AnchorUnderMouse ); + // increasing of diagonal coefficients (>300) leads to a crash sometimes // at the values of 100 some primitives are drawn incorrectly if( myZoomCoeff < 0 || qMax( aM11, aM22 ) < myZoomCoeff ) @@ -895,6 +928,8 @@ void GraphicsView_ViewPort::zoom( double theX1, double theY1, double theX2, doub myIsTransforming = false; applyTransform(); + + setTransformationAnchor( old_anchor ); } //================================================================ @@ -1012,6 +1047,32 @@ void GraphicsView_ViewPort::setZoomCoeff( const int& theZoomCoeff ) myZoomCoeff = theZoomCoeff; } +//================================================================ +// Function : setUnlimitedPanning +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setUnlimitedPanning( const bool& theValue ) +{ + if ( myUnlimitedPanning == theValue ) + return; + + myUnlimitedPanning = theValue; + + if( myUnlimitedPanning ) + { + myHBarPolicy = horizontalScrollBarPolicy(); + myVBarPolicy = verticalScrollBarPolicy(); + + setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOn ); + } + else + { + setHorizontalScrollBarPolicy( myHBarPolicy ); + setVerticalScrollBarPolicy( myVBarPolicy ); + } +} + //================================================================ // Function : currentBlock // Purpose : @@ -1043,7 +1104,6 @@ void GraphicsView_ViewPort::highlight( double theX, double theY ) bool anIsHighlighted = false; bool anIsOnObject = false; - GraphicsView_Object* aPreviousHighlightedObject = myHighlightedObject; GraphicsView_Object* aHighlightedObject = 0; QCursor aCursor; @@ -1194,7 +1254,6 @@ int GraphicsView_ViewPort::select( const QRectF& theRect, bool theIsAppend ) { aStatus = GVSS_NoChanged; - bool updateAll = false; if( !theIsAppend ) { if( !mySelectedObjects.isEmpty() ) @@ -1508,6 +1567,15 @@ bool GraphicsView_ViewPort::isSketching( bool* theIsPath ) const return myIsSketching; } +//================================================================ +// Function : setDraggingSelectedByLeftButton +// Purpose : +//================================================================ +void GraphicsView_ViewPort::setDraggingSelectedByLeftButton( const bool& theValue ) +{ + myDraggingSelectedByLeftButton = theValue; +} + //================================================================ // Function : dragObjects // Purpose : @@ -1535,8 +1603,9 @@ void GraphicsView_ViewPort::dragObjects( QGraphicsSceneMouseEvent* e ) else anObjectsToMove.append( anObject ); } - else if( hasInteractionFlag( DraggingByMiddleButton ) && - nbSelected() && ( e->buttons() & Qt::MidButton ) ) + else if( ( ( hasInteractionFlag( DraggingByMiddleButton ) && ( e->buttons() & Qt::MidButton ) ) || + ( isDraggingSelectedByLeftButton() && ( e->buttons() & Qt::LeftButton ) ) ) && + nbSelected() ) { for( initSelected(); moreSelected(); nextSelected() ) if( GraphicsView_Object* aMovingObject = selectedObject() ) @@ -1731,8 +1800,9 @@ void GraphicsView_ViewPort::onMouseEvent( QGraphicsSceneMouseEvent* e ) if( ( getHighlightedObject() && getHighlightedObject()->isMovable() && !( anAccel || e->button() != Qt::LeftButton ) ) || - ( hasInteractionFlag( DraggingByMiddleButton ) && - nbSelected() && !anAccel && e->button() == Qt::MidButton ) ) + ( ( ( hasInteractionFlag( DraggingByMiddleButton ) && e->button() == Qt::MidButton ) || + ( isDraggingSelectedByLeftButton() && e->button() == Qt::LeftButton ) ) && + nbSelected() && !anAccel ) ) { myIsDragging = true; myStoredCursor = cursor();