File indexing completed on 2024-04-28 04:18:50

0001 /*
0002 Gwenview: an image viewer
0003 Copyright 2009 Aurélien Gâteau <agateau@kde.org>
0004 
0005 This program is free software; you can redistribute it and/or
0006 modify it under the terms of the GNU General Public License
0007 as published by the Free Software Foundation; either version 2
0008 of the License, or (at your option) any later version.
0009 
0010 This program is distributed in the hope that it will be useful,
0011 but WITHOUT ANY WARRANTY; without even the implied warranty of
0012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013 GNU General Public License for more details.
0014 
0015 You should have received a copy of the GNU General Public License
0016 along with this program; if not, write to the Free Software
0017 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
0018 
0019 */
0020 #include "eventwatcher.h"
0021 
0022 namespace Gwenview
0023 {
0024 EventWatcher::EventWatcher(QObject *watched, const QList<QEvent::Type> &eventTypes)
0025     : QObject(watched)
0026     , mEventTypes(eventTypes)
0027 {
0028     Q_ASSERT(watched);
0029     watched->installEventFilter(this);
0030 }
0031 
0032 EventWatcher *EventWatcher::install(QObject *watched, const QList<QEvent::Type> &eventTypes, QObject *receiver, const char *slot)
0033 {
0034     auto watcher = new EventWatcher(watched, eventTypes);
0035     connect(watcher, SIGNAL(eventTriggered(QEvent *)), receiver, slot);
0036     return watcher;
0037 }
0038 
0039 EventWatcher *EventWatcher::install(QObject *watched, QEvent::Type eventType, QObject *receiver, const char *slot)
0040 {
0041     auto watcher = new EventWatcher(watched, QList<QEvent::Type>() << eventType);
0042     connect(watcher, SIGNAL(eventTriggered(QEvent *)), receiver, slot);
0043     return watcher;
0044 }
0045 
0046 bool EventWatcher::eventFilter(QObject *, QEvent *event)
0047 {
0048     if (mEventTypes.contains(event->type())) {
0049         Q_EMIT eventTriggered(event);
0050     }
0051     return false;
0052 }
0053 
0054 } // namespace
0055 
0056 #include "moc_eventwatcher.cpp"