17 #include "globalshortcut.h" 18 #include "globalshortcutregistry.h" 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()
62 QMetaObject::invokeMethod(
this,
"setupFilterOnWindow", Q_ARG(QQuickWindow*, this->window()));
64 connect(
this, &QQuickItem::windowChanged,
this, &GlobalShortcut::setupFilterOnWindow);
67 void GlobalShortcut::keyPressEvent(QKeyEvent * event)
69 if (!m_active)
return;
75 void GlobalShortcut::keyReleaseEvent(QKeyEvent * event)
77 if (!m_active)
return;
80 Q_EMIT
released(m_shortcut.toString());
83 void GlobalShortcut::setupFilterOnWindow(QQuickWindow *window)
90 registry->setupFilterOnWindow((qulonglong) window->winId());
The GlobalShortcutRegistry class.
void triggered(const QString &shortcut)
The GlobalShortcut class.
void released(const QString &shortcut)