From 6697d5f6c3366e95c73e22876534e467be1a5c44 Mon Sep 17 00:00:00 2001 From: CHEMIN Sebastien Date: Mon, 18 Mar 2024 12:21:51 +0100 Subject: [PATCH] Cleaning + background color + dump view --- src/GraphicsView/GraphicsView_Object.h | 3 - src/GraphicsView/GraphicsView_Scene.cxx | 2 - src/GraphicsView/GraphicsView_Scene.h | 36 --------- src/GraphicsView/GraphicsView_ViewFrame.cxx | 81 +++++---------------- src/GraphicsView/GraphicsView_ViewFrame.h | 10 +-- src/GraphicsView/GraphicsView_ViewPort.cxx | 57 +++++++++++---- src/GraphicsView/GraphicsView_ViewPort.h | 10 +-- src/GraphicsView/GraphicsView_Viewer.cxx | 31 ++------ src/GraphicsView/GraphicsView_Viewer.h | 46 ++++++------ 9 files changed, 101 insertions(+), 175 deletions(-) diff --git a/src/GraphicsView/GraphicsView_Object.h b/src/GraphicsView/GraphicsView_Object.h index 9d5793e5a..06bb2f4b4 100644 --- a/src/GraphicsView/GraphicsView_Object.h +++ b/src/GraphicsView/GraphicsView_Object.h @@ -24,9 +24,6 @@ #include class SUIT_DataOwner; - -class GraphicsView_ViewPort; - /* Class : GraphicsView_Object Description : Base class for all objects displayed at the scene diff --git a/src/GraphicsView/GraphicsView_Scene.cxx b/src/GraphicsView/GraphicsView_Scene.cxx index 267f32b74..946d46b2c 100644 --- a/src/GraphicsView/GraphicsView_Scene.cxx +++ b/src/GraphicsView/GraphicsView_Scene.cxx @@ -19,8 +19,6 @@ #include "GraphicsView_Scene.h" -//#define VIEWER_DEBUG - //======================================================================= // Name : GraphicsView_Scene // Purpose : Constructor diff --git a/src/GraphicsView/GraphicsView_Scene.h b/src/GraphicsView/GraphicsView_Scene.h index 269bce584..4ac423197 100644 --- a/src/GraphicsView/GraphicsView_Scene.h +++ b/src/GraphicsView/GraphicsView_Scene.h @@ -21,7 +21,6 @@ #define GRAPHICSVIEW_SCENE_H #include "GraphicsView.h" - #include class QGraphicsRectItem; @@ -37,40 +36,5 @@ class GRAPHICSVIEW_API GraphicsView_Scene : public QGraphicsScene public: GraphicsView_Scene( QObject* theParent = 0 ); ~GraphicsView_Scene(); -/* -public: - void processRectChanged(); - -protected slots: - void onSceneRectChanged( const QRectF& theRect ); // for debug - -protected: - virtual void keyPressEvent( QKeyEvent* ); - virtual void keyReleaseEvent( QKeyEvent* ); - virtual void mousePressEvent( QGraphicsSceneMouseEvent* ); - virtual void mouseMoveEvent( QGraphicsSceneMouseEvent* ); - virtual void mouseReleaseEvent( QGraphicsSceneMouseEvent* ); - virtual void mouseDoubleClickEvent( QGraphicsSceneMouseEvent* ); - virtual void wheelEvent( QGraphicsSceneWheelEvent* ); - virtual void contextMenuEvent( QGraphicsSceneContextMenuEvent* ); - - virtual void dragEnterEvent( QGraphicsSceneDragDropEvent* ); - virtual void dragLeaveEvent( QGraphicsSceneDragDropEvent* ); - virtual void dragMoveEvent( QGraphicsSceneDragDropEvent* ); - virtual void dropEvent( QGraphicsSceneDragDropEvent* ); - - -signals: - void gsKeyEvent( QKeyEvent* ); - void gsMouseEvent( QGraphicsSceneMouseEvent* ); - void gsWheelEvent( QGraphicsSceneWheelEvent* ); - void gsContextMenuEvent( QGraphicsSceneContextMenuEvent* ); - - void gsBoundingRectChanged(); - -private: - QGraphicsRectItem* mySceneRectItem; // for debug -*/ }; - #endif diff --git a/src/GraphicsView/GraphicsView_ViewFrame.cxx b/src/GraphicsView/GraphicsView_ViewFrame.cxx index 44cd01ac4..c97c62ec1 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.cxx +++ b/src/GraphicsView/GraphicsView_ViewFrame.cxx @@ -35,8 +35,8 @@ #include #include #include -#include -#include + +#include #include #include #include @@ -64,22 +64,15 @@ GraphicsView_ViewFrame::GraphicsView_ViewFrame( SUIT_Desktop* d, GraphicsView_Vi myViewPort = new GraphicsView_ViewPort( aFrame ); aLayout->addWidget( myViewPort ); - - connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), - this, SLOT( mouseEvent( QMouseEvent* ) ) ); -/* + connect( myViewPort, SIGNAL( vpKeyEvent( QKeyEvent* ) ), this, SLOT( keyEvent( QKeyEvent* ) ) ); - connect( myViewPort, SIGNAL( vpMouseEvent( QGraphicsSceneMouseEvent* ) ), - this, SLOT( mouseEvent( QGraphicsSceneMouseEvent* ) ) ); - connect( myViewPort, SIGNAL( vpWheelEvent( QGraphicsSceneWheelEvent* ) ), - this, SLOT( wheelEvent( QGraphicsSceneWheelEvent* ) ) ); - connect( myViewPort, SIGNAL( vpContextMenuEvent( QGraphicsSceneContextMenuEvent* ) ), - this, SLOT( contextMenuEvent( QGraphicsSceneContextMenuEvent* ) ) ); - - connect( myViewPort, SIGNAL( vpSketchingFinished( QPainterPath ) ), - this, SIGNAL( sketchingFinished( QPainterPath ) ) ); -*/ + connect( myViewPort, SIGNAL( vpMouseEvent( QMouseEvent* ) ), + this, SLOT( mouseEvent( QMouseEvent* ) ) ); + connect( myViewPort, SIGNAL( vpWheelEvent( QWheelEvent* ) ), + this, SLOT( wheelEvent( QWheelEvent* ) ) ); + connect( myViewPort, SIGNAL( vpContextMenuEvent( QContextMenuEvent* ) ), + this, SLOT( contextMenuEvent( QContextMenuEvent* ) ) ); } //======================================================================= @@ -211,8 +204,7 @@ int GraphicsView_ViewFrame::getToolBarId() //================================================================ QImage GraphicsView_ViewFrame::dumpView() { - return QImage(); -// return myViewPort->dumpView(); + return myViewPort->dumpView(); } //================================================================ @@ -221,13 +213,10 @@ QImage GraphicsView_ViewFrame::dumpView() //================================================================ bool GraphicsView_ViewFrame::dumpViewToFormat( const QImage& image, const QString& fileName, const QString& format ) { -/* bool isOK = myViewPort->dumpViewToFormat(fileName, format); if( !isOK ) isOK = SUIT_ViewWindow::dumpViewToFormat( image, fileName, format ); return isOK; -*/ - return false; } //================================================================ @@ -239,7 +228,7 @@ QString GraphicsView_ViewFrame::getVisualParameters() QTransform aTransform = myViewPort->transform(); QString aString; - aString.sprintf( "%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f", + aString.asprintf( "%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f*%.3f", aTransform.m11(), aTransform.m12(), aTransform.m13(), aTransform.m21(), aTransform.m22(), aTransform.m23(), aTransform.m31(), aTransform.m32(), aTransform.m33() ); @@ -270,8 +259,7 @@ void GraphicsView_ViewFrame::setVisualParameters( const QString& theParameters ) if( !anIsOk[ i ] ) return; -// myViewPort->setTransform( aTransform ); -// myViewPort->applyTransform(); + myViewPort->setTransform(aTransform); } //================================================================ @@ -309,7 +297,6 @@ void GraphicsView_ViewFrame::expandToolBarActions() void GraphicsView_ViewFrame::onViewPan() { myViewer->pan(); -// myViewer->activateTransform( GraphicsView_Viewer::Pan ); } //================================================================ @@ -319,7 +306,6 @@ void GraphicsView_ViewFrame::onViewPan() void GraphicsView_ViewFrame::onViewZoom() { myViewer->zoom(); -// myViewer->activateTransform( GraphicsView_Viewer::Zoom ); } //================================================================ @@ -329,7 +315,6 @@ void GraphicsView_ViewFrame::onViewZoom() void GraphicsView_ViewFrame::onViewFitAll() { myViewer->fitAll(); -// myViewer->activateTransform( GraphicsView_Viewer::FitAll ); } //================================================================ @@ -339,7 +324,6 @@ void GraphicsView_ViewFrame::onViewFitAll() void GraphicsView_ViewFrame::onViewFitArea() { myViewer->fitArea(); -// myViewer->activateTransform( GraphicsView_Viewer::FitRect ); } //================================================================ @@ -349,7 +333,6 @@ void GraphicsView_ViewFrame::onViewFitArea() void GraphicsView_ViewFrame::onViewFitSelect() { myViewer->fitSelect(); -// myViewer->activateTransform( GraphicsView_Viewer::FitSelect ); } //================================================================ @@ -376,7 +359,6 @@ void GraphicsView_ViewFrame::onViewReset() //================================================================ void GraphicsView_ViewFrame::keyEvent( QKeyEvent* e ) { -/* switch ( e->type() ) { case QEvent::KeyPress: @@ -388,35 +370,12 @@ void GraphicsView_ViewFrame::keyEvent( QKeyEvent* e ) default: break; } -*/ } //================================================================ // Function : mouseEvent // Purpose : //================================================================ -/* -void GraphicsView_ViewFrame::mouseEvent( QGraphicsSceneMouseEvent* e ) -{ - switch ( e->type() ) - { - case QEvent::GraphicsSceneMousePress: - emit mousePressed( e ); - break; - case QEvent::GraphicsSceneMouseMove: - emit mouseMoving( e ); - break; - case QEvent::GraphicsSceneMouseRelease: - emit mouseReleased( e ); - break; - case QEvent::GraphicsSceneMouseDoubleClick: - emit mouseDoubleClicked( e ); - break; - default: - break; - } -} -*/ void GraphicsView_ViewFrame::mouseEvent( QMouseEvent* e ) { switch ( e->type() ) @@ -441,11 +400,11 @@ void GraphicsView_ViewFrame::mouseEvent( QMouseEvent* e ) // Function : wheelEvent // Purpose : //================================================================ -void GraphicsView_ViewFrame::wheelEvent( QGraphicsSceneWheelEvent* e ) +void GraphicsView_ViewFrame::wheelEvent( QWheelEvent* e ) { switch ( e->type() ) { - case QEvent::GraphicsSceneWheel: + case QEvent::Wheel: emit wheeling( e ); break; default: @@ -457,13 +416,9 @@ void GraphicsView_ViewFrame::wheelEvent( QGraphicsSceneWheelEvent* e ) // Function : contextMenuEvent // Purpose : //================================================================ -void GraphicsView_ViewFrame::contextMenuEvent( QGraphicsSceneContextMenuEvent* e ) +void GraphicsView_ViewFrame::contextMenuEvent( QContextMenuEvent* e ) { - QPoint aPos = myViewPort->mapFromScene( e->scenePos() ); - QContextMenuEvent* anEvent = new QContextMenuEvent( (QContextMenuEvent::Reason)e->reason(), - aPos, e->screenPos(), e->modifiers() ); - emit contextMenuRequested( anEvent ); - delete anEvent; + emit contextMenuRequested(e); } /*! @@ -501,7 +456,7 @@ void GraphicsView_ViewFrame::hideEvent( QHideEvent* theEvent ) */ QString GraphicsView_ViewFrame::filter() const { - QStringList filters = SUIT_ViewWindow::filter().split( ";;", QString::SkipEmptyParts ); - filters << tr( "POSTSCRIPT_FILES" ); + QStringList filters = SUIT_ViewWindow::filter().split( ";;", Qt::SkipEmptyParts ); + filters << tr("POSTSCRIPT_FILES"); return filters.join( ";;" ); } diff --git a/src/GraphicsView/GraphicsView_ViewFrame.h b/src/GraphicsView/GraphicsView_ViewFrame.h index 06f2d8254..4cb25ba43 100644 --- a/src/GraphicsView/GraphicsView_ViewFrame.h +++ b/src/GraphicsView/GraphicsView_ViewFrame.h @@ -25,9 +25,7 @@ #include #include -class QGraphicsSceneContextMenuEvent; -class QGraphicsSceneMouseEvent; -class QGraphicsSceneWheelEvent; +class QContextMenuEvent; class QAction; @@ -78,8 +76,8 @@ protected slots: private slots: void keyEvent( QKeyEvent* ); void mouseEvent( QMouseEvent* ); - void wheelEvent( QGraphicsSceneWheelEvent* ); - void contextMenuEvent( QGraphicsSceneContextMenuEvent* ); + void wheelEvent( QWheelEvent* ); + void contextMenuEvent( QContextMenuEvent* ); signals: void keyPressed( QKeyEvent* ); @@ -88,7 +86,7 @@ signals: void mouseMoving( QMouseEvent* ); void mouseReleased( QMouseEvent* ); void mouseDoubleClicked( QMouseEvent* ); - void wheeling( QGraphicsSceneWheelEvent* ); + void wheeling( QWheelEvent* ); void sketchingFinished( QPainterPath ); diff --git a/src/GraphicsView/GraphicsView_ViewPort.cxx b/src/GraphicsView/GraphicsView_ViewPort.cxx index 310ba387d..44f7966ab 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.cxx +++ b/src/GraphicsView/GraphicsView_ViewPort.cxx @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include "SUIT_ResourceMgr.h" #include "SUIT_Session.h" @@ -83,10 +85,6 @@ void GraphicsView_ViewPort::fitAll() fitInView( aRect.adjusted(-myFitAllGap, -myFitAllGap, myFitAllGap, myFitAllGap), Qt::KeepAspectRatio); } -void GraphicsView_ViewPort::updateSceneRect(const QRectF &rect) -{ -} - void GraphicsView_ViewPort::fitSelect() { if (scene()->selectedItems().isEmpty()) @@ -100,6 +98,11 @@ void GraphicsView_ViewPort::fitSelect() fitInView(selectionRect.adjusted(-myFitAllGap, -myFitAllGap, myFitAllGap, myFitAllGap), Qt::KeepAspectRatio); } +void GraphicsView_ViewPort::fitRect(const QRectF& theRect) +{ + fitInView(theRect, Qt::KeepAspectRatio); +} + QRect GraphicsView_ViewPort::selectionRect() { if (myRectBand) @@ -114,11 +117,6 @@ QRect GraphicsView_ViewPort::selectionRect() return QRect(); } -void GraphicsView_ViewPort::fitRect(const QRectF& theRect) -{ - fitInView(theRect, Qt::KeepAspectRatio); -} - void GraphicsView_ViewPort::startDrawingRect( int x, int y ) { myRectBandStart = QPoint(x,y); @@ -158,9 +156,13 @@ void GraphicsView_ViewPort::finishDrawingRect() myRectBand = nullptr; } +void GraphicsView_ViewPort::updateSceneRect(const QRectF &rect) +{ +} + void GraphicsView_ViewPort::mousePressEvent(QMouseEvent *event) { - if (!zooming && !panning && items(event->pos()).count()==0) + if (!zooming && !panning && items(event->pos()).count()==0 && (event->buttons() & Qt::LeftButton)) { startDrawingRect(event->pos().x(), event->pos().y()); } @@ -234,9 +236,7 @@ void GraphicsView_ViewPort::resizeEvent(QResizeEvent *event) qreal widthRatio = w/w0; qreal heightRatio = h/h0; - - - + if (widthRatio>0 && heightRatio>0) { qreal scaleFactor = wsetValue( aVBar->value() + theDY ); } } + +//================================================================ +// Function : dumpView +// Purpose : +//================================================================ +QImage GraphicsView_ViewPort::dumpView( bool theWholeScene, + QSizeF theSize ) +{ + QPixmap screenshot = viewport()->grab(); + return screenshot.toImage(); +} + +bool GraphicsView_ViewPort::dumpViewToFormat(const QString& fileName, const QString& format) +{ + if( format!="PS" && format!="EPS" ) + return false; + + QPrinter printer(QPrinter::ScreenResolution); + printer.setOutputFormat(QPrinter::NativeFormat); + printer.setOutputFileName(fileName); + + QPainter painter; + if (!painter.begin(&printer)) + return false; + + render(&painter); + if (!painter.end()) + return false; + + return true; +} diff --git a/src/GraphicsView/GraphicsView_ViewPort.h b/src/GraphicsView/GraphicsView_ViewPort.h index ea04e08a5..46db685b4 100644 --- a/src/GraphicsView/GraphicsView_ViewPort.h +++ b/src/GraphicsView/GraphicsView_ViewPort.h @@ -21,12 +21,7 @@ #define GRAPHICSVIEW_VIEWPORT_H #include "GraphicsView.h" - -#include "GraphicsView_Defs.h" - #include -#include - class QRubberBand; @@ -59,6 +54,11 @@ public: void activatePanAction(); void pan( double theDX, double theDY ); + + QImage dumpView(bool theWholeScene = false, QSizeF theSize = QSizeF()); + bool dumpViewToFormat(const QString& fileName, const QString& format); + + signals: void vpMouseEvent(QMouseEvent*); diff --git a/src/GraphicsView/GraphicsView_Viewer.cxx b/src/GraphicsView/GraphicsView_Viewer.cxx index 0117fdce1..ca910ea81 100644 --- a/src/GraphicsView/GraphicsView_Viewer.cxx +++ b/src/GraphicsView/GraphicsView_Viewer.cxx @@ -19,7 +19,6 @@ #include "GraphicsView_Viewer.h" -#include "GraphicsView_Object.h" #include "GraphicsView_Selector.h" #include "GraphicsView_Scene.h" #include "GraphicsView_ViewFrame.h" @@ -27,16 +26,11 @@ #include -#include - -#include #include #include #include #include -#include - //======================================================================= // Name : GraphicsView_Viewer @@ -97,7 +91,7 @@ void GraphicsView_Viewer::contextMenuPopup( QMenu* thePopup ) if( thePopup->actions().count() > 0 ) thePopup->addSeparator(); -// thePopup->addAction( tr( "CHANGE_BGCOLOR" ), this, SLOT( onChangeBgColor() ) ); + thePopup->addAction(tr("CHANGE_BGCOLOR"), this, SLOT(onChangeBgColor())); } //================================================================ @@ -257,27 +251,18 @@ void GraphicsView_Viewer::handleMouseRelease(QMouseEvent* e) // Function : onChangeBgColor // Purpose : //================================================================ -/* + void GraphicsView_Viewer::onChangeBgColor() { 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 ); - } - } + QColor aColor = QColorDialog::getColor( aColor, aViewPort ); + + if (aColor.isValid()) + aViewPort->setBackgroundBrush(QBrush(aColor)); + } } -*/ + //================================================================ // Function : onSelectionDone // Purpose : diff --git a/src/GraphicsView/GraphicsView_Viewer.h b/src/GraphicsView/GraphicsView_Viewer.h index a45f6cb34..ba2dfa997 100644 --- a/src/GraphicsView/GraphicsView_Viewer.h +++ b/src/GraphicsView/GraphicsView_Viewer.h @@ -22,7 +22,6 @@ #include "GraphicsView.h" #include -#include class QKeyEvent; class QMouseEvent; @@ -44,23 +43,23 @@ class GRAPHICSVIEW_API GraphicsView_Viewer: public SUIT_ViewModel Q_OBJECT public: - GraphicsView_Viewer( const QString& title, QWidget* widget = nullptr ); + GraphicsView_Viewer(const QString& title, QWidget* widget = nullptr); ~GraphicsView_Viewer(); public: - virtual SUIT_ViewWindow* createView( SUIT_Desktop* ); + virtual SUIT_ViewWindow* createView(SUIT_Desktop*); - virtual QString getType() const { return Type(); } - static QString Type() { return "GraphicsView"; } + virtual QString getType() const { return Type(); } + static QString Type() { return "GraphicsView"; } - virtual void contextMenuPopup( QMenu* ); + virtual void contextMenuPopup(QMenu*); public: - GraphicsView_Selector* getSelector(); + GraphicsView_Selector* getSelector(); - GraphicsView_ViewFrame* getActiveView() const; - GraphicsView_ViewPort* getActiveViewPort() const; - GraphicsView_Scene* getActiveScene() const; + GraphicsView_ViewFrame* getActiveView() const; + GraphicsView_ViewPort* getActiveViewPort() const; + GraphicsView_Scene* getActiveScene() const; void fitAll(); void fitSelect(); @@ -69,28 +68,27 @@ public: void pan(); signals: - void selectionChanged(); + void selectionChanged(); protected: - virtual GraphicsView_ViewFrame* createViewFrame( SUIT_Desktop* theDesktop, QWidget* theWidget ); + virtual GraphicsView_ViewFrame* createViewFrame(SUIT_Desktop* theDesktop, QWidget* theWidget); protected slots: - virtual void onKeyEvent( QKeyEvent* ); - virtual void onMouseEvent( QMouseEvent* ); - virtual void onWheelEvent( QWheelEvent* ); + virtual void onKeyEvent(QKeyEvent*); + virtual void onMouseEvent(QMouseEvent*); + virtual void onWheelEvent(QWheelEvent*); - virtual void onSelectionDone(); + virtual void onSelectionDone(); + virtual void onChangeBgColor(); protected: - virtual void handleKeyPress( QKeyEvent* ); - virtual void handleKeyRelease( QKeyEvent* ); - virtual void handleMouseMove( QMouseEvent* ); - virtual void handleMousePress( QMouseEvent* ); - virtual void handleMouseRelease( QMouseEvent* ); - virtual void handleWheel(QWheelEvent*); - - // virtual void onChangeBgColor(); + virtual void handleKeyPress(QKeyEvent*); + virtual void handleKeyRelease(QKeyEvent*); + virtual void handleMouseMove(QMouseEvent*); + virtual void handleMousePress(QMouseEvent*); + virtual void handleMouseRelease(QMouseEvent*); + virtual void handleWheel(QWheelEvent*); protected: GraphicsView_Selector* mySelector; -- 2.39.2