mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
Pass NativeShortcut by value (trivially copyable)
This commit is contained in:
+7
-7
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
Q_LOGGING_CATEGORY(logQHotkey, "QHotkey")
|
Q_LOGGING_CATEGORY(logQHotkey, "QHotkey")
|
||||||
|
|
||||||
void QHotkey::addGlobalMapping(const QKeySequence &shortcut, const QHotkey::NativeShortcut &nativeShortcut)
|
void QHotkey::addGlobalMapping(const QKeySequence &shortcut, QHotkey::NativeShortcut nativeShortcut)
|
||||||
{
|
{
|
||||||
QMetaObject::invokeMethod(QHotkeyPrivate::instance(), "addMappingInvoked", Qt::QueuedConnection,
|
QMetaObject::invokeMethod(QHotkeyPrivate::instance(), "addMappingInvoked", Qt::QueuedConnection,
|
||||||
Q_ARG(Qt::Key, Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask)),
|
Q_ARG(Qt::Key, Qt::Key(shortcut[0] & ~Qt::KeyboardModifierMask)),
|
||||||
@@ -40,7 +40,7 @@ QHotkey::QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegi
|
|||||||
setShortcut(keyCode, modifiers, autoRegister);
|
setShortcut(keyCode, modifiers, autoRegister);
|
||||||
}
|
}
|
||||||
|
|
||||||
QHotkey::QHotkey(const QHotkey::NativeShortcut &shortcut, bool autoRegister, QObject *parent) :
|
QHotkey::QHotkey(QHotkey::NativeShortcut shortcut, bool autoRegister, QObject *parent) :
|
||||||
QHotkey(parent)
|
QHotkey(parent)
|
||||||
{
|
{
|
||||||
setNativeShortcut(shortcut, autoRegister);
|
setNativeShortcut(shortcut, autoRegister);
|
||||||
@@ -263,7 +263,7 @@ void QHotkeyPrivate::releaseShortcut(QHotkey::NativeShortcut shortcut)
|
|||||||
signal.invoke(hkey, Qt::QueuedConnection);
|
signal.invoke(hkey, Qt::QueuedConnection);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QHotkeyPrivate::addMappingInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers, const QHotkey::NativeShortcut &nativeShortcut)
|
void QHotkeyPrivate::addMappingInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers, QHotkey::NativeShortcut nativeShortcut)
|
||||||
{
|
{
|
||||||
mapping.insert({keycode, modifiers}, nativeShortcut);
|
mapping.insert({keycode, modifiers}, nativeShortcut);
|
||||||
}
|
}
|
||||||
@@ -335,26 +335,26 @@ bool QHotkey::NativeShortcut::isValid() const
|
|||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::NativeShortcut::operator ==(const QHotkey::NativeShortcut &other) const
|
bool QHotkey::NativeShortcut::operator ==(QHotkey::NativeShortcut other) const
|
||||||
{
|
{
|
||||||
return (key == other.key) &&
|
return (key == other.key) &&
|
||||||
(modifier == other.modifier) &&
|
(modifier == other.modifier) &&
|
||||||
valid == other.valid;
|
valid == other.valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QHotkey::NativeShortcut::operator !=(const QHotkey::NativeShortcut &other) const
|
bool QHotkey::NativeShortcut::operator !=(QHotkey::NativeShortcut other) const
|
||||||
{
|
{
|
||||||
return (key != other.key) ||
|
return (key != other.key) ||
|
||||||
(modifier != other.modifier) ||
|
(modifier != other.modifier) ||
|
||||||
valid != other.valid;
|
valid != other.valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint qHash(const QHotkey::NativeShortcut &key)
|
uint qHash(QHotkey::NativeShortcut key)
|
||||||
{
|
{
|
||||||
return qHash(key.key) ^ qHash(key.modifier);
|
return qHash(key.key) ^ qHash(key.modifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint qHash(const QHotkey::NativeShortcut &key, uint seed)
|
uint qHash(QHotkey::NativeShortcut key, uint seed)
|
||||||
{
|
{
|
||||||
return qHash(key.key, seed) ^ qHash(key.modifier, seed);
|
return qHash(key.key, seed) ^ qHash(key.modifier, seed);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -46,16 +46,16 @@ public:
|
|||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
|
|
||||||
//! Equality operator
|
//! Equality operator
|
||||||
bool operator ==(const NativeShortcut &other) const;
|
bool operator ==(NativeShortcut other) const;
|
||||||
//! Inequality operator
|
//! Inequality operator
|
||||||
bool operator !=(const NativeShortcut &other) const;
|
bool operator !=(NativeShortcut other) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool valid;
|
bool valid;
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Adds a global mapping of a key sequence to a replacement native shortcut
|
//! Adds a global mapping of a key sequence to a replacement native shortcut
|
||||||
static void addGlobalMapping(const QKeySequence &shortcut, const NativeShortcut &nativeShortcut);
|
static void addGlobalMapping(const QKeySequence &shortcut, NativeShortcut nativeShortcut);
|
||||||
|
|
||||||
//! Checks if global shortcuts are supported by the current platform
|
//! Checks if global shortcuts are supported by the current platform
|
||||||
static bool isPlatformSupported();
|
static bool isPlatformSupported();
|
||||||
@@ -67,7 +67,7 @@ public:
|
|||||||
//! 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 keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister = false, QObject *parent = nullptr);
|
explicit QHotkey(Qt::Key keyCode, Qt::KeyboardModifiers modifiers, bool autoRegister = false, QObject *parent = 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 = nullptr);
|
explicit QHotkey(NativeShortcut shortcut, bool autoRegister = false, QObject *parent = nullptr);
|
||||||
~QHotkey() override;
|
~QHotkey() override;
|
||||||
|
|
||||||
//! @readAcFn{QHotkey::registered}
|
//! @readAcFn{QHotkey::registered}
|
||||||
@@ -94,7 +94,7 @@ public slots:
|
|||||||
bool resetShortcut();
|
bool resetShortcut();
|
||||||
|
|
||||||
//! Set this hotkey to a native shortcut
|
//! Set this hotkey to a native shortcut
|
||||||
bool setNativeShortcut(NativeShortcut nativeShortcut, bool autoRegister = false);
|
bool setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister = false);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
//! Will be emitted if the shortcut is pressed
|
//! Will be emitted if the shortcut is pressed
|
||||||
@@ -114,8 +114,8 @@ private:
|
|||||||
bool _registered;
|
bool _registered;
|
||||||
};
|
};
|
||||||
|
|
||||||
uint QHOTKEY_SHARED_EXPORT qHash(const QHotkey::NativeShortcut &key);
|
uint QHOTKEY_SHARED_EXPORT qHash(QHotkey::NativeShortcut key);
|
||||||
uint QHOTKEY_SHARED_EXPORT qHash(const QHotkey::NativeShortcut &key, uint seed);
|
uint QHOTKEY_SHARED_EXPORT qHash(QHotkey::NativeShortcut key, uint seed);
|
||||||
|
|
||||||
QHOTKEY_SHARED_EXPORT Q_DECLARE_LOGGING_CATEGORY(logQHotkey)
|
QHOTKEY_SHARED_EXPORT Q_DECLARE_LOGGING_CATEGORY(logQHotkey)
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ private:
|
|||||||
QHash<QPair<Qt::Key, Qt::KeyboardModifiers>, QHotkey::NativeShortcut> mapping;
|
QHash<QPair<Qt::Key, Qt::KeyboardModifiers>, QHotkey::NativeShortcut> mapping;
|
||||||
QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;
|
QMultiHash<QHotkey::NativeShortcut, QHotkey*> shortcuts;
|
||||||
|
|
||||||
Q_INVOKABLE void addMappingInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers, const QHotkey::NativeShortcut &nativeShortcut);
|
Q_INVOKABLE void addMappingInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers, QHotkey::NativeShortcut nativeShortcut);
|
||||||
Q_INVOKABLE bool addShortcutInvoked(QHotkey *hotkey);
|
Q_INVOKABLE bool addShortcutInvoked(QHotkey *hotkey);
|
||||||
Q_INVOKABLE bool removeShortcutInvoked(QHotkey *hotkey);
|
Q_INVOKABLE bool removeShortcutInvoked(QHotkey *hotkey);
|
||||||
Q_INVOKABLE QHotkey::NativeShortcut nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers);
|
Q_INVOKABLE QHotkey::NativeShortcut nativeShortcutInvoked(Qt::Key keycode, Qt::KeyboardModifiers modifiers);
|
||||||
|
|||||||
Reference in New Issue
Block a user