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 #ifndef AUTOSCROLLER_H
0019 #define AUTOSCROLLER_H
0020 
0021 #include <QObject>
0022 #include <QLabel>
0023 
0024 class QMouseEvent;
0025 class QWheelEvent;
0026 class QRect;
0027 
0028 class WebView;
0029 class FrameScroller;
0030 
0031 class ScrollIndicator : public QLabel
0032 {
0033 public:
0034     explicit ScrollIndicator(QWidget *parent = nullptr);
0035 
0036     Qt::Orientations orientations() const;
0037     void setOrientations(Qt::Orientations orientations);
0038 
0039 private:
0040     void paintEvent(QPaintEvent *event) override;
0041 
0042     Qt::Orientations m_orientations;
0043 };
0044 
0045 class AutoScroller : public QObject
0046 {
0047     Q_OBJECT
0048 public:
0049     explicit AutoScroller(const QString &settingsFile, QObject* parent = nullptr);
0050     ~AutoScroller() override;
0051 
0052     bool mouseMove(QObject* obj, QMouseEvent* event);
0053     bool mousePress(QObject* obj, QMouseEvent* event);
0054     bool mouseRelease(QObject* obj, QMouseEvent* event);
0055     bool wheel(QObject* obj, QWheelEvent *event);
0056 
0057     double scrollDivider() const;
0058     void setScrollDivider(double divider);
0059 
0060 private:
0061     bool eventFilter(QObject* obj, QEvent* event) override;
0062 
0063     bool showIndicator(WebView* view, const QPoint &pos);
0064     void stopScrolling();
0065 
0066     QRect indicatorGlobalRect() const;
0067 
0068     WebView* m_view;
0069     ScrollIndicator* m_indicator;
0070     FrameScroller* m_frameScroller;
0071     QString m_settingsFile;
0072 };
0073 
0074 #endif // AUTOSCROLLER_H