VirtualBox

Changeset 35797 in vbox for trunk


Ignore:
Timestamp:
Jan 31, 2011 5:30:03 PM (14 years ago)
Author:
vboxsync
Message:

FE/Qt4: consolidate the key processing

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.cpp

    r35793 r35797  
    182182
    183183#ifdef Q_WS_MAC
     184    if (!iKeyCode || iKeyCode == ~0U)
     185        return false;
     186
    184187    UInt32 modMask = ::DarwinKeyCodeToDarwinModifierMask(iKeyCode);
    185188    switch (modMask)
     
    403406            int iKeyCode = UIHotKey::distinguishModifierVKey((int)pMsg->wParam, (int)pMsg->lParam);
    404407
    405             /* Check if symbol is valid else pass it to Qt: */
    406             if (!UIHotKey::isValidKey(iKeyCode))
    407                 return false;
    408 
    409             /* Stop the release-pending-keys timer: */
    410             m_pReleaseTimer->stop();
    411 
    412             /* Key press: */
    413             if (pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN)
    414             {
    415                 /* Clear reflected symbols if new sequence started: */
    416                 if (m_fStartNewSequence)
    417                     m_shownKeys.clear();
    418                 /* Make sure any keys pending for releasing are processed: */
    419                 sltReleasePendingKeys();
    420                 /* Check maximum combo size: */
    421                 if (m_shownKeys.size() < UIHotKeyCombination::m_iMaxComboSize)
    422                 {
    423                     /* Remember pressed symbol: */
    424                     m_pressedKeys << iKeyCode;
    425                     m_shownKeys.insert(iKeyCode, UIHotKey::toString(iKeyCode));
    426 
    427                     /* Remember what we already started a sequence: */
    428                     m_fStartNewSequence = false;
    429                 }
    430             }
    431             /* Key release: */
    432             else if (pMsg->message == WM_KEYUP || pMsg->message == WM_SYSKEYUP)
    433             {
    434                 /* Queue released symbol for processing: */
    435                 m_releasedKeys << iKeyCode;
    436 
    437                 /* If all pressed keys are now pending for releasing we should stop further handling.
    438                  * Now we have the status the user want: */
    439                 if (m_pressedKeys == m_releasedKeys)
    440                 {
    441                     m_pressedKeys.clear();
    442                     m_releasedKeys.clear();
    443                     m_fStartNewSequence = true;
    444                 }
    445                 else
    446                     m_pReleaseTimer->start();
    447             }
    448 
    449             /* Update text: */
    450             updateText();
    451 
    452             /* Prevent passing to Qt: */
    453             return true;
     408            /* Process the key event */
     409            return processKeyEvent(iKeyCode, pMsg->message == WM_KEYDOWN || pMsg->message == WM_SYSKEYDOWN);
    454410        }
    455411        default:
     
    474430            int iKeySym = (int)ks;
    475431
     432            /* Process the key event */
     433            return processKeyEvent(iKeySym, pEvent->type == XKeyPress);
    476434            /* Check if symbol is valid else pass it to Qt: */
    477             if (!UIHotKey::isValidKey(iKeySym))
    478                 return false;
    479 
    480             /* Stop the release-pending-keys timer: */
    481             m_pReleaseTimer->stop();
    482 
    483             /* Key press: */
    484             if (pEvent->type == XKeyPress)
    485             {
    486                 /* Clear reflected symbols if new sequence started: */
    487                 if (m_fStartNewSequence)
    488                     m_shownKeys.clear();
    489                 /* Make sure any keys pending for releasing are processed: */
    490                 sltReleasePendingKeys();
    491                 /* Check maximum combo size: */
    492                 if (m_shownKeys.size() < UIHotKeyCombination::m_iMaxComboSize)
    493                 {
    494                     /* Remember pressed symbol: */
    495                     m_pressedKeys << iKeySym;
    496                     m_shownKeys.insert(iKeySym, UIHotKey::toString(iKeySym));
    497 
    498                     /* Remember what we already started a sequence: */
    499                     m_fStartNewSequence = false;
    500                 }
    501             }
    502             /* Key release: */
    503             else if (pEvent->type == XKeyRelease)
    504             {
    505                 /* Queue released symbol for processing: */
    506                 m_releasedKeys << iKeySym;
    507 
    508                 /* If all pressed keys are now pending for releasing we should stop further handling.
    509                  * Now we have the status the user want: */
    510                 if (m_pressedKeys == m_releasedKeys)
    511                 {
    512                     m_pressedKeys.clear();
    513                     m_releasedKeys.clear();
    514                     m_fStartNewSequence = true;
    515                 }
    516                 else
    517                     m_pReleaseTimer->start();
    518             }
    519 
    520             /* Update text: */
    521             updateText();
    522 
    523             /* Prevent passing to Qt: */
    524             return true;
    525435        }
    526436    }
     
    534444bool UIHotKeyEditor::darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
    535445{
    536     UIHotKeyEditor *pEditor = (UIHotKeyEditor*)pvUser;
     446    UIHotKeyEditor *pEditor = static_cast<UIHotKeyEditor*>(pvUser);
    537447    EventRef inEvent = (EventRef)pvCarbonEvent;
    538448    UInt32 EventClass = ::GetEventClass(inEvent);
     
    563473            UInt32 changed = m_uDarwinKeyModifiers ^ modifierMask;
    564474
     475            if (!changed)
     476                break;
     477
    565478            /* Convert to keycode: */
    566479            unsigned iKeyCode = ::DarwinModifierMaskToDarwinKeycode(changed);
    567480
    568             /* Check if symbol is valid else pass it to Qt: */
    569             if (!iKeyCode || iKeyCode == ~0U || !UIHotKey::isValidKey(iKeyCode))
    570                 break;
    571 
    572             if (changed)
     481            if (processKeyEvent(iKeyCode, changed & modifierMask))
    573482            {
    574                 /* Stop the delete pending keys timer. */
    575                 m_pReleaseTimer->stop();
    576                 /* If modifierMask is empty, no key is pressed anymore.
    577                  * Stop all key handling and the deletion of keys. This is the status the user want: */
    578                 if (!modifierMask)
    579                     m_fStartNewSequence = true;
    580                 /* Key release: */
    581                 else if (!(changed & modifierMask))
    582                 {
    583                     /* Queue released symbol for processing: */
    584                     m_releasedKeys << iKeyCode;
    585                     m_pReleaseTimer->start();
    586                 }
    587                 /* Key press: */
    588                 else
    589                 {
    590                     /* Clear reflected symbols if new sequence started: */
    591                     if (m_fStartNewSequence)
    592                         m_shownKeys.clear();
    593                     /* Make sure any keys pending for releasing are processed: */
    594                     sltReleasePendingKeys();
    595                     /* Check maximum combo size: */
    596                     if (m_shownKeys.size() < UIHotKeyCombination::m_iMaxComboSize)
    597                     {
    598                         /* Remember pressed symbol: */
    599                         m_pressedKeys << iKeyCode;
    600                         m_shownKeys.insert(iKeyCode, UIHotKey::toString(iKeyCode));
    601 
    602                         /* Remember what we already started a sequence: */
    603                         m_fStartNewSequence = false;
    604                     }
    605                 }
     483                /* Save the new modifier mask state. */
     484                m_uDarwinKeyModifiers = modifierMask;
     485                return true;
    606486            }
    607             /* Save the new modifier mask state. */
    608             m_uDarwinKeyModifiers = modifierMask;
    609 
    610             /* Update text: */
    611             updateText();
    612         }
    613         break;
     487            break;
     488        }
    614489    }
    615490    return false;
    616491}
    617492#endif /* Q_WS_MAC */
     493
     494bool UIHotKeyEditor::processKeyEvent(int iKeyCode, bool fKeyPress)
     495{
     496    /* Check if symbol is valid else pass it to Qt: */
     497    if (!UIHotKey::isValidKey(iKeyCode))
     498        return false;
     499
     500    /* Stop the release-pending-keys timer: */
     501    m_pReleaseTimer->stop();
     502
     503    /* Key press: */
     504    if (fKeyPress)
     505    {
     506        /* Clear reflected symbols if new sequence started: */
     507        if (m_fStartNewSequence)
     508            m_shownKeys.clear();
     509        /* Make sure any keys pending for releasing are processed: */
     510        sltReleasePendingKeys();
     511        /* Check maximum combo size: */
     512        if (m_shownKeys.size() < UIHotKeyCombination::m_iMaxComboSize)
     513        {
     514            /* Remember pressed symbol: */
     515            m_pressedKeys << iKeyCode;
     516            m_shownKeys.insert(iKeyCode, UIHotKey::toString(iKeyCode));
     517
     518            /* Remember what we already started a sequence: */
     519            m_fStartNewSequence = false;
     520        }
     521    }
     522    /* Key release: */
     523    else
     524    {
     525        /* Queue released symbol for processing: */
     526        m_releasedKeys << iKeyCode;
     527
     528        /* If all pressed keys are now pending for releasing we should stop further handling.
     529         * Now we have the status the user want: */
     530        if (m_pressedKeys == m_releasedKeys)
     531        {
     532            m_pressedKeys.clear();
     533            m_releasedKeys.clear();
     534            m_fStartNewSequence = true;
     535        }
     536        else
     537            m_pReleaseTimer->start();
     538    }
     539
     540    /* Update text: */
     541    updateText();
     542
     543    /* Prevent passing to Qt: */
     544    return true;
     545}
    618546
    619547void UIHotKeyEditor::keyPressEvent(QKeyEvent *pEvent)
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIHotKeyEditor.h

    r35791 r35797  
    7676#endif /* Q_WS_MAC */
    7777
     78    bool processKeyEvent(int iKeyCode, bool fKeyPress);
     79
    7880    void keyPressEvent(QKeyEvent *pEvent);
    7981    void focusInEvent(QFocusEvent *pEvent);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette