17 #include "globalshortcut.h" 18 #include "globalshortcutregistry.h" 25 GlobalShortcut::GlobalShortcut(QQuickItem *parent)
35 void GlobalShortcut::setShortcut(
const QVariant &shortcut)
37 if (m_shortcut == shortcut)
40 m_shortcut = shortcut;
41 registry->addShortcut(shortcut,
this);
42 Q_EMIT shortcutChanged(shortcut);
45 bool GlobalShortcut::isActive()
const 50 void GlobalShortcut::setActive(
bool active)
52 if (m_active == active)
56 Q_EMIT activeChanged(active);
59 void GlobalShortcut::componentComplete()
61 connect(
this, &QQuickItem::windowChanged,
this, &GlobalShortcut::setupFilterOnWindow);
64 void GlobalShortcut::keyPressEvent(QKeyEvent * event)
66 if (!m_active)
return;
69 Q_EMIT triggered(m_shortcut.toString());
72 void GlobalShortcut::keyReleaseEvent(QKeyEvent * event)
74 if (!m_active)
return;
77 Q_EMIT released(m_shortcut.toString());
80 void GlobalShortcut::setupFilterOnWindow(QQuickWindow *window)
87 registry->setupFilterOnWindow((qulonglong) window->winId());
The GlobalShortcutRegistry class.