mirror of
https://github.com/Skycoder42/QHotkey.git
synced 2026-11-19 12:49:58 +03:00
added native shortcut support (win)
This commit is contained in:
@@ -28,6 +28,12 @@ QHotkey::QHotkey(Qt::Key key, Qt::KeyboardModifiers modifiers, bool autoRegister
|
||||
this->setShortcut(key, modifiers, autoRegister);
|
||||
}
|
||||
|
||||
QHotkey::QHotkey(const QHotkey::NativeShortcut &shortcut, bool autoRegister, QObject *parent) :
|
||||
QHotkey(parent)
|
||||
{
|
||||
this->setNativeShortcut(shortcut, autoRegister);
|
||||
}
|
||||
|
||||
QHotkey::~QHotkey()
|
||||
{
|
||||
if(this->registered)
|
||||
@@ -52,6 +58,11 @@ Qt::KeyboardModifiers QHotkey::modifiers() const
|
||||
return this->mods;
|
||||
}
|
||||
|
||||
QHotkey::NativeShortcut QHotkey::currentNativeShortcut() const
|
||||
{
|
||||
return this->nativeShortcut;
|
||||
}
|
||||
|
||||
bool QHotkey::isRegistered() const
|
||||
{
|
||||
return this->registered;
|
||||
@@ -118,6 +129,32 @@ bool QHotkey::resetShortcut()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool QHotkey::setNativeShortcut(QHotkey::NativeShortcut nativeShortcut, bool autoRegister)
|
||||
{
|
||||
if(this->registered) {
|
||||
if(autoRegister) {
|
||||
if(!QHotkeyPrivate::instance()->removeShortcut(this))
|
||||
return false;
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
if(nativeShortcut.isValid()) {
|
||||
this->key = Qt::Key_unknown;
|
||||
this->mods = Qt::NoModifier;
|
||||
this->nativeShortcut = nativeShortcut;
|
||||
if(autoRegister)
|
||||
return QHotkeyPrivate::instance()->addShortcut(this);
|
||||
else
|
||||
return true;
|
||||
} else {
|
||||
this->key = Qt::Key_unknown;
|
||||
this->mods = Qt::NoModifier;
|
||||
this->nativeShortcut = NativeShortcut();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool QHotkey::setRegistered(bool registered)
|
||||
{
|
||||
if(this->registered && !registered)
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
explicit QHotkey(const QKeySequence &shortcut, bool autoRegister = false, QObject *parent = Q_NULLPTR);
|
||||
//! 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);
|
||||
//! Constructs a hotkey from a native shortcut and optionally registers it
|
||||
explicit QHotkey(const NativeShortcut &shortcut, bool autoRegister = false, QObject *parent = Q_NULLPTR);
|
||||
//! Destructor
|
||||
~QHotkey();
|
||||
|
||||
@@ -54,6 +56,9 @@ public:
|
||||
//! READ-Accessor for QHotkey::shortcut - the modifiers only
|
||||
Qt::KeyboardModifiers modifiers() const;
|
||||
|
||||
// Get the current native shortcut
|
||||
NativeShortcut currentNativeShortcut() const;
|
||||
|
||||
public slots:
|
||||
//! WRITE-Accessor for QHotkey::registered
|
||||
bool setRegistered(bool registered);
|
||||
@@ -65,6 +70,8 @@ public slots:
|
||||
//! RESET-Accessor for QHotkey::shortcut
|
||||
bool resetShortcut();
|
||||
|
||||
bool setNativeShortcut(NativeShortcut nativeShortcut, bool autoRegister = false);
|
||||
|
||||
signals:
|
||||
//! Will be emitted if the shortcut is pressed
|
||||
void activated(QPrivateSignal);
|
||||
|
||||
Reference in New Issue
Block a user