lena_pi/LenaPi/MouseEventSpy.cpp
Jan-Martin Raemer 1f12d93300 Make LenaPi usable on Android devices
- Add app icon
- prevend android device from shutting down cpu while playing music
- fix scaling bug
- fix energy saver for RasPi by reconnecting to music player
- minor refactorings and renaming
2022-07-16 12:19:57 +02:00

44 lines
903 B
C++

#include "MouseEventSpy.h"
#include <QGuiApplication>
#include <QDebug>
void MouseEventSpy::init()
{
instance();
}
MouseEventSpy* MouseEventSpy::instance()
{
static MouseEventSpy* inst;
if (!inst)
{
inst = new MouseEventSpy();
QGuiApplication* app = qGuiApp;
app->installEventFilter(inst);
}
return inst;
}
bool MouseEventSpy::eventFilter(QObject* watched, QEvent* event)
{
QEvent::Type t = event->type();
if (isMouseEvent(t)
&& event->spontaneous() // Take only mouse events from outside of Qt
)
{
emit mouseEventDetected();
}
return QObject::eventFilter(watched, event);
}
bool MouseEventSpy::isMouseEvent(QEvent::Type t)
{
return (t == QEvent::MouseButtonDblClick
|| t == QEvent::MouseButtonPress
|| t == QEvent::MouseButtonRelease
|| t == QEvent::MouseMove);
}