summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/webview.cpp167
-rw-r--r--src/webview.h22
2 files changed, 90 insertions, 99 deletions
diff --git a/src/webview.cpp b/src/webview.cpp
index 31ab70c8..70a432c7 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -32,8 +32,6 @@
// Auto Includes
#include "rekonq.h"
-#include <math.h>
-
// Local Includes
#include "mainwindow.h"
#include "mainview.h"
@@ -52,7 +50,6 @@
// Qt Includes
#include <QtCore/QDir>
-
#include <QtGui/QAction>
#include <QtGui/QContextMenuEvent>
#include <QtGui/QWheelEvent>
@@ -70,18 +67,14 @@
WebView::WebView(QWidget* parent)
: KWebView(parent, false)
, _mousePos(QPoint(0, 0))
- , _scrollTimer(new QTimer(this))
+ , _autoScrollTimer(new QTimer(this))
, _VScrollSpeed(0)
, _HScrollSpeed(0)
, _canEnableAutoScroll(true)
, _isAutoScrollEnabled(false)
- , smoothScroller(0)
- , nbSteps(0)
- , timer(new QTimer(this))
- , nbTicks(0)
- , time(new QTime())
- , smoothScrolling(false)
- , dy(0)
+ , _smoothScrollTimer(new QTimer(this))
+ , _smoothScrolling(false)
+ , _dy(0)
{
WebPage *page = new WebPage(this);
setPage(page);
@@ -111,17 +104,24 @@ WebView::WebView(QWidget* parent)
connect(this, SIGNAL(loadUrl(const KUrl &, const Rekonq::OpenType &)),
Application::instance(), SLOT(loadUrl(const KUrl &, const Rekonq::OpenType &)));
- // scrolling timer
- connect(_scrollTimer, SIGNAL(timeout()), this, SLOT(scrollFrameChanged()));
- _scrollTimer->setInterval(100);
- timer->setInterval(16);
- connect(timer, SIGNAL(timeout()), this, SLOT(scrollTick()));
+ // Auto scroll timer
+ connect(_autoScrollTimer, SIGNAL(timeout()), this, SLOT(scrollFrameChanged()));
+ _autoScrollTimer->setInterval(100);
+
+ // Smooth scroll timer
+ connect(_smoothScrollTimer, SIGNAL(timeout()), this, SLOT(scrollTick()));
+ _smoothScrollTimer->setInterval(16);
}
WebView::~WebView()
{
- delete _scrollTimer;
+ delete _autoScrollTimer;
+
+ if (_smoothScrolling)
+ stopScrolling();
+ delete _smoothScrollTimer;
+
disconnect();
WebPage* p = page();
@@ -130,12 +130,6 @@ WebView::~WebView()
QString path = WebSnap::imagePathFromUrl(p->mainFrame()->url().toString());
QFile::remove(path);
preview.save(path);
-
- if (smoothScrolling)
- stopScrolling();
-
- delete timer;
- delete time;
}
@@ -355,7 +349,7 @@ void WebView::mousePressEvent(QMouseEvent *event)
setCursor(Qt::ArrowCursor);
_VScrollSpeed = 0;
_HScrollSpeed = 0;
- _scrollTimer->stop();
+ _autoScrollTimer->stop();
_isAutoScrollEnabled = false;
return;
}
@@ -398,8 +392,8 @@ void WebView::mouseMoveEvent(QMouseEvent *event)
QPoint r = _mousePos - _clickPos;
_HScrollSpeed = r.x() / 2; // you are too fast..
_VScrollSpeed = r.y() / 2;
- if (!_scrollTimer->isActive())
- _scrollTimer->start();
+ if (!_autoScrollTimer->isActive())
+ _autoScrollTimer->start();
return;
}
@@ -498,43 +492,43 @@ void WebView::keyPressEvent(QKeyEvent *event)
if (event->key() == Qt::Key_Up)
{
_VScrollSpeed--;
- if (!_scrollTimer->isActive())
- _scrollTimer->start();
+ if (!_autoScrollTimer->isActive())
+ _autoScrollTimer->start();
return;
}
if (event->key() == Qt::Key_Down)
{
_VScrollSpeed++;
- if (!_scrollTimer->isActive())
- _scrollTimer->start();
+ if (!_autoScrollTimer->isActive())
+ _autoScrollTimer->start();
return;
}
if (event->key() == Qt::Key_Right)
{
_HScrollSpeed++;
- if (!_scrollTimer->isActive())
- _scrollTimer->start();
+ if (!_autoScrollTimer->isActive())
+ _autoScrollTimer->start();
return;
}
if (event->key() == Qt::Key_Left)
{
_HScrollSpeed--;
- if (!_scrollTimer->isActive())
- _scrollTimer->start();
+ if (!_autoScrollTimer->isActive())
+ _autoScrollTimer->start();
return;
}
- if (_scrollTimer->isActive())
+ if (_autoScrollTimer->isActive())
{
- _scrollTimer->stop();
+ _autoScrollTimer->stop();
}
else
{
if (_VScrollSpeed || _HScrollSpeed)
- _scrollTimer->start();
+ _autoScrollTimer->start();
}
}
@@ -571,15 +565,15 @@ void WebView::wheelEvent(QWheelEvent *event)
int numDegrees = event->delta() / 8;
int numSteps = numDegrees / 15;
- if ((numSteps > 0) != !bas)
+ if ((numSteps > 0) != !_scrollBottom)
stopScrolling();
if (numSteps > 0)
- bas = false;
+ _scrollBottom = false;
else
- bas = true;
+ _scrollBottom = true;
- setupSmoothScrolling( 100);
+ setupSmoothScrolling(100);
return;
}
@@ -616,77 +610,74 @@ void WebView::scrollFrameChanged()
_HScrollSpeed = 0;
}
-// Scroll chat to bottom
+
void WebView::setupSmoothScrolling(int posY)
{
- int ddy = qMax(steps ? abs(dy)/steps : 0,3);
-
- dy += posY;
-
- if (dy <= 0)
- {
- stopScrolling();
- return;
- }
-
- steps = 8;
-
- if (dy / steps < ddy)
- {
- // Don't move slower than average 4px/step in minimum one direction
- // This means fewer than normal steps
- steps = (abs(dy)+ddy-1)/ddy;
- if (steps < 1)
- steps = 1;
- }
-
- time->start();
- if (!smoothScrolling)
- {
- smoothScrolling = true;
- timer->start();
- scrollTick();
- }
+ int ddy = qMax(_smoothScrollSteps ? abs(_dy)/_smoothScrollSteps : 0,3);
+
+ _dy += posY;
+
+ if (_dy <= 0)
+ {
+ stopScrolling();
+ return;
+ }
+
+ _smoothScrollSteps = 8;
+
+ if (_dy / _smoothScrollSteps < ddy)
+ {
+ _smoothScrollSteps = (abs(_dy)+ddy-1)/ddy;
+ if (_smoothScrollSteps < 1)
+ _smoothScrollSteps = 1;
+ }
+
+ _smoothScrollTime.start();
+
+ if (!_smoothScrolling)
+ {
+ _smoothScrolling = true;
+ _smoothScrollTimer->start();
+ scrollTick();
+ }
}
void WebView::scrollTick()
{
- if (dy == 0)
+ if (_dy == 0)
{
stopScrolling();
return;
}
- if (steps < 1)
- steps = 1;
+ if (_smoothScrollSteps < 1)
+ _smoothScrollSteps = 1;
- int takesteps = time->restart() / 16;
+ int takesteps = _smoothScrollTime.restart() / 16;
int scroll_y = 0;
if (takesteps < 1)
takesteps = 1;
- if (takesteps > steps)
- takesteps = steps;
+ if (takesteps > _smoothScrollSteps)
+ takesteps = _smoothScrollSteps;
for(int i = 0; i < takesteps; i++)
{
- int ddy = (dy / (steps+1)) * 2;
+ int ddy = (_dy / (_smoothScrollSteps+1)) * 2;
// limit step to requested scrolling distance
- if (abs(ddy) > abs(dy)) ddy = dy;
+ if (abs(ddy) > abs(_dy))
+ ddy = _dy;
// update remaining scroll
- dy -= ddy;
+ _dy -= ddy;
scroll_y += ddy;
- steps--;
- }
-
-
+ _smoothScrollSteps--;
+ }
- //page()->mainFrame()->setScrollPosition( QPoint( 0, frame ) );
- if (bas)
+ if (_scrollBottom)
page()->mainFrame()->setScrollPosition( QPoint( 0, page()->mainFrame()->scrollPosition().y() + scroll_y ) );
else
page()->mainFrame()->setScrollPosition( QPoint( 0, page()->mainFrame()->scrollPosition().y() - scroll_y ) );
@@ -695,7 +686,7 @@ void WebView::scrollTick()
void WebView::stopScrolling()
{
- timer->stop();
- dy = 0;
- smoothScrolling = false;
+ _smoothScrollTimer->stop();
+ _dy = 0;
+ _smoothScrolling = false;
}
diff --git a/src/webview.h b/src/webview.h
index cc5508cb..b17940c7 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -32,7 +32,8 @@
// Rekonq Includes
#include "rekonq_defines.h"
-#include <QTimeLine>
+//Qt Includes
+#include <QTime>
// KDE Includes
#include <KWebView>
@@ -87,21 +88,20 @@ private:
QPoint _mousePos;
QPoint _clickPos;
- QTimer *_scrollTimer;
+ // Auto Scroll
+ QTimer *_autoScrollTimer;
int _VScrollSpeed;
int _HScrollSpeed;
bool _canEnableAutoScroll;
bool _isAutoScrollEnabled;
- QTimeLine *smoothScroller;
- QTimer *timer;
- int nbSteps;
- int nbTicks;
- bool bas;
- QTime *time;
- bool smoothScrolling;
- int dy;
- int steps;
+ // Smooth Scroll
+ QTimer *_smoothScrollTimer;
+ QTime _smoothScrollTime;
+ bool _scrollBottom;
+ bool _smoothScrolling;
+ int _dy;
+ int _smoothScrollSteps;
};
#endif