summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/webview.cpp44
-rw-r--r--src/webview.h6
2 files changed, 43 insertions, 7 deletions
diff --git a/src/webview.cpp b/src/webview.cpp
index e874411d..6f6ec128 100644
--- a/src/webview.cpp
+++ b/src/webview.cpp
@@ -66,7 +66,8 @@ WebView::WebView(QWidget* parent)
, _scrollTimer( new QTimer(this) )
, _VScrollSpeed(0)
, _HScrollSpeed(0)
- , _disableAutoScroll(false)
+ , _canEnableAutoScroll(true)
+ , _isAutoScrollEnabled(false)
{
WebPage *page = new WebPage(this);
setPage(page);
@@ -321,27 +322,60 @@ void WebView::contextMenuEvent(QContextMenuEvent *event)
void WebView::mousePressEvent(QMouseEvent *event)
{
- QWebHitTestResult result = page()->mainFrame()->hitTestContent( event->pos() );
- _disableAutoScroll = result.isContentEditable();
+ if(_isAutoScrollEnabled)
+ {
+ setCursor(Qt::ArrowCursor);
+ _VScrollSpeed = 0;
+ _HScrollSpeed = 0;
+ _scrollTimer->stop();
+ _isAutoScrollEnabled = false;
+ return;
+ }
+ QWebHitTestResult result = page()->mainFrame()->hitTestContent( event->pos() );
+ _canEnableAutoScroll = !result.isContentEditable() && result.linkUrl().isEmpty();
+
switch(event->button())
{
case Qt::XButton1:
triggerPageAction(KWebPage::Back);
break;
+
case Qt::XButton2:
triggerPageAction(KWebPage::Forward);
break;
+
+ case Qt::MidButton:
+ if(_canEnableAutoScroll && !_isAutoScrollEnabled)
+ {
+ setCursor( KIcon("transform-move").pixmap(32) );
+ _clickPos = event->pos();
+ _isAutoScrollEnabled = true;
+ }
+ break;
+
default:
- KWebView::mousePressEvent(event);
break;
};
+ KWebView::mousePressEvent(event);
}
void WebView::mouseMoveEvent(QMouseEvent *event)
{
_mousePos = event->pos();
+
+ if(_isAutoScrollEnabled)
+ {
+ QPoint r = _mousePos - _clickPos;
+ _HScrollSpeed = r.x() / 2; // you are too fast..
+ _VScrollSpeed = r.y() / 2;
+ if( !_scrollTimer->isActive() )
+ _scrollTimer->start();
+
+ return;
+ }
+
if (Application::instance()->mainWindow()->isFullScreen())
{
if (event->pos().y()>=0 && event->pos().y()<=4)
@@ -430,7 +464,7 @@ void WebView::keyPressEvent(QKeyEvent *event)
}
}
- if(_disableAutoScroll)
+ if(!_canEnableAutoScroll)
{
KWebView::keyPressEvent(event);
return;
diff --git a/src/webview.h b/src/webview.h
index 0fe83ae4..c6ca2688 100644
--- a/src/webview.h
+++ b/src/webview.h
@@ -52,7 +52,7 @@ public:
protected:
void contextMenuEvent(QContextMenuEvent *event);
- void mousePressEvent(QMouseEvent *event); // need to be ported
+ void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
@@ -75,11 +75,13 @@ signals:
private:
QPoint _mousePos;
+ QPoint _clickPos;
QTimer *_scrollTimer;
int _VScrollSpeed;
int _HScrollSpeed;
- bool _disableAutoScroll;
+ bool _canEnableAutoScroll;
+ bool _isAutoScrollEnabled;
};
#endif