From d8e1497ef3cae08db8deb1400066f73d4d56a862 Mon Sep 17 00:00:00 2001 From: CHEMIN Sebastien Date: Wed, 13 Mar 2024 09:55:36 +0100 Subject: [PATCH] Cleaning viewer (in progress) --- src/GraphicsView/GraphicsView_Selector.cxx | 15 +- src/GraphicsView/GraphicsView_Selector.h | 14 +- src/GraphicsView/GraphicsView_Viewer.cxx | 179 +++++++-------------- src/GraphicsView/GraphicsView_Viewer.h | 45 +----- src/LightApp/LightApp_GVSelector.cxx | 6 +- src/LightApp/LightApp_GVSelector.h | 3 +- 6 files changed, 76 insertions(+), 186 deletions(-) diff --git a/src/GraphicsView/GraphicsView_Selector.cxx b/src/GraphicsView/GraphicsView_Selector.cxx index 8de409fec..7b7e3d55c 100644 --- a/src/GraphicsView/GraphicsView_Selector.cxx +++ b/src/GraphicsView/GraphicsView_Selector.cxx @@ -19,17 +19,14 @@ #include "GraphicsView_Selector.h" #include "GraphicsView_Viewer.h" -#include "GraphicsView_ViewPort.h" -#include "GraphicsView_ViewFrame.h" //======================================================================= // Name : GraphicsView_Selector // Purpose : Constructor //======================================================================= -GraphicsView_Selector::GraphicsView_Selector( GraphicsView_Viewer* theViewer ) -: QObject( 0 ), - myViewer( theViewer ), - myLocked( false ) +GraphicsView_Selector::GraphicsView_Selector(GraphicsView_Viewer* theViewer) +: QObject( nullptr ), + myViewer(theViewer) { } @@ -41,13 +38,11 @@ GraphicsView_Selector::~GraphicsView_Selector() { } - - //================================================================ // Function : select // Purpose : //================================================================ -void GraphicsView_Selector::select( const QRectF& selRect, bool append ) +void GraphicsView_Selector::select( const QRectF& selRect) { - emit selSelectionDone(GVSCS_Global); + emit selSelectionDone(); } diff --git a/src/GraphicsView/GraphicsView_Selector.h b/src/GraphicsView/GraphicsView_Selector.h index e17639f4a..d1815f380 100644 --- a/src/GraphicsView/GraphicsView_Selector.h +++ b/src/GraphicsView/GraphicsView_Selector.h @@ -22,8 +22,6 @@ #include "GraphicsView.h" -#include "GraphicsView_Defs.h" - #include #include @@ -38,22 +36,18 @@ class GRAPHICSVIEW_API GraphicsView_Selector : public QObject Q_OBJECT public: - GraphicsView_Selector( GraphicsView_Viewer* ); + GraphicsView_Selector(GraphicsView_Viewer*); ~GraphicsView_Selector(); public: - void lock( bool theState ) { myLocked = theState; } - virtual void select( const QRectF&, bool append = false ); + virtual void select(const QRectF&); signals: - void selSelectionDone( GV_SelectionChangeStatus ); - void selSelectionCancel(); + void selSelectionDone(); protected: - GraphicsView_Viewer* myViewer; - bool myLocked; - + GraphicsView_Viewer* myViewer; }; #endif diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index 9c593f619..0117fdce1 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -24,7 +24,6 @@ #include "GraphicsView_Scene.h" #include "GraphicsView_ViewFrame.h" #include "GraphicsView_ViewPort.h" -//#include "GraphicsView_ViewTransformer.h" #include @@ -32,8 +31,7 @@ #include #include -#include -#include +#include #include #include @@ -47,9 +45,7 @@ GraphicsView_Viewer::GraphicsView_Viewer( const QString& /*title*/, QWidget* widget ) : SUIT_ViewModel(), mySelector( 0 ), -// myTransformer( 0 ), - myWidget( widget ), - myIsInitialized( false ) + myWidget( widget ) { } @@ -75,6 +71,12 @@ SUIT_ViewWindow* GraphicsView_Viewer::createView( SUIT_Desktop* theDesktop ) { GraphicsView_ViewFrame* aViewFrame = createViewFrame( theDesktop, myWidget ); + connect( aViewFrame, SIGNAL( keyPressed( QKeyEvent* ) ), + this, SLOT( onKeyEvent( QKeyEvent* ) ) ); + + connect( aViewFrame, SIGNAL( keyReleased( QKeyEvent* ) ), + this, SLOT( onKeyEvent( QKeyEvent* ) ) ); + connect( aViewFrame, SIGNAL( mousePressed( QMouseEvent* ) ), this, SLOT( onMouseEvent( QMouseEvent* ) ) ); @@ -108,12 +110,7 @@ GraphicsView_Selector* GraphicsView_Viewer::getSelector() { mySelector = new GraphicsView_Selector( this ); if( mySelector ) - { - connect( mySelector, SIGNAL( selSelectionDone( GV_SelectionChangeStatus ) ), - this, SLOT( onSelectionDone( GV_SelectionChangeStatus ) ) ); - connect( mySelector, SIGNAL( selSelectionCancel() ), - this, SLOT( onSelectionCancel() ) ); - } + connect( mySelector, SIGNAL(selSelectionDone()), this, SLOT( onSelectionDone())); } return mySelector; } @@ -126,7 +123,7 @@ GraphicsView_ViewFrame* GraphicsView_Viewer::getActiveView() const { if( SUIT_ViewManager* aViewManager = getViewManager() ) return dynamic_cast( aViewManager->getActiveView() ); - return NULL; + return nullptr; } //================================================================ @@ -137,7 +134,7 @@ GraphicsView_ViewPort* GraphicsView_Viewer::getActiveViewPort() const { if( GraphicsView_ViewFrame* aViewFrame = getActiveView() ) return aViewFrame->getViewPort(); - return NULL; + return nullptr; } //================================================================ @@ -148,97 +145,15 @@ GraphicsView_Scene* GraphicsView_Viewer::getActiveScene() const { if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) return dynamic_cast( aViewPort->scene() ); - return NULL; -} - -//================================================================ -// Function : activateTransform -// Purpose : -//================================================================ -/* -void GraphicsView_Viewer::activateTransform( int theType ) -{ - if( theType == NoTransform ) // finish current transform - { - if ( myTransformer ) - { - onTransformationFinished(); - delete myTransformer; - myTransformer = 0; - } - } - else // activate new transform - { - activateTransform( NoTransform ); - myTransformer = createTransformer( theType ); - onTransformationStarted(); - myTransformer->exec(); - } + return nullptr; } -//================================================================ -// Function : setIsInitialized -// Purpose : -//================================================================ -void GraphicsView_Viewer::setIsInitialized( bool theFlag ) -{ - myIsInitialized = theFlag; -} - -//================================================================ -// Function : createTransformer -// Purpose : -//================================================================ -GraphicsView_ViewTransformer* GraphicsView_Viewer::createTransformer( int theType ) -{ - return new GraphicsView_ViewTransformer( this, theType ); -} - -//================================================================ -// Function : onTransformationStarted -// Purpose : -//================================================================ -void GraphicsView_Viewer::onTransformationStarted() -{ - - if( GraphicsView_Selector* aSelector = getSelector() ) - { - aSelector->undetectAll(); - aSelector->lock( true ); // disable selection - } - - // watch events: any mouse/key event outside the - // viewport will be considered as the end of transform - - if( myTransformer ) - qApp->installEventFilter( this ); - -} - -//================================================================ -// Function : onTransformationFinished -// Purpose : -//================================================================ -void GraphicsView_Viewer::onTransformationFinished() -{ - - if( GraphicsView_Selector* aSelector = getSelector() ) - aSelector->lock( false ); // enable selection - - // stop watching events - if( myTransformer ) - qApp->removeEventFilter( this ); - -} -*/ - //================================================================ // Function : onKeyEvent // Purpose : //================================================================ void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e ) { -/* switch( e->type() ) { case QEvent::KeyPress: @@ -249,26 +164,24 @@ void GraphicsView_Viewer::onKeyEvent( QKeyEvent* e ) break; default: break; } -*/ } //================================================================ // Function : onMouseEvent // Purpose : //================================================================ -void GraphicsView_Viewer::onMouseEvent( QMouseEvent* e ) +void GraphicsView_Viewer::onMouseEvent(QMouseEvent* e) { - switch( e->type() ) { case QEvent::MouseButtonPress: - handleMousePress( e ); + handleMousePress(e); break; case QEvent::MouseMove: - handleMouseMove( e ); + handleMouseMove(e); break; case QEvent::MouseButtonRelease: - handleMouseRelease( e ); + handleMouseRelease(e); break; default: break; } @@ -277,12 +190,12 @@ void GraphicsView_Viewer::onMouseEvent( QMouseEvent* e ) // Function : onWheelEvent // Purpose : //================================================================ -void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e ) +void GraphicsView_Viewer::onWheelEvent(QWheelEvent* e) { - switch( e->type() ) + switch(e->type()) { - case QEvent::GraphicsSceneWheel: - handleWheel( e ); + case QEvent::Wheel: + handleWheel(e); break; default: break; } @@ -293,67 +206,85 @@ void GraphicsView_Viewer::onWheelEvent( QGraphicsSceneWheelEvent* e ) // Purpose : //================================================================ void GraphicsView_Viewer::handleKeyPress( QKeyEvent* e ) -{ +{ + Q_UNUSED(e); } //================================================================ // Function : handleKeyRelease // Purpose : //================================================================ -void GraphicsView_Viewer::handleKeyRelease( QKeyEvent* /*e*/ ) //!< TODO: unused variable +void GraphicsView_Viewer::handleKeyRelease(QKeyEvent* e) { + Q_UNUSED(e); } //================================================================ // Function : handleMousePress // Purpose : //================================================================ -void GraphicsView_Viewer::handleMousePress( QMouseEvent* e ) +void GraphicsView_Viewer::handleMousePress(QMouseEvent* e) { + Q_UNUSED(e); } -void GraphicsView_Viewer::handleWheel( QGraphicsSceneWheelEvent* e ) +void GraphicsView_Viewer::handleWheel(QWheelEvent* e) { + Q_UNUSED(e); } //================================================================ // Function : handleMouseMove // Purpose : //================================================================ -void GraphicsView_Viewer::handleMouseMove( QMouseEvent* e ) +void GraphicsView_Viewer::handleMouseMove(QMouseEvent* e) { + Q_UNUSED(e); } //================================================================ // Function : handleMouseRelease // Purpose : //================================================================ -void GraphicsView_Viewer::handleMouseRelease( QMouseEvent* e ) +void GraphicsView_Viewer::handleMouseRelease(QMouseEvent* e) { GraphicsView_ViewPort* aViewPort = getActiveViewPort(); if ( getSelector() ) - { - getSelector()->select( aViewPort->selectionRect(), true ); - } + getSelector()->select(aViewPort->selectionRect()); } - //================================================================ -// Function : onSelectionDone +// Function : onChangeBgColor // Purpose : //================================================================ -void GraphicsView_Viewer::onSelectionDone( GV_SelectionChangeStatus theStatus ) +/* +void GraphicsView_Viewer::onChangeBgColor() { - emit selectionChanged( theStatus ); + if( GraphicsView_ViewPort* aViewPort = getActiveViewPort() ) + { + QColor aColor = aViewPort->isForegroundEnabled() ? + aViewPort->foregroundColor() : aViewPort->backgroundColor(); + aColor = QColorDialog::getColor( aColor, aViewPort ); + if ( aColor.isValid() ) + { + if( aViewPort->isForegroundEnabled() ) + { + aViewPort->setForegroundColor( aColor ); + aViewPort->updateForeground(); + } + else + aViewPort->setBackgroundColor( aColor ); + } + } } - +*/ //================================================================ -// Function : onSelectionCancel +// Function : onSelectionDone // Purpose : //================================================================ -void GraphicsView_Viewer::onSelectionCancel() +void GraphicsView_Viewer::onSelectionDone() { - emit selectionChanged( GVSCS_Invalid ); + emit selectionChanged(); } void GraphicsView_Viewer::fitAll() diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index 5ac77cabb..a45f6cb34 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -21,23 +21,17 @@ #define GRAPHICSVIEW_VIEWER_H #include "GraphicsView.h" - -#include "GraphicsView_Defs.h" - #include - #include -class QGraphicsSceneMouseEvent; -class QGraphicsSceneWheelEvent; class QKeyEvent; class QMouseEvent; +class QWheelEvent; class SUIT_ViewWindow; class GraphicsView_Selector; class GraphicsView_Scene; -//class GraphicsView_ViewTransformer; class GraphicsView_ViewFrame; class GraphicsView_ViewPort; @@ -50,10 +44,7 @@ class GRAPHICSVIEW_API GraphicsView_Viewer: public SUIT_ViewModel Q_OBJECT public: -// enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect, -// Zoom, PanGlobal, Pan, FitWidth, UserTransform = 100 }; -public: - GraphicsView_Viewer( const QString& title, QWidget* widget = NULL ); + GraphicsView_Viewer( const QString& title, QWidget* widget = nullptr ); ~GraphicsView_Viewer(); public: @@ -71,40 +62,25 @@ public: GraphicsView_ViewPort* getActiveViewPort() const; GraphicsView_Scene* getActiveScene() const; - //void activateTransform( int ); - void fitAll(); void fitSelect(); void fitArea(); void zoom(); void pan(); - bool isInitialized() const { return myIsInitialized; } - void setIsInitialized( bool ); - signals: - void selectionChanged( GV_SelectionChangeStatus ); - void wheelScaleChanged(); + void selectionChanged(); protected: -// virtual GraphicsView_ViewTransformer* createTransformer( int ); - virtual GraphicsView_ViewFrame* createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget ); -// virtual void onTransformationStarted(); -// virtual void onTransformationFinished(); + virtual GraphicsView_ViewFrame* createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget ); protected slots: virtual void onKeyEvent( QKeyEvent* ); virtual void onMouseEvent( QMouseEvent* ); - virtual void onWheelEvent( QGraphicsSceneWheelEvent* ); - -// virtual void onSketchingFinished( QPainterPath ); - - virtual void onSelectionDone( GV_SelectionChangeStatus ); - virtual void onSelectionCancel(); - -// virtual void onChangeBgColor(); + virtual void onWheelEvent( QWheelEvent* ); + virtual void onSelectionDone(); protected: virtual void handleKeyPress( QKeyEvent* ); @@ -112,18 +88,13 @@ protected: virtual void handleMouseMove( QMouseEvent* ); virtual void handleMousePress( QMouseEvent* ); virtual void handleMouseRelease( QMouseEvent* ); - virtual void handleWheel( QGraphicsSceneWheelEvent* ); + virtual void handleWheel(QWheelEvent*); - // testing ImageViewer - enum QueueOperation { BringToFront, SendToBack, BringForward, SendBackward }; - void processQueueOperation( const QueueOperation ); + // virtual void onChangeBgColor(); protected: GraphicsView_Selector* mySelector; -// GraphicsView_ViewTransformer* myTransformer; QWidget* myWidget; - - bool myIsInitialized; }; #endif diff --git a/src/LightApp/LightApp_GVSelector.cxx b/src/LightApp/LightApp_GVSelector.cxx index 061fcd943..9126d32a3 100644 --- a/src/LightApp/LightApp_GVSelector.cxx +++ b/src/LightApp/LightApp_GVSelector.cxx @@ -30,8 +30,8 @@ LightApp_GVSelector::LightApp_GVSelector( GraphicsView_Viewer* theViewer, : SUIT_Selector( theSelMgr, theViewer ), myViewer( theViewer ) { - connect( theViewer, SIGNAL( selectionChanged( GV_SelectionChangeStatus ) ), - this, SLOT( onSelectionChanged( GV_SelectionChangeStatus ) ) ); + connect( theViewer, SIGNAL( selectionChanged() ), + this, SLOT( onSelectionChanged() ) ); } LightApp_GVSelector::~LightApp_GVSelector() @@ -90,7 +90,7 @@ void LightApp_GVSelector::setSelection( const SUIT_DataOwnerPtrList& theList) } } -void LightApp_GVSelector::onSelectionChanged( GV_SelectionChangeStatus ) +void LightApp_GVSelector::onSelectionChanged() { selectionChanged(); } diff --git a/src/LightApp/LightApp_GVSelector.h b/src/LightApp/LightApp_GVSelector.h index 02df9bacf..acc72739a 100644 --- a/src/LightApp/LightApp_GVSelector.h +++ b/src/LightApp/LightApp_GVSelector.h @@ -25,7 +25,6 @@ #include #include #include -#include class GraphicsView_Viewer; @@ -44,7 +43,7 @@ protected: virtual void setSelection( const SUIT_DataOwnerPtrList& ); protected slots: - void onSelectionChanged( GV_SelectionChangeStatus ); + void onSelectionChanged(); protected: GraphicsView_Viewer* myViewer; -- 2.39.2