]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Adding Foreground drawing objects
authorCHEMIN Sébastien 236498 <sc236498@is245491.intra.cea.fr>
Fri, 17 May 2024 14:33:38 +0000 (16:33 +0200)
committerCHEMIN Sébastien 236498 <sc236498@is245491.intra.cea.fr>
Mon, 27 May 2024 14:32:58 +0000 (16:32 +0200)
src/QtViewer/CMakeLists.txt
src/QtViewer/QtViewer_PainterObject.cxx [new file with mode: 0644]
src/QtViewer/QtViewer_PainterObject.h [new file with mode: 0644]
src/QtViewer/QtViewer_ViewPort.cxx
src/QtViewer/QtViewer_ViewPort.h

index 413bc41ec06ab3f6dd0b5e3953e8e0b2a3793dcb..2d688c2020ecee5a3933b82eb7619836a9d86367 100644 (file)
@@ -51,6 +51,7 @@ SET(_moc_HEADERS
 SET(_other_HEADERS
   QtViewer.h
   QtViewer_Object.h
+  QtViewer_PainterObject.h
 )
 
 # header files / to install
@@ -88,6 +89,7 @@ QT_WRAP_MOC(_moc_SOURCES ${_moc_HEADERS})
 # sources / static
 SET(_other_SOURCES
   QtViewer_Object.cxx
+  QtViewer_PainterObject.cxx
   QtViewer_Scene.cxx
   QtViewer_Selector.cxx
   QtViewer_ViewFrame.cxx
diff --git a/src/QtViewer/QtViewer_PainterObject.cxx b/src/QtViewer/QtViewer_PainterObject.cxx
new file mode 100644 (file)
index 0000000..bc4bbf0
--- /dev/null
@@ -0,0 +1,24 @@
+#include "QtViewer_PainterObject.h"
+  
+
+QtViewer_PainterObject::QtViewer_PainterObject()
+{
+}
+
+QtViewer_PainterObject::~QtViewer_PainterObject()
+{
+}
+
+void QtViewer_PainterObject::draw(QPainter* painter)
+{
+/*
+  painter->save();
+  painter->resetTransform();
+  double w1 = h/10.;
+  painter->setPen(QPen(Qt::black));
+  QRectF aRect(w-w1,h/4.,w1, h/2.);
+  painter->fillRect(aRect,QGradient::StarWine);
+  painter->drawRect(aRect);
+  painter->restore();
+*/
+}
diff --git a/src/QtViewer/QtViewer_PainterObject.h b/src/QtViewer/QtViewer_PainterObject.h
new file mode 100644 (file)
index 0000000..6f4a692
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef QTVIEWER_PAINTEROBJECT_H
+#define QTVIEWER_PAINTEROBJECT_H
+
+#include "QtViewer.h"
+#include <QPainter>
+
+class QTVIEWER_API QtViewer_PainterObject 
+{
+public:
+
+  QtViewer_PainterObject();
+  ~QtViewer_PainterObject();
+
+  virtual void draw(QPainter* painter); 
+};
+#endif
index 691c5fe1012ec55ff9095d71b20e8dbb66cce496..040f79516ed148403440c4f8ed06f59d89845cc7 100644 (file)
@@ -30,6 +30,8 @@
 #include "SUIT_ResourceMgr.h"
 #include "SUIT_Session.h"
 
+#include "QtViewer_PainterObject.h"
+
 //=======================================================================
 // Name    : QtViewer_ViewPort
 // Purpose : Constructor
@@ -74,6 +76,14 @@ QtViewer_ViewPort::~QtViewer_ViewPort()
   zoomCursor = nullptr;
 }
 
+void QtViewer_ViewPort::drawForeground(QPainter *painter, const QRectF &rect)
+{
+  Q_UNUSED(rect);
+
+  for (QtViewer_PainterObject* obj : foregroundObjects)
+    obj->draw(painter);
+}
+
 void QtViewer_ViewPort::addItem( QGraphicsItem* theItem )
 {
   scene()->addItem(theItem);
@@ -208,7 +218,7 @@ void QtViewer_ViewPort::mouseMoveEvent(QMouseEvent *event)
 
     }
     previousPos = currentPos;  
-
+    viewport()->update();
     }
   else if (zooming && (event->buttons() & Qt::LeftButton))
   {
@@ -311,6 +321,7 @@ void QtViewer_ViewPort::activatePanAction()
   zooming = false;
   globalPanning = false;
   setCursor(Qt::SizeAllCursor);
+  viewport()->update();
 }
 
 void QtViewer_ViewPort::activateGlobalPanAction() 
index b7ddd153dada6487b8a9c846e535b263b73962fa..e419c91e357408f8db0b50ef009ce09facc0271d 100644 (file)
@@ -23,6 +23,7 @@
 #include "QtViewer.h"
 #include <QGraphicsView>
 
+class QtViewer_PainterObject;
 class QRubberBand;
 
 /*
@@ -58,6 +59,7 @@ public:
   QImage dumpView(bool theWholeScene = false, QSizeF theSize = QSizeF());
   bool dumpViewToFormat(const QString& fileName, const QString& format);
 
+  void addForegroundObject(QtViewer_PainterObject* obj) { foregroundObjects.append(obj); }
 
 signals:
   void vpMouseEvent(QMouseEvent*);
@@ -75,6 +77,8 @@ protected:
   virtual void wheelEvent(QWheelEvent *event);
   virtual void keyPressEvent(QKeyEvent *event);
 
+  virtual void drawForeground(QPainter *painter, const QRectF &rect);
+
   void clearActions();
  
 private:
@@ -90,6 +94,8 @@ private:
   bool globalPanning;
   QPoint previousPos;
   QCursor* zoomCursor;
+
+  QList<QtViewer_PainterObject*> foregroundObjects;
 };
 
 #endif