diff --git a/src/filewidgets/CMakeLists.txt b/src/filewidgets/CMakeLists.txt --- a/src/filewidgets/CMakeLists.txt +++ b/src/filewidgets/CMakeLists.txt @@ -38,6 +38,7 @@ kurlnavigatortogglebutton.cpp kurlnavigator.cpp kurlnavigatormenu.cpp + kurlnavigatorpathselectoreventfilter.cpp ) diff --git a/src/filewidgets/kurlnavigator.cpp b/src/filewidgets/kurlnavigator.cpp --- a/src/filewidgets/kurlnavigator.cpp +++ b/src/filewidgets/kurlnavigator.cpp @@ -27,6 +27,7 @@ #include "kurlnavigatordropdownbutton_p.h" #include "kurlnavigatorbutton_p.h" #include "kurlnavigatortogglebutton_p.h" +#include "kurlnavigatorpathselectoreventfilter_p.h" #include "urlutil_p.h" #include @@ -367,6 +368,11 @@ QString spacer; QPointer popup = new QMenu(q); + + auto *popupFilter = new KUrlNavigatorPathSelectorEventFilter(popup.data()); + connect(popupFilter, &KUrlNavigatorPathSelectorEventFilter::tabRequested, q, &KUrlNavigator::tabRequested); + popup->installEventFilter(popupFilter); + popup->setLayoutDirection(Qt::LeftToRight); const QUrl placeUrl = retrievePlaceUrl(); diff --git a/src/filewidgets/kurlnavigatorpathselectoreventfilter.cpp b/src/filewidgets/kurlnavigatorpathselectoreventfilter.cpp new file mode 100644 --- /dev/null +++ b/src/filewidgets/kurlnavigatorpathselectoreventfilter.cpp @@ -0,0 +1,62 @@ +/* + * Copyright 2018 Kai Uwe Broulik + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#include "kurlnavigatorpathselectoreventfilter_p.h" + +#include +#include +#include + +using namespace KDEPrivate; + +KUrlNavigatorPathSelectorEventFilter::KUrlNavigatorPathSelectorEventFilter(QObject *parent) + : QObject(parent) +{ + +} + +KUrlNavigatorPathSelectorEventFilter::~KUrlNavigatorPathSelectorEventFilter() +{ + +} + +bool KUrlNavigatorPathSelectorEventFilter::eventFilter(QObject *watched, QEvent *event) +{ + if (event->type() == QEvent::MouseButtonRelease) { + QMouseEvent *me = static_cast(event); + if (me->button() == Qt::MiddleButton) { + if (QMenu *menu = qobject_cast(watched)) { + if (QAction *action = menu->activeAction()) { + const QUrl url(action->data().toString()); + if (url.isValid()) { + menu->close(); + + emit tabRequested(url); + return true; + } + } + } + } + } + + return QObject::eventFilter(watched, event); +} + +#include "moc_kurlnavigatorpathselectoreventfilter_p.cpp" diff --git a/src/filewidgets/kurlnavigatorpathselectoreventfilter_p.h b/src/filewidgets/kurlnavigatorpathselectoreventfilter_p.h new file mode 100644 --- /dev/null +++ b/src/filewidgets/kurlnavigatorpathselectoreventfilter_p.h @@ -0,0 +1,44 @@ +/* + * Copyright 2018 Kai Uwe Broulik + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + +#pragma once + +#include + +namespace KDEPrivate +{ + +class KUrlNavigatorPathSelectorEventFilter : public QObject +{ + Q_OBJECT + +public: + explicit KUrlNavigatorPathSelectorEventFilter(QObject *parent); + ~KUrlNavigatorPathSelectorEventFilter() override; + +Q_SIGNALS: + void tabRequested(const QUrl &url); + +protected: + bool eventFilter(QObject *watched, QEvent *event) override; + +}; + +} // namespace KDEPrivate