Hi,
sorry for not done the mouse-scrolling, yet.
the patch applied to this thread is not the same as in SrcSrc branch.
the SrcSrc code is the first approach...which has less code but cannot scroll
horizontal.
The patch attached now applies against master again and you can also controll
the scrolling speed in each direction, plus it scrolls in the current active
webpage (useful, if you want to scroll an iframe)
Thanks,
Johannes
On Tuesday 20 October 2009 02:35:56 Andrea Diamantini wrote:
> On Monday 19 October 2009 22:56:53 Panagiotis Papadopoulos wrote:
> > Andrea, can you please merge this one too?
> > 0.3 then at least will have "partial" support for this, which is already
> > cool enough :-P The middle mouse button scrolling can be added later :-)
>
> Implemented in SrcSrc branch.
> Pano, can you please test this to be "absolutely" sure this is ok and it's
> your wanted feature.
> (I really don't make use of this at all..)
>
> Regards,
>
diff --git a/src/webview.cpp b/src/webview.cpp
index 1815e87..0cca779 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -52,12 +52,18 @@
#include <QtGui/QClipboard>
#include <QtGui/QKeyEvent>
#include <QtGui/QAction>
+#include <QtCore/QTimer>
WebView::WebView(QWidget* parent)
: QWebView(parent)
, m_page(new WebPage(this))
, m_progress(0)
+ , m_scrollTimer(new QTimer(this))
+ , m_scrollDirection(WebView::NoScroll)
+ , m_scrollSpeedVertical(0)
+ , m_scrollSpeedHorizontal(0)
+
{
setPage(m_page);
@@ -65,6 +71,10 @@ WebView::WebView(QWidget* parent)
connect(this, SIGNAL(loadProgress(int)), this, SLOT(slotUpdateProgress(int)));
connect(this, SIGNAL(loadFinished(bool)), this, SLOT(slotLoadFinished(bool)));
connect(this, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
+
+ connect(m_scrollTimer, SIGNAL(timeout()), this, SLOT(scrollFrameChanged()));
+ m_scrollTimer->setInterval(50);
+
}
@@ -329,8 +339,82 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
}
+void WebView::stopScrollAnimation()
+{
+ m_scrollTimer->stop();
+ m_scrollSpeedVertical = 0;
+ m_scrollSpeedHorizontal = 0;
+ m_scrollDirection = WebView::NoScroll;
+}
+
+
+void WebView::startScrollAnimation(ScrollDirection direction)
+{
+ // if no scrollspeed, set the requested direction, otherwise it's just a slowdown or speedup
+ if (m_scrollSpeedVertical == 0 && (direction == WebView::Up || direction == WebView::Down))
+ m_scrollDirection |= direction;
+ if (m_scrollSpeedHorizontal == 0 && (direction == WebView::Left || direction == WebView::Right))
+ m_scrollDirection |= direction;
+
+ // update scrollspeed
+ switch (direction)
+ {
+ case WebView::Up:
+ --m_scrollSpeedVertical;
+ break;
+ case WebView::Down:
+ ++m_scrollSpeedVertical;
+ break;
+ case WebView::Left:
+ --m_scrollSpeedHorizontal;
+ break;
+ case WebView::Right:
+ ++m_scrollSpeedHorizontal;
+ break;
+ default:
+ break;
+ }
+
+ if (!m_scrollTimer->isActive())
+ m_scrollTimer->start();
+
+ return;
+}
+
+
+void WebView::scrollFrameChanged()
+{
+ // clear finished scrolling
+ if (m_scrollSpeedVertical == 0)
+ m_scrollDirection &= ~WebView::Up | ~WebView::Down;
+ if (m_scrollSpeedHorizontal == 0)
+ m_scrollDirection &= ~WebView::Left | ~WebView::Right;
+
+ // all scrolling finished
+ if (m_scrollDirection == WebView::NoScroll)
+ {
+ m_scrollTimer->stop();
+ return;
+ }
+
+ // do the scrolling
+ page()->currentFrame()->scroll(m_scrollSpeedHorizontal, m_scrollSpeedVertical);
+
+ // check if we reached the end
+ int y = page()->currentFrame()->scrollPosition().y();
+ int x = page()->currentFrame()->scrollPosition().x();
+
+ if (y == 0 || y == page()->currentFrame()->scrollBarMaximum(Qt::Vertical))
+ m_scrollSpeedVertical = 0;
+ if (x == 0 || x == page()->currentFrame()->scrollBarMaximum(Qt::Horizontal))
+ m_scrollSpeedHorizontal = 0;
+}
+
+
void WebView::mousePressEvent(QMouseEvent *event)
{
+ stopScrollAnimation();
+
m_page->m_pressedButtons = event->buttons();
m_page->m_keyboardModifiers = event->modifiers();
@@ -359,6 +443,8 @@ void WebView::mouseMoveEvent(QMouseEvent *event)
void WebView::wheelEvent(QWheelEvent *event)
{
+ stopScrollAnimation();
+
if (QApplication::keyboardModifiers() & Qt::ControlModifier)
{
int numDegrees = event->delta() / 8;
@@ -438,6 +524,31 @@ void WebView::keyPressEvent(QKeyEvent *event)
triggerPageAction(QWebPage::Copy);
return;
}
+
+ if ((event->modifiers() == Qt::ShiftModifier) && (event->key() == Qt::Key_Down))
+ {
+ startScrollAnimation(WebView::Down);
+ return;
+ }
+
+ if ((event->modifiers() == Qt::ShiftModifier) && (event->key() == Qt::Key_Up))
+ {
+ startScrollAnimation(WebView::Up);
+ return;
+ }
+
+ if ((event->modifiers() == Qt::ShiftModifier) && (event->key() == Qt::Key_Left))
+ {
+ startScrollAnimation(WebView::Left);
+ return;
+ }
+
+ if ((event->modifiers() == Qt::ShiftModifier) && (event->key() == Qt::Key_Right))
+ {
+ startScrollAnimation(WebView::Right);
+ return;
+ }
+
QWebView::keyPressEvent(event);
}
diff --git a/src/webview.h b/src/webview.h
index 3388348..2a42b2d 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -37,13 +37,23 @@
// Forward Declarations
class WebPage;
+class QTimer;
class WebView : public QWebView
{
Q_OBJECT
+ Q_ENUMS(ScrollDirection)
public:
+ enum ScrollDirection
+ {
+ NoScroll = 0,
+ Up = 2,
+ Down = 4,
+ Left = 6,
+ Right = 16
+ };
explicit WebView(QWidget *parent = 0);
~WebView();
@@ -71,10 +81,18 @@ private slots:
void openLinkInNewWindow();
void openLinkInNewTab();
+ void startScrollAnimation(ScrollDirection direction);
+ void stopScrollAnimation();
+ void scrollFrameChanged();
+
private:
WebPage *m_page;
int m_progress;
QString m_statusBarText;
+ QTimer *m_scrollTimer;
+ int m_scrollDirection;
+ int m_scrollSpeedVertical;
+ int m_scrollSpeedHorizontal;
};
#endif
_______________________________________________
rekonq mailing list
[email protected]
https://mail.kde.org/mailman/listinfo/rekonq