Skip to content

Commit

Permalink
Possible to open background/selected tab from "Open in new tab" action
Browse files Browse the repository at this point in the history
Inverts the prefered option to opening new tabs with middle mouse click.
Closes QupZilla#635
  • Loading branch information
nowrep committed Jan 26, 2013
1 parent 3caf553 commit 1f2b0ee
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/lib/autofill/pageformcompleter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
49 changes: 39 additions & 10 deletions src/lib/webview/webview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QAction*>(sender())) {
openUrlInNewTab(action->data().toUrl(), position);
QUrl actionUrl;

if (!url.isEmpty()) {
actionUrl = url;
}
else {
openUrlInNewTab(url, position);
else if (QAction* action = qobject_cast<QAction*>(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<QAction*>(sender())) {
actionUrl = action->data().toUrl();
}

userDefinedOpenUrlInNewTab(actionUrl, true);
}

void WebView::loadClickedFrame()
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()));
Expand Down Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions src/lib/webview/webview.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ============================================================
* QupZilla - WebKit based browser
* Copyright (C) 2010-2012 David Rosca <[email protected]>
* Copyright (C) 2010-2013 David Rosca <[email protected]>
*
* 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
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 1f2b0ee

Please sign in to comment.