19 #include "windowkeysfilter.h"
21 #include <QQuickWindow>
23 WindowKeysFilter::WindowKeysFilter(QQuickItem *parent)
26 connect(
this, &QQuickItem::windowChanged,
27 this, &WindowKeysFilter::setupFilterOnWindow);
30 bool WindowKeysFilter::eventFilter(QObject *watched, QEvent *event)
32 Q_ASSERT(!m_filteredWindow.isNull());
33 Q_ASSERT(watched == static_cast<QObject*>(m_filteredWindow.data()));
35 if (event->type() == QEvent::KeyPress ||
event->type() == QEvent::KeyRelease) {
38 QCoreApplication::sendEvent(
this, event);
39 return event->isAccepted();
46 void WindowKeysFilter::setupFilterOnWindow(QQuickWindow *window)
48 if (!m_filteredWindow.isNull()) {
49 m_filteredWindow->removeEventFilter(
this);
50 m_filteredWindow.clear();
54 window->installEventFilter(
this);
55 m_filteredWindow = window;