mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
code cleanup
This commit is contained in:
+75
-70
@@ -10,81 +10,81 @@ Q_LOGGING_CATEGORY(logQHotkey, "QHotkey")
|
|||||||
|
|
||||||
QHotkey::QHotkey(QObject *parent) :
|
QHotkey::QHotkey(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
key(Qt::Key_unknown),
|
_keyCode(Qt::Key_unknown),
|
||||||
mods(Qt::NoModifier),
|
_modifiers(Qt::NoModifier),
|
||||||
nativeShortcut(),
|
_nativeShortcut(),
|
||||||
registered(false)
|
_registered(false)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
QHotkey::QHotkey(const QKeySequence &sequence, bool autoRegister, QObject *parent) :
|
QHotkey::QHotkey(const QKeySequence &sequence, bool autoRegister, QObject *parent) :
|
||||||
QHotkey(parent)
|
QHotkey(parent)
|
||||||
{
|
{
|
||||||
this->setShortcut(sequence, autoRegister);
|
setShortcut(sequence, autoRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHotkey::QHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister, QObject *parent) :
|
QHotkey::QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister, QObject *parent) :
|
||||||
QHotkey(parent)
|
QHotkey(parent)
|
||||||
{
|
{
|
||||||
this->setShortcut(key, modifiers, autoRegister);
|
setShortcut(keyCode, modifiers, autoRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHotkey::QHotkey(const QHotkey::NativeShortcut &shortcut, bool autoRegister, QObject *parent) :
|
QHotkey::QHotkey(const QHotkey::NativeShortcut &shortcut, bool autoRegister, QObject *parent) :
|
||||||
QHotkey(parent)
|
QHotkey(parent)
|
||||||
{
|
{
|
||||||
this->setNativeShortcut(shortcut, autoRegister);
|
setNativeShortcut(shortcut, autoRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHotkey::~QHotkey()
|
QHotkey::~QHotkey()
|
||||||
{
|
{
|
||||||
if(this->registered)
|
if(_registered)
|
||||||
QHotkeyPrivate::instance()->removeShortcut(this);
|
QHotkeyPrivate::instance()->removeShortcut(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QKeySequence QHotkey::shortcut() const
|
QKeySequence QHotkey::shortcut() const
|
||||||
{
|
{
|
||||||
if(this->key == Qt::Key_unknown)
|
if(_keyCode == Qt::Key_unknown)
|
||||||
return QKeySequence();
|
return QKeySequence();
|
||||||
else
|
else
|
||||||
return QKeySequence(this->key | this->mods);
|
return QKeySequence(_keyCode | _modifiers);
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::Key QHotkey::keyCode() const
|
Qt::Key QHotkey::keyCode() const
|
||||||
{
|
{
|
||||||
return this->key;
|
return _keyCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Qt::KeyboardModifiers QHotkey::modifiers() const
|
Qt::KeyboardModifiers QHotkey::modifiers() const
|
||||||
{
|
{
|
||||||
return this->mods;
|
return _modifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHotkey::NativeShortcut QHotkey::currentNativeShortcut() const
|
QHotkey::NativeShortcut QHotkey::currentNativeShortcut() const
|
||||||
{
|
{
|
||||||
return this->nativeShortcut;
|
return _nativeShortcut;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::isRegistered() const
|
bool QHotkey::isRegistered() const
|
||||||
{
|
{
|
||||||
return this->registered;
|
return _registered;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::setShortcut(const QKeySequence &shortcut, bool autoRegister)
|
bool QHotkey::setShortcut(const QKeySequence &shortcut, bool autoRegister)
|
||||||
{
|
{
|
||||||
if(shortcut.isEmpty()) {
|
if(shortcut.isEmpty()) {
|
||||||
return this->resetShortcut();
|
return resetShortcut();
|
||||||
} else if(shortcut.count() > 1) {
|
} else if(shortcut.count() > 1) {
|
||||||
qCWarning(logQHotkey, "Keysequences with multiple shortcuts are not allowed! "
|
qCWarning(logQHotkey, "Keysequences with multiple shortcuts are not allowed! "
|
||||||
"Only the first shortcut will be used!");
|
"Only the first shortcut will be used!");
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->setShortcut(Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask),
|
return setShortcut(Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask),
|
||||||
Qt::KeyboardModifiers(shortcut[0] & Qt::KeyboardModifierMask),
|
Qt::KeyboardModifiers(shortcut[0] & Qt::KeyboardModifierMask),
|
||||||
autoRegister);
|
autoRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister)
|
bool QHotkey::setShortcut(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister)
|
||||||
{
|
{
|
||||||
if(this->registered) {
|
if(_registered) {
|
||||||
if(autoRegister) {
|
if(autoRegister) {
|
||||||
if(!QHotkeyPrivate::instance()->removeShortcut(this))
|
if(!QHotkeyPrivate::instance()->removeShortcut(this))
|
||||||
return false;
|
return false;
|
||||||
@@ -92,46 +92,46 @@ bool QHotkey::setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool aut
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(key == Qt::Key_unknown) {
|
if(keyCode == Qt::Key_unknown) {
|
||||||
this->key = Qt::Key_unknown;
|
_keyCode = Qt::Key_unknown;
|
||||||
this->mods = Qt::NoModifier;
|
_modifiers = Qt::NoModifier;
|
||||||
this->nativeShortcut = NativeShortcut();
|
_nativeShortcut = NativeShortcut();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->key = key;
|
_keyCode = keyCode;
|
||||||
this->mods = modifiers;
|
_modifiers = modifiers;
|
||||||
this->nativeShortcut = QHotkeyPrivate::instance()->nativeShortcut(key, modifiers);
|
_nativeShortcut = QHotkeyPrivate::instance()->nativeShortcut(keyCode, modifiers);
|
||||||
if(this->nativeShortcut.isValid()) {
|
if(_nativeShortcut.isValid()) {
|
||||||
if(autoRegister)
|
if(autoRegister)
|
||||||
return QHotkeyPrivate::instance()->addShortcut(this);
|
return QHotkeyPrivate::instance()->addShortcut(this);
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
qCWarning(logQHotkey) << "Unable to map shortcut to native keys. Key:" << key << "Modifiers:" << modifiers;
|
qCWarning(logQHotkey) << "Unable to map shortcut to native keys. Key:" << keyCode << "Modifiers:" << modifiers;
|
||||||
this->key = Qt::Key_unknown;
|
_keyCode = Qt::Key_unknown;
|
||||||
this->mods = Qt::NoModifier;
|
_modifiers = Qt::NoModifier;
|
||||||
this->nativeShortcut = NativeShortcut();
|
_nativeShortcut = NativeShortcut();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::resetShortcut()
|
bool QHotkey::resetShortcut()
|
||||||
{
|
{
|
||||||
if(this->registered &&
|
if(_registered &&
|
||||||
!QHotkeyPrivate::instance()->removeShortcut(this)) {
|
!QHotkeyPrivate::instance()->removeShortcut(this)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->key = Qt::Key_unknown;
|
_keyCode = Qt::Key_unknown;
|
||||||
this->mods = Qt::NoModifier;
|
_modifiers = Qt::NoModifier;
|
||||||
this->nativeShortcut = NativeShortcut();
|
_nativeShortcut = NativeShortcut();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister)
|
bool QHotkey::setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister)
|
||||||
{
|
{
|
||||||
if(this->registered) {
|
if(_registered) {
|
||||||
if(autoRegister) {
|
if(autoRegister) {
|
||||||
if(!QHotkeyPrivate::instance()->removeShortcut(this))
|
if(!QHotkeyPrivate::instance()->removeShortcut(this))
|
||||||
return false;
|
return false;
|
||||||
@@ -140,27 +140,27 @@ bool QHotkey::setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool aut
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(nativeShortcut.isValid()) {
|
if(nativeShortcut.isValid()) {
|
||||||
this->key = Qt::Key_unknown;
|
_keyCode = Qt::Key_unknown;
|
||||||
this->mods = Qt::NoModifier;
|
_modifiers = Qt::NoModifier;
|
||||||
this->nativeShortcut = nativeShortcut;
|
_nativeShortcut = nativeShortcut;
|
||||||
if(autoRegister)
|
if(autoRegister)
|
||||||
return QHotkeyPrivate::instance()->addShortcut(this);
|
return QHotkeyPrivate::instance()->addShortcut(this);
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
this->key = Qt::Key_unknown;
|
_keyCode = Qt::Key_unknown;
|
||||||
this->mods = Qt::NoModifier;
|
_modifiers = Qt::NoModifier;
|
||||||
this->nativeShortcut = NativeShortcut();
|
_nativeShortcut = NativeShortcut();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::setRegistered(bool registered)
|
bool QHotkey::setRegistered(bool registered)
|
||||||
{
|
{
|
||||||
if(this->registered && !registered)
|
if(_registered && !registered)
|
||||||
return QHotkeyPrivate::instance()->removeShortcut(this);
|
return QHotkeyPrivate::instance()->removeShortcut(this);
|
||||||
else if(!this->registered && registered) {
|
else if(!_registered && registered) {
|
||||||
if(!this->nativeShortcut.isValid())
|
if(!_nativeShortcut.isValid())
|
||||||
return false;
|
return false;
|
||||||
else
|
else
|
||||||
return QHotkeyPrivate::instance()->addShortcut(this);
|
return QHotkeyPrivate::instance()->addShortcut(this);
|
||||||
@@ -181,15 +181,15 @@ QHotkeyPrivate::QHotkeyPrivate() :
|
|||||||
|
|
||||||
QHotkeyPrivate::~QHotkeyPrivate()
|
QHotkeyPrivate::~QHotkeyPrivate()
|
||||||
{
|
{
|
||||||
if(!this->shortcuts.isEmpty())
|
if(!shortcuts.isEmpty())
|
||||||
qCWarning(logQHotkey, "QHotkeyPrivate destroyed with registered shortcuts!");
|
qCWarning(logQHotkey) << "QHotkeyPrivate destroyed with registered shortcuts!";
|
||||||
if(qApp && qApp->eventDispatcher())
|
if(qApp && qApp->eventDispatcher())
|
||||||
qApp->eventDispatcher()->removeNativeEventFilter(this);
|
qApp->eventDispatcher()->removeNativeEventFilter(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcut(Qt::Key keycode, Qt::KeyboardModifiers modifiers)
|
QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcut(Qt::Key keycode, Qt::KeyboardModifiers modifiers)
|
||||||
{
|
{
|
||||||
Qt::ConnectionType conType = (QThread::currentThread() == this->thread() ?
|
Qt::ConnectionType conType = (QThread::currentThread() == thread() ?
|
||||||
Qt::DirectConnection :
|
Qt::DirectConnection :
|
||||||
Qt::BlockingQueuedConnection);
|
Qt::BlockingQueuedConnection);
|
||||||
QHotkey::NativeShortcut res;
|
QHotkey::NativeShortcut res;
|
||||||
@@ -204,10 +204,10 @@ QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcut(Qt::Key keycode, Qt::Keyb
|
|||||||
|
|
||||||
bool QHotkeyPrivate::addShortcut(QHotkey *hotkey)
|
bool QHotkeyPrivate::addShortcut(QHotkey *hotkey)
|
||||||
{
|
{
|
||||||
if(hotkey->registered)
|
if(hotkey->_registered)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Qt::ConnectionType conType = (QThread::currentThread() == this->thread() ?
|
Qt::ConnectionType conType = (QThread::currentThread() == thread() ?
|
||||||
Qt::DirectConnection :
|
Qt::DirectConnection :
|
||||||
Qt::BlockingQueuedConnection);
|
Qt::BlockingQueuedConnection);
|
||||||
bool res = false;
|
bool res = false;
|
||||||
@@ -224,10 +224,10 @@ bool QHotkeyPrivate::addShortcut(QHotkey *hotkey)
|
|||||||
|
|
||||||
bool QHotkeyPrivate::removeShortcut(QHotkey *hotkey)
|
bool QHotkeyPrivate::removeShortcut(QHotkey *hotkey)
|
||||||
{
|
{
|
||||||
if(!hotkey->registered)
|
if(!hotkey->_registered)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Qt::ConnectionType conType = (QThread::currentThread() == this->thread() ?
|
Qt::ConnectionType conType = (QThread::currentThread() == thread() ?
|
||||||
Qt::DirectConnection :
|
Qt::DirectConnection :
|
||||||
Qt::BlockingQueuedConnection);
|
Qt::BlockingQueuedConnection);
|
||||||
bool res = false;
|
bool res = false;
|
||||||
@@ -245,38 +245,43 @@ bool QHotkeyPrivate::removeShortcut(QHotkey *hotkey)
|
|||||||
void QHotkeyPrivate::activateShortcut(QHotkey::NativeShortcut shortcut)
|
void QHotkeyPrivate::activateShortcut(QHotkey::NativeShortcut shortcut)
|
||||||
{
|
{
|
||||||
QMetaMethod signal = QMetaMethod::fromSignal(&QHotkey::activated);
|
QMetaMethod signal = QMetaMethod::fromSignal(&QHotkey::activated);
|
||||||
for(QHotkey *hkey : this->shortcuts.values(shortcut))
|
for(QHotkey *hkey : shortcuts.values(shortcut))
|
||||||
signal.invoke(hkey, Qt::QueuedConnection);
|
signal.invoke(hkey, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkeyPrivate::addShortcutInvoked(QHotkey *hotkey)
|
bool QHotkeyPrivate::addShortcutInvoked(QHotkey *hotkey)
|
||||||
{
|
{
|
||||||
QHotkey::NativeShortcut shortcut = hotkey->nativeShortcut;
|
QHotkey::NativeShortcut shortcut = hotkey->_nativeShortcut;
|
||||||
|
|
||||||
if(!this->shortcuts.contains(shortcut)) {
|
if(!shortcuts.contains(shortcut)) {
|
||||||
if(!this->registerShortcut(shortcut))
|
if(!registerShortcut(shortcut))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->shortcuts.insert(shortcut, hotkey);
|
shortcuts.insert(shortcut, hotkey);
|
||||||
hotkey->registered = true;
|
hotkey->_registered = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkeyPrivate::removeShortcutInvoked(QHotkey *hotkey)
|
bool QHotkeyPrivate::removeShortcutInvoked(QHotkey *hotkey)
|
||||||
{
|
{
|
||||||
QHotkey::NativeShortcut shortcut = hotkey->nativeShortcut;
|
QHotkey::NativeShortcut shortcut = hotkey->_nativeShortcut;
|
||||||
|
|
||||||
if(this->shortcuts.remove(shortcut, hotkey) == 0)
|
if(shortcuts.remove(shortcut, hotkey) == 0)
|
||||||
return false;
|
return false;
|
||||||
hotkey->registered = false;
|
hotkey->_registered = false;
|
||||||
emit hotkey->registeredChanged(true);
|
emit hotkey->registeredChanged(true);
|
||||||
if(this->shortcuts.count(shortcut) == 0)
|
if(shortcuts.count(shortcut) == 0)
|
||||||
return this->unregisterShortcut(shortcut);
|
return unregisterShortcut(shortcut);
|
||||||
else
|
else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers)
|
||||||
|
{
|
||||||
|
return {this->nativeKeycode(keycode), this->nativeModifiers(modifiers)};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
QHotkey::NativeShortcut::NativeShortcut() :
|
QHotkey::NativeShortcut::NativeShortcut() :
|
||||||
@@ -293,21 +298,21 @@ QHotkey::NativeShortcut::NativeShortcut(quint32 key, quint32 modifier) :
|
|||||||
|
|
||||||
bool QHotkey::NativeShortcut::isValid() const
|
bool QHotkey::NativeShortcut::isValid() const
|
||||||
{
|
{
|
||||||
return this->valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::NativeShortcut::operator ==(const QHotkey::NativeShortcut &other) const
|
bool QHotkey::NativeShortcut::operator ==(const QHotkey::NativeShortcut &other) const
|
||||||
{
|
{
|
||||||
return (this->key == other.key) &&
|
return (key == other.key) &&
|
||||||
(this->modifier == other.modifier) &&
|
(modifier == other.modifier) &&
|
||||||
this->valid == other.valid;
|
valid == other.valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::NativeShortcut::operator !=(const QHotkey::NativeShortcut &other) const
|
bool QHotkey::NativeShortcut::operator !=(const QHotkey::NativeShortcut &other) const
|
||||||
{
|
{
|
||||||
return (this->key != other.key) ||
|
return (key != other.key) ||
|
||||||
(this->modifier != other.modifier) ||
|
(modifier != other.modifier) ||
|
||||||
this->valid != other.valid;
|
valid != other.valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint qHash(const QHotkey::NativeShortcut &key)
|
uint qHash(const QHotkey::NativeShortcut &key)
|
||||||
|
|||||||
+6
-6
@@ -48,7 +48,7 @@ public:
|
|||||||
//! Constructs a hotkey with a shortcut and optionally registers it
|
//! Constructs a hotkey with a shortcut and optionally registers it
|
||||||
explicit QHotkey(const QKeySequence &shortcut, bool autoRegister = false, QObject *parent = Q_NULLPTR);
|
explicit QHotkey(const QKeySequence &shortcut, bool autoRegister = false, QObject *parent = Q_NULLPTR);
|
||||||
//! Constructs a hotkey with a key and modifiers and optionally registers it
|
//! Constructs a hotkey with a key and modifiers and optionally registers it
|
||||||
explicit QHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister = false, QObject *parent = Q_NULLPTR);
|
explicit QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister = false, QObject *parent = Q_NULLPTR);
|
||||||
//! Constructs a hotkey from a native shortcut and optionally registers it
|
//! Constructs a hotkey from a native shortcut and optionally registers it
|
||||||
explicit QHotkey(const NativeShortcut &shortcut, bool autoRegister = false, QObject *parent = Q_NULLPTR);
|
explicit QHotkey(const NativeShortcut &shortcut, bool autoRegister = false, QObject *parent = Q_NULLPTR);
|
||||||
//! Destructor
|
//! Destructor
|
||||||
@@ -73,7 +73,7 @@ public slots:
|
|||||||
//! WRITE-Accessor for QHotkey::shortcut
|
//! WRITE-Accessor for QHotkey::shortcut
|
||||||
bool setShortcut(const QKeySequence &shortcut, bool autoRegister = false);
|
bool setShortcut(const QKeySequence &shortcut, bool autoRegister = false);
|
||||||
//! WRITE-Accessor for QHotkey::shortcut
|
//! WRITE-Accessor for QHotkey::shortcut
|
||||||
bool setShortcut(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister = false);
|
bool setShortcut(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister = false);
|
||||||
//! RESET-Accessor for QHotkey::shortcut
|
//! RESET-Accessor for QHotkey::shortcut
|
||||||
bool resetShortcut();
|
bool resetShortcut();
|
||||||
|
|
||||||
@@ -88,11 +88,11 @@ signals:
|
|||||||
void registeredChanged(bool registered);
|
void registeredChanged(bool registered);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Qt::Key key;
|
Qt::Key _keyCode;
|
||||||
Qt::KeyboardModifiers mods;
|
Qt::KeyboardModifiers _modifiers;
|
||||||
|
|
||||||
NativeShortcut nativeShortcut;
|
NativeShortcut _nativeShortcut;
|
||||||
bool registered;
|
bool _registered;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint qHash(const QHotkey::NativeShortcut &key);
|
uint qHash(const QHotkey::NativeShortcut &key);
|
||||||
|
|||||||
@@ -163,9 +163,9 @@ quint32 QHotkeyPrivateMac::nativeKeycode(Qt::Key keycode)
|
|||||||
else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE) {
|
else if (!(keyToChar[k] & kUCKeyOutputSequenceIndexMask) && keyToChar[k] < 0xFFFE) {
|
||||||
if (keyToChar[k] == ch) return k;
|
if (keyToChar[k] == ch) return k;
|
||||||
}
|
}
|
||||||
} // for k
|
}
|
||||||
} // for j
|
}
|
||||||
} // for i
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-9
@@ -31,13 +31,12 @@ protected:
|
|||||||
virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
|
virtual bool registerShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
|
||||||
virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
|
virtual bool unregisterShortcut(QHotkey::NativeShortcut shortcut) = 0;//platform implement
|
||||||
|
|
||||||
private:/*functions*/
|
|
||||||
Q_INVOKABLE bool addShortcutInvoked(QHotkey *hotkey);
|
|
||||||
Q_INVOKABLE bool removeShortcutInvoked(QHotkey *hotkey);
|
|
||||||
Q_INVOKABLE inline QHotkey::NativeShortcut nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;
|
QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;
|
||||||
|
|
||||||
|
Q_INVOKABLE bool addShortcutInvoked(QHotkey *hotkey);
|
||||||
|
Q_INVOKABLE bool removeShortcutInvoked(QHotkey *hotkey);
|
||||||
|
Q_INVOKABLE QHotkey::NativeShortcut nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers);
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NATIVE_INSTANCE(ClassName) \
|
#define NATIVE_INSTANCE(ClassName) \
|
||||||
@@ -48,8 +47,4 @@ private:
|
|||||||
return hotkeyPrivate;\
|
return hotkeyPrivate;\
|
||||||
}
|
}
|
||||||
|
|
||||||
inline QHotkey::NativeShortcut QHotkeyPrivate::nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers) {
|
|
||||||
return {this->nativeKeycode(keycode), this->nativeModifiers(modifiers)};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // QHOTKEY_P_H
|
#endif // QHOTKEY_P_H
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ bool QHotkeyPrivateX11::registerShortcut(QHotkey::NativeShortcut shortcut)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(errorHandler.hasError) {
|
if(errorHandler.hasError) {
|
||||||
qCWarning(logQHotkey) << "[QHotkey] Failed to register hotkey. Error:"
|
qCWarning(logQHotkey) << "Failed to register hotkey. Error:"
|
||||||
<< qPrintable(errorHandler.errorString);
|
<< qPrintable(errorHandler.errorString);
|
||||||
this->unregisterShortcut(shortcut);
|
this->unregisterShortcut(shortcut);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -18,6 +18,3 @@ mac {
|
|||||||
}
|
}
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/QHotkey
|
INCLUDEPATH += $$PWD/QHotkey
|
||||||
|
|
||||||
DISTFILES += \
|
|
||||||
$$PWD/QHotkey/qhotkey.pri
|
|
||||||
|
|||||||
Reference in New Issue
Block a user