add hotkey

This commit is contained in:
朱子楚\zhuzi
2024-05-16 00:35:04 +08:00
parent 876b230141
commit 354f7f2e3e
26 changed files with 2083 additions and 114 deletions

32
src/FluHotkey.cpp Normal file
View File

@ -0,0 +1,32 @@
#include "FluHotkey.h"
#include "QGuiApplication"
FluHotkey::FluHotkey(QObject *parent)
: QObject{parent}
{
_sequence = "";
_isRegistered = false;
connect(this,&FluHotkey::sequenceChanged,this,[=]{
if(_hotkey){
delete _hotkey;
_hotkey = nullptr;
}
_hotkey = new QHotkey(QKeySequence(_sequence), true, qApp);
this->isRegistered(_hotkey->isRegistered());
QObject::connect(_hotkey, &QHotkey::activated, qApp, [=](){
Q_EMIT this->activated();
});
QObject::connect(_hotkey, &QHotkey::registeredChanged, qApp, [=](){
this->isRegistered(_hotkey->isRegistered());
});
});
}
FluHotkey::~FluHotkey(){
if(_hotkey){
delete _hotkey;
_hotkey = nullptr;
}
}