]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Cleaning + background color + dump view
authorCHEMIN Sebastien <sc236498@is245491.intra.cea.fr>
Mon, 18 Mar 2024 11:21:51 +0000 (12:21 +0100)
committerCHEMIN Sebastien <sc236498@is245491.intra.cea.fr>
Mon, 18 Mar 2024 11:21:51 +0000 (12:21 +0100)
src/GraphicsView/GraphicsView_Object.h
src/GraphicsView/GraphicsView_Scene.cxx
src/GraphicsView/GraphicsView_Scene.h
src/GraphicsView/GraphicsView_ViewFrame.cxx
src/GraphicsView/GraphicsView_ViewFrame.h
src/GraphicsView/GraphicsView_ViewPort.cxx
src/GraphicsView/GraphicsView_ViewPort.h
src/GraphicsView/GraphicsView_Viewer.cxx
src/GraphicsView/GraphicsView_Viewer.h

index 9d5793e5a5920f8f9f8545a5c0685e3098213933..06bb2f4b412c8a6077ea8e018f757633cfdd8204 100644 (file)
@@ -24,9 +24,6 @@
 #include <QGraphicsItem>
 
 class SUIT_DataOwner;
-
-class GraphicsView_ViewPort;
-
 /*
   Class       : GraphicsView_Object
   Description : Base class for all objects displayed at the scene
index 267f32b746380a8c39026ddc6ae984b91da12d01..946d46b2c30a0fb19e0d9dcc8d6d14c56d30aecf 100644 (file)
@@ -19,8 +19,6 @@
 
 #include "GraphicsView_Scene.h"
 
-//#define VIEWER_DEBUG
-
 //=======================================================================
 // Name    : GraphicsView_Scene
 // Purpose : Constructor
index 269bce584b90377ca37765ebfc24364b01ebe756..4ac4231974fdc6bfe6cef34754b63c3202105072 100644 (file)
@@ -21,7 +21,6 @@
 #define GRAPHICSVIEW_SCENE_H
 
 #include "GraphicsView.h"
-
 #include <QGraphicsScene>
 
 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
index 44cd01ac4f50fe2cc202efd917c65498dbefde13..c97c62ec1a189cdf80d291c037d3cd73363ed70f 100644 (file)
@@ -35,8 +35,8 @@
 #include <QColor>
 #include <QFrame>
 #include <QFileDialog>
-#include <QGraphicsSceneMouseEvent>
-#include <QGraphicsSceneWheelEvent>
+
+#include <QWheelEvent>
 #include <QHBoxLayout>
 #include <QImage>
 #include <QMouseEvent>
@@ -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( ";;" );
 }
index 06f2d82540c011f427c3005250720b34927dc8af..4cb25ba43f7c3593927747601df8438e170fab1a 100644 (file)
@@ -25,9 +25,7 @@
 #include <SUIT_ViewWindow.h>
 #include <QPainterPath>
 
-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 );
 
index 310ba387db2c12064eda446e0f282ee8daf68f3b..44f7966ab5a1df4e2111f194dc1d758eb473d73e 100644 (file)
@@ -24,6 +24,8 @@
 #include <QMouseEvent>
 #include <QCursor>
 #include <QScrollBar>
+#include <QPainter>
+#include <QPrinter>
 
 #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 = w<h ? widthRatio : heightRatio;
@@ -316,3 +316,34 @@ void GraphicsView_ViewPort::pan( double theDX, double theDY )
     aVBar->setValue( 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;
+} 
index ea04e08a5e26df2a9870a0b876434ef4704e20b6..46db685b43bbc2d34971c2bab6d52aeb1eb18138 100644 (file)
 #define GRAPHICSVIEW_VIEWPORT_H
 
 #include "GraphicsView.h"
-
-#include "GraphicsView_Defs.h"
-
 #include <QGraphicsView>
-#include <QPainterPath>
-
 
 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*);
 
index 0117fdce10bb83e2806892f6c24c5406feb66aab..ca910ea810183ff5a84e108f8697298f095cd740 100644 (file)
@@ -19,7 +19,6 @@
 
 #include "GraphicsView_Viewer.h"
 
-#include "GraphicsView_Object.h"
 #include "GraphicsView_Selector.h"
 #include "GraphicsView_Scene.h"
 #include "GraphicsView_ViewFrame.h"
 
 #include <SUIT_ViewManager.h>
 
-#include <ImageComposer_Image.h>
-
-#include <QApplication>
 #include <QColorDialog>
 #include <QWheelEvent>
 #include <QKeyEvent>
 #include <QMenu>
 
-#include <math.h>
-
 
 //=======================================================================
 // 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  : 
index a45f6cb34d443497f5f39ae74dc7a0a333c9f84a..ba2dfa99720b9cb03363b1af4b90abddcb36e98f 100644 (file)
@@ -22,7 +22,6 @@
 
 #include "GraphicsView.h"
 #include <SUIT_ViewModel.h>
-#include <QPainterPath>
 
 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;