From 742326bde7dab187729acf36909536bf91dbab56 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 17 Feb 2013 11:07:02 +0100 Subject: [PATCH] Added possibility to select text on page with Shift+Arrow keys. Shift+Right Arrow => select next char Shift+Left Arrow => select previous char Shift+Ctrl+Right Arrow => select next word Shift+Ctrl+Left Arrow => select previous word Shift+Home => select start of line Shift+End => select end of line Shift+Ctrl+Home => select start of document Shift+Ctrl+End => select end of document --- src/lib/webview/webview.cpp | 68 +++++++++++++++++++++++++++++++++++++ src/lib/webview/webview.h | 4 ++- 2 files changed, 71 insertions(+), 1 deletion(-) diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index 8f87b5392..34cf1ec71 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -1226,6 +1226,74 @@ void WebView::keyPressEvent(QKeyEvent* event) } break; + case Qt::Key_Up: + if (event->modifiers() & Qt::ShiftModifier) { + triggerPageAction(QWebPage::SelectPreviousLine); + event->accept(); + return; + } + break; + + case Qt::Key_Down: + if (event->modifiers() & Qt::ShiftModifier) { + triggerPageAction(QWebPage::SelectNextLine); + event->accept(); + return; + } + break; + + case Qt::Key_Left: + if (event->modifiers() & Qt::ShiftModifier) { + if (event->modifiers() == Qt::ShiftModifier) { + triggerPageAction(QWebPage::SelectPreviousChar); + } + else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { + triggerPageAction(QWebPage::SelectPreviousWord); + } + event->accept(); + return; + } + break; + + case Qt::Key_Right: + if (event->modifiers() & Qt::ShiftModifier) { + if (event->modifiers() == Qt::ShiftModifier) { + triggerPageAction(QWebPage::SelectNextChar); + } + else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { + triggerPageAction(QWebPage::SelectNextWord); + } + event->accept(); + return; + } + break; + + case Qt::Key_Home: + if (event->modifiers() & Qt::ShiftModifier) { + if (event->modifiers() == Qt::ShiftModifier) { + triggerPageAction(QWebPage::SelectStartOfLine); + } + else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { + triggerPageAction(QWebPage::SelectStartOfDocument); + } + event->accept(); + return; + } + break; + + case Qt::Key_End: + if (event->modifiers() & Qt::ShiftModifier) { + if (event->modifiers() == Qt::ShiftModifier) { + triggerPageAction(QWebPage::SelectEndOfLine); + } + else if (event->modifiers() == (Qt::ShiftModifier | Qt::ControlModifier)) { + triggerPageAction(QWebPage::SelectEndOfDocument); + } + event->accept(); + return; + } + break; + default: break; } diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h index 29a107e15..eb6d30da5 100644 --- a/src/lib/webview/webview.h +++ b/src/lib/webview/webview.h @@ -38,7 +38,9 @@ public: WebPage* page() const; void setPage(QWebPage* page); - void load(const QNetworkRequest &request, QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, const QByteArray &body = QByteArray()); + void load(const QNetworkRequest &request, + QNetworkAccessManager::Operation operation = QNetworkAccessManager::GetOperation, + const QByteArray &body = QByteArray()); bool loadingError() const; bool isLoading() const;