From a6988ee8f1c5bd675a571cc948238ac8b90198dc Mon Sep 17 00:00:00 2001 From: David Rosca Date: Fri, 20 Jan 2017 15:09:57 +0100 Subject: [PATCH] TabIcon: Draw small dot in corner when there is activity in pinned tab --- src/lib/tabwidget/tabicon.cpp | 20 ++++++++++++++++++++ src/lib/webengine/webview.cpp | 27 ++++++++++++++++++++++++--- src/lib/webengine/webview.h | 12 ++++++++---- 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/lib/tabwidget/tabicon.cpp b/src/lib/tabwidget/tabicon.cpp index a0de8bc84..a3563fdfa 100644 --- a/src/lib/tabwidget/tabicon.cpp +++ b/src/lib/tabwidget/tabicon.cpp @@ -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) diff --git a/src/lib/webengine/webview.cpp b/src/lib/webengine/webview.cpp index ca9c02ea5..e9ef26040 100644 --- a/src/lib/webengine/webview.cpp +++ b/src/lib/webengine/webview.cpp @@ -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(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 diff --git a/src/lib/webengine/webview.h b/src/lib/webengine/webview.h index 85ba54c40..3a56bb4f3 100644 --- a/src/lib/webengine/webview.h +++ b/src/lib/webengine/webview.h @@ -1,6 +1,6 @@ /* ============================================================ -* QupZilla - WebKit based browser -* Copyright (C) 2010-2016 David Rosca +* QupZilla - Qt web browser +* Copyright (C) 2010-2017 David Rosca * * 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;