From 22375f63545a0030c8187d24e8e5428937a65aaa Mon Sep 17 00:00:00 2001 From: =?utf8?q?CHEMIN=20S=C3=A9bastien=20236498?= Date: Mon, 3 Jun 2024 08:35:17 +0200 Subject: [PATCH] Add possibility to draw foreground objects --- src/QtViewer/CMakeLists.txt | 2 ++ src/QtViewer/QtViewer_PainterObject.cxx | 14 ++++++++++++++ src/QtViewer/QtViewer_PainterObject.h | 16 ++++++++++++++++ src/QtViewer/QtViewer_ViewPort.cxx | 21 ++++++++++++++++++++- src/QtViewer/QtViewer_ViewPort.h | 7 +++++++ 5 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 src/QtViewer/QtViewer_PainterObject.cxx create mode 100644 src/QtViewer/QtViewer_PainterObject.h diff --git a/src/QtViewer/CMakeLists.txt b/src/QtViewer/CMakeLists.txt index 413bc41ec..2d688c202 100644 --- a/src/QtViewer/CMakeLists.txt +++ b/src/QtViewer/CMakeLists.txt @@ -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 index 000000000..aad7cbba7 --- /dev/null +++ b/src/QtViewer/QtViewer_PainterObject.cxx @@ -0,0 +1,14 @@ +#include "QtViewer_PainterObject.h" + + +QtViewer_PainterObject::QtViewer_PainterObject() +{ +} + +QtViewer_PainterObject::~QtViewer_PainterObject() +{ +} + +void QtViewer_PainterObject::draw(QPainter* painter) +{ +} diff --git a/src/QtViewer/QtViewer_PainterObject.h b/src/QtViewer/QtViewer_PainterObject.h new file mode 100644 index 000000000..6f4a692b2 --- /dev/null +++ b/src/QtViewer/QtViewer_PainterObject.h @@ -0,0 +1,16 @@ +#ifndef QTVIEWER_PAINTEROBJECT_H +#define QTVIEWER_PAINTEROBJECT_H + +#include "QtViewer.h" +#include + +class QTVIEWER_API QtViewer_PainterObject +{ +public: + + QtViewer_PainterObject(); + ~QtViewer_PainterObject(); + + virtual void draw(QPainter* painter); +}; +#endif diff --git a/src/QtViewer/QtViewer_ViewPort.cxx b/src/QtViewer/QtViewer_ViewPort.cxx index 691c5fe10..44402b418 100644 --- a/src/QtViewer/QtViewer_ViewPort.cxx +++ b/src/QtViewer/QtViewer_ViewPort.cxx @@ -30,6 +30,8 @@ #include "SUIT_ResourceMgr.h" #include "SUIT_Session.h" +#include "QtViewer_PainterObject.h" + //======================================================================= // Name : QtViewer_ViewPort // Purpose : Constructor @@ -74,6 +76,22 @@ QtViewer_ViewPort::~QtViewer_ViewPort() zoomCursor = nullptr; } +void QtViewer_ViewPort::resetForeground() +{ + for (QSharedPointer obj : foregroundObjects) + obj.reset(); + + foregroundObjects.clear(); +} + +void QtViewer_ViewPort::drawForeground(QPainter *painter, const QRectF &rect) +{ + Q_UNUSED(rect); + + for (QSharedPointer obj : foregroundObjects) + obj->draw(painter); +} + void QtViewer_ViewPort::addItem( QGraphicsItem* theItem ) { scene()->addItem(theItem); @@ -208,7 +226,7 @@ void QtViewer_ViewPort::mouseMoveEvent(QMouseEvent *event) } previousPos = currentPos; - + viewport()->update(); } else if (zooming && (event->buttons() & Qt::LeftButton)) { @@ -311,6 +329,7 @@ void QtViewer_ViewPort::activatePanAction() zooming = false; globalPanning = false; setCursor(Qt::SizeAllCursor); + viewport()->update(); } void QtViewer_ViewPort::activateGlobalPanAction() diff --git a/src/QtViewer/QtViewer_ViewPort.h b/src/QtViewer/QtViewer_ViewPort.h index b7ddd153d..2749f9dd0 100644 --- a/src/QtViewer/QtViewer_ViewPort.h +++ b/src/QtViewer/QtViewer_ViewPort.h @@ -23,6 +23,7 @@ #include "QtViewer.h" #include +class QtViewer_PainterObject; class QRubberBand; /* @@ -58,6 +59,8 @@ public: QImage dumpView(bool theWholeScene = false, QSizeF theSize = QSizeF()); bool dumpViewToFormat(const QString& fileName, const QString& format); + void addForegroundObject( QSharedPointer obj) { foregroundObjects.append(obj); } + void resetForeground(); signals: void vpMouseEvent(QMouseEvent*); @@ -75,6 +78,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 +95,8 @@ private: bool globalPanning; QPoint previousPos; QCursor* zoomCursor; + + QList > foregroundObjects; }; #endif -- 2.39.2