33
44#include " HotkeyManager.h"
55
6+ #include " ../global/TextUtils.h"
7+
8+ #include < unordered_map>
9+ #include < unordered_set>
10+
611#include < QDebug>
7- #include < QHash>
812#include < QRegularExpression>
913#include < QSettings>
1014#include < QTextStream>
@@ -329,11 +333,13 @@ void HotkeyManager::parseRawContent()
329333 QRegularExpressionMatch match = hotkeyRegex.match (trimmedLine);
330334 if (match.hasMatch ()) {
331335 QString keyStr = normalizeKeyString (match.captured (1 ));
332- QString command = match.captured (2 ).trimmed ();
333- if (!keyStr.isEmpty () && !command .isEmpty ()) {
336+ QString commandQStr = match.captured (2 ).trimmed ();
337+ if (!keyStr.isEmpty () && !commandQStr .isEmpty ()) {
334338 // Convert string to HotkeyKey for fast lookup
335339 HotkeyKey hk = stringToHotkeyKey (keyStr);
336340 if (hk.key != 0 ) {
341+ // Convert command to std::string for storage (cold path - OK)
342+ std::string command = mmqt::toStdStringUtf8 (commandQStr);
337343 m_hotkeys[hk] = command;
338344 m_orderedHotkeys.emplace_back (keyStr, command);
339345 }
@@ -404,7 +410,7 @@ void HotkeyManager::removeHotkey(const QString &keyName)
404410 }
405411
406412 HotkeyKey hk = stringToHotkeyKey (normalizedKey);
407- if (! m_hotkeys.contains (hk)) {
413+ if (m_hotkeys.count (hk) == 0 ) {
408414 return ;
409415 }
410416
@@ -433,34 +439,54 @@ void HotkeyManager::removeHotkey(const QString &keyName)
433439 saveToSettings ();
434440}
435441
436- QString HotkeyManager::getCommand (int key, Qt::KeyboardModifiers modifiers, bool isNumpad) const
442+ std::string HotkeyManager::getCommand (int key, Qt::KeyboardModifiers modifiers, bool isNumpad) const
437443{
438444 // Strip KeypadModifier from modifiers - numpad distinction is tracked via isNumpad flag
439445 HotkeyKey hk (key, modifiers & ~Qt::KeypadModifier, isNumpad);
440446 auto it = m_hotkeys.find (hk);
441447 if (it != m_hotkeys.end ()) {
442- return it. value () ;
448+ return it-> second ;
443449 }
444- return QString ();
450+ return std::string ();
445451}
446452
447- QString HotkeyManager::getCommand (const QString &keyName) const
453+ std::string HotkeyManager::getCommand (const QString &keyName) const
448454{
449455 QString normalizedKey = normalizeKeyString (keyName);
450456 if (normalizedKey.isEmpty ()) {
451- return QString ();
457+ return std::string ();
452458 }
453459
454460 HotkeyKey hk = stringToHotkeyKey (normalizedKey);
455461 if (hk.key == 0 ) {
456- return QString ();
462+ return std::string ();
457463 }
458464
459465 auto it = m_hotkeys.find (hk);
460466 if (it != m_hotkeys.end ()) {
461- return it. value () ;
467+ return it-> second ;
462468 }
463- return QString ();
469+ return std::string ();
470+ }
471+
472+ QString HotkeyManager::getCommandQString (int key,
473+ Qt::KeyboardModifiers modifiers,
474+ bool isNumpad) const
475+ {
476+ const std::string cmd = getCommand (key, modifiers, isNumpad);
477+ if (cmd.empty ()) {
478+ return QString ();
479+ }
480+ return mmqt::toQStringUtf8 (cmd);
481+ }
482+
483+ QString HotkeyManager::getCommandQString (const QString &keyName) const
484+ {
485+ const std::string cmd = getCommand (keyName);
486+ if (cmd.empty ()) {
487+ return QString ();
488+ }
489+ return mmqt::toQStringUtf8 (cmd);
464490}
465491
466492bool HotkeyManager::hasHotkey (const QString &keyName) const
@@ -471,7 +497,7 @@ bool HotkeyManager::hasHotkey(const QString &keyName) const
471497 }
472498
473499 HotkeyKey hk = stringToHotkeyKey (normalizedKey);
474- return hk.key != 0 && m_hotkeys.contains (hk);
500+ return hk.key != 0 && m_hotkeys.count (hk) > 0 ;
475501}
476502
477503QString HotkeyManager::normalizeKeyString (const QString &keyString)
@@ -658,11 +684,12 @@ void HotkeyManager::clear()
658684 m_rawContent.clear ();
659685}
660686
661- QStringList HotkeyManager::getAllKeyNames () const
687+ std::vector<QString> HotkeyManager::getAllKeyNames () const
662688{
663- QStringList result;
689+ std::vector<QString> result;
690+ result.reserve (m_orderedHotkeys.size ());
664691 for (const auto &pair : m_orderedHotkeys) {
665- result << pair.first ;
692+ result. push_back ( pair.first ) ;
666693 }
667694 return result;
668695}
@@ -692,65 +719,65 @@ bool HotkeyManager::isValidBaseKey(const QString &baseKey)
692719 return getValidBaseKeys ().contains (baseKey.toUpper ());
693720}
694721
695- QStringList HotkeyManager::getAvailableKeyNames ()
722+ std::vector<QString> HotkeyManager::getAvailableKeyNames ()
696723{
697- return QStringList {// Function keys
698- " F1" ,
699- " F2" ,
700- " F3" ,
701- " F4" ,
702- " F5" ,
703- " F6" ,
704- " F7" ,
705- " F8" ,
706- " F9" ,
707- " F10" ,
708- " F11" ,
709- " F12" ,
710- // Numpad
711- " NUMPAD0" ,
712- " NUMPAD1" ,
713- " NUMPAD2" ,
714- " NUMPAD3" ,
715- " NUMPAD4" ,
716- " NUMPAD5" ,
717- " NUMPAD6" ,
718- " NUMPAD7" ,
719- " NUMPAD8" ,
720- " NUMPAD9" ,
721- " NUMPAD_SLASH" ,
722- " NUMPAD_ASTERISK" ,
723- " NUMPAD_MINUS" ,
724- " NUMPAD_PLUS" ,
725- " NUMPAD_PERIOD" ,
726- // Navigation
727- " HOME" ,
728- " END" ,
729- " INSERT" ,
730- " PAGEUP" ,
731- " PAGEDOWN" ,
732- // Arrow keys
733- " UP" ,
734- " DOWN" ,
735- " LEFT" ,
736- " RIGHT" ,
737- // Misc
738- " ACCENT" ,
739- " 0" ,
740- " 1" ,
741- " 2" ,
742- " 3" ,
743- " 4" ,
744- " 5" ,
745- " 6" ,
746- " 7" ,
747- " 8" ,
748- " 9" ,
749- " HYPHEN" ,
750- " EQUAL" };
724+ return std::vector<QString> {// Function keys
725+ " F1" ,
726+ " F2" ,
727+ " F3" ,
728+ " F4" ,
729+ " F5" ,
730+ " F6" ,
731+ " F7" ,
732+ " F8" ,
733+ " F9" ,
734+ " F10" ,
735+ " F11" ,
736+ " F12" ,
737+ // Numpad
738+ " NUMPAD0" ,
739+ " NUMPAD1" ,
740+ " NUMPAD2" ,
741+ " NUMPAD3" ,
742+ " NUMPAD4" ,
743+ " NUMPAD5" ,
744+ " NUMPAD6" ,
745+ " NUMPAD7" ,
746+ " NUMPAD8" ,
747+ " NUMPAD9" ,
748+ " NUMPAD_SLASH" ,
749+ " NUMPAD_ASTERISK" ,
750+ " NUMPAD_MINUS" ,
751+ " NUMPAD_PLUS" ,
752+ " NUMPAD_PERIOD" ,
753+ // Navigation
754+ " HOME" ,
755+ " END" ,
756+ " INSERT" ,
757+ " PAGEUP" ,
758+ " PAGEDOWN" ,
759+ // Arrow keys
760+ " UP" ,
761+ " DOWN" ,
762+ " LEFT" ,
763+ " RIGHT" ,
764+ // Misc
765+ " ACCENT" ,
766+ " 0" ,
767+ " 1" ,
768+ " 2" ,
769+ " 3" ,
770+ " 4" ,
771+ " 5" ,
772+ " 6" ,
773+ " 7" ,
774+ " 8" ,
775+ " 9" ,
776+ " HYPHEN" ,
777+ " EQUAL" };
751778}
752779
753- QStringList HotkeyManager::getAvailableModifiers ()
780+ std::vector<QString> HotkeyManager::getAvailableModifiers ()
754781{
755- return QStringList {" CTRL" , " SHIFT" , " ALT" , " META" };
782+ return std::vector<QString> {" CTRL" , " SHIFT" , " ALT" , " META" };
756783}
0 commit comments