33 , m_animationRunning(false)
34 , m_audioIconDisplayed(false)
36 setObjectName(
QSL(
"tab-icon"));
38 m_updateTimer =
new QTimer(
this);
39 m_updateTimer->setInterval(
data()->animationInterval);
40 connect(m_updateTimer, &QTimer::timeout,
this, &TabIcon::updateAnimationFrame);
42 m_hideTimer =
new QTimer(
this);
43 m_hideTimer->setInterval(250);
44 connect(m_hideTimer, &QTimer::timeout,
this, &TabIcon::hide);
53 connect(m_tab->
webView(), &QWebEngineView::loadStarted,
this, &TabIcon::showLoadingAnimation);
54 connect(m_tab->
webView(), &QWebEngineView::loadFinished,
this, &TabIcon::hideLoadingAnimation);
58 auto pageChanged = [
this](
WebPage *page) {
59 connect(page, &QWebEnginePage::recentlyAudibleChanged,
this, &TabIcon::updateAudioIcon);
67void TabIcon::showLoadingAnimation()
71 updateAnimationFrame();
75void TabIcon::hideLoadingAnimation()
77 m_animationRunning =
false;
79 m_updateTimer->stop();
85 m_sitePixmap = m_tab->
icon(
true).pixmap(16);
86 if (m_sitePixmap.isNull()) {
87 if (m_tab->
url().isEmpty() || m_tab->
url().scheme() ==
QL1S(
"falkon")) {
113void TabIcon::updateAnimationFrame()
115 if (!m_animationRunning) {
116 m_updateTimer->start();
117 m_animationRunning =
true;
126 if (!shouldBeVisible()) {
132 if (isVisible() && width() == 16) {
136 setFixedSize(16, qMax(minimumHeight(), 16));
143 if (shouldBeVisible()) {
147 if (isHidden() && width() == 1) {
151 setFixedSize(1, qMax(minimumHeight(), 16));
156bool TabIcon::shouldBeVisible()
const
161 return !m_sitePixmap.isNull() || m_animationRunning || m_audioIconDisplayed || (m_tab && m_tab->
isPinned());
164bool TabIcon::event(QEvent *event)
166 if (event->type() == QEvent::ToolTip) {
167 auto *e =
static_cast<QHelpEvent*
>(event);
168 if (m_audioIconDisplayed && m_audioIconRect.contains(e->pos())) {
169 QToolTip::showText(e->globalPos(), m_tab->
isMuted() ? tr(
"Unmute Tab") : tr(
"Mute Tab"),
this);
175 return QWidget::event(event);
178void TabIcon::updateAudioIcon(
bool recentlyAudible)
181 m_audioIconDisplayed =
true;
184 m_audioIconDisplayed =
false;
191void TabIcon::paintEvent(QPaintEvent* event)
196 p.setRenderHint(QPainter::Antialiasing);
199 const int pixmapSize = qRound(size *
data()->animationPixmap.devicePixelRatioF());
203 r.setX((r.width() - size) / 2);
204 r.setY((r.height() - size) / 2);
208 if (m_animationRunning) {
209 p.drawPixmap(r,
data()->animationPixmap, QRect(m_currentFrame * pixmapSize, 0, pixmapSize, pixmapSize));
210 }
else if (m_audioIconDisplayed && !m_tab->
isPinned()) {
212 p.drawPixmap(r, m_tab->
isMuted() ?
data()->audioMutedPixmap :
data()->audioPlayingPixmap);
213 }
else if (!m_sitePixmap.isNull()) {
214 p.drawPixmap(r, m_sitePixmap);
215 }
else if (m_tab && m_tab->
isPinned()) {
220 if (!m_animationRunning && m_audioIconDisplayed && m_tab->
isPinned()) {
221 const int s = size - 4;
222 const QRect r(width() - s, 0, s, s);
224 QColor c = palette().color(QPalette::Window);
229 p.drawPixmap(r, m_tab->
isMuted() ?
data()->audioMutedPixmap :
data()->audioPlayingPixmap);
236 const QRect r1(width() - s - 2, height() - s - 2, s + 2, s + 2);
237 QColor c1 = palette().color(QPalette::Window);
239 p.setPen(Qt::transparent);
243 const QRect r2(width() - s - 1, height() - s - 1, s, s);
244 QColor c2 = palette().color(QPalette::Text);
245 p.setPen(Qt::transparent);
251void TabIcon::mousePressEvent(QMouseEvent *event)
254 if (m_audioIconDisplayed && event->button() == Qt::LeftButton && m_audioIconRect.contains(event->position().toPoint())) {
259 QWidget::mousePressEvent(event);
static QIcon emptyWebIcon()
void setWebTab(WebTab *tab)
TabIcon(QWidget *parent=nullptr)
TabbedWebView * webView() const
QIcon icon(bool allowNull=false) const
bool backgroundActivity() const
void backgroundActivityChanged(bool)
void pageChanged(WebPage *page)
QPixmap audioPlayingPixmap