File indexing completed on 2024-04-21 03:55:26

0001 /*
0002     SPDX-FileCopyrightText: 2018 Kai Uwe Broulik <kde@privat.broulik.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0005 */
0006 
0007 #include "kurlnavigatorpathselectoreventfilter_p.h"
0008 
0009 #include <QEvent>
0010 #include <QMenu>
0011 #include <QMouseEvent>
0012 
0013 using namespace KDEPrivate;
0014 
0015 KUrlNavigatorPathSelectorEventFilter::KUrlNavigatorPathSelectorEventFilter(QObject *parent)
0016     : QObject(parent)
0017 {
0018 }
0019 
0020 KUrlNavigatorPathSelectorEventFilter::~KUrlNavigatorPathSelectorEventFilter()
0021 {
0022 }
0023 
0024 bool KUrlNavigatorPathSelectorEventFilter::eventFilter(QObject *watched, QEvent *event)
0025 {
0026     if (event->type() == QEvent::MouseButtonRelease) {
0027         QMouseEvent *me = static_cast<QMouseEvent *>(event);
0028         if (me->button() == Qt::MiddleButton) {
0029             if (QMenu *menu = qobject_cast<QMenu *>(watched)) {
0030                 if (QAction *action = menu->activeAction()) {
0031                     const QUrl url(action->data().toString());
0032                     if (url.isValid()) {
0033                         menu->close();
0034 
0035                         Q_EMIT tabRequested(url);
0036                         return true;
0037                     }
0038                 }
0039             }
0040         }
0041     }
0042 
0043     return QObject::eventFilter(watched, event);
0044 }
0045 
0046 #include "moc_kurlnavigatorpathselectoreventfilter_p.cpp"