summaryrefslogtreecommitdiffhomepage
path: root/logic
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-10-25 03:11:42 +0200
committerStanislaw Halik <sthalik@misaki.pl>2018-10-25 03:11:42 +0200
commit0a1a0e9df00f37a210b67a11cf8f99550cafeeaf (patch)
tree35da3c9a2d6464025dc324647253966d4a63a351 /logic
parenta4c9807acacc87f323f31d252a37c0ed2029ee5b (diff)
cleanups only
Diffstat (limited to 'logic')
-rw-r--r--logic/shortcuts.cpp41
-rw-r--r--logic/win32-shortcuts.cpp54
2 files changed, 51 insertions, 44 deletions
diff --git a/logic/shortcuts.cpp b/logic/shortcuts.cpp
index f03c8973..a0027fea 100644
--- a/logic/shortcuts.cpp
+++ b/logic/shortcuts.cpp
@@ -29,9 +29,9 @@ void Shortcuts::free_binding(K& key)
#endif
}
-void Shortcuts::bind_shortcut(K &key, const key_opts& k, bool held)
+void Shortcuts::bind_shortcut(K& key, const key_opts& k, bool held)
{
-#if !defined(_WIN32)
+#if !defined _WIN32
(void)held;
using sh = QxtGlobalShortcut;
if (key)
@@ -46,13 +46,12 @@ void Shortcuts::bind_shortcut(K &key, const key_opts& k, bool held)
key->setShortcut(QKeySequence::fromString(k.keycode, QKeySequence::PortableText));
key->setEnabled();
}
-}
#else
- key = K();
+ key = {};
int idx = 0;
- QKeySequence code;
+ QKeySequence code(QKeySequence::UnknownKey);
- if (k.guid != "")
+ if (!k.guid->isEmpty())
{
key.guid = k.guid;
key.keycode = k.button & ~Qt::KeyboardModifierMask;
@@ -63,26 +62,27 @@ void Shortcuts::bind_shortcut(K &key, const key_opts& k, bool held)
}
else
{
- if (k.keycode == "")
- code = QKeySequence(Qt::Key_unknown);
- else
+ if (!k.keycode->isEmpty())
code = QKeySequence::fromString(k.keycode, QKeySequence::PortableText);
Qt::KeyboardModifiers mods = Qt::NoModifier;
- if (code != Qt::Key_unknown)
- win_key::from_qt(code, idx, mods);
-
- key.guid = "";
- key.keycode = idx;
- key.held = held;
- key.ctrl = !!(mods & Qt::ControlModifier);
- key.alt = !!(mods & Qt::AltModifier);
- key.shift = !!(mods & Qt::ShiftModifier);
+ if (!code.isEmpty() &&
+ code != QKeySequence{ QKeySequence::UnknownKey } &&
+ win_key::from_qt(code, idx, mods))
+ {
+ key.guid = "";
+ key.keycode = idx;
+ key.held = held;
+ key.ctrl = !!(mods & Qt::ControlModifier);
+ key.alt = !!(mods & Qt::AltModifier);
+ key.shift = !!(mods & Qt::ShiftModifier);
+ }
}
-}
#endif
+}
#ifdef _WIN32
+
void Shortcuts::receiver(const Key& k)
{
const unsigned sz = keys.size();
@@ -105,6 +105,7 @@ void Shortcuts::receiver(const Key& k)
f(k.held);
}
}
+
#endif
Shortcuts::~Shortcuts()
@@ -127,7 +128,7 @@ void Shortcuts::reload(const t_keys& keys_)
for (unsigned i = 0; i < sz; i++)
{
- auto const& [opts, fun, held] = keys_[i];
+ auto const&[opts, fun, held] = keys_[i];
#ifdef _WIN32
K k;
#else
diff --git a/logic/win32-shortcuts.cpp b/logic/win32-shortcuts.cpp
index 4da86afd..1e2f1b77 100644
--- a/logic/win32-shortcuts.cpp
+++ b/logic/win32-shortcuts.cpp
@@ -119,26 +119,26 @@ static const win_key windows_key_sequences[] {
{ DIK_PAUSE, Qt::Key_Pause},
{ DIK_NUMLOCK, Qt::Key_NumLock},
{ DIK_CAPSLOCK, Qt::Key_CapsLock},
-#define mod(x, y) Qt::Key(int(x) | int((y)))
- { DIK_NUMPAD0, mod(Qt::Key_0, Qt::KeypadModifier)},
- { DIK_NUMPAD0, mod(Qt::Key_0, Qt::KeypadModifier)},
- { DIK_NUMPAD1, mod(Qt::Key_1, Qt::KeypadModifier)},
- { DIK_NUMPAD2, mod(Qt::Key_2, Qt::KeypadModifier)},
- { DIK_NUMPAD3, mod(Qt::Key_3, Qt::KeypadModifier)},
- { DIK_NUMPAD4, mod(Qt::Key_4, Qt::KeypadModifier)},
- { DIK_NUMPAD5, mod(Qt::Key_5, Qt::KeypadModifier)},
- { DIK_NUMPAD6, mod(Qt::Key_6, Qt::KeypadModifier)},
- { DIK_NUMPAD7, mod(Qt::Key_7, Qt::KeypadModifier)},
- { DIK_NUMPAD8, mod(Qt::Key_8, Qt::KeypadModifier)},
- { DIK_NUMPAD9, mod(Qt::Key_9, Qt::KeypadModifier)},
- { DIK_NUMPADCOMMA, mod(Qt::Key_Comma, Qt::KeypadModifier)},
- { DIK_NUMPADENTER, mod(Qt::Key_Enter, Qt::KeypadModifier)},
- { DIK_NUMPADEQUALS, mod(Qt::Key_Equal, Qt::KeypadModifier)},
- { DIK_NUMPADMINUS, mod(Qt::Key_Minus, Qt::KeypadModifier)},
- { DIK_NUMPADPERIOD, mod(Qt::Key_Period, Qt::KeypadModifier)},
- { DIK_NUMPADPLUS, mod(Qt::Key_Plus, Qt::KeypadModifier)},
- { DIK_NUMPADSLASH, mod(Qt::Key_Slash, Qt::KeypadModifier)},
- { DIK_NUMPADSTAR, mod(Qt::Key_multiply, Qt::KeypadModifier)},
+#define key_mod(x, y) Qt::Key(int(x) | int((y)))
+ { DIK_NUMPAD0, key_mod(Qt::Key_0, Qt::KeypadModifier)},
+ { DIK_NUMPAD0, key_mod(Qt::Key_0, Qt::KeypadModifier)},
+ { DIK_NUMPAD1, key_mod(Qt::Key_1, Qt::KeypadModifier)},
+ { DIK_NUMPAD2, key_mod(Qt::Key_2, Qt::KeypadModifier)},
+ { DIK_NUMPAD3, key_mod(Qt::Key_3, Qt::KeypadModifier)},
+ { DIK_NUMPAD4, key_mod(Qt::Key_4, Qt::KeypadModifier)},
+ { DIK_NUMPAD5, key_mod(Qt::Key_5, Qt::KeypadModifier)},
+ { DIK_NUMPAD6, key_mod(Qt::Key_6, Qt::KeypadModifier)},
+ { DIK_NUMPAD7, key_mod(Qt::Key_7, Qt::KeypadModifier)},
+ { DIK_NUMPAD8, key_mod(Qt::Key_8, Qt::KeypadModifier)},
+ { DIK_NUMPAD9, key_mod(Qt::Key_9, Qt::KeypadModifier)},
+ { DIK_NUMPADCOMMA, key_mod(Qt::Key_Comma, Qt::KeypadModifier)},
+ { DIK_NUMPADENTER, key_mod(Qt::Key_Enter, Qt::KeypadModifier)},
+ { DIK_NUMPADEQUALS, key_mod(Qt::Key_Equal, Qt::KeypadModifier)},
+ { DIK_NUMPADMINUS, key_mod(Qt::Key_Minus, Qt::KeypadModifier)},
+ { DIK_NUMPADPERIOD, key_mod(Qt::Key_Period, Qt::KeypadModifier)},
+ { DIK_NUMPADPLUS, key_mod(Qt::Key_Plus, Qt::KeypadModifier)},
+ { DIK_NUMPADSLASH, key_mod(Qt::Key_Slash, Qt::KeypadModifier)},
+ { DIK_NUMPADSTAR, key_mod(Qt::Key_multiply, Qt::KeypadModifier)},
};
bool win_key::to_qt(const Key& k, QKeySequence& qt_, Qt::KeyboardModifiers &mods)
@@ -158,11 +158,17 @@ bool win_key::to_qt(const Key& k, QKeySequence& qt_, Qt::KeyboardModifiers &mods
return false;
}
-bool win_key::from_qt(QKeySequence const& qt_, int& dik, Qt::KeyboardModifiers& mods)
+bool win_key::from_qt(const QKeySequence& qt_, int& dik, Qt::KeyboardModifiers& mods)
{
// CAVEAT don't use QVariant::toUInt() or conversion fails
- const unsigned qt = static_cast<unsigned>(QVariant(qt_).toInt());
- const unsigned our_mods = unsigned(qt & Qt::KeyboardModifierMask);
+#if 0
+ const unsigned qt = QVariant(qt_).toInt(); // verbose
+#endif
+ const unsigned qt = int(qt_); // deprecated
+ const unsigned our_mods = qt & Qt::KeyboardModifierMask;
+
+ if (qt == 0)
+ return false;
{
for (const win_key& wk : windows_key_sequences)
@@ -182,7 +188,7 @@ bool win_key::from_qt(QKeySequence const& qt_, int& dik, Qt::KeyboardModifiers&
if (unsigned(wk.qt) == key)
{
dik = wk.win;
- mods = static_cast<Qt::KeyboardModifiers>(our_mods);
+ mods = { (Qt::KeyboardModifier)our_mods };
return true;
}
}