diff --git a/HotkeyTest/hottestwidget.cpp b/HotkeyTest/hottestwidget.cpp index abec428..d3e33d2 100644 --- a/HotkeyTest/hottestwidget.cpp +++ b/HotkeyTest/hottestwidget.cpp @@ -3,12 +3,174 @@ HotTestWidget::HotTestWidget(QWidget *parent) : QWidget(parent), - ui(new Ui::HotTestWidget) + ui(new Ui::HotTestWidget), + hotkey_1(new QHotkey(this)), + hotkey_2(new QHotkey(this)), + hotkey_3(new QHotkey(this)), + hotkey_4(new QHotkey(this)), + hotkey_5(new QHotkey(this)), + testHotkeys() { ui->setupUi(this); + + //1 + connect(this->ui->hotkeyCheckbox_1, &QCheckBox::toggled, + this->hotkey_1, &QHotkey::setRegistered); + connect(this->ui->hotkeySequenceEdit_1, &QKeySequenceEdit::keySequenceChanged, + this, &HotTestWidget::setShortcut_1); + connect(this->hotkey_1, &QHotkey::activated, + this, &HotTestWidget::increase_1); + + //2 + connect(this->ui->hotkeyCheckbox_2, &QCheckBox::toggled, + this->hotkey_2, &QHotkey::setRegistered); + connect(this->ui->hotkeySequenceEdit_2, &QKeySequenceEdit::keySequenceChanged, + this, &HotTestWidget::setShortcut_2); + connect(this->hotkey_2, &QHotkey::activated, + this, &HotTestWidget::increase_2); + + //3 + connect(this->ui->hotkeyCheckbox_3, &QCheckBox::toggled, + this->hotkey_3, &QHotkey::setRegistered); + connect(this->ui->hotkeySequenceEdit_3, &QKeySequenceEdit::keySequenceChanged, + this, &HotTestWidget::setShortcut_3); + connect(this->hotkey_3, &QHotkey::activated, + this, &HotTestWidget::increase_3); + + //4 + connect(this->ui->hotkeyCheckbox_4, &QCheckBox::toggled, + this->hotkey_4, &QHotkey::setRegistered); + connect(this->ui->hotkeySequenceEdit_4, &QKeySequenceEdit::keySequenceChanged, + this, &HotTestWidget::setShortcut_4); + connect(this->hotkey_4, &QHotkey::activated, + this, &HotTestWidget::increase_4); + + //5 + connect(this->ui->hotkeyCheckbox_5, &QCheckBox::toggled, + this->hotkey_5, &QHotkey::setRegistered); + connect(this->ui->hotkeySequenceEdit_5, &QKeySequenceEdit::keySequenceChanged, + this, &HotTestWidget::setShortcut_5); + connect(this->hotkey_5, &QHotkey::activated, + this, &HotTestWidget::increase_5); + + //test connections + this->testHotkeys += new QHotkey(Qt::Key_F, Qt::NoModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyFCheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_F12, Qt::ControlModifier | Qt::AltModifier | Qt::MetaModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyCtrlAltMetaF12CheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_Cancel, Qt::ControlModifier | Qt::ShiftModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyCtrlShiftCancelCheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_Delete, Qt::MetaModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyMetaDelCheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_NumLock, Qt::NoModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyNumlockCheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_5, Qt::ControlModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyCtrl5CheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_Tab, Qt::ShiftModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyShiftTabCheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_Comma, Qt::ShiftModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyShiftCheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_Semicolon, Qt::ShiftModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyShiftCheckBox_2, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_K, Qt::ShiftModifier | Qt::AltModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyShiftAltKCheckBox, &QCheckBox::toggle); + this->testHotkeys += new QHotkey(Qt::Key_K, Qt::ShiftModifier | Qt::AltModifier, false, this); + connect(this->testHotkeys.last(), &QHotkey::activated, + this->ui->hotkeyShiftAltKCheckBox_2, &QCheckBox::toggle); } HotTestWidget::~HotTestWidget() { delete ui; } + +void HotTestWidget::setShortcut_1(const QKeySequence &sequence) +{ + this->hotkey_1->setShortcut(sequence, false); +} + +void HotTestWidget::setShortcut_2(const QKeySequence &sequence) +{ + this->hotkey_2->setShortcut(sequence, false); +} + +void HotTestWidget::setShortcut_3(const QKeySequence &sequence) +{ + this->hotkey_3->setShortcut(sequence, false); +} + +void HotTestWidget::setShortcut_4(const QKeySequence &sequence) +{ + this->hotkey_4->setShortcut(sequence, false); +} + +void HotTestWidget::setShortcut_5(const QKeySequence &sequence) +{ + this->hotkey_5->setShortcut(sequence, false); +} + +void HotTestWidget::increase_1() +{ + this->ui->hotkeyCount_1->display(this->ui->hotkeyCount_1->intValue() + 1); +} + +void HotTestWidget::increase_2() +{ + this->ui->hotkeyCount_2->display(this->ui->hotkeyCount_2->intValue() + 1); +} + +void HotTestWidget::increase_3() +{ + this->ui->hotkeyCount_3->display(this->ui->hotkeyCount_3->intValue() + 1); +} + +void HotTestWidget::increase_4() +{ + this->ui->hotkeyCount_4->display(this->ui->hotkeyCount_4->intValue() + 1); +} + +void HotTestWidget::increase_5() +{ + this->ui->hotkeyCount_5->display(this->ui->hotkeyCount_5->intValue() + 1); +} + +void HotTestWidget::on_resetButton_1_clicked() +{ + this->ui->hotkeyCount_1->display(0); +} + +void HotTestWidget::on_resetButton_2_clicked() +{ + this->ui->hotkeyCount_2->display(0); +} + +void HotTestWidget::on_resetButton_3_clicked() +{ + this->ui->hotkeyCount_3->display(0); +} + +void HotTestWidget::on_resetButton_4_clicked() +{ + this->ui->hotkeyCount_4->display(0); +} + +void HotTestWidget::on_resetButton_5_clicked() +{ + this->ui->hotkeyCount_5->display(0); +} + +void HotTestWidget::on_groupBox_toggled(bool checked) +{ + for(QHotkey *hotkey : this->testHotkeys) + hotkey->setRegistered(checked); +} diff --git a/HotkeyTest/hottestwidget.h b/HotkeyTest/hottestwidget.h index 4ad38f2..3b9d6c3 100644 --- a/HotkeyTest/hottestwidget.h +++ b/HotkeyTest/hottestwidget.h @@ -2,6 +2,7 @@ #define HOTTESTWIDGET_H #include +#include namespace Ui { class HotTestWidget; @@ -15,8 +16,37 @@ public: explicit HotTestWidget(QWidget *parent = 0); ~HotTestWidget(); +private slots: + void setShortcut_1(const QKeySequence &sequence); + void setShortcut_2(const QKeySequence &sequence); + void setShortcut_3(const QKeySequence &sequence); + void setShortcut_4(const QKeySequence &sequence); + void setShortcut_5(const QKeySequence &sequence); + + void increase_1(); + void increase_2(); + void increase_3(); + void increase_4(); + void increase_5(); + + void on_resetButton_1_clicked(); + void on_resetButton_2_clicked(); + void on_resetButton_3_clicked(); + void on_resetButton_4_clicked(); + void on_resetButton_5_clicked(); + + void on_groupBox_toggled(bool checked); + private: Ui::HotTestWidget *ui; + + QHotkey *hotkey_1; + QHotkey *hotkey_2; + QHotkey *hotkey_3; + QHotkey *hotkey_4; + QHotkey *hotkey_5; + + QList testHotkeys; }; #endif // HOTTESTWIDGET_H diff --git a/HotkeyTest/hottestwidget.ui b/HotkeyTest/hottestwidget.ui index 2dc55a7..93eff1e 100644 --- a/HotkeyTest/hottestwidget.ui +++ b/HotkeyTest/hottestwidget.ui @@ -1,20 +1,1104 @@ + HotTestWidget - - + + 0 0 - 400 - 300 + 656 + 467 - + HotTestWidget + + + + + 1 + + + + Playground + + + + + + Hotkey &1: + + + + + + + + + + Count: + + + + + + + false + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 120 + 120 + 120 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + true + + + QFrame::Panel + + + QFrame::Sunken + + + QLCDNumber::Flat + + + + + + + Qt::LeftArrow + + + + + + + Hotkey &2: + + + + + + + + + + Count: + + + + + + + false + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 120 + 120 + 120 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + true + + + QFrame::Panel + + + QFrame::Sunken + + + QLCDNumber::Flat + + + + + + + Qt::LeftArrow + + + + + + + Hotkey &3: + + + + + + + + + + Count: + + + + + + + false + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 120 + 120 + 120 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + true + + + QFrame::Panel + + + QFrame::Sunken + + + QLCDNumber::Flat + + + + + + + Qt::LeftArrow + + + + + + + Hotkey &4: + + + + + + + + + + Count: + + + + + + + false + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 120 + 120 + 120 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + true + + + QFrame::Panel + + + QFrame::Sunken + + + QLCDNumber::Flat + + + + + + + Qt::LeftArrow + + + + + + + Hotkey &5: + + + + + + + + + + Count: + + + + + + + false + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 85 + 255 + 0 + + + + + + + 255 + 255 + 255 + + + + + + + 0 + 0 + 0 + + + + + + + + + 120 + 120 + 120 + + + + + + + 0 + 0 + 0 + + + + + + + 0 + 0 + 0 + + + + + + + + true + + + QFrame::Panel + + + QFrame::Sunken + + + QLCDNumber::Flat + + + + + + + Qt::LeftArrow + + + + + + + Qt::Vertical + + + + 20 + 41 + + + + + + + + Qt::Vertical + + + + 20 + 41 + + + + + + + + Qt::Vertical + + + + 20 + 41 + + + + + + + + Qt::Vertical + + + + 20 + 41 + + + + + + + + Qt::Vertical + + + + 20 + 41 + + + + + + + + + Testings + + + + + + <b>Testing:</b> Please press the combinations listed below to check whether they work properly or not. Everytime a shortcut is triggered, the checkbox will toggle it's value. Set the test active to begin. + + + true + + + + + + + Test Active: + + + true + + + false + + + + + + Hotkey: F + + + + + + + + + + Hotkey: ctrl+alt+meta+F12 + + + + + + + + + + Hotkey: ctrl+shift+cancel + + + + + + + + + + Hotkey: meta+del + + + + + + + + + + Hotkey: numlock + + + + + + + + + + Hotkey: ctrl+5 + + + + + + + + + + Hotkey: shift+Tab + + + + + + + + + + Hotkey: shift+, + + + + + + + + + + Hotkey: shift+; + + + + + + + + + + Hotkey: shift+alt+K + + + + + + + + + + Hotkey: shift+alt+K + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + - - + + + hotkeyCheckbox_1 + hotkeySequenceEdit_1 + resetButton_1 + hotkeyCheckbox_2 + hotkeySequenceEdit_2 + resetButton_2 + hotkeyCheckbox_3 + hotkeySequenceEdit_3 + resetButton_3 + hotkeyCheckbox_4 + hotkeySequenceEdit_4 + resetButton_4 + hotkeyCheckbox_5 + hotkeySequenceEdit_5 + resetButton_5 + - + + + hotkeyCheckbox_1 + toggled(bool) + hotkeyCount_1 + setEnabled(bool) + + + 36 + 52 + + + 375 + 62 + + + + + hotkeyCheckbox_2 + toggled(bool) + hotkeyCount_2 + setEnabled(bool) + + + 44 + 82 + + + 359 + 82 + + + + + hotkeyCheckbox_3 + toggled(bool) + hotkeyCount_3 + setEnabled(bool) + + + 52 + 113 + + + 375 + 120 + + + + + hotkeyCheckbox_4 + toggled(bool) + hotkeyCount_4 + setEnabled(bool) + + + 58 + 140 + + + 375 + 149 + + + + + hotkeyCheckbox_5 + toggled(bool) + hotkeyCount_5 + setEnabled(bool) + + + 28 + 163 + + + 375 + 178 + + + + + hotkeyCheckbox_1 + toggled(bool) + hotkeySequenceEdit_1 + setDisabled(bool) + + + 62 + 50 + + + 127 + 52 + + + + + hotkeyCheckbox_2 + toggled(bool) + hotkeySequenceEdit_2 + setDisabled(bool) + + + 83 + 79 + + + 161 + 81 + + + + + hotkeyCheckbox_3 + toggled(bool) + hotkeySequenceEdit_3 + setDisabled(bool) + + + 75 + 106 + + + 116 + 109 + + + + + hotkeyCheckbox_4 + toggled(bool) + hotkeySequenceEdit_4 + setDisabled(bool) + + + 69 + 135 + + + 117 + 141 + + + + + hotkeyCheckbox_5 + toggled(bool) + hotkeySequenceEdit_5 + setDisabled(bool) + + + 81 + 168 + + + 145 + 164 + + + + diff --git a/QHotkey/QHotkey b/QHotkey/QHotkey new file mode 100644 index 0000000..21d5e57 --- /dev/null +++ b/QHotkey/QHotkey @@ -0,0 +1 @@ +#include "qhotkey.h" diff --git a/QHotkey/qhotkey.cpp b/QHotkey/qhotkey.cpp index 37149cd..4b04a11 100644 --- a/QHotkey/qhotkey.cpp +++ b/QHotkey/qhotkey.cpp @@ -10,17 +10,22 @@ Q_GLOBAL_STATIC(QHotkeyPrivate, hotkeyPrivate) QHotkey::QHotkey(QObject *parent) : QObject(parent), - enabled(true), key(Qt::Key_unknown), mods(Qt::NoModifier), - nativeShortcut(), + nativeHkey(), registered(false) {} -QHotkey::QHotkey(const QKeySequence &sequence, QObject *parent) : +QHotkey::QHotkey(const QKeySequence &sequence, bool autoRegister, QObject *parent) : QHotkey(parent) { - this->setShortcut(sequence); + this->setShortcut(sequence, autoRegister); +} + +QHotkey::QHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister, QObject *parent) : + QHotkey(parent) +{ + this->setShortcut(key, modifiers, autoRegister); } QHotkey::~QHotkey() @@ -37,42 +42,19 @@ QKeySequence QHotkey::shortcut() const return QKeySequence(this->key | this->mods); } -bool QHotkey::setShortcut(const QKeySequence &shortcut) +Qt::Key QHotkey::keyCode() const { - if(this->registered) { - if(!hotkeyPrivate->removeShortcut(this)) { - qWarning("QHotkey: Failed to unset previous shortcut. Cannot set new one."); - return false; - } - } - - if(shortcut.isEmpty()) { - this->key = Qt::Key_unknown; - this->mods = Qt::NoModifier; - this->nativeShortcut = NativeShortcut(); - return true; - } else if(shortcut.count() > 1) { - qWarning("QHotkey: Keysequences with multiple shortcuts are not allowed! " - "Only the first shortcut will be used!"); - } - - this->key = Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask); - this->mods = Qt::KeyboardModifiers(shortcut[0] & Qt::KeyboardModifierMask); - this->nativeShortcut = hotkeyPrivate->nativeShortcut(this->key, this->mods); - if(this->nativeShortcut.isValid()) - return hotkeyPrivate->addShortcut(this); - else { - qWarning("QHotkey: Unable to map shortcut to native keys."); - this->key = Qt::Key_unknown; - this->mods = Qt::NoModifier; - this->nativeShortcut = NativeShortcut(); - return false; - } + return this->key; } -bool QHotkey::isEnabled() const +Qt::KeyboardModifiers QHotkey::modifiers() const { - return this->enabled; + return this->mods; +} + +QHotkey::NativeShortcut QHotkey::nativeShortcut() const +{ + return this->nativeHkey; } bool QHotkey::isRegistered() const @@ -80,9 +62,74 @@ bool QHotkey::isRegistered() const return this->registered; } -void QHotkey::setEnabled(bool enabled) +bool QHotkey::setShortcut(const QKeySequence &shortcut, bool autoRegister) { - this->enabled = enabled; + if(shortcut.isEmpty()) { + return this->resetShortcut(); + } else if(shortcut.count() > 1) { + qWarning("QHotkey: Keysequences with multiple shortcuts are not allowed! " + "Only the first shortcut will be used!"); + } + + return this->setShortcut(Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask), + Qt::KeyboardModifiers(shortcut[0] & Qt::KeyboardModifierMask), + autoRegister); +} + +bool QHotkey::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister) +{ + if(this->registered) { + if(autoRegister) { + if(!hotkeyPrivate->removeShortcut(this)) + return false; + } else { + qWarning("QHotkey: Can't change the shortcut while the hotkey is registered"); + return false; + } + } + + this->key = key; + this->mods = modifiers; + this->nativeHkey = hotkeyPrivate->nativeShortcut(key, modifiers); + if(this->nativeHkey.isValid()) { + if(autoRegister) + return hotkeyPrivate->addShortcut(this); + else + return true; + } else { + qWarning("QHotkey: Unable to map shortcut to native keys."); + this->key = Qt::Key_unknown; + this->mods = Qt::NoModifier; + this->nativeHkey = NativeShortcut(); + return false; + } +} + +bool QHotkey::resetShortcut() +{ + if(this->registered && + !hotkeyPrivate->removeShortcut(this)) { + qWarning("QHotkey: Failed to unregister shortcut"); + return false; + } + + this->key = Qt::Key_unknown; + this->mods = Qt::NoModifier; + this->nativeHkey = NativeShortcut(); + return true; +} + +bool QHotkey::setRegistered(bool registered) +{ + if(this->registered && !registered) + return hotkeyPrivate->removeShortcut(this); + else if(!this->registered && registered) { + if(!this->nativeHkey.isValid()) + return false; + else + return hotkeyPrivate->addShortcut(this); + } else + return true; } @@ -154,7 +201,7 @@ bool QHotkeyPrivate::addShortcut(QHotkey *hotkey) { if(hotkey->registered) return false; - QHotkey::NativeShortcut shortcut = hotkey->nativeShortcut; + QHotkey::NativeShortcut shortcut = hotkey->nativeHkey; LOCKER; if(!this->shortcuts.contains(shortcut)) { @@ -164,6 +211,7 @@ bool QHotkeyPrivate::addShortcut(QHotkey *hotkey) this->shortcuts.insert(shortcut, hotkey); hotkey->registered = true; + emit hotkey->registeredChanged(true); return true; } @@ -171,12 +219,13 @@ bool QHotkeyPrivate::removeShortcut(QHotkey *hotkey) { if(!hotkey->registered) return false; - QHotkey::NativeShortcut shortcut = hotkey->nativeShortcut; + QHotkey::NativeShortcut shortcut = hotkey->nativeHkey; LOCKER; if(this->shortcuts.remove(shortcut, hotkey) == 0) return false; hotkey->registered = false; + emit hotkey->registeredChanged(true); if(this->shortcuts.count(shortcut) == 0) return this->unregisterShortcut(shortcut); else @@ -188,8 +237,6 @@ void QHotkeyPrivate::activateShortcut(QHotkey::NativeShortcut shortcut) LOCKER; QMetaMethod signal = QMetaMethod::fromSignal(&QHotkey::activated); - for(QHotkey *hkey : this->shortcuts.values(shortcut)) { - if(hkey->isEnabled()) - signal.invoke(hkey, Qt::QueuedConnection); - } + for(QHotkey *hkey : this->shortcuts.values(shortcut)) + signal.invoke(hkey, Qt::QueuedConnection); } diff --git a/QHotkey/qhotkey.h b/QHotkey/qhotkey.h index 8d4b4f2..5b3bcb5 100644 --- a/QHotkey/qhotkey.h +++ b/QHotkey/qhotkey.h @@ -10,8 +10,8 @@ class QHotkey : public QObject Q_OBJECT friend class QHotkeyPrivate; - Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled) - Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut RESET reset) + Q_PROPERTY(bool registered READ isRegistered WRITE setRegistered NOTIFY registeredChanged) + Q_PROPERTY(QKeySequence shortcut READ shortcut WRITE setShortcut RESET resetShortcut) public: struct NativeShortcut { @@ -28,33 +28,33 @@ public: }; explicit QHotkey(QObject *parent = 0); - explicit QHotkey(const QKeySequence &shortcut, QObject *parent = 0); + explicit QHotkey(const QKeySequence &shortcut, bool autoRegister = true, QObject *parent = 0); + explicit QHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister = true, QObject *parent = 0); ~QHotkey(); - QKeySequence shortcut() const; - bool setShortcut(const QKeySequence& shortcut); - bool isEnabled() const; bool isRegistered() const; + QKeySequence shortcut() const; + Qt::Key keyCode() const; + Qt::KeyboardModifiers modifiers() const; + NativeShortcut nativeShortcut() const; public slots: - void setEnabled(bool enabled = true); - inline void setDisabled(bool disabled = true) { - this->setEnabled(!disabled); - } + bool setRegistered(bool registered); - inline void reset() { - this->setShortcut(QKeySequence()); - } + bool setShortcut(const QKeySequence& shortcut, bool autoRegister = true); + bool setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister = true); + bool resetShortcut(); signals: void activated(); + void registeredChanged(bool registered); + private: - bool enabled; Qt::Key key; Qt::KeyboardModifiers mods; - NativeShortcut nativeShortcut; + NativeShortcut nativeHkey; bool registered; };