]> cloud.milkyroute.net Git - dolphin.git/blob - src/middleclickactioneventfilter.cpp
Fix indentation
[dolphin.git] / src / middleclickactioneventfilter.cpp
1 /***************************************************************************
2 * Copyright (C) 2017 Kai Uwe Broulik <kde@privat.broulik.de> *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20 #include "middleclickactioneventfilter.h"
21
22 #include <QAction>
23 #include <QEvent>
24 #include <QMouseEvent>
25 #include <QToolBar>
26
27 MiddleClickActionEventFilter::MiddleClickActionEventFilter(QObject *parent) : QObject(parent)
28 {
29
30 }
31
32 MiddleClickActionEventFilter::~MiddleClickActionEventFilter() = default;
33
34 bool MiddleClickActionEventFilter::eventFilter(QObject *watched, QEvent *event)
35 {
36 if (event->type() == QEvent::MouseButtonPress
37 || event->type() == QEvent::MouseButtonRelease) {
38 QMouseEvent *me = static_cast<QMouseEvent *>(event);
39
40 if (me->button() == Qt::MiddleButton) {
41 QToolBar *toolBar = qobject_cast<QToolBar *>(watched);
42
43 QAction *action = toolBar->actionAt(me->pos());
44 if (action) {
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);
50 }
51 m_lastMiddlePressedAction = nullptr;
52 }
53 }
54 }
55 }
56
57 return QObject::eventFilter(watched, event);
58 }