Refactoring and documentation
This commit is contained in:
parent
87a208d305
commit
3fb5be5a74
10 changed files with 149 additions and 75 deletions
|
|
@ -3,30 +3,12 @@
|
|||
#include <QGuiApplication>
|
||||
#include <QDebug>
|
||||
|
||||
MouseEventSpy::MouseEventSpy(QObject *parent) : QObject(parent)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Create instance if necessary.
|
||||
*
|
||||
* If no instance has been created yet, create new instance and install it as event filter
|
||||
* in QGuiApplication.
|
||||
*
|
||||
* @see MouseEventSpy::instance()
|
||||
*/
|
||||
void MouseEventSpy::init()
|
||||
{
|
||||
instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Implements the singleton pattern.
|
||||
* @return Instance
|
||||
*
|
||||
* If no instance has been created yet, create new instance and install it as event filter
|
||||
* in QGuiApplication.
|
||||
*/
|
||||
|
||||
MouseEventSpy* MouseEventSpy::instance()
|
||||
{
|
||||
static MouseEventSpy* inst;
|
||||
|
|
@ -39,28 +21,20 @@ MouseEventSpy* MouseEventSpy::instance()
|
|||
return inst;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Expand QObject::eventFilter to react to MouseEvents.
|
||||
*
|
||||
* Restart timer each time a mouse event is detected.
|
||||
*/
|
||||
|
||||
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
|
||||
)
|
||||
&& event->spontaneous() // Take only mouse events from outside of Qt
|
||||
)
|
||||
{
|
||||
emit mouseEventDetected();
|
||||
}
|
||||
return QObject::eventFilter(watched, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Checks whether the event type is a mouse event.
|
||||
* @param t Event type
|
||||
* @return Returns whether the event type is a mouse event.
|
||||
*/
|
||||
|
||||
bool MouseEventSpy::isMouseEvent(QEvent::Type t)
|
||||
{
|
||||
return (t == QEvent::MouseButtonDblClick
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue