1
mirror of https://invent.kde.org/network/falkon.git synced 2024-12-20 10:46:35 +01:00

TabIcon: Draw small dot in corner when there is activity in pinned tab

This commit is contained in:
David Rosca 2017-01-20 15:09:57 +01:00
parent b13c8968fc
commit a6988ee8f1
3 changed files with 52 additions and 7 deletions

View File

@ -64,6 +64,7 @@ void TabIcon::setWebTab(WebTab* tab)
connect(m_tab->webView(), SIGNAL(loadStarted()), this, SLOT(showLoadingAnimation()));
connect(m_tab->webView(), SIGNAL(loadFinished(bool)), this, SLOT(hideLoadingAnimation()));
connect(m_tab->webView(), &WebView::iconChanged, this, &TabIcon::updateIcon);
connect(m_tab->webView(), &WebView::backgroundActivityChanged, this, [this]() { update(); });
connect(m_tab->webView()->page(), &QWebEnginePage::recentlyAudibleChanged, this, &TabIcon::updateAudioIcon);
updateIcon();
@ -175,6 +176,7 @@ void TabIcon::paintEvent(QPaintEvent* event)
Q_UNUSED(event);
QPainter p(this);
p.setRenderHint(QPainter::Antialiasing);
const int size = 16;
const int pixmapSize = qRound(size * s_data->animationPixmap.devicePixelRatioF());
@ -209,6 +211,24 @@ void TabIcon::paintEvent(QPaintEvent* event)
p.drawEllipse(r);
p.drawPixmap(r, m_tab->isMuted() ? s_data->audioMutedPixmap : s_data->audioPlayingPixmap);
}
// Draw background activity indicator
if (m_tab && m_tab->isPinned() && m_tab->webView()->backgroundActivity()) {
const int s = 5;
// Background
const QRect r1(width() - s - 2, height() - s - 2, s + 2, s + 2);
QColor c1 = palette().color(QPalette::Window);
c1.setAlpha(180);
p.setPen(Qt::transparent);
p.setBrush(c1);
p.drawEllipse(r1);
// Foreground
const QRect r2(width() - s - 1, height() - s - 1, s, s);
QColor c2 = palette().color(QPalette::Text);
p.setPen(Qt::transparent);
p.setBrush(c2);
p.drawEllipse(r2);
}
}
void TabIcon::mousePressEvent(QMouseEvent *event)

View File

@ -54,6 +54,7 @@ bool WebView::s_forceContextMenuOnMouseRelease = false;
WebView::WebView(QWidget* parent)
: QWebEngineView(parent)
, m_progress(100)
, m_backgroundActivity(false)
, m_page(0)
, m_firstLoad(false)
{
@ -62,6 +63,7 @@ WebView::WebView(QWidget* parent)
connect(this, &QWebEngineView::loadFinished, this, &WebView::slotLoadFinished);
connect(this, &QWebEngineView::iconChanged, this, &WebView::slotIconChanged);
connect(this, &QWebEngineView::urlChanged, this, &WebView::slotUrlChanged);
connect(this, &QWebEngineView::titleChanged, this, &WebView::slotTitleChanged);
m_currentZoomLevel = zoomLevels().indexOf(100);
@ -227,10 +229,9 @@ int WebView::loadingProgress() const
return m_progress;
}
void WebView::fakeLoadingProgress(int progress)
bool WebView::backgroundActivity() const
{
emit loadStarted();
emit loadProgress(progress);
return m_backgroundActivity;
}
int WebView::zoomLevel() const
@ -430,6 +431,16 @@ void WebView::slotUrlChanged(const QUrl &url)
}
}
void WebView::slotTitleChanged(const QString &title)
{
Q_UNUSED(title)
if (!isVisible() && !isLoading() && !m_backgroundActivity) {
m_backgroundActivity = true;
emit backgroundActivityChanged(m_backgroundActivity);
}
}
void WebView::openUrlInNewWindow()
{
if (QAction* action = qobject_cast<QAction*>(sender())) {
@ -616,6 +627,16 @@ void WebView::userDefinedOpenUrlInBgTab(const QUrl &url)
userDefinedOpenUrlInNewTab(actionUrl, true);
}
void WebView::showEvent(QShowEvent *event)
{
QWebEngineView::showEvent(event);
if (m_backgroundActivity) {
m_backgroundActivity = false;
emit backgroundActivityChanged(m_backgroundActivity);
}
}
void WebView::createContextMenu(QMenu *menu, WebHitTestResult &hitTest)
{
// cppcheck-suppress variableScope

View File

@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2016 David Rosca <nowrep@gmail.com>
* QupZilla - Qt web browser
* Copyright (C) 2010-2017 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
@ -49,7 +49,8 @@ public:
bool isLoading() const;
int loadingProgress() const;
void fakeLoadingProgress(int progress);
bool backgroundActivity() const;
// Set zoom level (0 - 17)
int zoomLevel() const;
@ -80,6 +81,7 @@ signals:
void showNotification(QWidget*);
void privacyChanged(bool);
void zoomLevelChanged(int);
void backgroundActivityChanged(bool);
public slots:
void zoomIn();
@ -116,6 +118,7 @@ protected slots:
void slotLoadFinished(bool ok);
void slotIconChanged();
void slotUrlChanged(const QUrl &url);
void slotTitleChanged(const QString &title);
// Context menu slots
void openUrlInNewWindow();
@ -139,6 +142,7 @@ protected slots:
void userDefinedOpenUrlInBgTab(const QUrl &url = QUrl());
protected:
void showEvent(QShowEvent *event) override;
void resizeEvent(QResizeEvent *event);
void contextMenuEvent(QContextMenuEvent *event);
@ -175,8 +179,8 @@ private:
void initializeActions();
int m_currentZoomLevel;
int m_progress;
bool m_backgroundActivity;
QUrl m_clickedUrl;
QPointF m_clickedPos;