2020-10-20 06:37:03 +00:00
|
|
|
// Copyright 2020 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-10-20 06:37:03 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
#include <QString>
|
|
|
|
|
2023-04-19 23:36:04 +00:00
|
|
|
#include "DolphinQt/Config/ToolTipControls/BalloonTip.h"
|
2020-10-20 06:37:03 +00:00
|
|
|
|
2021-05-04 20:50:23 +00:00
|
|
|
constexpr int TOOLTIP_DELAY = 300;
|
|
|
|
|
2020-10-20 06:37:03 +00:00
|
|
|
template <class Derived>
|
|
|
|
class ToolTipWidget : public Derived
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
using Derived::Derived;
|
|
|
|
|
|
|
|
void SetTitle(QString title) { m_title = std::move(title); }
|
|
|
|
|
|
|
|
void SetDescription(QString description) { m_description = std::move(description); }
|
|
|
|
|
|
|
|
private:
|
2021-04-25 00:18:28 +00:00
|
|
|
void enterEvent(QEnterEvent* event) override
|
2020-10-20 06:37:03 +00:00
|
|
|
{
|
|
|
|
if (m_timer_id)
|
|
|
|
return;
|
2021-05-04 20:50:23 +00:00
|
|
|
m_timer_id = this->startTimer(TOOLTIP_DELAY);
|
2020-10-20 06:37:03 +00:00
|
|
|
}
|
|
|
|
|
2022-05-08 07:48:30 +00:00
|
|
|
void leaveEvent(QEvent* event) override { KillAndHide(); }
|
|
|
|
void hideEvent(QHideEvent* event) override { KillAndHide(); }
|
2020-10-20 06:37:03 +00:00
|
|
|
|
|
|
|
void timerEvent(QTimerEvent* event) override
|
|
|
|
{
|
|
|
|
this->killTimer(*m_timer_id);
|
|
|
|
m_timer_id.reset();
|
|
|
|
|
|
|
|
BalloonTip::ShowBalloon(QIcon(), m_title, m_description,
|
|
|
|
this->parentWidget()->mapToGlobal(GetToolTipPosition()), this);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual QPoint GetToolTipPosition() const = 0;
|
|
|
|
|
2022-05-08 07:48:30 +00:00
|
|
|
void KillAndHide()
|
|
|
|
{
|
|
|
|
if (m_timer_id)
|
|
|
|
{
|
|
|
|
this->killTimer(*m_timer_id);
|
|
|
|
m_timer_id.reset();
|
|
|
|
}
|
|
|
|
BalloonTip::HideBalloon();
|
|
|
|
}
|
|
|
|
|
2020-10-20 06:37:03 +00:00
|
|
|
std::optional<int> m_timer_id;
|
|
|
|
QString m_title;
|
|
|
|
QString m_description;
|
|
|
|
};
|