Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to open link from clipboard in new tab by middle-clicking on new tab button. #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/newtabbutton.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2010 Stiletto <[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
* 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 <qevent.h>

void NewTabButton::mousePressEvent (QMouseEvent *event)
{
if (event->button () == Qt::MidButton)
emit middle_clicked();
else
QToolButton::mousePressEvent (event);
}

40 changes: 40 additions & 0 deletions src/newtabbutton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2010 Stiletto <[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
* 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 <qtoolbutton.h>

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

2 changes: 2 additions & 0 deletions src/src.pri
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ HEADERS += \
downloadmanager.h \
modelmenu.h \
modeltoolbar.h \
newtabbutton.h \
plaintexteditsearch.h \
searchbar.h \
searchbutton.h \
Expand Down Expand Up @@ -74,6 +75,7 @@ SOURCES += \
downloadmanager.cpp \
modelmenu.cpp \
modeltoolbar.cpp \
newtabbutton.cpp \
plaintexteditsearch.cpp \
searchbar.cpp \
searchbutton.cpp \
Expand Down
17 changes: 16 additions & 1 deletion src/tabwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -82,6 +83,7 @@
#include "webviewsearch.h"

#include <qcompleter.h>
#include <qclipboard.h>
#include <qdir.h>
#include <qevent.h>
#include <qlistview.h>
Expand Down Expand Up @@ -172,10 +174,12 @@ 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(middle_clicked()),
this, SLOT(newTabFromClipboard()));
#endif

connect(m_tabBar, SIGNAL(tabCloseRequested(int)),
Expand Down Expand Up @@ -364,6 +368,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
Expand Down
4 changes: 3 additions & 1 deletion src/tabwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class QStackedWidget;
QT_END_NAMESPACE

class BrowserMainWindow;
class NewTabButton;
class TabBar;
class WebView;
class WebActionMapper;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -207,7 +209,7 @@ private slots:
QCompleter *m_lineEditCompleter;
QStackedWidget *m_locationBars;
TabBar *m_tabBar;
QToolButton *addTabButton;
NewTabButton *addTabButton;
QToolButton *closeTabButton;
};

Expand Down