Skip to content

Commit

Permalink
set openglwindow event target to waveformviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB committed May 5, 2023
1 parent f125c46 commit 2b41420
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/widget/openglwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/widget/wglwidgetqopengl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/widget/wglwidgetqopengl.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class WGLWidget : public QWidget {
private:
OpenGLWindow* m_pOpenGLWindow{};
QWidget* m_pContainerWidget{};
QWidget* m_pWindowEventTarget{};

public:
WGLWidget(QWidget* parent);
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/widget/wwaveformviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2b41420

Please sign in to comment.