From: CHEMIN Sébastien 236498 Date: Fri, 17 May 2024 14:33:38 +0000 (+0200) Subject: Adding Foreground drawing objects X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=0fab84f5c2b78eee8153b89b8d0ab540ea7c1e05;p=modules%2Fgui.git Adding Foreground drawing objects --- 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