mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 10:46:35 +01:00
Bring back AutoScroll plugin
This commit is contained in:
parent
758fd6c687
commit
fa2779e6b9
@ -3,13 +3,9 @@ TARGET = $$qtLibraryTarget(AutoScroll)
|
||||
os2: TARGET = AutoScrl
|
||||
|
||||
SOURCES += autoscrollplugin.cpp \
|
||||
autoscroller.cpp \
|
||||
framescroller.cpp \
|
||||
autoscrollsettings.cpp
|
||||
|
||||
HEADERS += autoscrollplugin.h \
|
||||
autoscroller.h \
|
||||
framescroller.h \
|
||||
autoscrollsettings.h
|
||||
|
||||
FORMS += \
|
||||
|
@ -31,5 +31,6 @@
|
||||
<file>locale/sr.qm</file>
|
||||
<file>locale/tr_TR.qm</file>
|
||||
<file>locale/zh_TW.qm</file>
|
||||
<file>data/autoscroll.js</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@ -1,218 +0,0 @@
|
||||
/* ============================================================
|
||||
* AutoScroll - Autoscroll for QupZilla
|
||||
* Copyright (C) 2014 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "autoscroller.h"
|
||||
#include "framescroller.h"
|
||||
#include "webview.h"
|
||||
#include "webpage.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QMouseEvent>
|
||||
#include <QWebFrame>
|
||||
#include <QSettings>
|
||||
#include <QLabel>
|
||||
|
||||
AutoScroller::AutoScroller(const QString &settingsFile, QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_view(0)
|
||||
, m_settingsFile(settingsFile)
|
||||
{
|
||||
m_indicator = new QLabel;
|
||||
m_indicator->resize(32, 32);
|
||||
m_indicator->setContentsMargins(0, 0, 0, 0);
|
||||
m_indicator->installEventFilter(this);
|
||||
|
||||
QSettings settings(m_settingsFile, QSettings::IniFormat);
|
||||
settings.beginGroup("AutoScroll");
|
||||
|
||||
m_frameScroller = new FrameScroller(this);
|
||||
m_frameScroller->setScrollDivider(settings.value("ScrollDivider", 8.0).toDouble());
|
||||
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
AutoScroller::~AutoScroller()
|
||||
{
|
||||
delete m_indicator;
|
||||
}
|
||||
|
||||
bool AutoScroller::mouseMove(QObject* obj, QMouseEvent* event)
|
||||
{
|
||||
Q_UNUSED(obj)
|
||||
|
||||
if (m_indicator->isVisible()) {
|
||||
QRect rect = indicatorGlobalRect();
|
||||
int xlength = 0;
|
||||
int ylength = 0;
|
||||
|
||||
if (rect.left() > event->globalPos().x()) {
|
||||
xlength = event->globalPos().x() - rect.left();
|
||||
}
|
||||
else if (rect.right() < event->globalPos().x()) {
|
||||
xlength = event->globalPos().x() - rect.right();
|
||||
}
|
||||
if (rect.top() > event->globalPos().y()) {
|
||||
ylength = event->globalPos().y() - rect.top();
|
||||
}
|
||||
else if (rect.bottom() < event->globalPos().y()) {
|
||||
ylength = event->globalPos().y() - rect.bottom();
|
||||
}
|
||||
|
||||
m_frameScroller->startScrolling(xlength, ylength);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AutoScroller::mousePress(QObject* obj, QMouseEvent* event)
|
||||
{
|
||||
bool middleButton = event->buttons() == Qt::MiddleButton;
|
||||
WebView* view = qobject_cast<WebView*>(obj);
|
||||
Q_ASSERT(view);
|
||||
|
||||
// Start?
|
||||
if (m_view != view && middleButton) {
|
||||
return showIndicator(view, event->pos());
|
||||
}
|
||||
else if (!m_indicator->isVisible() && middleButton) {
|
||||
return showIndicator(view, event->pos());
|
||||
}
|
||||
|
||||
// Stop
|
||||
if (m_indicator->isVisible()) {
|
||||
stopScrolling();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AutoScroller::mouseRelease(QObject* obj, QMouseEvent* event)
|
||||
{
|
||||
Q_UNUSED(obj)
|
||||
|
||||
if (m_indicator->isVisible()) {
|
||||
if (!indicatorGlobalRect().contains(event->globalPos())) {
|
||||
stopScrolling();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
double AutoScroller::scrollDivider() const
|
||||
{
|
||||
return m_frameScroller->scrollDivider();
|
||||
}
|
||||
|
||||
void AutoScroller::setScrollDivider(double divider)
|
||||
{
|
||||
QSettings settings(m_settingsFile, QSettings::IniFormat);
|
||||
settings.beginGroup("AutoScroll");
|
||||
settings.setValue("ScrollDivider", divider);
|
||||
settings.endGroup();
|
||||
|
||||
m_frameScroller->setScrollDivider(divider);
|
||||
}
|
||||
|
||||
bool AutoScroller::eventFilter(QObject* obj, QEvent* event)
|
||||
{
|
||||
if (obj == m_indicator) {
|
||||
switch (event->type()) {
|
||||
case QEvent::Enter:
|
||||
m_frameScroller->stopScrolling();
|
||||
break;
|
||||
|
||||
case QEvent::Wheel:
|
||||
case QEvent::Hide:
|
||||
case QEvent::MouseButtonPress:
|
||||
stopScrolling();
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AutoScroller::showIndicator(WebView* view, const QPoint &pos)
|
||||
{
|
||||
QWebFrame* frame = view->page()->frameAt(pos);
|
||||
|
||||
if (!frame) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const QWebHitTestResult res = frame->hitTestContent(pos);
|
||||
|
||||
if (res.isContentEditable() || !res.linkUrl().isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool vertical = frame->scrollBarGeometry(Qt::Vertical).isValid();
|
||||
bool horizontal = frame->scrollBarGeometry(Qt::Horizontal).isValid();
|
||||
|
||||
if (!vertical && !horizontal) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vertical && horizontal) {
|
||||
m_indicator->setPixmap(QPixmap(":/autoscroll/data/scroll_all.png"));
|
||||
}
|
||||
else if (vertical) {
|
||||
m_indicator->setPixmap(QPixmap(":/autoscroll/data/scroll_vertical.png"));
|
||||
}
|
||||
else {
|
||||
m_indicator->setPixmap(QPixmap(":/autoscroll/data/scroll_horizontal.png"));
|
||||
}
|
||||
|
||||
m_view = view;
|
||||
|
||||
QPoint p;
|
||||
p.setX(pos.x() - m_indicator->pixmap()->width() / 2);
|
||||
p.setY(pos.y() - m_indicator->pixmap()->height() / 2);
|
||||
|
||||
m_indicator->setParent(view->overlayWidget());
|
||||
m_indicator->move(p);
|
||||
m_indicator->show();
|
||||
|
||||
m_frameScroller->setFrame(frame);
|
||||
|
||||
m_view->grabMouse();
|
||||
QApplication::setOverrideCursor(Qt::ArrowCursor);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AutoScroller::stopScrolling()
|
||||
{
|
||||
m_view->releaseMouse();
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
||||
m_indicator->hide();
|
||||
m_indicator->setParent(0);
|
||||
m_frameScroller->stopScrolling();
|
||||
}
|
||||
|
||||
QRect AutoScroller::indicatorGlobalRect() const
|
||||
{
|
||||
QPoint pos = m_indicator->parentWidget()->mapToGlobal(m_indicator->geometry().topLeft());
|
||||
return QRect(pos.x(), pos.y(), m_indicator->width(), m_indicator->height());
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
/* ============================================================
|
||||
* AutoScroll - Autoscroll for QupZilla
|
||||
* Copyright (C) 2014 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef AUTOSCROLLER_H
|
||||
#define AUTOSCROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QPoint>
|
||||
|
||||
class QMouseEvent;
|
||||
class QLabel;
|
||||
class QRect;
|
||||
|
||||
class WebView;
|
||||
class FrameScroller;
|
||||
|
||||
class AutoScroller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit AutoScroller(const QString &settingsFile, QObject* parent = 0);
|
||||
~AutoScroller();
|
||||
|
||||
bool mouseMove(QObject* obj, QMouseEvent* event);
|
||||
bool mousePress(QObject* obj, QMouseEvent* event);
|
||||
bool mouseRelease(QObject* obj, QMouseEvent* event);
|
||||
|
||||
double scrollDivider() const;
|
||||
void setScrollDivider(double divider);
|
||||
|
||||
private:
|
||||
bool eventFilter(QObject* obj, QEvent* event);
|
||||
|
||||
bool showIndicator(WebView* view, const QPoint &pos);
|
||||
void stopScrolling();
|
||||
|
||||
QRect indicatorGlobalRect() const;
|
||||
|
||||
WebView* m_view;
|
||||
QLabel* m_indicator;
|
||||
FrameScroller* m_frameScroller;
|
||||
QString m_settingsFile;
|
||||
};
|
||||
|
||||
#endif // AUTOSCROLLER_H
|
@ -17,28 +17,28 @@
|
||||
* ============================================================ */
|
||||
#include "autoscrollplugin.h"
|
||||
#include "autoscrollsettings.h"
|
||||
#include "autoscroller.h"
|
||||
#include "browserwindow.h"
|
||||
#include "pluginproxy.h"
|
||||
#include "mainapplication.h"
|
||||
#include "qztools.h"
|
||||
|
||||
#include <QSettings>
|
||||
#include <QTranslator>
|
||||
#include <QWebEngineProfile>
|
||||
#include <QWebEngineScriptCollection>
|
||||
|
||||
AutoScrollPlugin::AutoScrollPlugin()
|
||||
: QObject()
|
||||
, m_scroller(0)
|
||||
{
|
||||
}
|
||||
|
||||
PluginSpec AutoScrollPlugin::pluginSpec()
|
||||
{
|
||||
PluginSpec spec;
|
||||
spec.name = "AutoScroll";
|
||||
spec.info = "AutoScroll plugin";
|
||||
spec.description = "Provides support for autoscroll with middle mouse button";
|
||||
spec.version = "0.1.5";
|
||||
spec.author = "David Rosca <nowrep@gmail.com>";
|
||||
spec.icon = QPixmap(":/autoscroll/data/scroll_all.png");
|
||||
spec.name = QSL("AutoScroll");
|
||||
spec.info = QSL("AutoScroll plugin");
|
||||
spec.description = QSL("Provides support for autoscroll");
|
||||
spec.version = QSL("0.2.0");
|
||||
spec.author = QSL("David Rosca <nowrep@gmail.com>");
|
||||
spec.icon = QPixmap(QSL(":/autoscroll/data/scroll_all.png"));
|
||||
spec.hasSettings = true;
|
||||
|
||||
return spec;
|
||||
@ -48,16 +48,17 @@ void AutoScrollPlugin::init(InitState state, const QString &settingsPath)
|
||||
{
|
||||
Q_UNUSED(state)
|
||||
|
||||
m_scroller = new AutoScroller(settingsPath + QL1S("/extensions.ini"), this);
|
||||
m_settingsPath = settingsPath;
|
||||
|
||||
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseMoveHandler);
|
||||
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler);
|
||||
QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseReleaseHandler);
|
||||
updateScript();
|
||||
}
|
||||
|
||||
void AutoScrollPlugin::unload()
|
||||
{
|
||||
m_scroller->deleteLater();
|
||||
QWebEngineScript script = mApp->webProfile()->scripts()->findScript(QSL("_qupzilla_autoscroll"));
|
||||
if (!script.isNull()) {
|
||||
mApp->webProfile()->scripts()->remove(script);
|
||||
}
|
||||
}
|
||||
|
||||
bool AutoScrollPlugin::testPlugin()
|
||||
@ -66,48 +67,53 @@ bool AutoScrollPlugin::testPlugin()
|
||||
return (Qz::VERSION == QLatin1String(QUPZILLA_VERSION));
|
||||
}
|
||||
|
||||
QTranslator* AutoScrollPlugin::getTranslator(const QString &locale)
|
||||
QTranslator *AutoScrollPlugin::getTranslator(const QString &locale)
|
||||
{
|
||||
QTranslator* translator = new QTranslator(this);
|
||||
translator->load(locale, ":/autoscroll/locale/");
|
||||
translator->load(locale, QSL(":/autoscroll/locale/"));
|
||||
return translator;
|
||||
}
|
||||
|
||||
void AutoScrollPlugin::showSettings(QWidget* parent)
|
||||
void AutoScrollPlugin::showSettings(QWidget *parent)
|
||||
{
|
||||
if (!m_settings) {
|
||||
m_settings = new AutoScrollSettings(m_scroller, parent);
|
||||
m_settings = new AutoScrollSettings(m_settingsPath, parent);
|
||||
connect(m_settings, &AutoScrollSettings::settingsChanged, this, &AutoScrollPlugin::updateScript);
|
||||
}
|
||||
|
||||
m_settings.data()->show();
|
||||
m_settings.data()->raise();
|
||||
}
|
||||
|
||||
bool AutoScrollPlugin::mouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
|
||||
void AutoScrollPlugin::updateScript()
|
||||
{
|
||||
if (type == Qz::ON_WebView) {
|
||||
return m_scroller->mouseMove(obj, event);
|
||||
const QString name = QSL("_qupzilla_autoscroll");
|
||||
|
||||
QWebEngineScript oldScript = mApp->webProfile()->scripts()->findScript(name);
|
||||
if (!oldScript.isNull()) {
|
||||
mApp->webProfile()->scripts()->remove(oldScript);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
QWebEngineScript script;
|
||||
script.setName(name);
|
||||
script.setInjectionPoint(QWebEngineScript::DocumentCreation);
|
||||
script.setWorldId(QWebEngineScript::ApplicationWorld);
|
||||
script.setRunsOnSubFrames(false);
|
||||
|
||||
bool AutoScrollPlugin::mousePress(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
|
||||
{
|
||||
if (type == Qz::ON_WebView) {
|
||||
return m_scroller->mousePress(obj, event);
|
||||
}
|
||||
QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
|
||||
settings.beginGroup(QSL("AutoScroll"));
|
||||
|
||||
return false;
|
||||
}
|
||||
QString source = QzTools::readAllFileContents(QSL(":/autoscroll/data/autoscroll.js"));
|
||||
source.replace(QSL("%MOVE_SPEED%"), settings.value(QSL("Speed"), 5).toString());
|
||||
source.replace(QSL("%CTRL_CLICK%"), settings.value(QSL("CtrlClick"), true).toString());
|
||||
source.replace(QSL("%MIDDLE_CLICK%"), settings.value(QSL("MiddleClick"), true).toString());
|
||||
source.replace(QSL("%IMG_ALL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_all.png"))));
|
||||
source.replace(QSL("%IMG_HORIZONTAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_horizontal.png"))));
|
||||
source.replace(QSL("%IMG_VERTICAL%"), QzTools::pixmapToByteArray(QPixmap(QSL(":/autoscroll/data/scroll_vertical.png"))));
|
||||
|
||||
bool AutoScrollPlugin::mouseRelease(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event)
|
||||
{
|
||||
if (type == Qz::ON_WebView) {
|
||||
return m_scroller->mouseRelease(obj, event);
|
||||
}
|
||||
script.setSourceCode(source);
|
||||
|
||||
return false;
|
||||
mApp->webProfile()->scripts()->insert(script);
|
||||
}
|
||||
|
||||
#if QT_VERSION < 0x050000
|
||||
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "plugininterface.h"
|
||||
|
||||
class AutoScroller;
|
||||
class AutoScrollSettings;
|
||||
|
||||
class AutoScrollPlugin : public QObject, public PluginInterface
|
||||
@ -29,7 +28,7 @@ class AutoScrollPlugin : public QObject, public PluginInterface
|
||||
Q_INTERFACES(PluginInterface)
|
||||
|
||||
#if QT_VERSION >= 0x050000
|
||||
Q_PLUGIN_METADATA(IID "QupZilla.Browser.plugin.TestPlugin")
|
||||
Q_PLUGIN_METADATA(IID "QupZilla.Browser.plugin.AutoScroll")
|
||||
#endif
|
||||
|
||||
public:
|
||||
@ -40,16 +39,14 @@ public:
|
||||
void unload();
|
||||
bool testPlugin();
|
||||
|
||||
QTranslator* getTranslator(const QString &locale);
|
||||
void showSettings(QWidget* parent);
|
||||
|
||||
bool mouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
|
||||
bool mousePress(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
|
||||
bool mouseRelease(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event);
|
||||
QTranslator *getTranslator(const QString &locale);
|
||||
void showSettings(QWidget *parent);
|
||||
|
||||
private:
|
||||
AutoScroller* m_scroller;
|
||||
void updateScript();
|
||||
|
||||
QString m_settingsPath;
|
||||
QPointer<AutoScrollSettings> m_settings;
|
||||
};
|
||||
|
||||
#endif // TESTPLUGIN_H
|
||||
#endif // AUTOSCROLLPLUGIN_H
|
||||
|
@ -17,16 +17,24 @@
|
||||
* ============================================================ */
|
||||
#include "autoscrollsettings.h"
|
||||
#include "ui_autoscrollsettings.h"
|
||||
#include "autoscroller.h"
|
||||
#include "qzcommon.h"
|
||||
|
||||
AutoScrollSettings::AutoScrollSettings(AutoScroller* scroller, QWidget* parent)
|
||||
#include <QSettings>
|
||||
|
||||
AutoScrollSettings::AutoScrollSettings(const QString &settingsPath, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui::AutoScrollSettings)
|
||||
, m_scroller(scroller)
|
||||
, m_settingsPath(settingsPath)
|
||||
{
|
||||
setAttribute(Qt::WA_DeleteOnClose);
|
||||
ui->setupUi(this);
|
||||
ui->divider->setValue(m_scroller->scrollDivider());
|
||||
|
||||
QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
|
||||
settings.beginGroup(QSL("AutoScroll"));
|
||||
|
||||
ui->speed->setValue(11 - settings.value(QSL("Speed"), 5).toInt());
|
||||
ui->ctrlScroll->setChecked(settings.value(QSL("CtrlClick"), false).toBool());
|
||||
ui->middleScroll->setChecked(settings.value(QSL("MiddleClick"), true).toBool());
|
||||
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accepted()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close()));
|
||||
@ -39,6 +47,14 @@ AutoScrollSettings::~AutoScrollSettings()
|
||||
|
||||
void AutoScrollSettings::accepted()
|
||||
{
|
||||
m_scroller->setScrollDivider(ui->divider->value());
|
||||
QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat);
|
||||
settings.beginGroup(QSL("AutoScroll"));
|
||||
|
||||
settings.setValue(QSL("Speed"), 11 - ui->speed->value());
|
||||
settings.setValue(QSL("CtrlClick"), ui->ctrlScroll->isChecked());
|
||||
settings.setValue(QSL("MiddleClick"), ui->middleScroll->isChecked());
|
||||
|
||||
close();
|
||||
|
||||
emit settingsChanged();
|
||||
}
|
||||
|
@ -32,15 +32,18 @@ class AutoScrollSettings : public QDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AutoScrollSettings(AutoScroller* scroller, QWidget* parent = 0);
|
||||
explicit AutoScrollSettings(const QString &settingsPath, QWidget *parent = Q_NULLPTR);
|
||||
~AutoScrollSettings();
|
||||
|
||||
signals:
|
||||
void settingsChanged();
|
||||
|
||||
private slots:
|
||||
void accepted();
|
||||
|
||||
private:
|
||||
Ui::AutoScrollSettings* ui;
|
||||
AutoScroller* m_scroller;
|
||||
QString m_settingsPath;
|
||||
};
|
||||
|
||||
#endif // AUTOSCROLLSETTINGS_H
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>411</width>
|
||||
<height>179</height>
|
||||
<height>208</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -89,53 +89,50 @@
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Scroll Divider:</string>
|
||||
<string>Scroll speed:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDoubleSpinBox" name="divider">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Scroll with middle mouse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Scroll with Ctrl + left mouse</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QCheckBox" name="middleScroll"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QCheckBox" name="ctrlScroll"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="speed">
|
||||
<property name="minimum">
|
||||
<double>1.000000000000000</double>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>10</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_6">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string><b>Note:</b> Setting higher divider will slow down scrolling</string>
|
||||
<string><b>Note:</b> You must reload the page to apply the settings</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
301
src/plugins/AutoScroll/data/autoscroll.js
Normal file
301
src/plugins/AutoScroll/data/autoscroll.js
Normal file
@ -0,0 +1,301 @@
|
||||
/*
|
||||
* AutoScroll
|
||||
*
|
||||
* modified from https://chrome.google.com/webstore/detail/autoscroll/occjjkgifpmdgodlplnacmkejpdionan
|
||||
*/
|
||||
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
function hypot(x, y) {
|
||||
return Math.sqrt(x * x + y * y)
|
||||
}
|
||||
|
||||
var startAnimation = function (f) {
|
||||
(function anon() {
|
||||
f(requestAnimationFrame(anon))
|
||||
})()
|
||||
}
|
||||
var stopAnimation = cancelAnimationFrame
|
||||
|
||||
// The timer that does the actual scrolling; must be very fast so the scrolling is smooth
|
||||
var cycle = {
|
||||
dirX: 0,
|
||||
dirY: 0,
|
||||
start: function (elem) {
|
||||
var self = this
|
||||
|
||||
startAnimation(function (id) {
|
||||
self.timeout = id
|
||||
|
||||
var x = self.dirX
|
||||
, y = self.dirY
|
||||
|
||||
if (x !== 0) {
|
||||
elem.scrollLeft += x
|
||||
}
|
||||
if (y !== 0) {
|
||||
elem.scrollTop += y
|
||||
}
|
||||
})
|
||||
},
|
||||
stop: function () {
|
||||
this.dirX = 0
|
||||
this.dirY = 0
|
||||
stopAnimation(this.timeout)
|
||||
}
|
||||
}
|
||||
|
||||
var options = {
|
||||
dragThreshold: 10,
|
||||
moveThreshold: 20,
|
||||
moveSpeed: %MOVE_SPEED%,
|
||||
stickyScroll: true,
|
||||
ctrlClick: %CTRL_CLICK%,
|
||||
middleClick: %MIDDLE_CLICK%
|
||||
}
|
||||
|
||||
function make(parent, f) {
|
||||
var state = {}
|
||||
|
||||
function image(o) {
|
||||
if (o.width && o.height) {
|
||||
return "data:image/png;base64,%IMG_ALL%"
|
||||
} else if (o.width) {
|
||||
return "data:image/png;base64,%IMG_HORIZONTAL%"
|
||||
} else {
|
||||
return "data:image/png;base64,%IMG_VERTICAL%"
|
||||
}
|
||||
}
|
||||
|
||||
function shouldSticky(x, y) {
|
||||
return options["stickyScroll"] && hypot(x, y) < options["dragThreshold"]
|
||||
}
|
||||
|
||||
function scale(value) {
|
||||
return value / options["moveSpeed"]
|
||||
}
|
||||
|
||||
var e = document.createElement("iframe")
|
||||
e.style.setProperty("display", "none", "important")
|
||||
e.style.setProperty("position", "fixed", "important")
|
||||
e.style.setProperty("padding", "0px", "important")
|
||||
e.style.setProperty("margin", "0px", "important")
|
||||
e.style.setProperty("left", "0px", "important")
|
||||
e.style.setProperty("top", "0px", "important")
|
||||
e.style.setProperty("width", "100%", "important")
|
||||
e.style.setProperty("height", "100%", "important")
|
||||
e.style.setProperty("background-color", "transparent", "important")
|
||||
e.style.setProperty("z-index", "2147483647", "important") // 32-bit signed int
|
||||
e.style.setProperty("border", "none", "important")
|
||||
parent.appendChild(e)
|
||||
|
||||
var inner = e.contentDocument.body
|
||||
|
||||
function stopScroll(e) {
|
||||
if (e.stopImmediatePropagation) {
|
||||
e.stopImmediatePropagation()
|
||||
}
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
function unclick() {
|
||||
cycle.stop()
|
||||
inner.style.removeProperty("cursor")
|
||||
inner.style.setProperty("display", "none", "important")
|
||||
e.style.setProperty("display", "none", "important")
|
||||
delete state.oldX
|
||||
delete state.oldY
|
||||
delete state.click
|
||||
|
||||
// Force relayout
|
||||
getComputedStyle(inner).left;
|
||||
getComputedStyle(e).left;
|
||||
getComputedStyle(eCursor).left;
|
||||
|
||||
removeEventListener("scroll", stopScroll, true)
|
||||
}
|
||||
|
||||
inner.addEventListener("mousewheel", function (event) {
|
||||
event.preventDefault()
|
||||
}, true)
|
||||
|
||||
inner.addEventListener("mousemove", function (event) {
|
||||
var x = event.clientX - state.oldX,
|
||||
y = event.clientY - state.oldY
|
||||
|
||||
if (hypot(x, y) > options["moveThreshold"]) {
|
||||
x = scale(x)
|
||||
y = scale(y)
|
||||
|
||||
cycle.dirX = Math.round(x) | 0
|
||||
cycle.dirY = Math.round(y) | 0
|
||||
} else {
|
||||
cycle.dirX = 0
|
||||
cycle.dirY = 0
|
||||
}
|
||||
}, true)
|
||||
|
||||
inner.addEventListener("mouseup", function (event) {
|
||||
var x = event.clientX - state.oldX,
|
||||
y = event.clientY - state.oldY
|
||||
|
||||
if (state.click || !shouldSticky(x, y)) {
|
||||
unclick()
|
||||
} else {
|
||||
state.click = true
|
||||
}
|
||||
}, true)
|
||||
|
||||
var eCursor = document.createElement("img")
|
||||
eCursor.style.setProperty("position", "absolute")
|
||||
inner.appendChild(eCursor)
|
||||
|
||||
function show(o, x, y) {
|
||||
state.oldX = x
|
||||
state.oldY = y
|
||||
|
||||
addEventListener("scroll", stopScroll, true)
|
||||
|
||||
eCursor.setAttribute("src", image(o))
|
||||
eCursor.style.setProperty("left", (x - 13) + "px")
|
||||
eCursor.style.setProperty("top", (y - 13) + "px")
|
||||
inner.style.setProperty("display", "block", "important")
|
||||
e.style.setProperty("display", "block", "important")
|
||||
cycle.start(o.element)
|
||||
}
|
||||
|
||||
f(show)
|
||||
}
|
||||
|
||||
var htmlNode = document.documentElement
|
||||
|
||||
function isInvalid(elem) {
|
||||
if (elem.localName === "input") {
|
||||
return !(elem.type === "button" ||
|
||||
elem.type === "checkbox" ||
|
||||
elem.type === "file" ||
|
||||
elem.type === "hidden" ||
|
||||
elem.type === "image" ||
|
||||
elem.type === "radio" ||
|
||||
elem.type === "reset" ||
|
||||
elem.type === "submit")
|
||||
} else {
|
||||
while (true) {
|
||||
if (elem === document.body || elem === htmlNode) {
|
||||
return false
|
||||
} else if (elem.localName === "a" && elem.href || elem.localName === "textarea") {
|
||||
return true
|
||||
} else {
|
||||
elem = elem.parentNode
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function canScroll(elem, style) {
|
||||
return style === "auto" || style === "scroll"
|
||||
}
|
||||
|
||||
function canScrollTop(elem, style) {
|
||||
return style === "auto" || style === "scroll" || style === "visible"
|
||||
}
|
||||
|
||||
function hasWidth(elem, can) {
|
||||
var style = getComputedStyle(elem)
|
||||
return can(elem, style.overflowX) && elem.scrollWidth > elem.clientWidth
|
||||
}
|
||||
|
||||
function hasHeight(elem, can) {
|
||||
var style = getComputedStyle(elem)
|
||||
return can(elem, style.overflowY) && elem.scrollHeight > elem.clientHeight
|
||||
}
|
||||
|
||||
function findScroll(elem) {
|
||||
while (elem !== document &&
|
||||
elem !== document.body &&
|
||||
elem !== htmlNode) {
|
||||
|
||||
var width = hasWidth(elem, canScroll)
|
||||
, height = hasHeight(elem, canScroll)
|
||||
|
||||
if (width || height) {
|
||||
return {
|
||||
element: elem,
|
||||
width: width,
|
||||
height: height
|
||||
}
|
||||
|
||||
} else {
|
||||
elem = elem.parentNode
|
||||
}
|
||||
}
|
||||
|
||||
var body_width = hasWidth(document.body, canScrollTop);
|
||||
var body_height = hasHeight(document.body, canScrollTop);
|
||||
|
||||
var html_width = hasWidth(htmlNode, canScrollTop);
|
||||
var html_height = hasHeight(htmlNode, canScrollTop);
|
||||
|
||||
var width = (body_width || html_width);
|
||||
var height = (body_height || html_height);
|
||||
|
||||
if (width || height) {
|
||||
return {
|
||||
element: document.body,
|
||||
width: width,
|
||||
height: height
|
||||
};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
function getBody(x) {
|
||||
if (x === null) {
|
||||
return null;
|
||||
|
||||
} else {
|
||||
return {
|
||||
element: (x.element === htmlNode ? document.body : x.element),
|
||||
width: x.width,
|
||||
height: x.height
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function ready(f) {
|
||||
if (document.body) {
|
||||
f()
|
||||
} else {
|
||||
var observer = new MutationObserver(function () {
|
||||
if (document.body) {
|
||||
observer.disconnect()
|
||||
f()
|
||||
}
|
||||
})
|
||||
observer.observe(htmlNode, { childList: true })
|
||||
}
|
||||
}
|
||||
|
||||
ready(function () {
|
||||
make(document.body, function (show) {
|
||||
addEventListener("mousedown", function (e) {
|
||||
if (((e.button === 1 && options.middleClick) ||
|
||||
(e.button === 0 && (e.ctrlKey || e.metaKey) && options.ctrlClick)) &&
|
||||
e.clientX < htmlNode.clientWidth &&
|
||||
!isInvalid(e.target)) {
|
||||
var elem = getBody(findScroll(e.target))
|
||||
if (elem !== null) {
|
||||
if (e.stopImmediatePropagation) {
|
||||
e.stopImmediatePropagation()
|
||||
}
|
||||
e.stopPropagation()
|
||||
e.preventDefault()
|
||||
show(elem, e.clientX, e.clientY)
|
||||
}
|
||||
}
|
||||
}, true)
|
||||
})
|
||||
})
|
||||
})()
|
@ -1,74 +0,0 @@
|
||||
/* ============================================================
|
||||
* AutoScroll - Autoscroll for QupZilla
|
||||
* Copyright (C) 2014 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#include "framescroller.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include <QWebFrame>
|
||||
#include <QtCore/qmath.h>
|
||||
|
||||
FrameScroller::FrameScroller(QObject* parent)
|
||||
: QObject(parent)
|
||||
, m_frame(0)
|
||||
, m_lengthX(0)
|
||||
, m_lengthY(0)
|
||||
, m_divider(8.0)
|
||||
{
|
||||
m_timer = new QTimer(this);
|
||||
m_timer->setInterval(10);
|
||||
connect(m_timer, SIGNAL(timeout()), this, SLOT(scrollStep()));
|
||||
}
|
||||
|
||||
void FrameScroller::setFrame(QWebFrame* frame)
|
||||
{
|
||||
m_frame = frame;
|
||||
}
|
||||
|
||||
double FrameScroller::scrollDivider() const
|
||||
{
|
||||
return m_divider;
|
||||
}
|
||||
|
||||
void FrameScroller::setScrollDivider(double divider)
|
||||
{
|
||||
m_divider = divider;
|
||||
}
|
||||
|
||||
void FrameScroller::startScrolling(int lengthX, int lengthY)
|
||||
{
|
||||
Q_ASSERT(m_frame);
|
||||
|
||||
m_lengthX = lengthX;
|
||||
m_lengthY = lengthY;
|
||||
|
||||
if (m_lengthX == 0 && m_lengthY == 0) {
|
||||
m_timer->stop();
|
||||
}
|
||||
else if (!m_timer->isActive()) {
|
||||
m_timer->start();
|
||||
}
|
||||
}
|
||||
|
||||
void FrameScroller::stopScrolling()
|
||||
{
|
||||
m_timer->stop();
|
||||
}
|
||||
|
||||
void FrameScroller::scrollStep()
|
||||
{
|
||||
m_frame->scroll(qCeil(m_lengthX / m_divider), qCeil(m_lengthY / m_divider));
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/* ============================================================
|
||||
* AutoScroll - Autoscroll for QupZilla
|
||||
* Copyright (C) 2014 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
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* ============================================================ */
|
||||
#ifndef FRAMESCROLLER_H
|
||||
#define FRAMESCROLLER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
class QTimer;
|
||||
class QWebFrame;
|
||||
|
||||
class FrameScroller : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit FrameScroller(QObject* parent = 0);
|
||||
|
||||
void setFrame(QWebFrame* frame);
|
||||
|
||||
double scrollDivider() const;
|
||||
void setScrollDivider(double divider);
|
||||
|
||||
void startScrolling(int lengthX, int lengthY);
|
||||
void stopScrolling();
|
||||
|
||||
private slots:
|
||||
void scrollStep();
|
||||
|
||||
private:
|
||||
QWebFrame* m_frame;
|
||||
QTimer* m_timer;
|
||||
|
||||
int m_lengthX;
|
||||
int m_lengthY;
|
||||
double m_divider;
|
||||
};
|
||||
|
||||
#endif // FRAMESCROLLER_H
|
@ -20,7 +20,6 @@
|
||||
|
||||
#include "plugininterface.h"
|
||||
|
||||
class WebPage;
|
||||
class GM_Manager;
|
||||
|
||||
class GM_Plugin : public QObject, public PluginInterface
|
||||
|
@ -42,7 +42,6 @@ isEqual(QT_MAJOR_VERSION, 5): !qtHaveModule(KWallet): disablePlugin(KWalletPassw
|
||||
|
||||
# QtWebEngine disable
|
||||
disablePlugin(AccessKeysNavigation)
|
||||
disablePlugin(AutoScroll)
|
||||
disablePlugin(CopyTitle)
|
||||
disablePlugin(MailHandle)
|
||||
disablePlugin(MouseGestures)
|
||||
|
Loading…
Reference in New Issue
Block a user