File indexing completed on 2024-05-19 04:59:14

0001 /* ============================================================
0002 * AutoScroll - Autoscroll for Falkon
0003 * Copyright (C) 2014  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 "framescroller.h"
0019 #include "webpage.h"
0020 
0021 #include <QTimer>
0022 #include <QtMath>
0023 
0024 FrameScroller::FrameScroller(QObject* parent)
0025     : QObject(parent)
0026     , m_page(nullptr)
0027     , m_lengthX(0)
0028     , m_lengthY(0)
0029     , m_divider(8.0)
0030 {
0031     m_timer = new QTimer(this);
0032     m_timer->setInterval(10);
0033     connect(m_timer, &QTimer::timeout, this, &FrameScroller::scrollStep);
0034 }
0035 
0036 void FrameScroller::setPage(WebPage *page)
0037 {
0038     m_page = page;
0039 }
0040 
0041 double FrameScroller::scrollDivider() const
0042 {
0043     return m_divider;
0044 }
0045 
0046 void FrameScroller::setScrollDivider(double divider)
0047 {
0048     m_divider = divider;
0049 }
0050 
0051 void FrameScroller::startScrolling(int lengthX, int lengthY)
0052 {
0053     m_lengthX = lengthX;
0054     m_lengthY = lengthY;
0055 
0056     if (m_lengthX == 0 && m_lengthY == 0) {
0057         m_timer->stop();
0058     }
0059     else if (!m_timer->isActive()) {
0060         m_timer->start();
0061     }
0062 }
0063 
0064 void FrameScroller::stopScrolling()
0065 {
0066     m_timer->stop();
0067 }
0068 
0069 void FrameScroller::scrollStep()
0070 {
0071     m_page->scroll(qCeil(m_lengthX / m_divider), qCeil(m_lengthY / m_divider));
0072 }