@@ -17,30 +17,41 @@ shortcut_handler::shortcut_handler(gui::shortcuts::shortcut_handler_id handler_i
1717 continue ;
1818 }
1919
20- const QKeySequence key_sequence = sc_settings.get_key_sequence (info, gui_settings);
21- QShortcut* shortcut = new QShortcut (key_sequence, parent);
22- shortcut->setAutoRepeat (info.allow_auto_repeat );
20+ QKeySequence key_sequence = sc_settings.get_key_sequence (info, gui_settings);
2321
2422 shortcut_key_info key_info{};
25- key_info.shortcut = shortcut ;
23+ key_info.shortcut = make_shortcut (shortcut_key, info, key_sequence) ;
2624 key_info.info = info;
27- key_info.key_sequence = key_sequence;
25+ key_info.key_sequence = std::move ( key_sequence) ;
2826
29- m_shortcuts[shortcut_key] = key_info;
27+ m_shortcuts[shortcut_key] = std::move (key_info);
28+ }
29+ }
3030
31- connect (shortcut, &QShortcut::activated, this , [this , key = shortcut_key]()
32- {
33- handle_shortcut (key, m_shortcuts[key].key_sequence );
34- });
35- connect (shortcut, &QShortcut::activatedAmbiguously, this , [this , key = shortcut_key]()
36- {
37- // TODO: do not allow same shortcuts and remove this connect
38- // activatedAmbiguously will trigger if you have the same key sequence for several shortcuts
39- const QKeySequence& key_sequence = m_shortcuts[key].key_sequence ;
40- shortcut_log.error (" %s: Shortcut activated ambiguously: %s (%s)" , m_handler_id, key, key_sequence.toString ());
41- handle_shortcut (key, key_sequence);
42- });
31+ QShortcut* shortcut_handler::make_shortcut (gui::shortcuts::shortcut key, const shortcut_info& info, const QKeySequence& key_sequence)
32+ {
33+ if (key_sequence.isEmpty ())
34+ {
35+ return nullptr ;
4336 }
37+
38+ QShortcut* shortcut = new QShortcut (key_sequence, parent ());
39+ shortcut->setAutoRepeat (info.allow_auto_repeat );
40+
41+ connect (shortcut, &QShortcut::activated, this , [this , key]()
42+ {
43+ handle_shortcut (key, m_shortcuts[key].key_sequence );
44+ });
45+ connect (shortcut, &QShortcut::activatedAmbiguously, this , [this , key]()
46+ {
47+ // TODO: do not allow same shortcuts and remove this connect
48+ // activatedAmbiguously will trigger if you have the same key sequence for several shortcuts
49+ const QKeySequence& key_sequence = m_shortcuts[key].key_sequence ;
50+ shortcut_log.error (" %s: Shortcut activated ambiguously: %s (%s)" , m_handler_id, key, key_sequence.toString ());
51+ handle_shortcut (key, key_sequence);
52+ });
53+
54+ return shortcut;
4455}
4556
4657void shortcut_handler::update ()
@@ -61,9 +72,22 @@ void shortcut_handler::update()
6172
6273 shortcut_key_info& key_info = m_shortcuts[shortcut_key];
6374 key_info.key_sequence = key_sequence;
75+
6476 if (key_info.shortcut )
6577 {
66- key_info.shortcut ->setKey (key_sequence);
78+ if (key_sequence.isEmpty ())
79+ {
80+ key_info.shortcut ->deleteLater ();
81+ key_info.shortcut = nullptr ;
82+ }
83+ else
84+ {
85+ key_info.shortcut ->setKey (key_sequence);
86+ }
87+ }
88+ else
89+ {
90+ key_info.shortcut = make_shortcut (shortcut_key, info, key_sequence);
6791 }
6892 }
6993}
0 commit comments