1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 02:36:34 +01:00

TabIcon: Make static image data public

This commit is contained in:
David Rosca 2018-02-01 15:23:41 +01:00
parent 7bba5b79ed
commit 47be65f903
No known key found for this signature in database
GPG Key ID: EBC3FC294452C6D8
2 changed files with 31 additions and 27 deletions

View File

@ -25,10 +25,6 @@
#include <QToolTip>
#include <QMouseEvent>
#define ANIMATION_INTERVAL 70
TabIcon::Data *TabIcon::s_data = Q_NULLPTR;
TabIcon::TabIcon(QWidget* parent)
: QWidget(parent)
, m_tab(0)
@ -38,16 +34,8 @@ TabIcon::TabIcon(QWidget* parent)
{
setObjectName(QSL("tab-icon"));
if (!s_data) {
s_data = new TabIcon::Data;
s_data->animationPixmap = QIcon(QSL(":icons/other/loading.png")).pixmap(288, 16);
s_data->framesCount = s_data->animationPixmap.width() / s_data->animationPixmap.height();
s_data->audioPlayingPixmap = QIcon::fromTheme(QSL("audio-volume-high"), QIcon(QSL(":icons/other/audioplaying.svg"))).pixmap(16);
s_data->audioMutedPixmap = QIcon::fromTheme(QSL("audio-volume-muted"), QIcon(QSL(":icons/other/audiomuted.svg"))).pixmap(16);
}
m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(ANIMATION_INTERVAL);
m_updateTimer->setInterval(data()->animationInterval);
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateAnimationFrame()));
m_hideTimer = new QTimer(this);
@ -106,6 +94,21 @@ void TabIcon::updateIcon()
update();
}
// static
TabIcon::Data *TabIcon::data()
{
static Data *data = nullptr;
if (!data) {
data = new TabIcon::Data;
data->animationInterval = 70;
data->animationPixmap = QIcon(QSL(":icons/other/loading.png")).pixmap(288, 16);
data->framesCount = data->animationPixmap.width() / data->animationPixmap.height();
data->audioPlayingPixmap = QIcon::fromTheme(QSL("audio-volume-high"), QIcon(QSL(":icons/other/audioplaying.svg"))).pixmap(16);
data->audioMutedPixmap = QIcon::fromTheme(QSL("audio-volume-muted"), QIcon(QSL(":icons/other/audiomuted.svg"))).pixmap(16);
}
return data;
}
void TabIcon::updateAnimationFrame()
{
if (!m_animationRunning) {
@ -114,7 +117,7 @@ void TabIcon::updateAnimationFrame()
}
update();
m_currentFrame = (m_currentFrame + 1) % s_data->framesCount;
m_currentFrame = (m_currentFrame + 1) % data()->framesCount;
}
void TabIcon::show()
@ -188,7 +191,7 @@ void TabIcon::paintEvent(QPaintEvent* event)
p.setRenderHint(QPainter::Antialiasing);
const int size = 16;
const int pixmapSize = qRound(size * s_data->animationPixmap.devicePixelRatioF());
const int pixmapSize = qRound(size * data()->animationPixmap.devicePixelRatioF());
// Center the pixmap in rect
QRect r = rect();
@ -198,10 +201,10 @@ void TabIcon::paintEvent(QPaintEvent* event)
r.setHeight(size);
if (m_animationRunning) {
p.drawPixmap(r, s_data->animationPixmap, QRect(m_currentFrame * pixmapSize, 0, pixmapSize, pixmapSize));
p.drawPixmap(r, data()->animationPixmap, QRect(m_currentFrame * pixmapSize, 0, pixmapSize, pixmapSize));
} else if (m_audioIconDisplayed && !m_tab->isPinned()) {
m_audioIconRect = r;
p.drawPixmap(r, m_tab->isMuted() ? s_data->audioMutedPixmap : s_data->audioPlayingPixmap);
p.drawPixmap(r, m_tab->isMuted() ? data()->audioMutedPixmap : data()->audioPlayingPixmap);
} else if (!m_sitePixmap.isNull()) {
p.drawPixmap(r, m_sitePixmap);
} else if (m_tab && m_tab->isPinned()) {
@ -218,7 +221,7 @@ void TabIcon::paintEvent(QPaintEvent* event)
p.setPen(c);
p.setBrush(c);
p.drawEllipse(r);
p.drawPixmap(r, m_tab->isMuted() ? s_data->audioMutedPixmap : s_data->audioPlayingPixmap);
p.drawPixmap(r, m_tab->isMuted() ? data()->audioMutedPixmap : data()->audioPlayingPixmap);
}
// Draw background activity indicator

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2014-2018 David Rosca <nowrep@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -32,11 +32,20 @@ class FALKON_EXPORT TabIcon : public QWidget
Q_OBJECT
public:
struct Data {
int framesCount;
int animationInterval;
QPixmap animationPixmap;
QPixmap audioPlayingPixmap;
QPixmap audioMutedPixmap;
};
explicit TabIcon(QWidget* parent = 0);
void setWebTab(WebTab* tab);
void updateIcon();
static Data *data();
signals:
void resized();
@ -64,14 +73,6 @@ private:
bool m_animationRunning;
bool m_audioIconDisplayed;
QRect m_audioIconRect;
struct Data {
int framesCount;
QPixmap animationPixmap;
QPixmap audioPlayingPixmap;
QPixmap audioMutedPixmap;
};
static Data *s_data;
};
#endif // TABICON_H