From 2b414200f956697614ad75ec43645c3f26b9e8ef Mon Sep 17 00:00:00 2001 From: m0dB <79429057+m0dB@users.noreply.github.com> Date: Fri, 5 May 2023 02:39:46 +0200 Subject: [PATCH] set openglwindow event target to waveformviewer --- src/widget/openglwindow.cpp | 17 ++++++++++------- src/widget/wglwidgetqopengl.cpp | 10 +++++++++- src/widget/wglwidgetqopengl.h | 4 ++++ src/widget/wwaveformviewer.cpp | 1 + 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/widget/openglwindow.cpp b/src/widget/openglwindow.cpp index fca428bb3ec..3f4f30d5b84 100644 --- a/src/widget/openglwindow.cpp +++ b/src/widget/openglwindow.cpp @@ -75,17 +75,20 @@ bool OpenGLWindow::event(QEvent* ev) { } if (t != QEvent::Resize && t != QEvent::Move && t != QEvent::Expose) { - // Send all events to the widget that owns the window container widget that contains - // this QOpenGLWindow. - // Except for: + // Send all events to the relevant widget. In the case of WSpinny and + // WVuMeter, that's m_pWidget itself (the widget that contains the window + // container widget that contains this QOpenGLWindow), in the case of + // waveforms, it will be the parent WWaveformViewer. + // + // All events except for: // - Resize and Move - // Any change to the geometry comes from m_pWidget and its child m_pContainerWidget. - // If we send the resulting events back to the m_pWidget we will quickly overflow + // Any change to the geometry comes from the widget layouts. + // If we send the resulting events back we will quickly overflow // the event queue with repeated resize and move events. // - Expose - // This event is only for windows + // This event is only for windows. - QApplication::sendEvent(m_pWidget, ev); + QApplication::sendEvent(m_pWidget->windowEventTarget(), ev); } } diff --git a/src/widget/wglwidgetqopengl.cpp b/src/widget/wglwidgetqopengl.cpp index 9064955bdfc..f0393223abc 100644 --- a/src/widget/wglwidgetqopengl.cpp +++ b/src/widget/wglwidgetqopengl.cpp @@ -5,7 +5,7 @@ #include "widget/wglwidget.h" WGLWidget::WGLWidget(QWidget* parent) - : QWidget(parent) { + : QWidget(parent), m_pWindowEventTarget(this) { // When the widget is resized or moved, the QOpenGLWindow visibly resizes // or moves before the widgets do. This can be solved by calling // setAttribute(Qt::WA_PaintOnScreen); @@ -25,6 +25,14 @@ QPaintDevice* WGLWidget::paintDevice() { return m_pOpenGLWindow; } +void WGLWidget::setWindowEventTarget(QWidget* widget) { + m_pWindowEventTarget = widget; +} + +QWidget* WGLWidget::windowEventTarget() const { + return m_pWindowEventTarget; +} + void WGLWidget::showEvent(QShowEvent* event) { if (!m_pOpenGLWindow) { m_pOpenGLWindow = new OpenGLWindow(this); diff --git a/src/widget/wglwidgetqopengl.h b/src/widget/wglwidgetqopengl.h index b775d4ea945..23151edc192 100644 --- a/src/widget/wglwidgetqopengl.h +++ b/src/widget/wglwidgetqopengl.h @@ -17,6 +17,7 @@ class WGLWidget : public QWidget { private: OpenGLWindow* m_pOpenGLWindow{}; QWidget* m_pContainerWidget{}; + QWidget* m_pWindowEventTarget{}; public: WGLWidget(QWidget* parent); @@ -32,6 +33,9 @@ class WGLWidget : public QWidget { void swapBuffers(); + void setWindowEventTarget(QWidget* target); + QWidget* windowEventTarget() const; + // called (indirectly) by WaveformWidgetFactory virtual void paintGL(); // called by OpenGLWindow diff --git a/src/widget/wwaveformviewer.cpp b/src/widget/wwaveformviewer.cpp index a709e3c414e..21d9b10117a 100644 --- a/src/widget/wwaveformviewer.cpp +++ b/src/widget/wwaveformviewer.cpp @@ -274,6 +274,7 @@ void WWaveformViewer::setWaveformWidget(WaveformWidgetAbstract* waveformWidget) // OpenGLWindow will display it. if (m_waveformWidget->getGLWidget()) { m_waveformWidget->getGLWidget()->setToolTip(toolTip()); + m_waveformWidget->getGLWidget()->setWindowEventTarget(this); } #endif // Make connection to show "Passthrough" label on the waveform, except for