1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-04 17:30:55 +00:00
dolphin/src/middleclickactioneventfilter.cpp
Friedrich W. H. Kossebau ed2d352c42 Add explicit moc includes to sources for moc-covered headers
* speeds up incremental builds as changes to a header will not always
  need the full mocs_compilation.cpp for all the target's headers rebuild,
  while having a moc file sourced into a source file only adds minor
  extra costs, due to small own code and the used headers usually
  already covered by the source file, being for the same class/struct
* seems to not slow down clean builds, due to empty mocs_compilation.cpp
  resulting in those quickly processed, while the minor extra cost of the
  sourced moc files does not outweigh that in summary.
  Measured times actually improved by some percent points.
  (ideally CMake would just skip empty mocs_compilation.cpp & its object
  file one day)
* enables compiler to see all methods of a class in same compilation unit
  to do some sanity checks
* potentially more inlining in general, due to more in the compilation unit
* allows to keep using more forward declarations in the header, as with the
  moc code being sourced into the cpp file there definitions can be ensured
  and often are already for the needs of the normal class methods
2023-07-05 07:59:18 +00:00

64 lines
2.2 KiB
C++

/*
* SPDX-FileCopyrightText: 2017 Kai Uwe Broulik <kde@privat.broulik.de>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "middleclickactioneventfilter.h"
#include <QAction>
#include <QEvent>
#include <QMenu>
#include <QMouseEvent>
#include <QToolBar>
MiddleClickActionEventFilter::MiddleClickActionEventFilter(QObject *parent)
: QObject(parent)
{
}
MiddleClickActionEventFilter::~MiddleClickActionEventFilter() = default;
bool MiddleClickActionEventFilter::eventFilter(QObject *watched, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) {
QMouseEvent *me = static_cast<QMouseEvent *>(event);
if (me->button() == Qt::MiddleButton) {
QToolBar *toolBar = qobject_cast<QToolBar *>(watched);
if (toolBar) {
QAction *action = toolBar->actionAt(me->pos());
if (action) {
if (event->type() == QEvent::MouseButtonPress) {
m_lastMiddlePressedAction = action;
} else if (event->type() == QEvent::MouseButtonRelease) {
if (m_lastMiddlePressedAction == action) {
Q_EMIT actionMiddleClicked(action);
}
m_lastMiddlePressedAction = nullptr;
}
}
}
QMenu *menu = qobject_cast<QMenu *>(watched);
if (menu) {
QAction *action = menu->actionAt(me->pos());
if (action) {
if (event->type() == QEvent::MouseButtonPress) {
m_lastMiddlePressedAction = action;
} else if (event->type() == QEvent::MouseButtonRelease) {
if (m_lastMiddlePressedAction == action) {
Q_EMIT actionMiddleClicked(action);
return true;
}
m_lastMiddlePressedAction = nullptr;
}
}
}
}
}
return QObject::eventFilter(watched, event);
}
#include "moc_middleclickactioneventfilter.cpp"