From 10bba39bd442d011dd46a77751709e10f7a69139 Mon Sep 17 00:00:00 2001 From: nowrep Date: Sun, 2 Jun 2013 16:46:26 +0200 Subject: [PATCH] New tab button in toolbar opens tab with url from clipboard on middle click. Closes #907 --- src/lib/navigation/navigationbar.cpp | 1 + src/lib/webview/tabwidget.cpp | 17 +++++++++++------ src/lib/webview/tabwidget.h | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib/navigation/navigationbar.cpp b/src/lib/navigation/navigationbar.cpp index aadecce2b..c922bfb17 100644 --- a/src/lib/navigation/navigationbar.cpp +++ b/src/lib/navigation/navigationbar.cpp @@ -182,6 +182,7 @@ NavigationBar::NavigationBar(QupZilla* mainClass) connect(m_buttonHome, SIGNAL(middleMouseClicked()), p_QupZilla, SLOT(goHomeInNewTab())); connect(m_buttonHome, SIGNAL(controlClicked()), p_QupZilla, SLOT(goHomeInNewTab())); connect(m_buttonAddTab, SIGNAL(clicked()), p_QupZilla, SLOT(addTab())); + connect(m_buttonAddTab, SIGNAL(middleMouseClicked()), p_QupZilla->tabWidget(), SLOT(addTabFromClipboard())); connect(m_exitFullscreen, SIGNAL(clicked(bool)), p_QupZilla, SLOT(toggleFullScreen(bool))); } diff --git a/src/lib/webview/tabwidget.cpp b/src/lib/webview/tabwidget.cpp index 2af27c884..a065f7e03 100644 --- a/src/lib/webview/tabwidget.cpp +++ b/src/lib/webview/tabwidget.cpp @@ -63,12 +63,7 @@ void AddTabButton::wheelEvent(QWheelEvent* event) void AddTabButton::mouseReleaseEvent(QMouseEvent* event) { if (event->button() == Qt::MiddleButton && rect().contains(event->pos())) { - QString selectionClipboard = QApplication::clipboard()->text(QClipboard::Selection); - QUrl guessedUrl = WebView::guessUrlFromString(selectionClipboard); - - if (!guessedUrl.isEmpty()) { - m_tabWidget->addView(guessedUrl, Qz::NT_SelectedNewEmptyTab); - } + m_tabWidget->addTabFromClipboard(); } ToolButton::mouseReleaseEvent(event); @@ -388,6 +383,16 @@ int TabWidget::addView(WebTab* tab) return index; } +void TabWidget::addTabFromClipboard() +{ + QString selectionClipboard = QApplication::clipboard()->text(QClipboard::Selection); + QUrl guessedUrl = WebView::guessUrlFromString(selectionClipboard); + + if (!guessedUrl.isEmpty()) { + addView(guessedUrl, Qz::NT_SelectedNewEmptyTab); + } +} + void TabWidget::closeTab(int index, bool force) { if (index == -1) { diff --git a/src/lib/webview/tabwidget.h b/src/lib/webview/tabwidget.h index 05f8e5881..b2c1933ae 100644 --- a/src/lib/webview/tabwidget.h +++ b/src/lib/webview/tabwidget.h @@ -108,6 +108,7 @@ public slots: int addView(QNetworkRequest req, const QString &title = tr("New tab"), const Qz::NewTabPositionFlags &openFlags = Qz::NT_SelectedTab, bool selectLine = false, int position = -1); int addView(WebTab* tab); + void addTabFromClipboard(); int duplicateTab(int index); void closeTab(int index = -1, bool force = false);