Hi,
attached a version of a autoscrolling in WebView i hacked together at lunch.
Feel free to reuse or extend to fulfill the needs of
https://bugs.kde.org/show_bug.cgi?id=203338
(use with "shift"+arrowkeys)
Johannes
diff --git a/src/webview.cpp b/src/webview.cpp
index dca8b6f..d71a7cd 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -62,9 +62,10 @@
WebView::WebView(QWidget* parent)
: QWebView(parent)
, m_page(new WebPage(this))
+ , m_scrollAnimationTimeLine(0)
{
setPage(m_page);
-
+
connect(page(), SIGNAL(statusBarMessage(const QString&)), this, SLOT(setStatusBarText(const QString&)));
}
@@ -270,6 +271,20 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
void WebView::keyPressEvent(QKeyEvent *event)
{
+ if ((event->modifiers() == Qt::ShiftModifier) && (event->key() == Qt::Key_Down))
+ {
+ startScrollAnimation(QTimeLine::Forward);
+ return;
+ }
+
+ if ((event->modifiers() == Qt::ShiftModifier) && (event->key() == Qt::Key_Up))
+ {
+ startScrollAnimation(QTimeLine::Backward);
+ return;
+ }
+
+ stopScrollAnimation();
+
if ((event->modifiers() == Qt::ControlModifier) && (event->key() == Qt::Key_Tab))
{
emit ctrlTabPressed();
@@ -286,8 +301,54 @@ void WebView::keyPressEvent(QKeyEvent *event)
}
+void WebView::stopScrollAnimation()
+{
+ if (m_scrollAnimationTimeLine)
+ {
+ m_scrollAnimationTimeLine->stop();
+ delete m_scrollAnimationTimeLine;
+ m_scrollAnimationTimeLine = 0;
+ }
+}
+
+
+void WebView::startScrollAnimation(QTimeLine::Direction direction)
+{
+ if (m_scrollAnimationTimeLine)
+ {
+ if (m_scrollAnimationTimeLine->direction() == direction)
+ return;
+ else
+ stopScrollAnimation();
+ }
+
+ // the speed factor (here "2") should be configureable
+ m_scrollAnimationTimeLine = new QTimeLine(page()->mainFrame()->scrollBarMaximum(Qt::Vertical) * 2, this);
+
+ if (direction == QTimeLine::Forward)
+ m_scrollAnimationTimeLine->setFrameRange(page()->mainFrame()->scrollBarValue(Qt::Vertical),
+ page()->mainFrame()->scrollBarMaximum(Qt::Vertical));
+ else
+ m_scrollAnimationTimeLine->setFrameRange(0, page()->mainFrame()->scrollBarValue(Qt::Vertical));
+
+ connect(m_scrollAnimationTimeLine, SIGNAL(frameChanged(int)), this, SLOT(slotScrollVertical(int)));
+ m_scrollAnimationTimeLine->setDirection(direction);
+ m_scrollAnimationTimeLine->start();
+
+ return;
+}
+
+
+void WebView::slotScrollVertical(int scroll)
+{
+ page()->mainFrame()->scroll(0, scroll - page()->mainFrame()->scrollBarValue(Qt::Vertical));
+}
+
+
void WebView::mousePressEvent(QMouseEvent *event)
{
+ stopScrollAnimation();
+
m_page->m_pressedButtons = event->buttons();
m_page->m_keyboardModifiers = event->modifiers();
@@ -307,6 +368,8 @@ void WebView::mousePressEvent(QMouseEvent *event)
void WebView::wheelEvent(QWheelEvent *event)
{
+ stopScrollAnimation();
+
if (QApplication::keyboardModifiers() & Qt::ControlModifier)
{
int numDegrees = event->delta() / 8;
diff --git a/src/webview.h b/src/webview.h
index 5a2638b..1fa700f 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -33,11 +33,13 @@
// Qt Includes
#include <QWebView>
+#include <QtCore/QTimeLine>
// Forward Declarations
class WebPage;
+
class WebView : public QWebView
{
Q_OBJECT
@@ -67,9 +69,13 @@ protected:
private slots:
void setStatusBarText(const QString &string);
void slotSearch();
+ void slotScrollVertical(int scroll);
+ void stopScrollAnimation();
+ void startScrollAnimation(QTimeLine::Direction direction);
private:
WebPage *m_page;
+ QTimeLine *m_scrollAnimationTimeLine;
QString m_statusBarText;
};
_______________________________________________
rekonq mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/rekonq