From ec6384711a5cd4805657cb42eda0dc17f46b95e1 Mon Sep 17 00:00:00 2001 From: Felix Rohrbach Date: Wed, 5 Jan 2011 09:45:49 +0100 Subject: Horizontal scroll wheel may now be used to navigate through history (Disabled by default). --- src/mainview.cpp | 2 + src/mainview.h | 2 + src/mainwindow.cpp | 4 ++ src/rekonq.kcfg | 3 ++ src/settings/settings_general.ui | 16 ++++++++ src/webview.cpp | 82 +++++++++++++++++++++++----------------- src/webview.h | 2 + 7 files changed, 77 insertions(+), 34 deletions(-) diff --git a/src/mainview.cpp b/src/mainview.cpp index 850101e2..94dc1688 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -286,6 +286,8 @@ WebTab *MainView::newWebTab(bool focused) connect(tab, SIGNAL(titleChanged(const QString &)), this, SLOT(webViewTitleChanged(const QString &))); connect(tab->view(), SIGNAL(urlChanged(const QUrl &)), this, SLOT(webViewUrlChanged(const QUrl &))); connect(tab->view(), SIGNAL(iconChanged()), this, SLOT(webViewIconChanged())); + connect(tab->view(), SIGNAL(openPreviousInHistory()), this, SIGNAL(openPreviousInHistory())); + connect(tab->view(), SIGNAL(openNextInHistory()), this, SIGNAL(openNextInHistory())); // connecting webPage signals with mainview connect(tab->page(), SIGNAL(windowCloseRequested()), this, SLOT(windowCloseRequested())); diff --git a/src/mainview.h b/src/mainview.h index 1d04d284..bc8b6765 100644 --- a/src/mainview.h +++ b/src/mainview.h @@ -106,6 +106,8 @@ Q_SIGNALS: void showStatusBarMessage(const QString &message, Rekonq::Notify status = Rekonq::Info); void linkHovered(const QString &link); void browserTabLoading(bool); + void openPreviousInHistory(); + void openNextInHistory(); void printRequested(QWebFrame *frame); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 3a9c1246..11c00c28 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -304,6 +304,10 @@ void MainWindow::postLaunch() // (shift +) ctrl + tab switching connect(this, SIGNAL(ctrlTabPressed()), m_view, SLOT(nextTab())); connect(this, SIGNAL(shiftCtrlTabPressed()), m_view, SLOT(previousTab())); + + // wheel history navigation + connect(m_view, SIGNAL(openPreviousInHistory()), this, SLOT(openPrevious())); + connect(m_view, SIGNAL(openNextInHistory()), this, SLOT(openNext())); // update toolbar actions signals connect(m_view, SIGNAL(tabsChanged()), this, SLOT(updateActions())); diff --git a/src/rekonq.kcfg b/src/rekonq.kcfg index b605e69e..6700b4e1 100644 --- a/src/rekonq.kcfg +++ b/src/rekonq.kcfg @@ -76,6 +76,9 @@ true + + false + diff --git a/src/settings/settings_general.ui b/src/settings/settings_general.ui index dccf479a..0b27dab2 100644 --- a/src/settings/settings_general.ui +++ b/src/settings/settings_general.ui @@ -174,6 +174,22 @@ + + + + Navigation + + + + + + Use horizontal scroll wheel to go through web history + + + + + + diff --git a/src/webview.cpp b/src/webview.cpp index 2c0b59ea..4fcf5417 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -617,42 +617,56 @@ void WebView::keyPressEvent(QKeyEvent *event) void WebView::wheelEvent(QWheelEvent *event) { - // To let some websites (eg: google maps) to handle wheel events - int prevPos = page()->currentFrame()->scrollPosition().y(); - KWebView::wheelEvent(event); - int newPos = page()->currentFrame()->scrollPosition().y(); - - // Sync with the zoom slider - if (event->modifiers() == Qt::ControlModifier) + if( event->orientation() == Qt::Vertical || !ReKonfig::hScrollWheelHistory() ) { - // Limits of the slider - if (zoomFactor() > 1.9) - setZoomFactor(1.9); - else if (zoomFactor() < 0.1) - setZoomFactor(0.1); - - // Round the factor (Fix slider's end value) - int newFactor = zoomFactor() * 10; - if ((zoomFactor() * 10 - newFactor) > 0.5) - newFactor++; - - emit zoomChanged(newFactor); + // To let some websites (eg: google maps) to handle wheel events + int prevPos = page()->currentFrame()->scrollPosition().y(); + KWebView::wheelEvent(event); + int newPos = page()->currentFrame()->scrollPosition().y(); + + // Sync with the zoom slider + if (event->modifiers() == Qt::ControlModifier) + { + // Limits of the slider + if (zoomFactor() > 1.9) + setZoomFactor(1.9); + else if (zoomFactor() < 0.1) + setZoomFactor(0.1); + + // Round the factor (Fix slider's end value) + int newFactor = zoomFactor() * 10; + if ((zoomFactor() * 10 - newFactor) > 0.5) + newFactor++; + + emit zoomChanged(newFactor); + } + else if (ReKonfig::smoothScrolling() && prevPos != newPos) + { + + page()->currentFrame()->setScrollPosition(QPoint(page()->currentFrame()->scrollPosition().x(), prevPos)); + + if ((event->delta() > 0) != !m_scrollBottom) + stopScrolling(); + + if (event->delta() > 0) + m_scrollBottom = false; + else + m_scrollBottom = true; + + + setupSmoothScrolling(abs(newPos - prevPos)); + } } - else if (ReKonfig::smoothScrolling() && prevPos != newPos) - { - - page()->currentFrame()->setScrollPosition(QPoint(page()->currentFrame()->scrollPosition().x(), prevPos)); - - if ((event->delta() > 0) != !m_scrollBottom) - stopScrolling(); - - if (event->delta() > 0) - m_scrollBottom = false; - else - m_scrollBottom = true; - - - setupSmoothScrolling(abs(newPos - prevPos)); + // use horizontal wheel events to go back and forward in tab history + else { + // left -> go to previous page + if( event->delta() > 0 ){ + emit openPreviousInHistory(); + } + // right -> go to next page + if( event->delta() < 0 ){ + emit openNextInHistory(); + } } } diff --git a/src/webview.h b/src/webview.h index acd7eae2..a06a2cb2 100644 --- a/src/webview.h +++ b/src/webview.h @@ -85,6 +85,8 @@ private slots: signals: void loadUrl(const KUrl &, const Rekonq::OpenType &); void zoomChanged(int); + void openPreviousInHistory(); + void openNextInHistory(); private: QPoint m_mousePos; -- cgit v1.2.1