FluentUI/src/FluHotkey.cpp

28 lines
795 B
C++
Raw Normal View History

2024-05-16 00:35:04 +08:00
#include "FluHotkey.h"
#include "QGuiApplication"
2024-06-28 17:09:23 +08:00
FluHotkey::FluHotkey(QObject *parent) : QObject{parent} {
2024-05-16 00:35:04 +08:00
_sequence = "";
_isRegistered = false;
2024-06-28 17:09:23 +08:00
connect(this, &FluHotkey::sequenceChanged, this, [=] {
if (_hotkey) {
delete _hotkey;
2024-05-16 00:35:04 +08:00
_hotkey = nullptr;
}
_hotkey = new QHotkey(QKeySequence(_sequence), true, qApp);
this->isRegistered(_hotkey->isRegistered());
2024-06-28 17:09:23 +08:00
QObject::connect(_hotkey, &QHotkey::activated, qApp, [=]() { Q_EMIT this->activated(); });
QObject::connect(_hotkey, &QHotkey::registeredChanged, qApp,
[=]() { this->isRegistered(_hotkey->isRegistered()); });
2024-05-16 00:35:04 +08:00
});
}
2024-06-28 17:09:23 +08:00
FluHotkey::~FluHotkey() {
if (_hotkey) {
2024-05-16 00:35:04 +08:00
delete _hotkey;
_hotkey = nullptr;
}
}