1
mirror of https://invent.kde.org/network/falkon.git synced 2024-11-11 09:32:12 +01:00

TabIcon: Show audio tooltip only when mouse is over audio icon

This commit is contained in:
David Rosca 2017-01-02 15:29:56 +01:00
parent 20abaaf9f9
commit 89ff7ca10a
2 changed files with 18 additions and 4 deletions

View File

@ -22,6 +22,7 @@
#include "tabbedwebview.h"
#include <QTimer>
#include <QToolTip>
#include <QMouseEvent>
#define ANIMATION_INTERVAL 70
@ -142,14 +143,26 @@ bool TabIcon::shouldBeVisible() const
return !m_sitePixmap.isNull() || m_animationRunning || m_audioIconDisplayed || (m_tab && m_tab->isPinned());
}
bool TabIcon::event(QEvent *event)
{
if (event->type() == QEvent::ToolTip) {
QHelpEvent *e = static_cast<QHelpEvent*>(event);
if (m_audioIconDisplayed && m_audioIconRect.contains(e->pos())) {
QToolTip::showText(e->globalPos(), m_tab->isMuted() ? tr("Unmute Tab") : tr("Mute Tab"), this);
event->accept();
return true;
}
}
return QWidget::event(event);
}
void TabIcon::updateAudioIcon(bool recentlyAudible)
{
if (m_tab->isMuted() || (!m_tab->isMuted() && recentlyAudible)) {
setToolTip(m_tab->isMuted() ? tr("Unmute Tab") : tr("Mute Tab"));
m_audioIconDisplayed = true;
show();
} else {
setToolTip(QString());
m_audioIconDisplayed = false;
hide();
}

View File

@ -52,8 +52,9 @@ private:
void hide();
bool shouldBeVisible() const;
void paintEvent(QPaintEvent* event);
void mousePressEvent(QMouseEvent* event);
bool event(QEvent *event) override;
void paintEvent(QPaintEvent* event) override;
void mousePressEvent(QMouseEvent* event) override;
WebTab* m_tab;
QTimer* m_updateTimer;