From 5339e309a08ff2d1434d1d41dffd62594552dc84 Mon Sep 17 00:00:00 2001 From: =?utf8?q?CHEMIN=20S=C3=A9bastien=20236498?= Date: Fri, 17 May 2024 16:33:38 +0200 Subject: [PATCH] Adding Foreground drawing objects --- src/QtViewer/CMakeLists.txt | 2 ++ src/QtViewer/QtViewer_PainterObject.cxx | 24 ++++++++++++++++++++++++ src/QtViewer/QtViewer_PainterObject.h | 16 ++++++++++++++++ src/QtViewer/QtViewer_ViewPort.cxx | 13 ++++++++++++- src/QtViewer/QtViewer_ViewPort.h | 6 ++++++ 5 files changed, 60 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..bc4bbf0d9 --- /dev/null +++ b/src/QtViewer/QtViewer_PainterObject.cxx @@ -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 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..040f79516 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,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() diff --git a/src/QtViewer/QtViewer_ViewPort.h b/src/QtViewer/QtViewer_ViewPort.h index b7ddd153d..e419c91e3 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,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 foregroundObjects; }; #endif -- 2.39.2