summaryrefslogtreecommitdiffstats
path: root/src/widget/tooltipqopengl.cpp
blob: 12c5aa4a207875653f6a69a998f25b929de890e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "widget/tooltipqopengl.h"

#include <widget/wglwidget.h>

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

ToolTipQOpenGL::ToolTipQOpenGL() {
    m_timer.setSingleShot(true);
    connect(&m_timer, &QTimer::timeout, this, &ToolTipQOpenGL::onTimeout);
}

void ToolTipQOpenGL::onTimeout() {
    if (m_widget) {
        QToolTip::showText(m_pos, m_widget->toolTip(), m_widget);
    }
}

ToolTipQOpenGL& ToolTipQOpenGL::singleton() {
    static ToolTipQOpenGL instance;
    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();
}