Kylin/Fluent/Hotkey.cpp

27 lines
808 B
C++
Raw Normal View History

2024-09-01 00:33:29 +08:00
#include "Hotkey.h"
#include "QHotkey"
#include <QGuiApplication>
Hotkey::Hotkey(QObject *parent) : QObject{parent} {
m_sequence = "";
m_isRegistered = false;
connect(this, &Hotkey::sequenceChanged, this, [=] {
if (m_hotkey) {
delete m_hotkey;
m_hotkey = nullptr;
}
m_hotkey = new QHotkey(QKeySequence(m_sequence), true, qApp);
this->isRegistered(m_hotkey->isRegistered());
QObject::connect(m_hotkey, &QHotkey::activated, qApp, [=]() { Q_EMIT this->activated(); });
QObject::connect(m_hotkey, &QHotkey::registeredChanged, qApp,
[=]() { this->isRegistered(m_hotkey->isRegistered()); });
});
}
Hotkey::~Hotkey() {
if (m_hotkey) {
delete m_hotkey;
m_hotkey = nullptr;
}
}