1
mirror of https://invent.kde.org/network/falkon.git synced 2024-09-22 02:02:10 +02:00

Implement audio mute for webtabs (#2019)

This commit is contained in:
Vlad 2016-08-05 11:50:50 +03:00 committed by David Rosca
parent d0a4cfa726
commit 134737afda
9 changed files with 88 additions and 0 deletions

View File

@ -64,5 +64,7 @@
<file>icons/menu/privatebrowsing.png</file> <file>icons/menu/privatebrowsing.png</file>
<file>icons/menu/settings.png</file> <file>icons/menu/settings.png</file>
<file>icons/other/startpage.png</file> <file>icons/other/startpage.png</file>
<file>icons/other/audioplaying.png</file>
<file>icons/other/audiomuted.png</file>
</qresource> </qresource>
</RCC> </RCC>

Binary file not shown.

After

Width:  |  Height:  |  Size: 241 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 B

View File

@ -330,6 +330,9 @@ void TabBar::contextMenuEvent(QContextMenuEvent* event)
} }
menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab())); menu.addAction(webTab->isPinned() ? tr("Un&pin Tab") : tr("&Pin Tab"), this, SLOT(pinTab()));
#if QT_VERSION >= QT_VERSION_CHECK(5,7,0)
menu.addAction(webTab->isMuted() ? tr("Un&mute Tab") : tr("&Mute Tab"), this, SLOT(muteTab()));
#endif
menu.addSeparator(); menu.addSeparator();
menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs())); menu.addAction(tr("Re&load All Tabs"), m_tabWidget, SLOT(reloadAllTabs()));
menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab())); menu.addAction(tr("&Bookmark This Tab"), this, SLOT(bookmarkTab()));
@ -460,6 +463,15 @@ void TabBar::pinTab()
} }
} }
void TabBar::muteTab()
{
WebTab* webTab = qobject_cast<WebTab*>(m_tabWidget->widget(m_clickedTab));
if (webTab) {
webTab->toggleMuted();
}
}
void TabBar::overrideTabTextColor(int index, QColor color) void TabBar::overrideTabTextColor(int index, QColor color)
{ {
if (!m_originalTabTextColor.isValid()) { if (!m_originalTabTextColor.isValid()) {

View File

@ -69,6 +69,7 @@ private slots:
void bookmarkTab(); void bookmarkTab();
void pinTab(); void pinTab();
void muteTab();
void closeCurrentTab(); void closeCurrentTab();
void closeAllButCurrent(); void closeAllButCurrent();

View File

@ -21,6 +21,7 @@
#include "tabbedwebview.h" #include "tabbedwebview.h"
#include <QTimer> #include <QTimer>
#include <QMouseEvent>
#define ANIMATION_INTERVAL 70 #define ANIMATION_INTERVAL 70
@ -29,12 +30,16 @@ TabIcon::TabIcon(QWidget* parent)
, m_tab(0) , m_tab(0)
, m_currentFrame(0) , m_currentFrame(0)
, m_animationRunning(false) , m_animationRunning(false)
, m_audioIconDisplayed(false)
{ {
setObjectName(QSL("tab-icon")); setObjectName(QSL("tab-icon"));
m_animationPixmap = QIcon(QSL(":icons/other/loading.png")).pixmap(288, 16); m_animationPixmap = QIcon(QSL(":icons/other/loading.png")).pixmap(288, 16);
m_framesCount = m_animationPixmap.width() / m_animationPixmap.height(); m_framesCount = m_animationPixmap.width() / m_animationPixmap.height();
m_audioPlayingPixmap = QIcon(QSL(":icons/other/audioplaying.png")).pixmap(15, 15);
m_audioMutedPixmap = QIcon(QSL(":icons/other/audiomuted.png")).pixmap(15, 15);
m_updateTimer = new QTimer(this); m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(ANIMATION_INTERVAL); m_updateTimer->setInterval(ANIMATION_INTERVAL);
connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateAnimationFrame())); connect(m_updateTimer, SIGNAL(timeout()), this, SLOT(updateAnimationFrame()));
@ -93,6 +98,16 @@ void TabIcon::updateAnimationFrame()
m_currentFrame = (m_currentFrame + 1) % m_framesCount; m_currentFrame = (m_currentFrame + 1) % m_framesCount;
} }
void TabIcon::updateAudioIcon(bool recentlyAudible)
{
if (m_tab->isMuted() || (!m_tab->isMuted() && recentlyAudible))
m_audioIconDisplayed = true;
else
m_audioIconDisplayed = false;
update();
}
void TabIcon::paintEvent(QPaintEvent* event) void TabIcon::paintEvent(QPaintEvent* event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
@ -113,4 +128,26 @@ void TabIcon::paintEvent(QPaintEvent* event)
p.drawPixmap(r, m_animationPixmap, QRect(m_currentFrame * pixmapSize, 0, pixmapSize, pixmapSize)); p.drawPixmap(r, m_animationPixmap, QRect(m_currentFrame * pixmapSize, 0, pixmapSize, pixmapSize));
else else
p.drawPixmap(r, m_sitePixmap); p.drawPixmap(r, m_sitePixmap);
if (m_audioIconDisplayed) {
if (m_tab->isMuted())
p.drawPixmap(QPointF(width() * 0.25, 0), m_audioMutedPixmap);
else
p.drawPixmap(QPointF(width() * 0.25, 0), m_audioPlayingPixmap);
}
}
void TabIcon::mousePressEvent(QMouseEvent *event)
{
#if QT_VERSION >= QT_VERSION_CHECK(5,7,0)
qreal x = event->localPos().x();
qreal y = event->localPos().y();
// if audio icon is clicked - we don't propagate mouse press to the tab
if (m_audioIconDisplayed && x >= width() * 0.25 && y < height() * 0.75)
m_tab->toggleMuted();
else
QWidget::mousePressEvent(event);
#else
QWidget::mousePressEvent(event);
#endif
} }

View File

@ -36,6 +36,7 @@ public:
void setWebTab(WebTab* tab); void setWebTab(WebTab* tab);
void setIcon(const QIcon &icon); void setIcon(const QIcon &icon);
void updateAudioIcon(bool recentlyAudible);
private slots: private slots:
void showIcon(); void showIcon();
@ -46,15 +47,19 @@ private slots:
private: private:
void paintEvent(QPaintEvent* event); void paintEvent(QPaintEvent* event);
void mousePressEvent(QMouseEvent* event);
WebTab* m_tab; WebTab* m_tab;
QTimer* m_updateTimer; QTimer* m_updateTimer;
QPixmap m_sitePixmap; QPixmap m_sitePixmap;
QPixmap m_animationPixmap; QPixmap m_animationPixmap;
QPixmap m_audioPlayingPixmap;
QPixmap m_audioMutedPixmap;
int m_currentFrame; int m_currentFrame;
int m_framesCount; int m_framesCount;
bool m_animationRunning; bool m_animationRunning;
bool m_audioIconDisplayed;
}; };
#endif // TABICON_H #endif // TABICON_H

View File

@ -142,6 +142,9 @@ WebTab::WebTab(BrowserWindow* window)
connect(m_webView, SIGNAL(loadStarted()), this, SLOT(loadStarted())); connect(m_webView, SIGNAL(loadStarted()), this, SLOT(loadStarted()));
connect(m_webView, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished())); connect(m_webView, SIGNAL(loadFinished(bool)), this, SLOT(loadFinished()));
connect(m_webView, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged(QString))); connect(m_webView, SIGNAL(titleChanged(QString)), this, SLOT(titleChanged(QString)));
#if QT_VERSION >= QT_VERSION_CHECK(5,7,0)
connect(m_webView->page(), &QWebEnginePage::recentlyAudibleChanged, tabIcon(), &TabIcon::updateAudioIcon);
#endif
} }
TabbedWebView* WebTab::webView() const TabbedWebView* WebTab::webView() const
@ -292,6 +295,30 @@ void WebTab::setPinned(bool state)
m_isPinned = state; m_isPinned = state;
} }
bool WebTab::isMuted() const
{
#if QT_VERSION >= QT_VERSION_CHECK(5,7,0)
return m_webView->page()->isAudioMuted();
#else
return false;
#endif
}
void WebTab::setMuted(bool muted)
{
#if QT_VERSION >= QT_VERSION_CHECK(5,7,0)
m_webView->page()->setAudioMuted(muted);
#else
Q_UNUSED(muted)
#endif
}
void WebTab::toggleMuted()
{
bool muted = isMuted();
setMuted(!muted);
}
LocationBar* WebTab::locationBar() const LocationBar* WebTab::locationBar() const
{ {
return m_locationBar; return m_locationBar;

View File

@ -84,6 +84,10 @@ public:
void setPinned(bool state); void setPinned(bool state);
void togglePinned(); void togglePinned();
bool isMuted() const;
void setMuted(bool muted);
void toggleMuted();
int tabIndex() const; int tabIndex() const;
bool isCurrentTab() const; bool isCurrentTab() const;