diff --git a/src/plugins/AutoScroll/AutoScroll.pro b/src/plugins/AutoScroll/AutoScroll.pro index 70831caa0..262450a36 100644 --- a/src/plugins/AutoScroll/AutoScroll.pro +++ b/src/plugins/AutoScroll/AutoScroll.pro @@ -4,12 +4,17 @@ os2: TARGET = AutoScrl SOURCES += autoscrollplugin.cpp \ autoscroller.cpp \ - framescroller.cpp + framescroller.cpp \ + autoscrollsettings.cpp HEADERS += autoscrollplugin.h \ autoscroller.h \ - framescroller.h + framescroller.h \ + autoscrollsettings.h RESOURCES += autoscroll.qrc include(../../plugins.pri) + +FORMS += \ + autoscrollsettings.ui diff --git a/src/plugins/AutoScroll/autoscroller.cpp b/src/plugins/AutoScroll/autoscroller.cpp index 0a6fc22fa..03708125e 100644 --- a/src/plugins/AutoScroll/autoscroller.cpp +++ b/src/plugins/AutoScroll/autoscroller.cpp @@ -1,5 +1,5 @@ /* ============================================================ -* QupZilla - WebKit based browser +* AutoScroll - Autoscroll for QupZilla * Copyright (C) 2014 David Rosca * * This program is free software: you can redistribute it and/or modify @@ -22,21 +22,27 @@ #include #include +#include #include #include -AutoScroller::AutoScroller(const QString &settings, QObject* parent) +AutoScroller::AutoScroller(const QString &settingsFile, QObject* parent) : QObject(parent) , m_view(0) + , m_settingsFile(settingsFile) { - Q_UNUSED(settings) - 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(); } bool AutoScroller::mouseMove(QObject* obj, QMouseEvent* event) @@ -104,6 +110,21 @@ bool AutoScroller::mouseRelease(QObject* obj, QMouseEvent* event) 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) { diff --git a/src/plugins/AutoScroll/autoscroller.h b/src/plugins/AutoScroll/autoscroller.h index c5815bb14..62cf5c700 100644 --- a/src/plugins/AutoScroll/autoscroller.h +++ b/src/plugins/AutoScroll/autoscroller.h @@ -1,5 +1,5 @@ /* ============================================================ -* QupZilla - WebKit based browser +* AutoScroll - Autoscroll for QupZilla * Copyright (C) 2014 David Rosca * * This program is free software: you can redistribute it and/or modify @@ -32,12 +32,15 @@ class AutoScroller : public QObject { Q_OBJECT public: - explicit AutoScroller(const QString &settings, QObject* parent = 0); + explicit AutoScroller(const QString &settingsFile, QObject* parent = 0); 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); @@ -49,6 +52,7 @@ private: WebView* m_view; QLabel* m_indicator; FrameScroller* m_frameScroller; + QString m_settingsFile; }; #endif // AUTOSCROLLER_H diff --git a/src/plugins/AutoScroll/autoscrollplugin.cpp b/src/plugins/AutoScroll/autoscrollplugin.cpp index 8585cad8f..661d66e01 100644 --- a/src/plugins/AutoScroll/autoscrollplugin.cpp +++ b/src/plugins/AutoScroll/autoscrollplugin.cpp @@ -1,5 +1,5 @@ /* ============================================================ -* QupZilla - WebKit based browser +* AutoScroll - Autoscroll for QupZilla * Copyright (C) 2014 David Rosca * * This program is free software: you can redistribute it and/or modify @@ -16,6 +16,7 @@ * along with this program. If not, see . * ============================================================ */ #include "autoscrollplugin.h" +#include "autoscrollsettings.h" #include "autoscroller.h" #include "qupzilla.h" #include "pluginproxy.h" @@ -35,10 +36,10 @@ PluginSpec AutoScrollPlugin::pluginSpec() spec.name = "AutoScroll"; spec.info = "AutoScroll plugin"; spec.description = "Provides support for autoscroll with middle mouse button"; - spec.version = "0.1.1"; + spec.version = "0.1.2"; spec.author = "David Rosca "; - spec.icon = QPixmap(":/autoscroll/data/icon.png"); - spec.hasSettings = false; + spec.icon = QPixmap(":/autoscroll/data/scroll_all.png"); + spec.hasSettings = true; return spec; } @@ -47,7 +48,7 @@ void AutoScrollPlugin::init(InitState state, const QString &settingsPath) { Q_UNUSED(state) - m_scroller = new AutoScroller(settingsPath, this); + m_scroller = new AutoScroller(settingsPath + QLatin1String("extensions.ini"), this); QZ_REGISTER_EVENT_HANDLER(PluginProxy::MouseMoveHandler); QZ_REGISTER_EVENT_HANDLER(PluginProxy::MousePressHandler); @@ -71,6 +72,16 @@ QTranslator* AutoScrollPlugin::getTranslator(const QString &locale) return translator; } +void AutoScrollPlugin::showSettings(QWidget* parent) +{ + if (!m_settings) { + m_settings = new AutoScrollSettings(m_scroller, parent); + } + + m_settings.data()->show(); + m_settings.data()->raise(); +} + bool AutoScrollPlugin::mouseMove(const Qz::ObjectName &type, QObject* obj, QMouseEvent* event) { if (type == Qz::ON_WebView) { diff --git a/src/plugins/AutoScroll/autoscrollplugin.h b/src/plugins/AutoScroll/autoscrollplugin.h index 5ac546b2d..1e05ff18a 100644 --- a/src/plugins/AutoScroll/autoscrollplugin.h +++ b/src/plugins/AutoScroll/autoscrollplugin.h @@ -1,5 +1,5 @@ /* ============================================================ -* QupZilla - WebKit based browser +* AutoScroll - Autoscroll for QupZilla * Copyright (C) 2014 David Rosca * * This program is free software: you can redistribute it and/or modify @@ -21,6 +21,7 @@ #include "plugininterface.h" class AutoScroller; +class AutoScrollSettings; class AutoScrollPlugin : public QObject, public PluginInterface { @@ -40,6 +41,7 @@ public: 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); @@ -47,6 +49,7 @@ public: private: AutoScroller* m_scroller; + QPointer m_settings; }; #endif // TESTPLUGIN_H diff --git a/src/plugins/AutoScroll/autoscrollsettings.cpp b/src/plugins/AutoScroll/autoscrollsettings.cpp new file mode 100644 index 000000000..4a2485717 --- /dev/null +++ b/src/plugins/AutoScroll/autoscrollsettings.cpp @@ -0,0 +1,44 @@ +/* ============================================================ +* AutoScroll - Autoscroll for QupZilla +* Copyright (C) 2014 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 +* 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 . +* ============================================================ */ +#include "autoscrollsettings.h" +#include "ui_autoscrollsettings.h" +#include "autoscroller.h" + +AutoScrollSettings::AutoScrollSettings(AutoScroller* scroller, QWidget* parent) + : QDialog(parent) + , ui(new Ui::AutoScrollSettings) + , m_scroller(scroller) +{ + setAttribute(Qt::WA_DeleteOnClose); + ui->setupUi(this); + ui->divider->setValue(m_scroller->scrollDivider()); + + connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accepted())); + connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(close())); +} + +AutoScrollSettings::~AutoScrollSettings() +{ + delete ui; +} + +void AutoScrollSettings::accepted() +{ + m_scroller->setScrollDivider(ui->divider->value()); + close(); +} diff --git a/src/plugins/AutoScroll/autoscrollsettings.h b/src/plugins/AutoScroll/autoscrollsettings.h new file mode 100644 index 000000000..c4bd27800 --- /dev/null +++ b/src/plugins/AutoScroll/autoscrollsettings.h @@ -0,0 +1,46 @@ +/* ============================================================ +* AutoScroll - Autoscroll for QupZilla +* Copyright (C) 2014 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 +* 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 . +* ============================================================ */ +#ifndef AUTOSCROLLSETTINGS_H +#define AUTOSCROLLSETTINGS_H + +#include + +namespace Ui +{ +class AutoScrollSettings; +} + +class AutoScroller; + +class AutoScrollSettings : public QDialog +{ + Q_OBJECT + +public: + explicit AutoScrollSettings(AutoScroller* scroller, QWidget* parent = 0); + ~AutoScrollSettings(); + +private slots: + void accepted(); + +private: + Ui::AutoScrollSettings* ui; + AutoScroller* m_scroller; +}; + +#endif // AUTOSCROLLSETTINGS_H diff --git a/src/plugins/AutoScroll/autoscrollsettings.ui b/src/plugins/AutoScroll/autoscrollsettings.ui new file mode 100644 index 000000000..2fd2740d1 --- /dev/null +++ b/src/plugins/AutoScroll/autoscrollsettings.ui @@ -0,0 +1,154 @@ + + + AutoScrollSettings + + + + 0 + 0 + 411 + 179 + + + + Dialog + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + :/autoscroll/data/scroll_all.png + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + <h1>AutoScroll</h1> + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Scroll Divider: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + <b>Note:</b> Setting higher divider will slow down scrolling + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + + diff --git a/src/plugins/AutoScroll/framescroller.cpp b/src/plugins/AutoScroll/framescroller.cpp index 36640d323..9f72f0cea 100644 --- a/src/plugins/AutoScroll/framescroller.cpp +++ b/src/plugins/AutoScroll/framescroller.cpp @@ -1,5 +1,5 @@ /* ============================================================ -* QupZilla - WebKit based browser +* AutoScroll - Autoscroll for QupZilla * Copyright (C) 2014 David Rosca * * This program is free software: you can redistribute it and/or modify @@ -26,6 +26,7 @@ FrameScroller::FrameScroller(QObject* parent) , m_frame(0) , m_lengthX(0) , m_lengthY(0) + , m_divider(8.0) { m_timer = new QTimer(this); m_timer->setInterval(10); @@ -37,6 +38,16 @@ 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); @@ -59,5 +70,5 @@ void FrameScroller::stopScrolling() void FrameScroller::scrollStep() { - m_frame->scroll(qCeil(m_lengthX / 8.0), qCeil(m_lengthY / 8.0)); + m_frame->scroll(qCeil(m_lengthX / m_divider), qCeil(m_lengthY / m_divider)); } diff --git a/src/plugins/AutoScroll/framescroller.h b/src/plugins/AutoScroll/framescroller.h index 67417ea14..32f1d9f92 100644 --- a/src/plugins/AutoScroll/framescroller.h +++ b/src/plugins/AutoScroll/framescroller.h @@ -1,5 +1,5 @@ /* ============================================================ -* QupZilla - WebKit based browser +* AutoScroll - Autoscroll for QupZilla * Copyright (C) 2014 David Rosca * * This program is free software: you can redistribute it and/or modify @@ -32,6 +32,9 @@ public: void setFrame(QWebFrame* frame); + double scrollDivider() const; + void setScrollDivider(double divider); + void startScrolling(int lengthX, int lengthY); void stopScrolling(); @@ -44,6 +47,7 @@ private: int m_lengthX; int m_lengthY; + double m_divider; }; #endif // FRAMESCROLLER_H