diff options
| author | 2023-03-07 21:11:06 +0600 | |
|---|---|---|
| committer | 2023-03-07 21:11:06 +0600 | |
| commit | d830bfc8ce7c6763d074beafdde7cab1835d31f9 (patch) | |
| tree | 179f81f3b42779b1f6fb69deed6b69dab39f4f89 /src/autolockeventfilter.h | |
| download | whatsie-upstream/4.12.0.tar.gz whatsie-upstream/4.12.0.zip | |
Import Upstream version 4.12.0upstream/4.12.0
Diffstat (limited to 'src/autolockeventfilter.h')
| -rw-r--r-- | src/autolockeventfilter.h | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/autolockeventfilter.h b/src/autolockeventfilter.h new file mode 100644 index 0000000..9c35c45 --- /dev/null +++ b/src/autolockeventfilter.h @@ -0,0 +1,59 @@ +#ifndef AUTOLOCKEVENTFILTER_H +#define AUTOLOCKEVENTFILTER_H + +#include <QDebug> +#include <QEvent> +#include <QTimer> + +class AutoLockEventFilter : public QObject { + Q_OBJECT + +public: + explicit AutoLockEventFilter(int timeoutmillis) + : timeoutmillis(timeoutmillis) { + autoLockTimer = new QTimer(this); + connect(autoLockTimer, &QTimer::timeout, this, + QOverload<>::of(&AutoLockEventFilter::lockApp)); + resetTimer(); + } + + ~AutoLockEventFilter() { + autoLockTimer->stop(); + autoLockTimer->deleteLater(); + } + +signals: + void autoLockTimerTimeout(); + +private: + QTimer *autoLockTimer = nullptr; + int timeoutmillis; + +public slots: + void stopTimer() { autoLockTimer->stop(); } + void resetTimer() { autoLockTimer->start(timeoutmillis); } + void lockApp() { emit autoLockTimerTimeout(); } + void setTimeoutmillis(int newTimeoutmillis) { + timeoutmillis = newTimeoutmillis; + } + +protected: + bool eventFilter(QObject *obj, QEvent *ev) { + if (ev->type() == QEvent::KeyPress + || ev->type() == QEvent::MouseMove + || ev->type() == QEvent::Wheel + || ev->type() == QEvent::TouchUpdate + || ev->type() == QEvent::MouseButtonRelease + || ev->type() == QEvent::MouseButtonPress + || ev->type() == QEvent::MouseButtonDblClick + || ev->type() == QEvent::Gesture + || ev->type() == QEvent::FocusIn + || ev->type() == QEvent::FocusOut + || ev->type() == QEvent::Enter + ) { + resetTimer(); + } + return QObject::eventFilter(obj, ev); + } +}; +#endif // AUTOLOCKEVENTFILTER_H |
