From 1a5ad1413b96aa6f181fd05e9f16034e7c22ac63 Mon Sep 17 00:00:00 2001 From: nowrep Date: Tue, 26 Jun 2012 23:39:23 +0200 Subject: [PATCH] Preferences: New option "Automatically switch to newly opened tabs" - also removed unnecessary option to make tabs movable * everyone wants the tabs to be movable :-) closes #382 --- src/lib/preferences/preferences.cpp | 5 ++- src/lib/preferences/preferences.ui | 47 ++++++++++++++--------------- src/lib/webview/tabbar.cpp | 1 - src/lib/webview/websettings.cpp | 5 +++ src/lib/webview/websettings.h | 1 + src/lib/webview/webview.cpp | 20 +++++++++--- src/lib/webview/webview.h | 3 ++ 7 files changed, 49 insertions(+), 33 deletions(-) diff --git a/src/lib/preferences/preferences.cpp b/src/lib/preferences/preferences.cpp index 70c052fa9..67bbcdabd 100644 --- a/src/lib/preferences/preferences.cpp +++ b/src/lib/preferences/preferences.cpp @@ -160,10 +160,10 @@ Preferences::Preferences(QupZilla* mainClass, QWidget* parent) //TABS settings.beginGroup("Browser-Tabs-Settings"); - ui->makeMovable->setChecked(settings.value("makeTabsMovable", true).toBool()); ui->hideTabsOnTab->setChecked(settings.value("hideTabsWithOneTab", false).toBool()); ui->activateLastTab->setChecked(settings.value("ActivateLastTabWhenClosingActual", false).toBool()); ui->openNewTabAfterActive->setChecked(settings.value("newTabAfterActive", true).toBool()); + ui->switchToNewTabs->setChecked(settings.value("OpenNewTabsSelected", false).toBool()); ui->dontQuitOnTab->setChecked(settings.value("dontQuitWithOneTab", false).toBool()); ui->askWhenClosingMultipleTabs->setChecked(settings.value("AskOnClosing", false).toBool()); ui->closedInsteadOpened->setChecked(settings.value("closedInsteadOpenedTabs", false).toBool()); @@ -748,7 +748,6 @@ void Preferences::saveSettings() //WINDOW settings.beginGroup("Browser-View-Settings"); - settings.setValue("showStatusbar", ui->showStatusbar->isChecked()); settings.setValue("showBookmarksToolbar", ui->showBookmarksToolbar->isChecked()); settings.setValue("showNavigationToolbar", ui->showNavigationToolbar->isChecked()); @@ -760,10 +759,10 @@ void Preferences::saveSettings() //TABS settings.beginGroup("Browser-Tabs-Settings"); - settings.setValue("makeTabsMovable", ui->makeMovable->isChecked()); settings.setValue("hideTabsWithOneTab", ui->hideTabsOnTab->isChecked()); settings.setValue("ActivateLastTabWhenClosingActual", ui->activateLastTab->isChecked()); settings.setValue("newTabAfterActive", ui->openNewTabAfterActive->isChecked()); + settings.setValue("OpenNewTabsSelected", ui->switchToNewTabs->isChecked()); settings.setValue("dontQuitWithOneTab", ui->dontQuitOnTab->isChecked()); settings.setValue("AskOnClosing", ui->askWhenClosingMultipleTabs->isChecked()); settings.setValue("closedInsteadOpenedTabs", ui->closedInsteadOpened->isChecked()); diff --git a/src/lib/preferences/preferences.ui b/src/lib/preferences/preferences.ui index f29c6bdda..5e3718faf 100644 --- a/src/lib/preferences/preferences.ui +++ b/src/lib/preferences/preferences.ui @@ -619,13 +619,6 @@ - - - - Make tabs movable - - - @@ -639,13 +632,6 @@ - - - - Show tab previews - - - @@ -667,28 +653,28 @@ - + Don't quit upon closing last tab - + Ask when closing multiple tabs - + Closed tabs list instead of opened in tab bar - + Qt::Vertical @@ -701,35 +687,35 @@ - + <b>Address Bar behaviour</b> - + Select all text by double clicking in address bar - + Select all text by clicking in address bar - + Add .co.uk domain by pressing ALT key - + Qt::Vertical @@ -769,6 +755,20 @@ + + + + Show tab previews + + + + + + + Automatically switch to newly opened tab + + + @@ -2238,7 +2238,6 @@ createProfile deleteProfile tabWidget_2 - makeMovable hideTabsOnTab askWhenClosingMultipleTabs selectAllOnFocus diff --git a/src/lib/webview/tabbar.cpp b/src/lib/webview/tabbar.cpp index b649d329b..b62583485 100644 --- a/src/lib/webview/tabbar.cpp +++ b/src/lib/webview/tabbar.cpp @@ -80,7 +80,6 @@ void TabBar::loadSettings() Settings settings; settings.beginGroup("Browser-Tabs-Settings"); - setMovable(settings.value("makeTabsMovable", true).toBool()); m_tabPreview->setAnimationsEnabled(settings.value("tabPreviewAnimationsEnabled", true).toBool()); m_showTabPreviews = settings.value("showTabPreviews", true).toBool(); diff --git a/src/lib/webview/websettings.cpp b/src/lib/webview/websettings.cpp index 0ef2c9929..12ce0e5ce 100644 --- a/src/lib/webview/websettings.cpp +++ b/src/lib/webview/websettings.cpp @@ -21,6 +21,7 @@ int WebSettings::defaultZoom = 100; bool WebSettings::loadTabsOnActivation = false; +Qz::NewTabPositionFlag WebSettings::newTabPosition; QStringList WebSettings::autoOpenProtocols; QStringList WebSettings::blockedProtocols; @@ -36,6 +37,10 @@ void WebSettings::loadSettings() blockedProtocols = settings.value("BlockOpeningProtocols", QStringList()).toStringList(); settings.endGroup(); + + settings.beginGroup("Browser-Tabs-Settings"); + newTabPosition = settings.value("OpenNewTabsSelected", false).toBool() ? Qz::NT_SelectedTab : Qz::NT_NotSelectedTab; + settings.endGroup(); } void WebSettings::saveSettings() diff --git a/src/lib/webview/websettings.h b/src/lib/webview/websettings.h index 6adfc930a..ef220aee2 100644 --- a/src/lib/webview/websettings.h +++ b/src/lib/webview/websettings.h @@ -33,6 +33,7 @@ public: static int defaultZoom; static bool loadTabsOnActivation; + static Qz::NewTabPositionFlag newTabPosition; static QStringList autoOpenProtocols; static QStringList blockedProtocols; }; diff --git a/src/lib/webview/webview.cpp b/src/lib/webview/webview.cpp index d5e488d10..bff61595f 100644 --- a/src/lib/webview/webview.cpp +++ b/src/lib/webview/webview.cpp @@ -497,6 +497,16 @@ void WebView::openUrlInBackgroundTab() } } +void WebView::userDefinedOpenUrlInNewTab(const QUrl &url) +{ + if (QAction* action = qobject_cast(sender())) { + openUrlInNewTab(action->data().toUrl(), WebSettings::newTabPosition); + } + else { + openUrlInNewTab(url, WebSettings::newTabPosition); + } +} + void WebView::loadClickedFrame() { QUrl frameUrl = m_clickedFrame->baseUrl(); @@ -770,7 +780,7 @@ void WebView::createLinkContextMenu(QMenu* menu, const QWebHitTestResult &hitTes } menu->addSeparator(); - menu->addAction(QIcon(":/icons/menu/popup.png"), tr("Open link in new &tab"), this, SLOT(openUrlInBackgroundTab()))->setData(hitTest.linkUrl()); + menu->addAction(QIcon(":/icons/menu/popup.png"), tr("Open link in new &tab"), this, SLOT(userDefinedOpenUrlInNewTab()))->setData(hitTest.linkUrl()); 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()); @@ -791,7 +801,7 @@ void WebView::createImageContextMenu(QMenu* menu, const QWebHitTestResult &hitTe Action* act = new Action(tr("Show i&mage")); act->setData(hitTest.imageUrl()); connect(act, SIGNAL(triggered()), this, SLOT(openActionUrl())); - connect(act, SIGNAL(middleClicked()), this, SLOT(openUrlInBackgroundTab())); + connect(act, SIGNAL(middleClicked()), this, SLOT(userDefinedOpenUrlInNewTab())); menu->addAction(act); menu->addAction(tr("Copy im&age"), this, SLOT(copyImageToClipboard()))->setData(hitTest.imageUrl()); menu->addAction(QIcon::fromTheme("edit-copy"), tr("Copy image ad&dress"), this, SLOT(copyLinkToClipboard()))->setData(hitTest.imageUrl()); @@ -845,7 +855,7 @@ void WebView::createSelectedTextContextMenu(QMenu* menu, const QWebHitTestResult act->setData(guessedUrl); connect(act, SIGNAL(triggered()), this, SLOT(openActionUrl())); - connect(act, SIGNAL(middleClicked()), this, SLOT(openUrlInBackgroundTab())); + connect(act, SIGNAL(middleClicked()), this, SLOT(userDefinedOpenUrlInNewTab())); menu->addAction(act); } @@ -976,7 +986,7 @@ void WebView::mousePressEvent(QMouseEvent* event) if (frame) { const QUrl &link = frame->hitTestContent(event->pos()).linkUrl(); if (event->modifiers() == Qt::ControlModifier && isUrlValid(link)) { - openUrlInNewTab(link, Qz::NT_NotSelectedTab); + userDefinedOpenUrlInNewTab(link); event->accept(); return; } @@ -1002,7 +1012,7 @@ void WebView::mouseReleaseEvent(QMouseEvent* event) if (frame) { const QUrl &link = frame->hitTestContent(event->pos()).linkUrl(); if (m_clickedUrl == link && isUrlValid(link)) { - openUrlInNewTab(link, Qz::NT_NotSelectedTab); + userDefinedOpenUrlInNewTab(link); event->accept(); return; } diff --git a/src/lib/webview/webview.h b/src/lib/webview/webview.h index 94efd3b0c..f196854cc 100644 --- a/src/lib/webview/webview.h +++ b/src/lib/webview/webview.h @@ -101,6 +101,9 @@ protected slots: void openUrlInSelectedTab(); void openUrlInBackgroundTab(); + // To support user's option whether to open in selected or background tab + void userDefinedOpenUrlInNewTab(const QUrl &url = QUrl()); + void createSearchEngine(); // Clicked frame actions