diff --git a/libs/ui/KisMouseClickEater.cpp b/libs/ui/KisMouseClickEater.cpp index 8641a0bb60..eea726bd8c 100644 --- a/libs/ui/KisMouseClickEater.cpp +++ b/libs/ui/KisMouseClickEater.cpp @@ -1,70 +1,88 @@ +/* + * Copyright (c) 2019 Dmitry Kazakov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #include "KisMouseClickEater.h" #include #include "kis_debug.h" KisMouseClickEater::KisMouseClickEater(Qt::MouseButtons buttons, int clicksToEat, QObject *parent) : QObject(parent), m_buttons(buttons), m_clicksToEat(clicksToEat) { reset(); } KisMouseClickEater::~KisMouseClickEater() { } void KisMouseClickEater::reset() { m_clicksHappened = 0; m_timeSinceReset.start(); m_blockTimedRelease = false; } bool KisMouseClickEater::eventFilter(QObject *watched, QEvent *event) { #ifdef Q_OS_WIN const int tabletMouseEventsFlowDelay = 500; #else const int tabletMouseEventsFlowDelay = 100; #endif if (event->type() == QEvent::TabletMove) { m_blockTimedRelease = true; } if (!m_blockTimedRelease && m_timeSinceReset.elapsed() > tabletMouseEventsFlowDelay) { return QObject::eventFilter(watched, event); } if (event->type() == QEvent::MouseButtonPress || event->type() == QEvent::MouseButtonRelease) { QMouseEvent *mevent = static_cast(event); if (mevent->button() & m_buttons) { if (m_clicksHappened >= m_clicksToEat) { return false; } if (event->type() == QEvent::MouseButtonRelease) { m_clicksHappened++; } return true; } } if (event->type() == QEvent::MouseMove) { QMouseEvent *mevent = static_cast(event); if (mevent->buttons() & m_buttons) { return m_clicksHappened < m_clicksToEat; } } return QObject::eventFilter(watched, event); } diff --git a/libs/ui/KisMouseClickEater.h b/libs/ui/KisMouseClickEater.h index eaa470aaab..ec5054e63b 100644 --- a/libs/ui/KisMouseClickEater.h +++ b/libs/ui/KisMouseClickEater.h @@ -1,29 +1,47 @@ +/* + * Copyright (c) 2019 Dmitry Kazakov + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + #ifndef KISMOUSECLICKEATER_H #define KISMOUSECLICKEATER_H #include #include #include class KisMouseClickEater : public QObject { public: KisMouseClickEater(Qt::MouseButtons buttons, int clicksToEat = 1, QObject *parent = 0); ~KisMouseClickEater(); void reset(); bool eventFilter(QObject *watched, QEvent *event) override; private: Qt::MouseButtons m_buttons = Qt::NoButton; int m_clicksToEat = 1; int m_clicksHappened = 0; bool m_blockTimedRelease = false; QElapsedTimer m_timeSinceReset; }; #endif // KISMOUSECLICKEATER_H