Skip to content

Commit

Permalink
fix tooltips for qopengl based wglwidgets
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dB committed Mar 4, 2023
1 parent c993a20 commit 50f1bb4
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1160,6 +1160,7 @@ else()
target_sources(mixxx-lib PRIVATE
src/widget/openglwindow.cpp
src/widget/wglwidgetqopengl.cpp
src/widget/tooltipqopengl.cpp
src/widget/qopengl/wvumetergl.cpp
src/widget/qopengl/wspinny.cpp
src/waveform/renderers/qopengl/shaderloader.cpp
Expand Down
13 changes: 12 additions & 1 deletion src/mixxxmainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

#include "widget/wglwidget.h"

#ifndef MIXXX_USE_QOPENGL
#ifdef MIXXX_USE_QOPENGL
#include "widget/tooltipqopengl.h"
#else
#include <QGLFormat>
#endif

Expand Down Expand Up @@ -111,6 +113,9 @@ void MixxxMainWindow::initialize() {
m_toolTipsCfg = static_cast<mixxx::TooltipsPreference>(
pConfig->getValue(ConfigKey("[Controls]", "Tooltips"),
static_cast<int>(mixxx::TooltipsPreference::TOOLTIPS_ON)));
#ifdef MIXXX_USE_QOPENGL
ToolTipQOpenGL::singleton()->setActive(m_toolTipsCfg == mixxx::TooltipsPreference::TOOLTIPS_ON);
#endif

#ifdef __ENGINEPRIME__
// Initialise library exporter
Expand Down Expand Up @@ -426,6 +431,9 @@ MixxxMainWindow::~MixxxMainWindow() {

delete m_pGuiTick;
delete m_pVisualsManager;
#ifdef MIXXX_USE_QOPENGL
delete ToolTipQOpenGL::singleton();
#endif
}

void MixxxMainWindow::initializeWindow() {
Expand Down Expand Up @@ -990,6 +998,9 @@ void MixxxMainWindow::slotShowKeywheel(bool toggle) {

void MixxxMainWindow::slotTooltipModeChanged(mixxx::TooltipsPreference tt) {
m_toolTipsCfg = tt;
#ifdef MIXXX_USE_QOPENGL
ToolTipQOpenGL::singleton()->setActive(m_toolTipsCfg == mixxx::TooltipsPreference::TOOLTIPS_ON);
#endif
}

void MixxxMainWindow::rebootMixxxView() {
Expand Down
1 change: 1 addition & 0 deletions src/widget/openglwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ bool OpenGLWindow::event(QEvent* ev) {
// Forward the following events to the WGLWidget
if (t == QEvent::MouseButtonDblClick || t == QEvent::MouseButtonPress ||
t == QEvent::MouseButtonRelease || t == QEvent::MouseMove ||
t == QEvent::Enter || t == QEvent::Leave ||
t == QEvent::DragEnter || t == QEvent::DragLeave ||
t == QEvent::DragMove || t == QEvent::Drop || t == QEvent::Wheel) {
m_pWidget->handleEventFromWindow(ev);
Expand Down
43 changes: 43 additions & 0 deletions src/widget/tooltipqopengl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "widget/tooltipqopengl.h"

#include <QStyle>
#include <QTimer>
#include <QToolTip>

ToolTipQOpenGL::ToolTipQOpenGL() {
m_timer = new QTimer();
m_timer->setSingleShot(true);
m_timer->callOnTimeout(this, [this]() {
if (m_widget) {
QToolTip::showText(m_pos, m_widget->toolTip(), m_widget);
}
});
}

ToolTipQOpenGL::~ToolTipQOpenGL() {
delete m_timer;
}

ToolTipQOpenGL* ToolTipQOpenGL::singleton() {
static ToolTipQOpenGL* instance = new ToolTipQOpenGL();
return instance;
}

void ToolTipQOpenGL::setActive(bool active) {
m_active = active;
if (!m_active) {
m_timer->stop();
}
}

void ToolTipQOpenGL::start(WGLWidget* widget, QPoint pos) {
if (m_active) {
m_widget = widget;
m_pos = pos;
m_timer->start(widget->style()->styleHint(QStyle::SH_ToolTip_WakeUpDelay));
}
}

void ToolTipQOpenGL::stop(WGLWidget* widget) {
m_timer->stop();
}
24 changes: 24 additions & 0 deletions src/widget/tooltipqopengl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include <QStyle>
#include <QTimer>
#include <QToolTip>

#include "widget/wglwidget.h"

// Tooltips don't work for the qopengl-based WGLWidget. This
// singleton mimics the standard tooltip behaviour for them.
class ToolTipQOpenGL : public QObject {
bool m_active{true};
QTimer* m_timer{};
QPoint m_pos{};
WGLWidget* m_widget{};
ToolTipQOpenGL();

public:
~ToolTipQOpenGL();
static ToolTipQOpenGL* singleton();
void setActive(bool active);
void start(WGLWidget* widget, QPoint pos);
void stop(WGLWidget* widget);
};
10 changes: 10 additions & 0 deletions src/widget/wglwidgetqopengl.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#include <QMouseEvent>
#include <QResizeEvent>

#include "widget/openglwindow.h"
#include "widget/tooltipqopengl.h"
#include "widget/wglwidget.h"

WGLWidget::WGLWidget(QWidget* parent)
: QWidget(parent) {
}

WGLWidget::~WGLWidget() {
ToolTipQOpenGL::singleton()->stop(this);
if (m_pOpenGLWindow) {
m_pOpenGLWindow->widgetDestroyed();
}
Expand All @@ -24,6 +27,7 @@ void WGLWidget::showEvent(QShowEvent* event) {
m_pContainerWidget = createWindowContainer(m_pOpenGLWindow, this);
m_pContainerWidget->resize(size());
m_pContainerWidget->show();
m_pContainerWidget->setAutoFillBackground(true);
}
QWidget::showEvent(event);
}
Expand All @@ -35,6 +39,12 @@ void WGLWidget::resizeEvent(QResizeEvent* event) {
}

void WGLWidget::handleEventFromWindow(QEvent* e) {
if (e->type() == QEvent::MouseMove) {
ToolTipQOpenGL::singleton()->start(this, dynamic_cast<QMouseEvent*>(e)->globalPos());
}
if (e->type() == QEvent::Leave) {
ToolTipQOpenGL::singleton()->stop(this);
}
event(e);
}

Expand Down

0 comments on commit 50f1bb4

Please sign in to comment.