GlobalShortcut: Use optional
This commit is contained in:
parent
fb2300e2fa
commit
92e39a3e21
@ -40,7 +40,6 @@ QHash<QPair<quint32, quint32>, GlobalShortcut*> GlobalShortcut::internal_shortcu
|
|||||||
GlobalShortcut::GlobalShortcut(QObject *parent)
|
GlobalShortcut::GlobalShortcut(QObject *parent)
|
||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
backend_(nullptr),
|
backend_(nullptr),
|
||||||
qt_key_(static_cast<Qt::Key>(0)),
|
|
||||||
qt_mods_(Qt::NoModifier),
|
qt_mods_(Qt::NoModifier),
|
||||||
native_key_(0),
|
native_key_(0),
|
||||||
native_key2_(0),
|
native_key2_(0),
|
||||||
@ -57,7 +56,6 @@ GlobalShortcut::GlobalShortcut(const QKeySequence &shortcut, GlobalShortcutsBack
|
|||||||
: QObject(parent),
|
: QObject(parent),
|
||||||
backend_(backend),
|
backend_(backend),
|
||||||
shortcut_(shortcut),
|
shortcut_(shortcut),
|
||||||
qt_key_(static_cast<Qt::Key>(0)),
|
|
||||||
qt_mods_(Qt::NoModifier),
|
qt_mods_(Qt::NoModifier),
|
||||||
native_key_(0),
|
native_key_(0),
|
||||||
native_key2_(0),
|
native_key2_(0),
|
||||||
@ -97,7 +95,7 @@ bool GlobalShortcut::setShortcut(const QKeySequence &shortcut) {
|
|||||||
qt_mods_ = Qt::KeyboardModifiers(shortcut[0] & all_mods);
|
qt_mods_ = Qt::KeyboardModifiers(shortcut[0] & all_mods);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
native_key_ = nativeKeycode(qt_key_);
|
native_key_ = nativeKeycode(qt_key_.value());
|
||||||
if (native_key_ == 0) return false;
|
if (native_key_ == 0) return false;
|
||||||
native_mods_ = nativeModifiers(qt_mods_);
|
native_mods_ = nativeModifiers(qt_mods_);
|
||||||
|
|
||||||
@ -105,7 +103,7 @@ bool GlobalShortcut::setShortcut(const QKeySequence &shortcut) {
|
|||||||
if (success) {
|
if (success) {
|
||||||
internal_shortcuts_.insert(qMakePair(native_key_, native_mods_), this);
|
internal_shortcuts_.insert(qMakePair(native_key_, native_mods_), this);
|
||||||
qLog(Info) << "Registered shortcut" << shortcut_.toString();
|
qLog(Info) << "Registered shortcut" << shortcut_.toString();
|
||||||
native_key2_ = nativeKeycode2(qt_key_);
|
native_key2_ = nativeKeycode2(qt_key_.value());
|
||||||
if (native_key2_ > 0 && registerShortcut(native_key2_, native_mods_)) {
|
if (native_key2_ > 0 && registerShortcut(native_key2_, native_mods_)) {
|
||||||
internal_shortcuts_.insert(qMakePair(native_key2_, native_mods_), this);
|
internal_shortcuts_.insert(qMakePair(native_key2_, native_mods_), this);
|
||||||
}
|
}
|
||||||
@ -149,7 +147,7 @@ bool GlobalShortcut::unsetShortcut() {
|
|||||||
qLog(Error) << "Failed to unregister shortcut" << shortcut_.toString();
|
qLog(Error) << "Failed to unregister shortcut" << shortcut_.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
qt_key_ = static_cast<Qt::Key>(0);
|
qt_key_.reset();
|
||||||
qt_mods_ = Qt::KeyboardModifiers();
|
qt_mods_ = Qt::KeyboardModifiers();
|
||||||
native_key_ = 0;
|
native_key_ = 0;
|
||||||
native_mods_ = 0;
|
native_mods_ = 0;
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QAbstractNativeEventFilter>
|
#include <QAbstractNativeEventFilter>
|
||||||
@ -74,7 +76,7 @@ class GlobalShortcut : public QObject, QAbstractNativeEventFilter {
|
|||||||
|
|
||||||
GlobalShortcutsBackend *backend_;
|
GlobalShortcutsBackend *backend_;
|
||||||
QKeySequence shortcut_;
|
QKeySequence shortcut_;
|
||||||
Qt::Key qt_key_;
|
std::optional<Qt::Key> qt_key_;
|
||||||
Qt::KeyboardModifiers qt_mods_;
|
Qt::KeyboardModifiers qt_mods_;
|
||||||
int native_key_;
|
int native_key_;
|
||||||
int native_key2_;
|
int native_key2_;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user