#include "MouseEventSpy.h" #include #include #include MouseEventSpy::MouseEventSpy(QObject *parent) : QObject(parent) { qDebug() << "created Instance"; } /** * Implements the SINGLETON PATTERN */ MouseEventSpy* MouseEventSpy::instance() { static MouseEventSpy* inst; if (inst == nullptr) { // If no instance has been created yet, create a new and install it as event filter. // Uppon first use of the instance, it will automatically // install itself in the QGuiApplication inst = new MouseEventSpy(); QGuiApplication* app = qGuiApp; app->installEventFilter(inst); } return inst; } /** * This is the method is necessary for 'installEventFilter' */ bool MouseEventSpy::eventFilter(QObject* watched, QEvent* event) { QEvent::Type t = event->type(); if ((t == QEvent::MouseButtonDblClick || t == QEvent::MouseButtonPress || t == QEvent::MouseButtonRelease || t == QEvent::MouseMove) && event->spontaneous() // Take only mouse events from outside of Qt ) emit mouseEventDetected(); qDebug("MouseEvent detected."); return QObject::eventFilter(watched, event); }