Skip to content
  • Dmitry Kazakov's avatar
    Fix broken shortcuts when user uses Space key as a modifier · adc8c597
    Dmitry Kazakov authored
    The Problem
    -----------
    
    Qt cannot use Space (or any non-modifier) key as a modifier. When
    we assign "Space+R" shortcut to "Reset rotation" in Krita settings,
    Qt actually assigns it not to "Space+R", but to "Space, R". That is,
    the user is expected to press the two keys sequentially, not
    simultaneously (though the latter option also works).
    
    It means that after the user presses "Space" key, Qt transits into a
    special state of an incomplete match and starts waiting for the following
    key. While in this state, Qt (without this patch) eats all the shortcut
    events.
    
    Solution
    --------
    
    There is no proper solution for the problem, because Qt will still wait
    for the second key to be pressed. That is, there is no way to instruct
    Qt that Space and R keys should be pressed simultaneously (it is not
    possible by design of QKeySequence.
    
    This patch adds a workaround for the problem. It makes sure that all the
    shortcut events are delivered to Krita, whatever the state Qt has
    internally.
    
    Test Plan
    ---------
    
    Configuration:
    
    1) Assign W as a primary shortcut for Zoom-In in **Canvas Input Settings**
    2) Assign Space,R as a primary shortcut for Zoom-Out in **Keyboard Shortcuts**
    3) Assign Space,W as a primary shortcut Rotate Canvas Left in **Keyboard Shortcuts**
    
    Testcase 1:
    
    1) Press Space, Release Space
    2) Press W, Release W
    
    Expected: canvas is zoomed in and not rotated, space+drag gesture still works fine
    
    Testcase 2:
    
    1) Press Space, Release Space
    2) Press W, Release W
    2) Press R, Release R
    
    Expected: no zoom-out action happens (because Space modifier has already been consumed by the former action)
    
    Testcase 3:
    
    1) Press Space, Release Space
    2) Press R, Release R
    
    Expected: zoom-out action happens, space+drag gesture still works fine
    
    
    Testcase 4:
    
    Press Space, W and R randomly, it should still behave "in a sane way" :)
    
    BUG:409613
    adc8c597