19 #include "windowkeysfilter.h"
21 #include <QQuickWindow>
23 WindowKeysFilter::WindowKeysFilter(QQuickItem *parent)
25 m_currentEventTimestamp(0)
27 connect(
this, &QQuickItem::windowChanged,
28 this, &WindowKeysFilter::setupFilterOnWindow);
31 bool WindowKeysFilter::eventFilter(QObject *watched, QEvent *event)
33 Q_ASSERT(!m_filteredWindow.isNull());
34 Q_ASSERT(watched == static_cast<QObject*>(m_filteredWindow.data()));
37 if (event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease) {
41 m_currentEventTimestamp =
static_cast<QInputEvent*
>(event)->timestamp();
42 Q_EMIT currentEventTimestampChanged();
44 QCoreApplication::sendEvent(
this, event);
46 m_currentEventTimestamp = 0;
47 Q_EMIT currentEventTimestampChanged();
49 return event->isAccepted();
56 void WindowKeysFilter::setupFilterOnWindow(QQuickWindow *window)
58 if (!m_filteredWindow.isNull()) {
59 m_filteredWindow->removeEventFilter(
this);
60 m_filteredWindow.clear();
64 window->installEventFilter(
this);
65 m_filteredWindow = window;
69 ulong WindowKeysFilter::currentEventTimestamp()
const
71 return m_currentEventTimestamp;