2 * SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #include "middleclickactioneventfilter.h"
12 #include <QMouseEvent>
15 MiddleClickActionEventFilter::MiddleClickActionEventFilter(QObject
*parent
) : QObject(parent
)
20 MiddleClickActionEventFilter::~MiddleClickActionEventFilter() = default;
22 bool MiddleClickActionEventFilter::eventFilter(QObject
*watched
, QEvent
*event
)
24 if (event
->type() == QEvent::MouseButtonPress
25 || event
->type() == QEvent::MouseButtonRelease
) {
26 QMouseEvent
*me
= static_cast<QMouseEvent
*>(event
);
28 if (me
->button() == Qt::MiddleButton
) {
29 QToolBar
*toolBar
= qobject_cast
<QToolBar
*>(watched
);
31 QAction
*action
= toolBar
->actionAt(me
->pos());
33 if (event
->type() == QEvent::MouseButtonPress
) {
34 m_lastMiddlePressedAction
= action
;
35 } else if (event
->type() == QEvent::MouseButtonRelease
) {
36 if (m_lastMiddlePressedAction
== action
) {
37 emit
actionMiddleClicked(action
);
39 m_lastMiddlePressedAction
= nullptr;
43 QMenu
*menu
= qobject_cast
<QMenu
*>(watched
);
45 QAction
*action
= menu
->actionAt(me
->pos());
47 if (event
->type() == QEvent::MouseButtonPress
) {
48 m_lastMiddlePressedAction
= action
;
49 } else if (event
->type() == QEvent::MouseButtonRelease
) {
50 if (m_lastMiddlePressedAction
== action
) {
51 emit
actionMiddleClicked(action
);
54 m_lastMiddlePressedAction
= nullptr;
61 return QObject::eventFilter(watched
, event
);