1 /***************************************************************************
2 * Copyright (C) 2017 Kai Uwe Broulik <kde@privat.broulik.de> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "middleclickactioneventfilter.h"
24 #include <QMouseEvent>
27 MiddleClickActionEventFilter::MiddleClickActionEventFilter(QObject
*parent
) : QObject(parent
)
32 MiddleClickActionEventFilter::~MiddleClickActionEventFilter() = default;
34 bool MiddleClickActionEventFilter::eventFilter(QObject
*watched
, QEvent
*event
)
36 if (event
->type() == QEvent::MouseButtonPress
37 || event
->type() == QEvent::MouseButtonRelease
) {
38 QMouseEvent
*me
= static_cast<QMouseEvent
*>(event
);
40 if (me
->button() == Qt::MiddleButton
) {
41 QToolBar
*toolBar
= qobject_cast
<QToolBar
*>(watched
);
43 QAction
*action
= toolBar
->actionAt(me
->pos());
45 if (event
->type() == QEvent::MouseButtonPress
) {
46 m_lastMiddlePressedAction
= action
;
47 } else if (event
->type() == QEvent::MouseButtonRelease
) {
48 if (m_lastMiddlePressedAction
== action
) {
49 emit
actionMiddleClicked(action
);
51 m_lastMiddlePressedAction
= nullptr;
57 return QObject::eventFilter(watched
, event
);