added EnergySaver intended to handle shutdown.

Moved timer from MouseEventSpy to EnergySaver.
Connected MouseEventSpy and MusicController to EnergySaver.
This commit is contained in:
Anika Raemer 2019-04-04 12:21:41 +02:00
parent ce8ea8f582
commit 8a8abd6c76
7 changed files with 132 additions and 53 deletions

View file

@ -3,18 +3,26 @@
#include <QGuiApplication>
#include <QDebug>
/**
* @brief Initialize timer.
* @param parent Parent object
*/
MouseEventSpy::MouseEventSpy(QObject *parent) : QObject(parent)
{
initTimer(10000);
mTimer.start();
}
/**
* @brief Implements the singleton pattern
* @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.
@ -45,24 +53,7 @@ bool MouseEventSpy::eventFilter(QObject* watched, QEvent* event)
{
emit mouseEventDetected();
}
if(mTimer.isActive()){
mTimer.stop();
}
mTimer.start();
return QObject::eventFilter(watched, event);
}
/**
* @brief Initialize and connect timer.
* @param interval Timeout interval in millisecond.
*/
void MouseEventSpy::initTimer(int interval)
{
connect(&mTimer, &QTimer::timeout, this, &MouseEventSpy::onTimeout);
mTimer.setInterval(interval);
mTimer.setSingleShot(true);
return QObject::eventFilter(watched, event);
}
/**
@ -77,12 +68,3 @@ bool MouseEventSpy::isMouseEvent(QEvent::Type t)
|| t == QEvent::MouseButtonRelease
|| t == QEvent::MouseMove);
}
/**
* @brief Behavior on timeout: shut down RaspberryPi.
* @todo Call shutdown script.
*/
void MouseEventSpy::onTimeout()
{
qDebug() << "shutting down.";
}