From 1f2b0eef8755e2b54c5907900c463e982ab8f0e6 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sat, 26 Jan 2013 12:04:30 +0100 Subject: [PATCH] Possible to open background/selected tab from "Open in new tab" action Inverts the prefered option to opening new tabs with middle mouse click. Closes #635 --- src/lib/autofill/pageformcompleter.cpp | 2 +- src/lib/webview/webview.cpp | 49 ++++++++++++++++++++------ src/lib/webview/webview.h | 6 ++-- 3 files changed, 44 insertions(+), 13 deletions(-) diff --git a/src/lib/autofill/pageformcompleter.cpp b/src/lib/autofill/pageformcompleter.cpp index 14c9c038a..e45ad5bb0 100644 --- a/src/lib/autofill/pageformcompleter.cpp +++ b/src/lib/autofill/pageformcompleter.cpp @@ -158,7 +158,7 @@ void PageFormCompleter::completePage(const QByteArray &data) const } bool PageFormCompleter::queryItemsContains(const QueryItems &queryItems, const QString &attributeName, - const QString &attributeValue) const + const QString &attributeValue) const { if (attributeName.isEmpty() || attributeValue.isEmpty()) { return false; diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index 55f9b357e..08618e8d5 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -566,12 +566,30 @@ void WebView::userDefinedOpenUrlInNewTab(const QUrl &url, bool invert) position = (position == Qz::NT_SelectedTab) ? Qz::NT_NotSelectedTab : Qz::NT_SelectedTab; } - if (QAction* action = qobject_cast(sender())) { - openUrlInNewTab(action->data().toUrl(), position); + QUrl actionUrl; + + if (!url.isEmpty()) { + actionUrl = url; } - else { - openUrlInNewTab(url, position); + else if (QAction* action = qobject_cast(sender())) { + actionUrl = action->data().toUrl(); } + + openUrlInNewTab(actionUrl, position); +} + +void WebView::userDefinedOpenUrlInBgTab(const QUrl &url) +{ + QUrl actionUrl; + + if (!url.isEmpty()) { + actionUrl = url; + } + else if (QAction* action = qobject_cast(sender())) { + actionUrl = action->data().toUrl(); + } + + userDefinedOpenUrlInNewTab(actionUrl, true); } void WebView::loadClickedFrame() @@ -584,14 +602,19 @@ void WebView::loadClickedFrame() load(frameUrl); } -void WebView::loadClickedFrameInNewTab() +void WebView::loadClickedFrameInNewTab(bool invert) { QUrl frameUrl = m_clickedFrame->baseUrl(); if (frameUrl.isEmpty()) { frameUrl = m_clickedFrame->requestedUrl(); } - openUrlInNewTab(frameUrl, Qz::NT_SelectedTab); + userDefinedOpenUrlInNewTab(frameUrl, invert); +} + +void WebView::loadClickedFrameInBgTab() +{ + loadClickedFrameInNewTab(true); } void WebView::reloadClickedFrame() @@ -777,7 +800,6 @@ void WebView::createContextMenu(QMenu* menu, const QWebHitTestResult &hitTest, c menu->addSeparator(); mApp->plugins()->populateWebViewMenu(menu, this, hitTest); - #if QTWEBKIT_FROM_2_2 // still bugged? in 4.8 RC (it shows selection of webkit's internal source, not html from page) // it may or may not be bug, but this implementation is useless for us @@ -805,9 +827,12 @@ void WebView::createPageContextMenu(QMenu* menu, const QPoint &pos) if (frameAtPos && page()->mainFrame() != frameAtPos) { m_clickedFrame = frameAtPos; - QMenu* frameMenu = new QMenu(tr("This frame")); + Menu* frameMenu = new Menu(tr("This frame")); frameMenu->addAction(tr("Show &only this frame"), this, SLOT(loadClickedFrame())); - frameMenu->addAction(QIcon(":/icons/menu/new-tab.png"), tr("Show this frame in new &tab"), this, SLOT(loadClickedFrameInNewTab())); + Action* act = new Action(QIcon(":/icons/menu/new-tab.png"), tr("Show this frame in new &tab")); + connect(act, SIGNAL(triggered()), this, SLOT(loadClickedFrameInNewTab())); + connect(act, SIGNAL(middleClicked()), this, SLOT(loadClickedFrameInBgTab())); + frameMenu->addAction(act); frameMenu->addSeparator(); frameMenu->addAction(qIconProvider->standardIcon(QStyle::SP_BrowserReload), tr("&Reload"), this, SLOT(reloadClickedFrame())); frameMenu->addAction(QIcon::fromTheme("document-print"), tr("Print frame"), this, SLOT(printClickedFrame())); @@ -848,7 +873,11 @@ void WebView::createLinkContextMenu(QMenu* menu, const QWebHitTestResult &hitTes } menu->addSeparator(); - menu->addAction(QIcon(":/icons/menu/new-tab.png"), tr("Open link in new &tab"), this, SLOT(userDefinedOpenUrlInNewTab()))->setData(hitTest.linkUrl()); + Action* act = new Action(QIcon(":/icons/menu/new-tab.png"), tr("Open link in new &tab")); + act->setData(hitTest.linkUrl()); + connect(act, SIGNAL(triggered()), this, SLOT(userDefinedOpenUrlInNewTab())); + connect(act, SIGNAL(middleClicked()), this, SLOT(userDefinedOpenUrlInBgTab())); + menu->addAction(act); menu->addAction(QIcon::fromTheme("window-new"), tr("Open link in new &window"), this, SLOT(openUrlInNewWindow()))->setData(hitTest.linkUrl()); menu->addSeparator(); menu->addAction(qIconProvider->fromTheme("user-bookmarks"), tr("B&ookmark link"), this, SLOT(bookmarkLink()))->setData(hitTest.linkUrl()); diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h index 2a4044afd..1eed1b4ce 100644 --- a/src/lib/webview/webview.h +++ b/src/lib/webview/webview.h @@ -1,6 +1,6 @@ /* ============================================================ * QupZilla - WebKit based browser -* Copyright (C) 2010-2012 David Rosca +* Copyright (C) 2010-2013 David Rosca * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -105,12 +105,14 @@ protected slots: // To support user's option whether to open in selected or background tab void userDefinedOpenUrlInNewTab(const QUrl &url = QUrl(), bool invert = false); + void userDefinedOpenUrlInBgTab(const QUrl &url = QUrl()); void createSearchEngine(); // Clicked frame actions void loadClickedFrame(); - void loadClickedFrameInNewTab(); + void loadClickedFrameInNewTab(bool invert = false); + void loadClickedFrameInBgTab(); void reloadClickedFrame(); void printClickedFrame(); void clickedFrameZoomIn();