File indexing completed on 2024-05-19 04:59:14
0001 /* ============================================================ 0002 * AutoScroll - Autoscroll for Falkon 0003 * Copyright (C) 2014-2017 David Rosca <nowrep@gmail.com> 0004 * 0005 * This program is free software: you can redistribute it and/or modify 0006 * it under the terms of the GNU General Public License as published by 0007 * the Free Software Foundation, either version 3 of the License, or 0008 * (at your option) any later version. 0009 * 0010 * This program is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0013 * GNU General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU General Public License 0016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0017 * ============================================================ */ 0018 #include "autoscrollplugin.h" 0019 #include "autoscrollsettings.h" 0020 #include "autoscroller.h" 0021 #include "browserwindow.h" 0022 #include "pluginproxy.h" 0023 #include "mainapplication.h" 0024 #include "../config.h" 0025 0026 AutoScrollPlugin::AutoScrollPlugin() 0027 : QObject() 0028 , m_scroller(nullptr) 0029 { 0030 } 0031 0032 void AutoScrollPlugin::init(InitState state, const QString &settingsPath) 0033 { 0034 Q_UNUSED(state) 0035 0036 m_scroller = new AutoScroller(settingsPath + QL1S("/extensions.ini"), this); 0037 0038 mApp->plugins()->registerAppEventHandler(PluginProxy::MouseMoveHandler, this); 0039 mApp->plugins()->registerAppEventHandler(PluginProxy::MousePressHandler, this); 0040 mApp->plugins()->registerAppEventHandler(PluginProxy::MouseReleaseHandler, this); 0041 mApp->plugins()->registerAppEventHandler(PluginProxy::WheelEventHandler, this); 0042 } 0043 0044 void AutoScrollPlugin::unload() 0045 { 0046 m_scroller->deleteLater(); 0047 } 0048 0049 bool AutoScrollPlugin::testPlugin() 0050 { 0051 // Require the version that the plugin was built with 0052 return (QString::fromLatin1(Qz::VERSION) == QLatin1String(FALKON_VERSION)); 0053 } 0054 0055 void AutoScrollPlugin::showSettings(QWidget* parent) 0056 { 0057 if (!m_settings) { 0058 m_settings = new AutoScrollSettings(m_scroller, parent); 0059 } 0060 0061 m_settings.data()->show(); 0062 m_settings.data()->raise(); 0063 } 0064 0065 bool AutoScrollPlugin::mouseMove(Qz::ObjectName type, QObject* obj, QMouseEvent* event) 0066 { 0067 if (type == Qz::ON_WebView) { 0068 return m_scroller->mouseMove(obj, event); 0069 } 0070 0071 return false; 0072 } 0073 0074 bool AutoScrollPlugin::mousePress(Qz::ObjectName type, QObject* obj, QMouseEvent* event) 0075 { 0076 if (type == Qz::ON_WebView) { 0077 return m_scroller->mousePress(obj, event); 0078 } 0079 0080 return false; 0081 } 0082 0083 bool AutoScrollPlugin::mouseRelease(Qz::ObjectName type, QObject* obj, QMouseEvent* event) 0084 { 0085 if (type == Qz::ON_WebView) { 0086 return m_scroller->mouseRelease(obj, event); 0087 } 0088 0089 return false; 0090 } 0091 0092 bool AutoScrollPlugin::wheelEvent(Qz::ObjectName type, QObject *obj, QWheelEvent *event) 0093 { 0094 if (type == Qz::ON_WebView) { 0095 return m_scroller->wheel(obj, event); 0096 } 0097 0098 return false; 0099 }