27 lines
808 B
C++
27 lines
808 B
C++
#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;
|
|
}
|
|
}
|