From 974fe50b0da2181ddd79202a2aec7efe78c84c13 Mon Sep 17 00:00:00 2001 From: Stiletto Date: Wed, 16 Feb 2011 13:25:57 +0300 Subject: [PATCH 1/2] Allow to open link from clipboard in new tab by middle-clicking on new tab button. --- src/newtabbutton.cpp | 31 +++++++++++++++++++++++++++++++ src/newtabbutton.h | 40 ++++++++++++++++++++++++++++++++++++++++ src/src.pri | 2 ++ src/tabwidget.cpp | 19 ++++++++++++++++++- src/tabwidget.h | 4 +++- 5 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 src/newtabbutton.cpp create mode 100644 src/newtabbutton.h diff --git a/src/newtabbutton.cpp b/src/newtabbutton.cpp new file mode 100644 index 00000000..61a8b1fd --- /dev/null +++ b/src/newtabbutton.cpp @@ -0,0 +1,31 @@ +/* + * Copyright 2010 Stiletto + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#include "newtabbutton.h" + +#include + +void NewTabButton::mousePressEvent (QMouseEvent *event) +{ + if (event->button () == Qt::MidButton) + emit middle_clicked(); + else + QToolButton::mousePressEvent (event); +} + diff --git a/src/newtabbutton.h b/src/newtabbutton.h new file mode 100644 index 00000000..83f6eee2 --- /dev/null +++ b/src/newtabbutton.h @@ -0,0 +1,40 @@ +/* + * Copyright 2010 Stiletto + * + * 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 + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA + */ + +#ifndef NEWTABBUTTON_H +#define NEWTABBUTTON_H + +#include + +class NewTabButton : public QToolButton +{ + Q_OBJECT + +public: + NewTabButton(QWidget *parent = 0) : QToolButton(parent) {}; + +signals: + void middle_clicked(); + +protected: + void mousePressEvent (QMouseEvent *event); +}; + +#endif // NEWTABBUTTON_H + diff --git a/src/src.pri b/src/src.pri index 7c1a0e34..a29afd42 100644 --- a/src/src.pri +++ b/src/src.pri @@ -46,6 +46,7 @@ HEADERS += \ downloadmanager.h \ modelmenu.h \ modeltoolbar.h \ + newtabbutton.h \ plaintexteditsearch.h \ searchbar.h \ searchbutton.h \ @@ -74,6 +75,7 @@ SOURCES += \ downloadmanager.cpp \ modelmenu.cpp \ modeltoolbar.cpp \ + newtabbutton.cpp \ plaintexteditsearch.cpp \ searchbar.cpp \ searchbutton.cpp \ diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index 7e5b0bf8..0ab76ebe 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -72,6 +72,7 @@ #include "historycompleter.h" #include "historymanager.h" #include "locationbar.h" +#include "newtabbutton.h" #include "opensearchengine.h" #include "opensearchmanager.h" #include "tabbar.h" @@ -82,6 +83,7 @@ #include "webviewsearch.h" #include +#include #include #include #include @@ -172,10 +174,14 @@ TabWidget::TabWidget(QWidget *parent) m_recentlyClosedTabsAction->setEnabled(false); #ifndef Q_WS_MAC // can't seem to figure out the background color :( - addTabButton = new QToolButton(this); + addTabButton = new NewTabButton(this); addTabButton->setDefaultAction(m_newTabAction); addTabButton->setAutoRaise(true); addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly); + connect(addTabButton, SIGNAL(triggered(QAction *)), + this, SLOT(aboutToShowRecentTriggeredAction(QAction *))); + connect(addTabButton, SIGNAL(middle_clicked()), + this, SLOT(newTabFromClipboard())); #endif connect(m_tabBar, SIGNAL(tabCloseRequested(int)), @@ -364,6 +370,17 @@ void TabWidget::newTab() makeNewTab(true); } +void TabWidget::newTabFromClipboard() +{ + QString url = QApplication::clipboard()->text(QClipboard::Selection); + if (url.isNull()) { + url = QApplication::clipboard()->text(QClipboard::Clipboard); + if (url.isNull()) + return; + } + loadString(url,NewTab); +} + WebView *TabWidget::makeNewTab(bool makeCurrent) { // line edit diff --git a/src/tabwidget.h b/src/tabwidget.h index 6ceff10d..11b251fc 100644 --- a/src/tabwidget.h +++ b/src/tabwidget.h @@ -77,6 +77,7 @@ class QStackedWidget; QT_END_NAMESPACE class BrowserMainWindow; +class NewTabButton; class TabBar; class WebView; class WebActionMapper; @@ -157,6 +158,7 @@ public slots: void loadUrl(const QUrl &url, TabWidget::OpenUrlIn tab = CurrentTab, const QString &title = QString()); void createTab(const QByteArray &historyState, TabWidget::OpenUrlIn tab = CurrentTab); void newTab(); + void newTabFromClipboard(); void cloneTab(int index = -1); void closeTab(int index = -1); void closeOtherTabs(int index); @@ -207,7 +209,7 @@ private slots: QCompleter *m_lineEditCompleter; QStackedWidget *m_locationBars; TabBar *m_tabBar; - QToolButton *addTabButton; + NewTabButton *addTabButton; QToolButton *closeTabButton; }; From 6cd850ddca3cbd47b2c82bdf55d330288fd82e10 Mon Sep 17 00:00:00 2001 From: Stiletto Date: Wed, 16 Feb 2011 14:04:26 +0300 Subject: [PATCH 2/2] Removed accidentally copypasted connect. --- src/tabwidget.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tabwidget.cpp b/src/tabwidget.cpp index 0ab76ebe..eb17bec1 100644 --- a/src/tabwidget.cpp +++ b/src/tabwidget.cpp @@ -178,8 +178,6 @@ TabWidget::TabWidget(QWidget *parent) addTabButton->setDefaultAction(m_newTabAction); addTabButton->setAutoRaise(true); addTabButton->setToolButtonStyle(Qt::ToolButtonIconOnly); - connect(addTabButton, SIGNAL(triggered(QAction *)), - this, SLOT(aboutToShowRecentTriggeredAction(QAction *))); connect(addTabButton, SIGNAL(middle_clicked()), this, SLOT(newTabFromClipboard())); #endif