diff --git a/src/lib/adblock/adblockicon.cpp b/src/lib/adblock/adblockicon.cpp index 40e4b075f..6b0f388bd 100644 --- a/src/lib/adblock/adblockicon.cpp +++ b/src/lib/adblock/adblockicon.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2018 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 @@ -30,20 +30,19 @@ #include #include -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(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; diff --git a/src/lib/adblock/adblockicon.h b/src/lib/adblock/adblockicon.h index 455e2a5ae..8f2bb65a2 100644 --- a/src/lib/adblock/adblockicon.h +++ b/src/lib/adblock/adblockicon.h @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2014 David Rosca +* Copyright (C) 2010-2018 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 @@ -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 > m_blockedPopups; diff --git a/src/lib/app/browserwindow.cpp b/src/lib/app/browserwindow.cpp index e3679810d..77d26f901 100644 --- a/src/lib/app/browserwindow.cpp +++ b/src/lib/app/browserwindow.cpp @@ -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; diff --git a/src/lib/app/browserwindow.h b/src/lib/app/browserwindow.h index ec429c87b..15b6df961 100644 --- a/src/lib/app/browserwindow.h +++ b/src/lib/app/browserwindow.h @@ -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 m_sideBar; SideBarManager* m_sideBarManager; diff --git a/src/lib/webtab/tabbedwebview.cpp b/src/lib/webtab/tabbedwebview.cpp index 9b40d1a91..654fecc38 100644 --- a/src/lib/webtab/tabbedwebview.cpp +++ b/src/lib/webtab/tabbedwebview.cpp @@ -1,6 +1,6 @@ /* ============================================================ * Falkon - Qt web browser -* Copyright (C) 2010-2017 David Rosca +* Copyright (C) 2010-2018 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 @@ -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()));