This opens the resulting page in a new tab.
BUG: 358649
Differential Revision: https://phabricator.kde.org/D7390
views/viewproperties.cpp
views/zoomlevelinfo.cpp
dolphinremoveaction.cpp
+ middleclickactioneventfilter.cpp
dolphinnewfilemenu.cpp
dolphindebug.cpp
)
#include "dolphintabwidget.h"
#include "dolphinviewcontainer.h"
#include "dolphintabpage.h"
+#include "middleclickactioneventfilter.h"
#include "panels/folders/folderspanel.h"
#include "panels/places/placespanel.h"
#include "panels/information/informationpanel.h"
if (!showMenu) {
createControlButton();
}
+
+ // enable middle-click on back/forward/up to open in a new tab
+ auto *middleClickEventFilter = new MiddleClickActionEventFilter(this);
+ connect(middleClickEventFilter, &MiddleClickActionEventFilter::actionMiddleClicked, this, &DolphinMainWindow::slotToolBarActionMiddleClicked);
+ toolBar()->installEventFilter(middleClickEventFilter);
}
DolphinMainWindow::~DolphinMainWindow()
updatePasteAction();
}
+void DolphinMainWindow::slotToolBarActionMiddleClicked(QAction *action)
+{
+ if (action == actionCollection()->action(QStringLiteral("go_back"))) {
+ goBackInNewTab();
+ } else if (action == actionCollection()->action(QStringLiteral("go_forward"))) {
+ goForwardInNewTab();
+ } else if (action == actionCollection()->action(QStringLiteral("go_up"))) {
+ goUpInNewTab();
+ } else if (action == actionCollection()->action(QStringLiteral("go_home"))) {
+ goHomeInNewTab();
+ }
+}
+
void DolphinMainWindow::selectAll()
{
clearStatusBar();
m_activeViewContainer->urlNavigator()->goHome();
}
-void DolphinMainWindow::goBack(Qt::MouseButtons buttons)
+void DolphinMainWindow::goBackInNewTab()
{
- // The default case (left button pressed) is handled in goBack().
- if (buttons == Qt::MiddleButton) {
- KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
- const int index = urlNavigator->historyIndex() + 1;
- openNewTab(urlNavigator->locationUrl(index));
- }
+ KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
+ const int index = urlNavigator->historyIndex() + 1;
+ openNewTab(urlNavigator->locationUrl(index));
}
-void DolphinMainWindow::goForward(Qt::MouseButtons buttons)
+void DolphinMainWindow::goForwardInNewTab()
{
- // The default case (left button pressed) is handled in goForward().
- if (buttons == Qt::MiddleButton) {
- KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
- const int index = urlNavigator->historyIndex() - 1;
- openNewTab(urlNavigator->locationUrl(index));
- }
+ KUrlNavigator* urlNavigator = activeViewContainer()->urlNavigator();
+ const int index = urlNavigator->historyIndex() - 1;
+ openNewTab(urlNavigator->locationUrl(index));
}
-void DolphinMainWindow::goUp(Qt::MouseButtons buttons)
+void DolphinMainWindow::goUpInNewTab()
{
- // The default case (left button pressed) is handled in goUp().
- if (buttons == Qt::MiddleButton) {
- openNewTab(KIO::upUrl(activeViewContainer()->url()));
- }
+ const QUrl currentUrl = activeViewContainer()->urlNavigator()->locationUrl();
+ openNewTab(KIO::upUrl(currentUrl));
}
-void DolphinMainWindow::goHome(Qt::MouseButtons buttons)
+void DolphinMainWindow::goHomeInNewTab()
{
- // The default case (left button pressed) is handled in goHome().
- if (buttons == Qt::MiddleButton) {
- openNewTab(Dolphin::homeUrl());
- }
+ openNewTab(Dolphin::homeUrl());
}
void DolphinMainWindow::compareFiles()
/** Changes the location to the home URL. */
void goHome();
- /**
- * Open the previous URL in the URL history in a new tab
- * if the middle mouse button is clicked.
- */
- void goBack(Qt::MouseButtons buttons);
+ /** Open the previous URL in the URL history in a new tab. */
+ void goBackInNewTab();
- /**
- * Open the next URL in the URL history in a new tab
- * if the middle mouse button is clicked.
- */
- void goForward(Qt::MouseButtons buttons);
+ /** Open the next URL in the URL history in a new tab. */
+ void goForwardInNewTab();
- /**
- * Open the URL one hierarchy above the current URL in a new tab
- * if the middle mouse button is clicked.
- */
- void goUp(Qt::MouseButtons buttons);
+ /** Open the URL one hierarchy above the current URL in a new tab. */
+ void goUpInNewTab();
- /**
- * Open the home URL in a new tab
- */
- void goHome(Qt::MouseButtons buttons);
+ /** * Open the home URL in a new tab. */
+ void goHomeInNewTab();
/** Opens Kompare for 2 selected files. */
void compareFiles();
*/
void slotDirectoryLoadingCompleted();
+ /**
+ * Is called when the user middle clicks a toolbar button.
+ *
+ * Here middle clicking Back/Forward/Up/Home will open the resulting
+ * folder in a new tab.
+ */
+ void slotToolBarActionMiddleClicked(QAction *action);
+
private:
void setupActions();
void setupDockWidgets();
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2017 Kai Uwe Broulik <kde@privat.broulik.de> *
+ * *
+ * 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 "middleclickactioneventfilter.h"
+
+#include <QAction>
+#include <QEvent>
+#include <QMouseEvent>
+#include <QToolBar>
+
+MiddleClickActionEventFilter::MiddleClickActionEventFilter(QObject *parent) : QObject(parent)
+{
+
+}
+
+MiddleClickActionEventFilter::~MiddleClickActionEventFilter() = default;
+
+bool MiddleClickActionEventFilter::eventFilter(QObject *watched, QEvent *event)
+{
+ if (event->type() == QEvent::MouseButtonPress
+ || event->type() == QEvent::MouseButtonRelease) {
+ QMouseEvent *me = static_cast<QMouseEvent *>(event);
+
+ if (me->button() == Qt::MiddleButton) {
+ QToolBar *toolBar = qobject_cast<QToolBar *>(watched);
+
+ QAction *action = toolBar->actionAt(me->pos());
+ if (action) {
+ if (event->type() == QEvent::MouseButtonPress) {
+ m_lastMiddlePressedAction = action;
+ } else if (event->type() == QEvent::MouseButtonRelease) {
+ if (m_lastMiddlePressedAction == action) {
+ emit actionMiddleClicked(action);
+ }
+ m_lastMiddlePressedAction = nullptr;
+ }
+ }
+ }
+ }
+
+ return QObject::eventFilter(watched, event);
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2017 Kai Uwe Broulik <kde@privat.broulik.de> *
+ * *
+ * 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 *
+ ***************************************************************************/
+
+#pragma once
+
+#include "dolphin_export.h"
+
+#include <QObject>
+#include <QPointer>
+
+class QAction;
+
+/**
+ * An event filter that allows to detect a middle click
+ * to trigger e.g. opening something in a new tab.
+ */
+class DOLPHIN_EXPORT MiddleClickActionEventFilter : public QObject
+{
+ Q_OBJECT
+
+public:
+ MiddleClickActionEventFilter(QObject *parent);
+ ~MiddleClickActionEventFilter() override;
+
+signals:
+ void actionMiddleClicked(QAction *action);
+
+protected:
+ bool eventFilter(QObject *watched, QEvent *event) override;
+
+private:
+ QPointer<QAction> m_lastMiddlePressedAction;
+
+};