diff options
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | src/application.cpp | 2 | ||||
-rw-r--r-- | src/mainview.cpp | 9 | ||||
-rw-r--r-- | src/webpage.cpp | 30 | ||||
-rw-r--r-- | src/webpage.h | 37 | ||||
-rw-r--r-- | src/webview.cpp | 83 | ||||
-rw-r--r-- | src/webview.h | 5 |
7 files changed, 139 insertions, 31 deletions
@@ -9,7 +9,7 @@ TO 0.2 release - private browsing color * rekonqrun * findbar NO notify system -- right click Google Search Integration +* right click Google Search Integration - packaging / license * tools menu (to be decided) - error pages (timeout loading) @@ -17,6 +17,6 @@ TO 0.2 release - no more KDEnetwork!! - no reKonfig in loadUrl * history menu -- clear private data +* clear private data - BKO - ctrl + url click diff --git a/src/application.cpp b/src/application.cpp index 60d5ee48..cc34d946 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -97,7 +97,7 @@ int Application::newInstance() { for (int i = 0; i < args->count(); ++i) { - loadUrl(args->arg(i), Rekonq::NewTab); + loadUrl(args->arg(i), Rekonq::NewTab); } args->clear(); } diff --git a/src/mainview.cpp b/src/mainview.cpp index f059e42b..bc33c1c0 100644 --- a/src/mainview.cpp +++ b/src/mainview.cpp @@ -309,9 +309,12 @@ void MainView::slotCurrentChanged(int index) this, SIGNAL(loadProgress(int))); } - connect(webView->page(), SIGNAL(statusBarMessage(const QString&)), this, SIGNAL(showStatusBarMessage(const QString&))); - connect(webView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)), this, SIGNAL(linkHovered(const QString&))); - connect(webView, SIGNAL(loadProgress(int)), this, SIGNAL(loadProgress(int))); + connect(webView->page(), SIGNAL(statusBarMessage(const QString&)), + this, SIGNAL(showStatusBarMessage(const QString&))); + connect(webView->page(), SIGNAL(linkHovered(const QString&, const QString&, const QString&)), + this, SIGNAL(linkHovered(const QString&))); + connect(webView, SIGNAL(loadProgress(int)), + this, SIGNAL(loadProgress(int))); emit setCurrentTitle(webView->title()); m_urlBars->setCurrentIndex(index); diff --git a/src/webpage.cpp b/src/webpage.cpp index bb6f0d9c..771b7f04 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -73,6 +73,8 @@ WebPage::WebPage(QObject *parent) : QWebPage(parent) + , m_keyboardModifiers(Qt::NoModifier) + , m_pressedButtons(Qt::NoButton) { setForwardUnsupportedContent(true); @@ -84,6 +86,34 @@ WebPage::WebPage(QObject *parent) } +bool WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type) +{ + if (m_keyboardModifiers & Qt::ControlModifier || m_pressedButtons == Qt::MidButton) + { + Application::instance()->loadUrl(request.url(), Rekonq::NewTab); + m_keyboardModifiers = Qt::NoModifier; + m_pressedButtons = Qt::NoButton; + return false; + } + + if (frame == mainFrame()) + { + return QWebPage::acceptNavigationRequest(frame, request, type); + } + else + { + // if frame doesn't exists (perhaps) we are pointing to a blank target.. + if (!frame) + { + Application::instance()->loadUrl(request.url(), Rekonq::NewTab); + return false; + } + } + + return QWebPage::acceptNavigationRequest(frame, request, type); +} + + WebPage *WebPage::createWindow(QWebPage::WebWindowType type) { kDebug() << "WebPage createWindow slot"; diff --git a/src/webpage.h b/src/webpage.h index cdfb8f00..6a74c7bf 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -50,21 +50,42 @@ public slots: protected: WebPage *createWindow(WebWindowType type); virtual WebPage *newWindow(WebWindowType type); - - QString chooseFile(QWebFrame *frame, const QString &suggestedFile); - void javaScriptAlert(QWebFrame *frame, const QString &msg); - bool javaScriptConfirm(QWebFrame *frame, const QString &msg); - bool javaScriptPrompt(QWebFrame *frame, const QString &msg, const QString &defaultValue, QString *result); + virtual bool acceptNavigationRequest(QWebFrame *frame, + const QNetworkRequest &request, + NavigationType type); + + QString chooseFile(QWebFrame *frame, + const QString &suggestedFile); + + void javaScriptAlert(QWebFrame *frame, + const QString &msg); + + bool javaScriptConfirm(QWebFrame *frame, + const QString &msg); + + bool javaScriptPrompt(QWebFrame *frame, + const QString &msg, + const QString &defaultValue, QString *result); + + QObject *createPlugin(const QString &classId, + const QUrl &url, + const QStringList ¶mNames, + const QStringList ¶mValues); - QObject *createPlugin(const QString &classId, const QUrl &url, const QStringList ¶mNames, const QStringList ¶mValues); - -protected Q_SLOTS: + +protected Q_SLOTS: virtual void slotHandleUnsupportedContent(QNetworkReply *reply); virtual void slotDownloadRequested(const QNetworkRequest &request); private: + friend class WebView; + void viewErrorPage(QNetworkReply *); + + // keyboard/mouse modifiers + Qt::KeyboardModifiers m_keyboardModifiers; + Qt::MouseButtons m_pressedButtons; }; #endif diff --git a/src/webview.cpp b/src/webview.cpp index ec747b36..e39cdacb 100644 --- a/src/webview.cpp +++ b/src/webview.cpp @@ -170,6 +170,20 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) a->setShortcut(KStandardShortcut::paste().primary()); menu.addAction(a); + menu.addSeparator(); + + a = new KAction(i18n("Google Search"), this); + a->setIcon(Application::icon(KUrl("http://www.google.com"))); + a->setData("gg:"); + connect(a, SIGNAL(triggered(bool)), this, SLOT(slotGooWikiSearch())); + menu.addAction(a); + + a = new KAction(i18n("Wikipedia Search"), this); + a->setIcon(Application::icon(KUrl("http://wikipedia.org"))); + a->setData("wk:"); + connect(a, SIGNAL(triggered(bool)), this, SLOT(slotGooWikiSearch())); + menu.addAction(a); + // TODO Add translate, show translation } else if (result.isContentEditable()) @@ -191,7 +205,34 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) a->setShortcut(KStandardShortcut::copy().primary()); menu.addAction(a); - // TODO Add search with google, wikipedia, show translation + menu.addSeparator(); + + a = new KAction(i18n("Google Search"), this); + a->setIcon(Application::icon(KUrl("http://www.google.com"))); + a->setData("gg:"); + connect(a, SIGNAL(triggered(bool)), this, SLOT(slotGooWikiSearch())); + menu.addAction(a); + + a = new KAction(i18n("Wikipedia Search"), this); + a->setIcon(Application::icon(KUrl("http://wikipedia.org"))); + a->setData("wk:"); + connect(a, SIGNAL(triggered(bool)), this, SLOT(slotGooWikiSearch())); + menu.addAction(a); + + // TODO Add translate, show translation + } + else if (!result.pixmap().isNull()) + { + menu.addSeparator(); + + // TODO Add "View Image" && remove copy_this_image action + a = pageAction(QWebPage::DownloadImageToDisk); + a->setIcon(KIcon("document-save")); + menu.addAction(a); + + a = pageAction(QWebPage::CopyImageToClipboard); + a->setIcon(KIcon("edit-copy")); + menu.addAction(a); } else { @@ -207,20 +248,6 @@ void WebView::contextMenuEvent(QContextMenuEvent *event) menu.addAction(mainwindow->actionByName("history_back")); menu.addAction(mainwindow->actionByName("history_forward")); menu.addAction(mainwindow->actionByName("view_redisplay")); - - if (!result.pixmap().isNull()) - { - menu.addSeparator(); - - // TODO Add "View Image" && remove copy_this_image action - a = pageAction(QWebPage::DownloadImageToDisk); - a->setIcon(KIcon("document-save")); - menu.addAction(a); - - a = pageAction(QWebPage::CopyImageToClipboard); - a->setIcon(KIcon("edit-copy")); - menu.addAction(a); - } menu.addSeparator(); @@ -271,6 +298,9 @@ void WebView::keyPressEvent(QKeyEvent *event) void WebView::mousePressEvent(QMouseEvent *event) { + m_page->m_pressedButtons = event->buttons(); + m_page->m_keyboardModifiers = event->modifiers(); + switch(event->button()) { case Qt::XButton1: @@ -283,3 +313,26 @@ void WebView::mousePressEvent(QMouseEvent *event) QWebView::mousePressEvent(event); }; } + + +void WebView::wheelEvent(QWheelEvent *event) +{ + if (QApplication::keyboardModifiers() & Qt::ControlModifier) + { + int numDegrees = event->delta() / 8; + int numSteps = numDegrees / 15; + setTextSizeMultiplier(textSizeMultiplier() + numSteps * 0.1); + event->accept(); + return; + } + QWebView::wheelEvent(event); +} + + +void WebView::slotGooWikiSearch() +{ + KAction *a = qobject_cast<KAction*>(sender()); + QString search = a->data().toString() + selectedText(); + KUrl urlSearch = KUrl::fromEncoded(search.toUtf8()); + Application::instance()->loadUrl(urlSearch, Rekonq::NewTab); +} diff --git a/src/webview.h b/src/webview.h index 4efb2733..ffdc874c 100644 --- a/src/webview.h +++ b/src/webview.h @@ -58,13 +58,14 @@ protected: * to make switch tab */ void keyPressEvent(QKeyEvent *event); + void wheelEvent(QWheelEvent *event); - private slots: void setProgress(int progress); void loadFinished(); void setStatusBarText(const QString &string); - + void slotGooWikiSearch(); + private: WebPage *m_page; |