VirtualBox

Changeset 79588 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Jul 8, 2019 10:10:41 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
131885
Message:

FE/Qt: bugref:6143. A small refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/softkeyboard/UISoftKeyboard.cpp

    r79555 r79588  
    6767
    6868const int iMessageTimeout = 3000;
    69 /** Lock key position are used to identify respective keys. */
     69/** Key position are used to identify respective keys. */
    7070const int iCapsLockPosition = 30;
    7171const int iNumLockPosition = 90;
    7272const int iScrollLockPosition = 125;
     73const int iLeftShiftPosition = 44;
     74const int iRightShiftPosition = 57;
     75const int iLeftCtrlPosition = 58;
     76const int iRightCtrlPosition = 64;
     77const int iAltPosition = 60;
     78const int iAltGrPosition = 62;
     79
    7380
    7481const QString strSubDirectorName("keyboardLayouts");
    7582
    76 enum UIKeyState
    77 {
    78     UIKeyState_NotPressed,
    79     UIKeyState_Pressed,
    80     UIKeyState_Locked,
    81     UIKeyState_Max
     83enum KeyState
     84{
     85    KeyState_NotPressed,
     86    KeyState_Pressed,
     87    KeyState_Locked,
     88    KeyState_Max
    8289};
    8390
    84 enum UIKeyType
    85 {
    86     /** Can be in UIKeyState_NotPressed and UIKeyState_Pressed states. */
    87     UIKeyType_Ordinary,
    88     /** e.g. CapsLock, NumLock. Can be only in UIKeyState_NotPressed, UIKeyState_Locked */
    89     UIKeyType_Lock,
     91enum KeyType
     92{
     93    /** Can be in KeyState_NotPressed and KeyState_Pressed states. */
     94    KeyType_Ordinary,
     95    /** e.g. CapsLock, NumLock. Can be only in KeyState_NotPressed, KeyState_Locked */
     96    KeyType_Lock,
    9097    /** e.g. Shift Can be in all 3 states*/
    91     UIKeyType_Modifier,
    92     UIKeyType_Max
     98    KeyType_Modifier,
     99    KeyType_Max
    93100};
    94101
     
    331338    int position() const;
    332339
    333     void setType(UIKeyType enmType);
    334     UIKeyType type() const;
     340    void setType(KeyType enmType);
     341    KeyType type() const;
    335342
    336343    void setIsNumPadKey(bool fIsNumPadKey);
     
    343350
    344351    void setParentWidget(UISoftKeyboardWidget* pParent);
    345     UIKeyState state() const;
     352    KeyState state() const;
    346353    QVector<LONG> scanCodeWithPrefix() const;
    347354
     
    367374    /** Stores the key polygon in local coordinates. */
    368375    QPolygon   m_polygon;
    369     UIKeyType  m_enmType;
    370     UIKeyState m_enmState;
     376    KeyType  m_enmType;
     377    KeyState m_enmState;
    371378    /** Key width as it is read from the xml file. */
    372379    int        m_iWidth;
     
    535542    float layoutAspectRatio();
    536543
    537     bool showOSMenuKeys();
     544    bool showOSMenuKeys() const;
    538545    void setShowOSMenuKeys(bool fShow);
    539546
    540     bool showNumPad();
     547    bool showNumPad() const;
    541548    void setShowNumPad(bool fShow);
    542549
     
    13871394
    13881395UISoftKeyboardKey::UISoftKeyboardKey()
    1389     : m_enmType(UIKeyType_Ordinary)
    1390     , m_enmState(UIKeyState_NotPressed)
     1396    : m_enmType(KeyType_Ordinary)
     1397    , m_enmState(KeyState_NotPressed)
    13911398    , m_iWidth(0)
    13921399    , m_iHeight(0)
     
    14761483}
    14771484
    1478 void UISoftKeyboardKey::setType(UIKeyType enmType)
     1485void UISoftKeyboardKey::setType(KeyType enmType)
    14791486{
    14801487    m_enmType = enmType;
    14811488}
    14821489
    1483 UIKeyType UISoftKeyboardKey::type() const
     1490KeyType UISoftKeyboardKey::type() const
    14841491{
    14851492    return m_enmType;
     
    15131520}
    15141521
    1515 UIKeyState UISoftKeyboardKey::state() const
     1522KeyState UISoftKeyboardKey::state() const
    15161523{
    15171524    return m_enmState;
     
    15261533{
    15271534    /* Lock key states are controlled by the event signals we get from the guest OS. See updateLockKeyState function: */
    1528     if (m_enmType != UIKeyType_Lock)
     1535    if (m_enmType != KeyType_Lock)
    15291536        updateState(false);
    15301537}
     
    15331540{
    15341541    /* Lock key states are controlled by the event signals we get from the guest OS. See updateLockKeyState function: */
    1535     if (m_enmType != UIKeyType_Lock)
     1542    if (m_enmType != KeyType_Lock)
    15361543        updateState(true);
    15371544}
     
    15711578void UISoftKeyboardKey::updateState(bool fPressed)
    15721579{
    1573     UIKeyState enmPreviousState = state();
    1574     if (m_enmType == UIKeyType_Modifier)
     1580    KeyState enmPreviousState = state();
     1581    if (m_enmType == KeyType_Modifier)
    15751582    {
    15761583        if (fPressed)
    15771584        {
    1578             if (m_enmState == UIKeyState_NotPressed)
    1579                 m_enmState = UIKeyState_Pressed;
    1580             else if(m_enmState == UIKeyState_Pressed)
    1581                 m_enmState = UIKeyState_Locked;
     1585            if (m_enmState == KeyState_NotPressed)
     1586                m_enmState = KeyState_Pressed;
     1587            else if(m_enmState == KeyState_Pressed)
     1588                m_enmState = KeyState_Locked;
    15821589            else
    1583                 m_enmState = UIKeyState_NotPressed;
     1590                m_enmState = KeyState_NotPressed;
    15841591        }
    15851592        else
    15861593        {
    1587             if(m_enmState == UIKeyState_Pressed)
    1588                 m_enmState = UIKeyState_NotPressed;
     1594            if(m_enmState == KeyState_Pressed)
     1595                m_enmState = KeyState_NotPressed;
    15891596        }
    15901597    }
    1591     else if (m_enmType == UIKeyType_Lock)
    1592     {
    1593         m_enmState = fPressed ? UIKeyState_Locked : UIKeyState_NotPressed;
    1594         // if (fPressed)
    1595         // {
    1596         //     if (m_enmState == UIKeyState_NotPressed)
    1597         //          m_enmState = UIKeyState_Locked;
    1598         //     else
    1599         //         m_enmState = UIKeyState_NotPressed;
    1600         // }
    1601     }
    1602     else if (m_enmType == UIKeyType_Ordinary)
    1603     {
    1604         if (m_enmState == UIKeyState_NotPressed)
    1605             m_enmState = UIKeyState_Pressed;
     1598    else if (m_enmType == KeyType_Lock)
     1599    {
     1600        m_enmState = fPressed ? KeyState_Locked : KeyState_NotPressed;
     1601    }
     1602    else if (m_enmType == KeyType_Ordinary)
     1603    {
     1604        if (m_enmState == KeyState_NotPressed)
     1605            m_enmState = KeyState_Pressed;
    16061606        else
    1607             m_enmState = UIKeyState_NotPressed;
     1607            m_enmState = KeyState_NotPressed;
    16081608    }
    16091609    if (enmPreviousState != state() && m_pParentWidget)
     
    16131613void UISoftKeyboardKey::updateLockState(bool fLocked)
    16141614{
    1615     if (m_enmType != UIKeyType_Lock)
    1616         return;
    1617     if (fLocked && m_enmState == UIKeyState_Locked)
    1618         return;
    1619     if (!fLocked && m_enmState == UIKeyState_NotPressed)
     1615    if (m_enmType != KeyType_Lock)
     1616        return;
     1617    if (fLocked && m_enmState == KeyState_Locked)
     1618        return;
     1619    if (!fLocked && m_enmState == KeyState_NotPressed)
    16201620        return;
    16211621    updateState(fLocked);
     
    18681868                   keyGeometry.height() - 2 * iMargin);
    18691869
    1870 
    18711870    painter.drawText(textRect, Qt::AlignLeft | Qt::AlignTop, strTopleftString);
    18721871    painter.drawText(textRect, Qt::AlignLeft | Qt::AlignBottom, strBottomleftString);
    1873 
    18741872    painter.drawText(textRect, Qt::AlignRight | Qt::AlignTop, strShiftAltGrCaption);
    18751873    painter.drawText(textRect, Qt::AlignRight | Qt::AlignBottom, strAltGrCaption);
     1874
    18761875#endif
    18771876}
     
    20712070            m_pCurrentKeyboardLayout->drawTextInRect(key.position(), key.keyGeometry(), painter);
    20722071
    2073             if (key.type() != UIKeyType_Ordinary)
     2072            if (key.type() != KeyType_Ordinary)
    20742073            {
    20752074                QColor ledColor;
    2076                 if (key.state() == UIKeyState_NotPressed)
     2075                if (key.state() == KeyState_NotPressed)
    20772076                    ledColor = color(KeyboardColorType_Font);
    2078                 else if (key.state() == UIKeyState_Pressed)
     2077                else if (key.state() == KeyState_Pressed)
    20792078                    ledColor = QColor(0, 191, 204);
    20802079                else
     
    22492248}
    22502249
    2251 bool UISoftKeyboardWidget::showOSMenuKeys()
     2250bool UISoftKeyboardWidget::showOSMenuKeys() const
    22522251{
    22532252    return m_fShowOSMenuKeys;
     
    22622261}
    22632262
    2264 bool UISoftKeyboardWidget::showNumPad()
     2263bool UISoftKeyboardWidget::showNumPad() const
    22652264{
    22662265    return m_fShowNumPad;
     
    22972296void UISoftKeyboardWidget::updateLockKeyStates(bool fCapsLockState, bool fNumLockState, bool fScrollLockState)
    22982297{
    2299     UISoftKeyboardPhysicalLayout *pPhysicalLayout = findPhysicalLayout(m_pCurrentKeyboardLayout->physicalLayoutUuid());
    2300     if (!pPhysicalLayout)
    2301         return;
    2302     pPhysicalLayout->updateLockKeyStates(fCapsLockState, fNumLockState, fScrollLockState);
     2298    for (int i = 0; i < m_physicalLayouts.size(); ++i)
     2299        m_physicalLayouts[i].updateLockKeyStates(fCapsLockState, fNumLockState, fScrollLockState);
    23032300    update();
    23042301}
     
    24282425    if (!pKey)
    24292426        return;
    2430     if (pKey->type() == UIKeyType_Ordinary)
     2427    if (pKey->type() == KeyType_Ordinary)
    24312428        pKey->release();
    24322429    /* We only send the scan codes of Ordinary keys: */
    2433     if (pKey->type() == UIKeyType_Modifier)
     2430    if (pKey->type() == KeyType_Modifier)
    24342431        return;
    24352432
     
    24582455    pKey->press();
    24592456
    2460     if (pKey->type() == UIKeyType_Modifier)
     2457    if (pKey->type() == KeyType_Modifier)
    24612458        return;
    24622459
     
    24812478    if (!pKey)
    24822479        return;
    2483     if (pKey->type() == UIKeyType_Modifier)
    2484     {
    2485         if (pKey->state() == UIKeyState_NotPressed)
     2480    if (pKey->type() == KeyType_Modifier)
     2481    {
     2482        if (pKey->state() == KeyState_NotPressed)
    24862483            m_pressedModifiers.removeOne(pKey);
    24872484        else
     
    29162913            QString strType = m_xmlReader.readElementText();
    29172914            if (strType == "modifier")
    2918                 key.setType(UIKeyType_Modifier);
     2915                key.setType(KeyType_Modifier);
    29192916            else if (strType == "lock")
    2920                 key.setType(UIKeyType_Lock);
     2917                key.setType(KeyType_Lock);
    29212918        }
    29222919        else if (m_xmlReader.name() == "osmenukey")
     
    32983295    QSpacerItem *pSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Expanding);
    32993296    if (pSpacer)
    3300         pSettingsLayout->addItem(pSpacer, 5, 0);
     3297        pSettingsLayout->addItem(pSpacer, 6, 0);
    33013298
    33023299    setLayout(pSettingsLayout);
     
    36463643void UISoftKeyboard::configure()
    36473644{
    3648     setWindowIcon(UIIconPool::iconSetFull(":/vm_show_logs_32px.png", ":/vm_show_logs_16px.png"));
     3645    setWindowIcon(UIIconPool::iconSet(":/keyboard_24px.png"));
    36493646    if (m_pKeyboardWidget && m_pSettingsWidget)
    36503647    {
     
    36613658    updateLayoutSelectorList();
    36623659    if (m_pKeyboardWidget && m_pKeyboardWidget->currentLayout() && m_pLayoutSelector)
     3660    {
    36633661        m_pLayoutSelector->setCurrentLayout(m_pKeyboardWidget->currentLayout()->uid());
     3662        m_pLayoutSelector->setCurrentLayoutIsEditable(m_pKeyboardWidget->currentLayout()->editable());
     3663    }
    36643664}
    36653665
Note: See TracChangeset for help on using the changeset viewer.

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