From: CHEMIN Sebastien Date: Mon, 4 Mar 2024 15:32:03 +0000 (+0100) Subject: Redo transformations (zoom, fitSelect, fitAll) X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=456953f57a4cb5112bf7551c9f868d62ef7ecc8a;p=modules%2Fgui.git Redo transformations (zoom, fitSelect, fitAll) --- diff --git a/src/GraphicsView/CMakeLists.txt b/src/GraphicsView/CMakeLists.txt index 3c562f921..5e96f3e68 100644 --- a/src/GraphicsView/CMakeLists.txt +++ b/src/GraphicsView/CMakeLists.txt @@ -52,7 +52,7 @@ SET(_other_HEADERS GraphicsView.h GraphicsView_Defs.h GraphicsView_Object.h - GraphicsView_ViewTransformer.h +# GraphicsView_ViewTransformer.h ) # header files / to install @@ -95,7 +95,7 @@ SET(_other_SOURCES GraphicsView_ViewFrame.cxx GraphicsView_ViewManager.cxx GraphicsView_ViewPort.cxx - GraphicsView_ViewTransformer.cxx +# GraphicsView_ViewTransformer.cxx GraphicsView_Viewer.cxx ) diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index 9dd7639cf..2570c048b 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -309,7 +309,7 @@ void GraphicsView_ViewFrame::expandToolBarActions() //================================================================ void GraphicsView_ViewFrame::onViewPan() { - myViewer->activateTransform( GraphicsView_Viewer::Pan ); +// myViewer->activateTransform( GraphicsView_Viewer::Pan ); } //================================================================ @@ -318,7 +318,7 @@ void GraphicsView_ViewFrame::onViewPan() //================================================================ void GraphicsView_ViewFrame::onViewZoom() { - myViewer->activateTransform( GraphicsView_Viewer::Zoom ); +// myViewer->activateTransform( GraphicsView_Viewer::Zoom ); } //================================================================ @@ -327,7 +327,8 @@ void GraphicsView_ViewFrame::onViewZoom() //================================================================ void GraphicsView_ViewFrame::onViewFitAll() { - myViewer->activateTransform( GraphicsView_Viewer::FitAll ); + myViewer->fitAll(); +// myViewer->activateTransform( GraphicsView_Viewer::FitAll ); } //================================================================ @@ -336,7 +337,8 @@ void GraphicsView_ViewFrame::onViewFitAll() //================================================================ void GraphicsView_ViewFrame::onViewFitArea() { - myViewer->activateTransform( GraphicsView_Viewer::FitRect ); + myViewer->fitArea(); +// myViewer->activateTransform( GraphicsView_Viewer::FitRect ); } //================================================================ @@ -345,7 +347,8 @@ void GraphicsView_ViewFrame::onViewFitArea() //================================================================ void GraphicsView_ViewFrame::onViewFitSelect() { - myViewer->activateTransform( GraphicsView_Viewer::FitSelect ); + myViewer->fitSelect(); +// myViewer->activateTransform( GraphicsView_Viewer::FitSelect ); } //================================================================ @@ -354,7 +357,7 @@ void GraphicsView_ViewFrame::onViewFitSelect() //================================================================ void GraphicsView_ViewFrame::onViewGlobalPan() { - myViewer->activateTransform( GraphicsView_Viewer::PanGlobal ); +// myViewer->activateTransform( GraphicsView_Viewer::PanGlobal ); } //================================================================ @@ -363,7 +366,7 @@ void GraphicsView_ViewFrame::onViewGlobalPan() //================================================================ void GraphicsView_ViewFrame::onViewReset() { - myViewer->activateTransform( GraphicsView_Viewer::Reset ); +// myViewer->activateTransform( GraphicsView_Viewer::Reset ); } //================================================================ diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 5c24397ce..d127eda6e 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -42,6 +42,7 @@ GraphicsView_ViewPort::GraphicsView_ViewPort( QWidget* theParent ) myRectBand = nullptr; myRectBandStart = QPoint(); myRectBandEnd = QPoint(); + fittingArea = false; } #include //======================================================================= @@ -131,12 +132,17 @@ void GraphicsView_ViewPort::finishSelectByRect() myRectBand->hide(); QRectF selectionRect = mapToScene(myRectBand->geometry()).boundingRect(); -// fitInView(selectionRect, Qt::KeepAspectRatio); + if (fittingArea) + fitInView(selectionRect, Qt::KeepAspectRatio); + else + { QList selectedItems = scene()->items(selectionRect, Qt::IntersectsItemShape); for (QGraphicsItem *item : selectedItems) item->setSelected(true); + } + fittingArea = false; myRectBandStart = QPoint(); myRectBandEnd = QPoint(); delete myRectBand; diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index aecf6a82c..5b5fe2944 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -53,6 +53,7 @@ public: void drawSelectByRect( int x, int y ); void finishSelectByRect(); QRect selectionRect(); + void setFitArea(bool isFitting) { fittingArea = isFitting; } signals: void vpMouseEvent(QMouseEvent*); @@ -74,6 +75,8 @@ private: QRubberBand* myRectBand; QPoint myRectBandStart; QPoint myRectBandEnd; + + bool fittingArea; }; #endif diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index ee7878d40..eaf21ceba 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -24,7 +24,7 @@ #include "GraphicsView_Scene.h" #include "GraphicsView_ViewFrame.h" #include "GraphicsView_ViewPort.h" -#include "GraphicsView_ViewTransformer.h" +//#include "GraphicsView_ViewTransformer.h" #include @@ -53,7 +53,7 @@ GraphicsView_Viewer::GraphicsView_Viewer( const QString& /*title*/, QWidget* widget ) : SUIT_ViewModel(), mySelector( 0 ), - myTransformer( 0 ), +// myTransformer( 0 ), myWidget( widget ), myIsInitialized( false ) { @@ -161,6 +161,7 @@ GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const // Function : activateTransform // Purpose : //================================================================ +/* void GraphicsView_Viewer::activateTransform( int theType ) { if( theType == NoTransform ) // finish current transform @@ -205,7 +206,7 @@ GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theTyp //================================================================ void GraphicsView_Viewer::onTransformationStarted() { -/* + if( GraphicsView_Selector* aSelector = getSelector() ) { aSelector->undetectAll(); @@ -214,7 +215,7 @@ void GraphicsView_Viewer::onTransformationStarted() // watch events: any mouse/key event outside the // viewport will be considered as the end of transform -*/ + if( myTransformer ) qApp->installEventFilter( this ); @@ -226,15 +227,16 @@ void GraphicsView_Viewer::onTransformationStarted() //================================================================ void GraphicsView_Viewer::onTransformationFinished() { -/* + if( GraphicsView_Selector* aSelector = getSelector() ) aSelector->lock( false ); // enable selection -*/ + // stop watching events if( myTransformer ) qApp->removeEventFilter( this ); } +*/ //================================================================ // Function : onKeyEvent @@ -359,3 +361,21 @@ void GraphicsView_Viewer::onSelectionCancel() { emit selectionChanged( GVSCS_Invalid ); } + +void GraphicsView_Viewer::fitAll() +{ + if (GraphicsView_ViewPort* aViewPort = getActiveViewPort()) + aViewPort->fitAll(); +} + +void GraphicsView_Viewer::fitSelect() +{ + if (GraphicsView_ViewPort* aViewPort = getActiveViewPort()) + aViewPort->fitSelect(); +} + +void GraphicsView_Viewer::fitArea() +{ + if (GraphicsView_ViewPort* aViewPort = getActiveViewPort()) + aViewPort->setFitArea(true); +} diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index d941e6c72..6058af49b 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -37,7 +37,7 @@ class SUIT_ViewWindow; class GraphicsView_Selector; class GraphicsView_Scene; -class GraphicsView_ViewTransformer; +//class GraphicsView_ViewTransformer; class GraphicsView_ViewFrame; class GraphicsView_ViewPort; @@ -50,8 +50,8 @@ class GRAPHICSVIEW_API GraphicsView_Viewer: public SUIT_ViewModel Q_OBJECT public: - enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect, - Zoom, PanGlobal, Pan, FitWidth, UserTransform = 100 }; +// enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect, +// Zoom, PanGlobal, Pan, FitWidth, UserTransform = 100 }; public: GraphicsView_Viewer( const QString& title, QWidget* widget = NULL ); ~GraphicsView_Viewer(); @@ -71,7 +71,11 @@ public: GraphicsView_ViewPort* getActiveViewPort() const; GraphicsView_Scene* getActiveScene() const; - void activateTransform( int ); + //void activateTransform( int ); + + void fitAll(); + void fitSelect(); + void fitArea(); bool isInitialized() const { return myIsInitialized; } void setIsInitialized( bool ); @@ -81,11 +85,11 @@ signals: void wheelScaleChanged(); protected: - virtual GraphicsView_ViewTransformer* createTransformer( int ); +// virtual GraphicsView_ViewTransformer* createTransformer( int ); virtual GraphicsView_ViewFrame* createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget ); - virtual void onTransformationStarted(); - virtual void onTransformationFinished(); +// virtual void onTransformationStarted(); +// virtual void onTransformationFinished(); protected slots: virtual void onKeyEvent( QKeyEvent* ); @@ -114,7 +118,7 @@ protected: protected: GraphicsView_Selector* mySelector; - GraphicsView_ViewTransformer* myTransformer; +// GraphicsView_ViewTransformer* myTransformer; QWidget* myWidget; bool myIsInitialized;