diff --git a/CMakeLists.txt b/CMakeLists.txt index 6fc90523abed..4442732c07c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/mixxxmainwindow.cpp b/src/mixxxmainwindow.cpp index bd5bafdd8c94..92d68dfa9738 100644 --- a/src/mixxxmainwindow.cpp +++ b/src/mixxxmainwindow.cpp @@ -5,7 +5,9 @@ #include "widget/wglwidget.h" -#ifndef MIXXX_USE_QOPENGL +#ifdef MIXXX_USE_QOPENGL +#include "widget/tooltipqopengl.h" +#else #include #endif @@ -111,6 +113,9 @@ void MixxxMainWindow::initialize() { m_toolTipsCfg = static_cast( pConfig->getValue(ConfigKey("[Controls]", "Tooltips"), static_cast(mixxx::TooltipsPreference::TOOLTIPS_ON))); +#ifdef MIXXX_USE_QOPENGL + ToolTipQOpenGL::singleton()->setActive(m_toolTipsCfg == mixxx::TooltipsPreference::TOOLTIPS_ON); +#endif #ifdef __ENGINEPRIME__ // Initialise library exporter @@ -426,6 +431,9 @@ MixxxMainWindow::~MixxxMainWindow() { delete m_pGuiTick; delete m_pVisualsManager; +#ifdef MIXXX_USE_QOPENGL + delete ToolTipQOpenGL::singleton(); +#endif } void MixxxMainWindow::initializeWindow() { @@ -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() { diff --git a/src/widget/openglwindow.cpp b/src/widget/openglwindow.cpp index 1a21fb357f21..b74d982061c2 100644 --- a/src/widget/openglwindow.cpp +++ b/src/widget/openglwindow.cpp @@ -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); diff --git a/src/widget/tooltipqopengl.cpp b/src/widget/tooltipqopengl.cpp new file mode 100644 index 000000000000..8b13e9d177eb --- /dev/null +++ b/src/widget/tooltipqopengl.cpp @@ -0,0 +1,43 @@ +#include "widget/tooltipqopengl.h" + +#include +#include +#include + +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(); +} diff --git a/src/widget/tooltipqopengl.h b/src/widget/tooltipqopengl.h new file mode 100644 index 000000000000..244f6ba7942f --- /dev/null +++ b/src/widget/tooltipqopengl.h @@ -0,0 +1,24 @@ +#pragma once + +#include +#include +#include + +#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); +}; diff --git a/src/widget/wglwidgetqopengl.cpp b/src/widget/wglwidgetqopengl.cpp index 66e93d70188a..fbb9e7b3b899 100644 --- a/src/widget/wglwidgetqopengl.cpp +++ b/src/widget/wglwidgetqopengl.cpp @@ -1,6 +1,8 @@ +#include #include #include "widget/openglwindow.h" +#include "widget/tooltipqopengl.h" #include "widget/wglwidget.h" WGLWidget::WGLWidget(QWidget* parent) @@ -8,6 +10,7 @@ WGLWidget::WGLWidget(QWidget* parent) } WGLWidget::~WGLWidget() { + ToolTipQOpenGL::singleton()->stop(this); if (m_pOpenGLWindow) { m_pOpenGLWindow->widgetDestroyed(); } @@ -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); } @@ -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(e)->globalPos()); + } + if (e->type() == QEvent::Leave) { + ToolTipQOpenGL::singleton()->stop(this); + } event(e); }