Clean unneeded base class.
This commit is contained in:
parent
2d65eecce3
commit
c8f01e6506
@ -519,7 +519,6 @@ equals(USE_WEBENGINE, true) {
|
||||
src/network-web/adblock/adblockurlinterceptor.h \
|
||||
src/network-web/urlinterceptor.h \
|
||||
src/network-web/networkurlinterceptor.h \
|
||||
src/gui/clickablelabel.h \
|
||||
src/miscellaneous/simpleregexp.h \
|
||||
src/gui/treewidget.h
|
||||
|
||||
@ -534,7 +533,6 @@ equals(USE_WEBENGINE, true) {
|
||||
src/network-web/adblock/adblocktreewidget.cpp \
|
||||
src/network-web/adblock/adblockurlinterceptor.cpp \
|
||||
src/network-web/networkurlinterceptor.cpp \
|
||||
src/gui/clickablelabel.cpp \
|
||||
src/miscellaneous/simpleregexp.cpp \
|
||||
src/gui/treewidget.cpp
|
||||
|
||||
|
@ -1,87 +0,0 @@
|
||||
// This file is part of RSS Guard.
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#include "gui/clickablelabel.h"
|
||||
|
||||
#include "miscellaneous/application.h"
|
||||
#include "miscellaneous/iconfactory.h"
|
||||
|
||||
#include <QMouseEvent>
|
||||
|
||||
|
||||
ClickableLabel::ClickableLabel(QWidget* parent)
|
||||
: QLabel(parent) {
|
||||
}
|
||||
|
||||
QString ClickableLabel::themeIcon() const {
|
||||
return m_themeIcon;
|
||||
}
|
||||
|
||||
void ClickableLabel::setThemeIcon(const QString& name) {
|
||||
m_themeIcon = name;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
QIcon ClickableLabel::fallbackIcon() const {
|
||||
return m_fallbackIcon;
|
||||
}
|
||||
|
||||
void ClickableLabel::setFallbackIcon(const QIcon& fallbackIcon) {
|
||||
m_fallbackIcon = fallbackIcon;
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void ClickableLabel::updateIcon() {
|
||||
if (!m_themeIcon.isEmpty()) {
|
||||
const QIcon icon = qApp->icons()->fromTheme(m_themeIcon);
|
||||
|
||||
if (!icon.isNull()) {
|
||||
setPixmap(icon.pixmap(size()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (!m_fallbackIcon.isNull()) {
|
||||
setPixmap(m_fallbackIcon.pixmap(size()));
|
||||
}
|
||||
}
|
||||
|
||||
void ClickableLabel::resizeEvent(QResizeEvent* ev) {
|
||||
QLabel::resizeEvent(ev);
|
||||
updateIcon();
|
||||
}
|
||||
|
||||
void ClickableLabel::mouseReleaseEvent(QMouseEvent* ev) {
|
||||
if (ev->button() == Qt::LeftButton && rect().contains(ev->pos())) {
|
||||
if (ev->modifiers() == Qt::ControlModifier) {
|
||||
emit middleClicked(ev->globalPos());
|
||||
}
|
||||
|
||||
else {
|
||||
emit clicked(ev->globalPos());
|
||||
}
|
||||
}
|
||||
|
||||
else if (ev->button() == Qt::MiddleButton && rect().contains(ev->pos())) {
|
||||
emit middleClicked(ev->globalPos());
|
||||
}
|
||||
|
||||
else {
|
||||
QLabel::mouseReleaseEvent(ev);
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
// This file is part of RSS Guard.
|
||||
//
|
||||
// Copyright (C) 2011-2017 by Martin Rotter <rotter.martinos@gmail.com>
|
||||
// Copyright (C) 2010-2014 by David Rosca <nowrep@gmail.com>
|
||||
//
|
||||
// RSS Guard is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// RSS Guard is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with RSS Guard. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#ifndef CLICKABLELABEL_H
|
||||
#define CLICKABLELABEL_H
|
||||
|
||||
#include <QLabel>
|
||||
#include <QIcon>
|
||||
|
||||
|
||||
class QMouseEvent;
|
||||
|
||||
class ClickableLabel : public QLabel {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QSize fixedsize READ size WRITE setFixedSize)
|
||||
Q_PROPERTY(int fixedwidth READ width WRITE setFixedWidth)
|
||||
Q_PROPERTY(int fixedheight READ height WRITE setFixedHeight)
|
||||
Q_PROPERTY(QString themeIcon READ themeIcon WRITE setThemeIcon)
|
||||
Q_PROPERTY(QIcon fallbackIcon READ fallbackIcon WRITE setFallbackIcon)
|
||||
|
||||
public:
|
||||
explicit ClickableLabel(QWidget* parent = 0);
|
||||
|
||||
QString themeIcon() const;
|
||||
void setThemeIcon(const QString& name);
|
||||
|
||||
QIcon fallbackIcon() const;
|
||||
void setFallbackIcon(const QIcon& fallbackIcon);
|
||||
|
||||
signals:
|
||||
void clicked(QPoint);
|
||||
void middleClicked(QPoint);
|
||||
|
||||
private:
|
||||
void updateIcon();
|
||||
|
||||
void resizeEvent(QResizeEvent* ev);
|
||||
void mouseReleaseEvent(QMouseEvent* ev);
|
||||
|
||||
QString m_themeIcon;
|
||||
QIcon m_fallbackIcon;
|
||||
|
||||
};
|
||||
|
||||
#endif // CLICKABLELABEL_H
|
@ -63,20 +63,23 @@
|
||||
FormMain::FormMain(QWidget* parent, Qt::WindowFlags f)
|
||||
: QMainWindow(parent, f), m_ui(new Ui::FormMain) {
|
||||
m_ui->setupUi(this);
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
m_adblockIcon = new AdBlockIcon(this);
|
||||
m_adblockIconAction = m_adblockIcon->menuAction();
|
||||
m_adblockIconAction->setObjectName(QSL("m_adblockIconAction"));
|
||||
m_ui->m_menuTools->addAction(m_adblockIconAction);
|
||||
m_adblockIcon->setObjectName(QSL("m_adblockIconAction"));
|
||||
m_ui->m_menuTools->addAction(m_adblockIcon);
|
||||
#endif
|
||||
|
||||
qApp->setMainForm(this);
|
||||
// Add these actions to the list of actions of the main window.
|
||||
// This allows to use actions via shortcuts
|
||||
// even if main menu is not visible.
|
||||
addActions(allActions());
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
addAction(m_adblockIconAction);
|
||||
addAction(m_adblockIcon);
|
||||
#endif
|
||||
|
||||
m_statusBar = new StatusBar(this);
|
||||
setStatusBar(m_statusBar);
|
||||
// Prepare main window and tabs.
|
||||
@ -183,7 +186,7 @@ QList<QAction*> FormMain::allActions() const {
|
||||
actions << m_ui->m_actionExpandCollapseItem;
|
||||
#if defined(USE_WEBENGINE)
|
||||
actions << m_ui->m_actionTabNewWebBrowser;
|
||||
actions << m_adblockIconAction;
|
||||
actions << m_adblockIcon;
|
||||
#endif
|
||||
actions << m_ui->m_actionTabsCloseAll;
|
||||
actions << m_ui->m_actionTabsCloseAllExceptCurrent;
|
||||
|
@ -114,7 +114,6 @@ class FormMain : public QMainWindow {
|
||||
|
||||
#if defined(USE_WEBENGINE)
|
||||
AdBlockIcon* m_adblockIcon;
|
||||
QAction* m_adblockIconAction;
|
||||
#endif
|
||||
|
||||
QScopedPointer<Ui::FormMain> m_ui;
|
||||
|
@ -144,7 +144,7 @@ void WebViewer::clear() {
|
||||
void WebViewer::contextMenuEvent(QContextMenuEvent* event) {
|
||||
event->accept();
|
||||
QMenu* menu = page()->createStandardContextMenu();
|
||||
menu->addAction(qApp->mainForm()->adblockIcon()->menuAction());
|
||||
menu->addAction(qApp->mainForm()->adblockIcon());
|
||||
const QPoint pos = event->globalPos();
|
||||
QPoint p(pos.x(), pos.y() + 1);
|
||||
menu->popup(p);
|
||||
|
@ -32,20 +32,27 @@
|
||||
#include <QTimer>
|
||||
|
||||
|
||||
AdBlockIcon::AdBlockIcon(QWidget* parent)
|
||||
: ClickableLabel(parent), m_menuAction(0), m_flashTimer(0), m_timerTicks(0), m_enabled(false) {
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
AdBlockIcon::AdBlockIcon(QObject* parent)
|
||||
: QAction(parent), m_flashTimer(0), m_timerTicks(0), m_enabled(AdBlockManager::instance()->isEnabled()) {
|
||||
setToolTip(tr("AdBlock lets you block unwanted content on web pages"));
|
||||
setFixedSize(16, 16);
|
||||
setText(QSL("AdBlock"));
|
||||
setMenu(new QMenu());
|
||||
setIcon(m_enabled ? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE) : qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
|
||||
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(showMenu(QPoint)));
|
||||
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
||||
m_enabled = AdBlockManager::instance()->isEnabled();
|
||||
connect(menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||
connect(this, &QAction::triggered, AdBlockManager::instance(), &AdBlockManager::showDialog);
|
||||
}
|
||||
|
||||
AdBlockIcon::~AdBlockIcon() {
|
||||
for (int i = 0; i < m_blockedPopups.count(); ++i) {
|
||||
delete m_blockedPopups.at(i).first;
|
||||
}
|
||||
|
||||
if (menu() != nullptr) {
|
||||
menu()->deleteLater();
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::popupBlocked(const QString& ruleString, const QUrl& url) {
|
||||
@ -77,18 +84,6 @@ void AdBlockIcon::popupBlocked(const QString& ruleString, const QUrl& url) {
|
||||
connect(m_flashTimer, &QTimer::timeout, this, &AdBlockIcon::animateIcon);
|
||||
}
|
||||
|
||||
QAction* AdBlockIcon::menuAction() {
|
||||
if (!m_menuAction) {
|
||||
m_menuAction = new QAction(tr("AdBlock"), this);
|
||||
m_menuAction->setMenu(new QMenu(this));
|
||||
connect(m_menuAction->menu(), SIGNAL(aboutToShow()), this, SLOT(createMenu()));
|
||||
connect(m_menuAction, &QAction::triggered, AdBlockManager::instance(), &AdBlockManager::showDialog);
|
||||
}
|
||||
|
||||
m_menuAction->setIcon(m_enabled ? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE) : qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
return m_menuAction;
|
||||
}
|
||||
|
||||
void AdBlockIcon::createMenu(QMenu* menu) {
|
||||
if (!menu) {
|
||||
menu = qobject_cast<QMenu*>(sender());
|
||||
@ -159,12 +154,12 @@ void AdBlockIcon::animateIcon() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pixmap()->isNull()) {
|
||||
setPixmap(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE).pixmap(16));
|
||||
if (icon().isNull()) {
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
}
|
||||
|
||||
else {
|
||||
setPixmap(QPixmap());
|
||||
setIcon(QIcon());
|
||||
}
|
||||
}
|
||||
|
||||
@ -177,15 +172,10 @@ void AdBlockIcon::stopAnimation() {
|
||||
|
||||
void AdBlockIcon::setEnabled(bool enabled) {
|
||||
if (enabled) {
|
||||
setPixmap(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE).pixmap(16));
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE));
|
||||
}
|
||||
|
||||
else {
|
||||
setPixmap(qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED).pixmap(16));
|
||||
}
|
||||
|
||||
if (m_menuAction != nullptr) {
|
||||
m_menuAction->setIcon(enabled ? qApp->icons()->miscIcon(ADBLOCK_ICON_ACTIVE) : qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
setIcon(qApp->icons()->miscIcon(ADBLOCK_ICON_DISABLED));
|
||||
}
|
||||
|
||||
m_enabled = enabled;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#ifndef ADBLOCKICON_H
|
||||
#define ADBLOCKICON_H
|
||||
|
||||
#include "gui/clickablelabel.h"
|
||||
#include <QAction>
|
||||
|
||||
#include "network-web/adblock/adblockrule.h"
|
||||
|
||||
@ -31,15 +31,14 @@ class QTimer;
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
class AdBlockIcon : public ClickableLabel {
|
||||
class AdBlockIcon : public QAction {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AdBlockIcon(QWidget* parent = 0);
|
||||
explicit AdBlockIcon(QObject* parent = 0);
|
||||
virtual ~AdBlockIcon();
|
||||
|
||||
void popupBlocked(const QString& ruleString, const QUrl& url);
|
||||
QAction* menuAction();
|
||||
|
||||
public slots:
|
||||
void setEnabled(bool enabled);
|
||||
@ -53,8 +52,6 @@ class AdBlockIcon : public ClickableLabel {
|
||||
void stopAnimation();
|
||||
|
||||
private:
|
||||
QAction* m_menuAction;
|
||||
|
||||
QVector<QPair<AdBlockRule*, QUrl>> m_blockedPopups;
|
||||
QTimer* m_flashTimer;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user