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

GreaseMonkey: Move icon from statusbar to navigationbar as tool button

This commit is contained in:
David Rosca 2018-01-05 14:17:45 +01:00
parent 0cbbd197ca
commit 23279f6e10
5 changed files with 38 additions and 23 deletions

View File

@ -281,6 +281,10 @@ void NavigationBar::addToolButton(AbstractButtonInterface *button)
data.button = button;
m_widgets[data.id] = data;
if (m_window->weView()) {
data.button->setWebPage(m_window->weView()->page());
}
reloadLayout();
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* GreaseMonkey plugin for Falkon
* Copyright (C) 2013-2017 David Rosca <nowrep@gmail.com>
* Copyright (C) 2013-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
@ -17,21 +17,32 @@
* ============================================================ */
#include "gm_icon.h"
#include "gm_manager.h"
#include "browserwindow.h"
GM_Icon::GM_Icon(GM_Manager* manager, BrowserWindow* window)
: ClickableLabel(window)
#include "webpage.h"
#include "webview.h"
GM_Icon::GM_Icon(GM_Manager *manager)
: AbstractButtonInterface(manager)
, m_manager(manager)
, m_window(window)
{
setCursor(Qt::PointingHandCursor);
setPixmap(QIcon(":gm/data/icon.svg").pixmap(16));
setIcon(QIcon(":gm/data/icon.svg"));
setTitle(tr("GreaseMonkey"));
setToolTip(tr("Open GreaseMonkey settings"));
connect(this, SIGNAL(clicked(QPoint)), this, SLOT(openSettings()));
connect(this, &AbstractButtonInterface::clicked, this, &GM_Icon::openSettings);
}
QString GM_Icon::id() const
{
return QSL("greasemonkey-icon");
}
QString GM_Icon::name() const
{
return tr("GreaseMonkey Icon");
}
void GM_Icon::openSettings()
{
m_manager->showSettings(m_window);
m_manager->showSettings(webPage() ? webPage()->view() : nullptr);
}

View File

@ -1,6 +1,6 @@
/* ============================================================
* GreaseMonkey plugin for Falkon
* Copyright (C) 2013-2014 David Rosca <nowrep@gmail.com>
* Copyright (C) 2013-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
@ -18,24 +18,25 @@
#ifndef GM_ICON_H
#define GM_ICON_H
#include "clickablelabel.h"
#include "abstractbuttoninterface.h"
class BrowserWindow;
class GM_Manager;
class GM_Icon : public ClickableLabel
class GM_Icon : public AbstractButtonInterface
{
Q_OBJECT
public:
explicit GM_Icon(GM_Manager* manager, BrowserWindow* window);
explicit GM_Icon(GM_Manager *manager);
QString id() const override;
QString name() const override;
private slots:
void openSettings();
private:
GM_Manager* m_manager;
BrowserWindow* m_window;
GM_Manager *m_manager;
};
#endif // GM_ICON_H

View File

@ -28,13 +28,13 @@
#include "qztools.h"
#include "mainapplication.h"
#include "networkmanager.h"
#include "navigationbar.h"
#include "desktopnotificationsfactory.h"
#include "javascript/externaljsobject.h"
#include <QTimer>
#include <QDir>
#include <QSettings>
#include <QStatusBar>
#include <QWebEngineProfile>
#include <QWebEngineScriptCollection>
@ -294,14 +294,13 @@ bool GM_Manager::canRunOnScheme(const QString &scheme)
void GM_Manager::mainWindowCreated(BrowserWindow* window)
{
GM_Icon* icon = new GM_Icon(this, window);
window->statusBar()->addPermanentWidget(icon);
GM_Icon *icon = new GM_Icon(this);
window->navigationBar()->addToolButton(icon);
m_windows[window] = icon;
}
void GM_Manager::mainWindowDeleted(BrowserWindow* window)
{
window->statusBar()->removeWidget(m_windows[window]);
delete m_windows[window];
m_windows.remove(window);
window->navigationBar()->removeToolButton(m_windows[window]);
delete m_windows.take(window);
}

View File

@ -40,7 +40,7 @@ PluginSpec GM_Plugin::pluginSpec()
spec.name = "GreaseMonkey";
spec.info = "Userscripts for Falkon";
spec.description = "Provides support for userscripts";
spec.version = "0.9.2";
spec.version = "0.9.3";
spec.author = "David Rosca <nowrep@gmail.com>";
spec.icon = QIcon(":gm/data/icon.svg").pixmap(32);
spec.hasSettings = true;