Added clickable label.
This commit is contained in:
parent
f02f8bab09
commit
b6d7e8be2e
5 changed files with 294 additions and 160 deletions
|
@ -334,7 +334,8 @@ HEADERS += src/core/feeddownloader.h \
|
|||
src/core/messagesmodelsqllayer.h \
|
||||
src/gui/treeviewcolumnsmenu.h \
|
||||
src/services/abstract/labelsrootitem.h \
|
||||
src/services/abstract/label.h
|
||||
src/services/abstract/label.h \
|
||||
src/gui/clickablelabel.h
|
||||
|
||||
SOURCES += src/core/feeddownloader.cpp \
|
||||
src/core/feedsmodel.cpp \
|
||||
|
@ -460,7 +461,8 @@ SOURCES += src/core/feeddownloader.cpp \
|
|||
src/core/messagesmodelsqllayer.cpp \
|
||||
src/gui/treeviewcolumnsmenu.cpp \
|
||||
src/services/abstract/labelsrootitem.cpp \
|
||||
src/services/abstract/label.cpp
|
||||
src/services/abstract/label.cpp \
|
||||
src/gui/clickablelabel.cpp
|
||||
|
||||
OBJECTIVE_SOURCES += src/miscellaneous/disablewindowtabbing.mm
|
||||
|
||||
|
|
85
src/gui/clickablelabel.cpp
Executable file
85
src/gui/clickablelabel.cpp
Executable file
|
@ -0,0 +1,85 @@
|
|||
// 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);
|
||||
}
|
||||
}
|
60
src/gui/clickablelabel.h
Executable file
60
src/gui/clickablelabel.h
Executable file
|
@ -0,0 +1,60 @@
|
|||
// 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
|
|
@ -20,25 +20,13 @@
|
|||
#include "adblockrule.h"
|
||||
#include "adblockmanager.h"
|
||||
#include "adblocksubscription.h"
|
||||
#include "mainapplication.h"
|
||||
#include "browserwindow.h"
|
||||
#include "webpage.h"
|
||||
#include "tabbedwebview.h"
|
||||
#include "tabwidget.h"
|
||||
#include "desktopnotificationsfactory.h"
|
||||
#include "qztools.h"
|
||||
|
||||
#include <QMenu>
|
||||
#include <QTimer>
|
||||
|
||||
AdBlockIcon::AdBlockIcon(BrowserWindow* window, QWidget* parent)
|
||||
: ClickableLabel(parent)
|
||||
, m_window(window)
|
||||
, m_menuAction(0)
|
||||
, m_flashTimer(0)
|
||||
, m_timerTicks(0)
|
||||
, m_enabled(false)
|
||||
{
|
||||
: ClickableLabel(parent), m_window(window), m_menuAction(0), m_flashTimer(0), m_timerTicks(0), m_enabled(false) {
|
||||
setCursor(Qt::PointingHandCursor);
|
||||
setToolTip(tr("AdBlock lets you block unwanted content on web pages"));
|
||||
setFixedSize(16, 16);
|
||||
|
@ -47,14 +35,13 @@ AdBlockIcon::AdBlockIcon(BrowserWindow* window, QWidget* parent)
|
|||
connect(AdBlockManager::instance(), SIGNAL(enabledChanged(bool)), this, SLOT(setEnabled(bool)));
|
||||
}
|
||||
|
||||
AdBlockIcon::~AdBlockIcon()
|
||||
{
|
||||
for (int i = 0; i < m_blockedPopups.count(); ++i)
|
||||
AdBlockIcon::~AdBlockIcon() {
|
||||
for (int i = 0; i < m_blockedPopups.count(); ++i) {
|
||||
delete m_blockedPopups.at(i).first;
|
||||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url)
|
||||
{
|
||||
void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url) {
|
||||
int index = ruleString.lastIndexOf(QLatin1String(" ("));
|
||||
|
||||
const QString subscriptionName = ruleString.left(index);
|
||||
|
@ -85,8 +72,7 @@ void AdBlockIcon::popupBlocked(const QString &ruleString, const QUrl &url)
|
|||
connect(m_flashTimer, SIGNAL(timeout()), this, SLOT(animateIcon()));
|
||||
}
|
||||
|
||||
QAction* AdBlockIcon::menuAction()
|
||||
{
|
||||
QAction *AdBlockIcon::menuAction() {
|
||||
if (!m_menuAction) {
|
||||
m_menuAction = new QAction(tr("AdBlock"), this);
|
||||
m_menuAction->setMenu(new QMenu);
|
||||
|
@ -98,10 +84,10 @@ QAction* AdBlockIcon::menuAction()
|
|||
return m_menuAction;
|
||||
}
|
||||
|
||||
void AdBlockIcon::createMenu(QMenu* menu)
|
||||
{
|
||||
void AdBlockIcon::createMenu(QMenu* menu) {
|
||||
if (!menu) {
|
||||
menu = qobject_cast<QMenu*>(sender());
|
||||
|
||||
if (!menu) {
|
||||
return;
|
||||
}
|
||||
|
@ -140,6 +126,7 @@ void AdBlockIcon::createMenu(QMenu* menu)
|
|||
|
||||
if (!m_blockedPopups.isEmpty()) {
|
||||
menu->addAction(tr("Blocked Popup Windows"))->setEnabled(false);
|
||||
|
||||
for (int i = 0; i < m_blockedPopups.count(); i++) {
|
||||
const QPair<AdBlockRule*, QUrl> &pair = m_blockedPopups.at(i);
|
||||
|
||||
|
@ -152,17 +139,16 @@ void AdBlockIcon::createMenu(QMenu* menu)
|
|||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::showMenu(const QPoint &pos)
|
||||
{
|
||||
void AdBlockIcon::showMenu(const QPoint &pos) {
|
||||
QMenu menu;
|
||||
createMenu(&menu);
|
||||
|
||||
menu.exec(pos);
|
||||
}
|
||||
|
||||
void AdBlockIcon::toggleCustomFilter()
|
||||
{
|
||||
void AdBlockIcon::toggleCustomFilter() {
|
||||
QAction* action = qobject_cast<QAction*>(sender());
|
||||
|
||||
if (!action) {
|
||||
return;
|
||||
}
|
||||
|
@ -180,9 +166,9 @@ void AdBlockIcon::toggleCustomFilter()
|
|||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::animateIcon()
|
||||
{
|
||||
void AdBlockIcon::animateIcon() {
|
||||
++m_timerTicks;
|
||||
|
||||
if (m_timerTicks > 10) {
|
||||
stopAnimation();
|
||||
return;
|
||||
|
@ -196,8 +182,7 @@ void AdBlockIcon::animateIcon()
|
|||
}
|
||||
}
|
||||
|
||||
void AdBlockIcon::stopAnimation()
|
||||
{
|
||||
void AdBlockIcon::stopAnimation() {
|
||||
m_timerTicks = 0;
|
||||
m_flashTimer->stop();
|
||||
disconnect(m_flashTimer, SIGNAL(timeout()), this, SLOT(animateIcon()));
|
||||
|
@ -205,8 +190,7 @@ void AdBlockIcon::stopAnimation()
|
|||
setEnabled(m_enabled);
|
||||
}
|
||||
|
||||
void AdBlockIcon::setEnabled(bool enabled)
|
||||
{
|
||||
void AdBlockIcon::setEnabled(bool enabled) {
|
||||
if (enabled) {
|
||||
setPixmap(QIcon(QSL(":icons/other/adblock.png")).pixmap(16));
|
||||
}
|
||||
|
|
|
@ -19,21 +19,24 @@
|
|||
#ifndef ADBLOCKICON_H
|
||||
#define ADBLOCKICON_H
|
||||
|
||||
#include "qzcommon.h"
|
||||
#include "clickablelabel.h"
|
||||
#include "adblockrule.h"
|
||||
#include "gui/clickablelabel.h"
|
||||
|
||||
#include "network-web/adblock/adblockrule.h"
|
||||
|
||||
|
||||
class QMenu;
|
||||
class QUrl;
|
||||
class QAction;
|
||||
class QTimer;
|
||||
|
||||
class BrowserWindow;
|
||||
|
||||
class QUPZILLA_EXPORT AdBlockIcon : public ClickableLabel
|
||||
{
|
||||
class AdBlockIcon : public ClickableLabel {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AdBlockIcon(BrowserWindow* window, QWidget* parent = 0);
|
||||
~AdBlockIcon();
|
||||
virtual ~AdBlockIcon();
|
||||
|
||||
void popupBlocked(const QString &ruleString, const QUrl &url);
|
||||
QAction *menuAction();
|
||||
|
|
Loading…
Add table
Reference in a new issue