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

AdBlockIcon: Move from statusbar to navigationbar as tool button

This commit is contained in:
David Rosca 2018-01-05 14:03:31 +01:00
parent 6824ea17f2
commit 0cbbd197ca
5 changed files with 55 additions and 49 deletions

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-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
@ -30,20 +30,19 @@
#include <QMenu>
#include <QTimer>
AdBlockIcon::AdBlockIcon(BrowserWindow* window, QWidget* parent)
: ClickableLabel(parent)
, m_window(window)
AdBlockIcon::AdBlockIcon(QObject *parent)
: AbstractButtonInterface(parent)
, m_menuAction(0)
, m_flashTimer(0)
, m_timerTicks(0)
, m_enabled(false)
{
setObjectName(QSL("adblockicon"));
setCursor(Qt::PointingHandCursor);
setTitle(tr("AdBlock"));
setToolTip(tr("AdBlock lets you block unwanted content on web pages"));
setFixedSize(16, 16);
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
connect(this, &AbstractButtonInterface::clicked, this, &AdBlockIcon::clicked);
setEnabled(AdBlockManager::instance()->isEnabled());
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
}
@ -53,6 +52,16 @@ AdBlockIcon::~AdBlockIcon()
delete m_blockedPopups.at(i).first;
}
QString AdBlockIcon::id() const
{
return QSL("adblock-icon");
}
QString AdBlockIcon::name() const
{
return tr("AdBlock Icon");
}
void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url)
{
int index = ruleString.lastIndexOf(QLatin1String(" ("));
@ -109,10 +118,14 @@ void AdBlockIcon::createMenu(QMenu* menu)
menu->clear();
WebPage* page = webPage();
if (!page) {
return;
}
AdBlockManager* manager = AdBlockManager::instance();
AdBlockCustomList* customList = manager->customList();
WebPage* page = m_window->weView()->page();
const QUrl pageUrl = page->url();
menu->addAction(tr("Show AdBlock &Settings"), manager, SLOT(showDialog()));
@ -152,14 +165,6 @@ void AdBlockIcon::createMenu(QMenu* menu)
}
}
void AdBlockIcon::showMenu(const QPoint &pos)
{
QMenu menu;
createMenu(&menu);
menu.exec(pos);
}
void AdBlockIcon::toggleCustomFilter()
{
QAction* action = qobject_cast<QAction*>(sender());
@ -188,11 +193,11 @@ void AdBlockIcon::animateIcon()
return;
}
if (pixmap()->isNull()) {
setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16));
if (icon().isNull()) {
setIcon(QIcon(QSL(":icons/other/adblock.png")));
}
else {
setPixmap(QPixmap());
setIcon(QIcon());
}
}
@ -205,13 +210,20 @@ void AdBlockIcon::stopAnimation()
setEnabled(m_enabled);
}
void AdBlockIcon::clicked(ClickController *controller)
{
QMenu menu;
createMenu(&menu);
menu.exec(controller->popupPosition(menu.sizeHint()));
}
void AdBlockIcon::setEnabled(bool enabled)
{
if (enabled) {
setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16));
setIcon(QIcon(QSL(":icons/other/adblock.png")));
}
else {
setPixmap(QIcon(QSL(":icons/other/adblock-disabled.png")).pixmap(16));
setIcon(QIcon(QSL(":icons/other/adblock-disabled.png")));
}
m_enabled = enabled;

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-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
@ -19,21 +19,31 @@
#define ADBLOCKICON_H
#include "qzcommon.h"
#include "clickablelabel.h"
#include "adblockrule.h"
#include "abstractbuttoninterface.h"
class QMenu;
class QUrl;
class QMenu;
class QAction;
class BrowserWindow;
class AdBlockRule;
<<<<<<< HEAD
class FALKON_EXPORT AdBlockIcon : public ClickableLabel
||||||| parent of d11997ee... AdBlockIcon: Move from statusbar to navigationbar as tool button
class QUPZILLA_EXPORT AdBlockIcon : public ClickableLabel
=======
class QUPZILLA_EXPORT AdBlockIcon : public AbstractButtonInterface
>>>>>>> d11997ee... AdBlockIcon: Move from statusbar to navigationbar as tool button
{
Q_OBJECT
public:
explicit AdBlockIcon(BrowserWindow* window, QWidget* parent = 0);
explicit AdBlockIcon(QObject *parent = nullptr);
~AdBlockIcon();
QString id() const override;
QString name() const override;
void popupBlocked(const QString &ruleString, const QUrl &url);
QAction* menuAction();
@ -42,14 +52,13 @@ public slots:
void createMenu(QMenu* menu = 0);
private slots:
void showMenu(const QPoint &pos);
void toggleCustomFilter();
void animateIcon();
void stopAnimation();
private:
BrowserWindow* m_window;
void clicked(ClickController *controller);
QAction* m_menuAction;
QVector<QPair<AdBlockRule*, QUrl> > m_blockedPopups;

View File

@ -414,14 +414,14 @@ void BrowserWindow::setupUi()
statusBar()->setObjectName("mainwindow-statusbar");
statusBar()->setCursor(Qt::ArrowCursor);
m_progressBar = new ProgressBar(statusBar());
m_adblockIcon = new AdBlockIcon(this);
m_ipLabel = new QLabel(this);
m_ipLabel->setObjectName("statusbar-ip-label");
m_ipLabel->setToolTip(tr("IP Address of current page"));
statusBar()->addPermanentWidget(m_progressBar);
statusBar()->addPermanentWidget(m_ipLabel);
statusBar()->addPermanentWidget(m_adblockIcon);
m_navigationToolbar->addToolButton(new AdBlockIcon(this));
// Workaround for Oxygen tooltips not having transparent background
QPalette pal = QToolTip::palette();
@ -608,8 +608,6 @@ void BrowserWindow::loadSettings()
}
settings.endGroup();
m_adblockIcon->setEnabled(settings.value("AdBlock/enabled", true).toBool());
statusBar()->setVisible(!isFullScreen() && showStatusBar);
m_bookmarksToolbar->setVisible(showBookmarksToolbar);
m_navigationToolbar->setVisible(showNavigationToolbar);
@ -696,11 +694,6 @@ QLabel* BrowserWindow::ipLabel() const
return m_ipLabel;
}
AdBlockIcon* BrowserWindow::adBlockIcon() const
{
return m_adblockIcon;
}
QMenu* BrowserWindow::superMenu() const
{
return m_superMenu;

View File

@ -115,7 +115,6 @@ public:
NavigationBar* navigationBar() const;
SideBarManager* sideBarManager() const;
QLabel* ipLabel() const;
AdBlockIcon* adBlockIcon() const;
QMenu* superMenu() const;
QUrl homepageUrl() const;
@ -203,8 +202,6 @@ private:
QVBoxLayout* m_mainLayout;
QSplitter* m_mainSplitter;
AdBlockIcon* m_adblockIcon;
TabWidget* m_tabWidget;
QPointer<SideBar> m_sideBar;
SideBarManager* m_sideBarManager;

View File

@ -1,6 +1,6 @@
/* ============================================================
* Falkon - Qt web browser
* Copyright (C) 2010-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2010-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
@ -28,7 +28,6 @@
#include "iconprovider.h"
#include "searchenginesmanager.h"
#include "enhancedmenu.h"
#include "adblockicon.h"
#include "locationbar.h"
#include "webhittestresult.h"
#include "webinspector.h"
@ -199,10 +198,6 @@ void TabbedWebView::_contextMenuEvent(QContextMenuEvent *event)
WebHitTestResult hitTest = page()->hitTestContent(event->pos());
createContextMenu(m_menu, hitTest);
if (!hitTest.isContentEditable() && !hitTest.isContentSelected() && m_window) {
m_menu->addAction(m_window->adBlockIcon()->menuAction());
}
if (WebInspector::isEnabled()) {
m_menu->addSeparator();
m_menu->addAction(tr("Inspect Element"), this, SLOT(inspectElement()));