VirtualBox

Changeset 82186 in vbox


Ignore:
Timestamp:
Nov 25, 2019 5:02:40 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134999
Message:

FE/Qt: bugref:9609: Rework UIAction and UIShortcut interfaces to support multiple shortcut sequences; Update their code accordingly to expose primary sequence getters.

Location:
trunk/src/VBox/Frontends/VirtualBox/src
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.cpp

    r80479 r82186  
    150150}
    151151
    152 void UIAction::setShortcut(const QKeySequence &shortcut)
     152void UIAction::setShortcuts(const QList<QKeySequence> &shortcuts)
    153153{
    154154    /* Only for manager's action-pool: */
    155155    if (m_enmActionPoolType == UIActionPoolType_Manager)
    156156    {
    157         /* If shortcut is visible: */
     157        /* If primary shortcut should be visible: */
    158158        if (!m_fShortcutHidden)
    159159            /* Call to base-class: */
    160             QAction::setShortcut(shortcut);
    161         /* Remember shortcut: */
    162         m_shortcut = shortcut;
    163     }
    164     /* Update text according new shortcut: */
     160            QAction::setShortcuts(shortcuts);
     161        /* Remember shortcuts: */
     162        m_shortcuts = shortcuts;
     163    }
     164    /* Update text according to new primary shortcut: */
    165165    updateText();
    166166}
     
    169169{
    170170    m_fShortcutHidden = false;
    171     if (!m_shortcut.isEmpty())
    172         QAction::setShortcut(m_shortcut);
     171    if (!m_shortcuts.isEmpty())
     172        QAction::setShortcuts(m_shortcuts);
    173173}
    174174
     
    177177    m_fShortcutHidden = true;
    178178    if (!shortcut().isEmpty())
    179         QAction::setShortcut(QKeySequence());
     179        QAction::setShortcuts(QList<QKeySequence>());
    180180}
    181181
     
    215215            if (machineMenuAction())
    216216                setText(uiCommon().insertKeyToActionText(nameInMenu(),
    217                                                            gShortcutPool->shortcut(actionPool(), this).toString()));
     217                                                         gShortcutPool->shortcut(actionPool(), this).primaryToPortableText()));
    218218            else
    219219                setText(nameInMenu());
     
    25782578            continue;
    25792579        /* Get the hot-key of the current action: */
    2580         const QString strHotKey = gShortcutPool->shortcut(this, pAction).toString();
     2580        const QString strHotKey = gShortcutPool->shortcut(this, pAction).primaryToPortableText();
    25812581        if (pAction->isEnabled() && pAction->isAllowed() && !strHotKey.isEmpty())
    25822582        {
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIActionPool.h

    r80479 r82186  
    248248    virtual QKeySequence defaultShortcut(UIActionPoolType) const { return QKeySequence(); }
    249249
    250     /** Defines current keyboard shortcut for this action. */
    251     void setShortcut(const QKeySequence &shortcut);
     250    /** Defines current keyboard shortcuts for this action. */
     251    void setShortcuts(const QList<QKeySequence> &shortcuts);
    252252    /** Make action show keyboard shortcut. */
    253253    void showShortcut();
     
    292292
    293293    /** Holds current action state. */
    294     int             m_iState;
     294    int                  m_iState;
    295295    /** Holds action icons. */
    296     QVector<QIcon>  m_icons;
     296    QVector<QIcon>       m_icons;
    297297    /** Holds the action name. */
    298     QString         m_strName;
     298    QString              m_strName;
    299299    /** Holds the action shortcut scope. */
    300     QString         m_strShortcutScope;
    301     /** Holds the action shortcut. */
    302     QKeySequence    m_shortcut;
     300    QString              m_strShortcutScope;
     301    /** Holds the action shortcuts. */
     302    QList<QKeySequence>  m_shortcuts;
    303303    /** Holds whether action shortcut hidden. */
    304     bool            m_fShortcutHidden;
     304    bool                 m_fShortcutHidden;
    305305};
    306306
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIShortcutPool.cpp

    r79365 r82186  
    5151}
    5252
    53 void UIShortcut::setSequence(const QKeySequence &sequence)
    54 {
    55     m_sequence = sequence;
    56 }
    57 
    58 const QKeySequence &UIShortcut::sequence() const
    59 {
    60     return m_sequence;
     53void UIShortcut::setSequences(const QList<QKeySequence> &sequences)
     54{
     55    m_sequences = sequences;
     56}
     57
     58const QList<QKeySequence> &UIShortcut::sequences() const
     59{
     60    return m_sequences;
    6161}
    6262
     
    7171}
    7272
    73 QString UIShortcut::toString() const
    74 {
    75     return m_sequence.toString();
     73QString UIShortcut::primaryToNativeText() const
     74{
     75    return m_sequences.isEmpty() ? QString() : m_sequences.first().toString(QKeySequence::NativeText);
     76}
     77
     78QString UIShortcut::primaryToPortableText() const
     79{
     80    return m_sequences.isEmpty() ? QString() : m_sequences.first().toString(QKeySequence::PortableText);
    7681}
    7782
     
    124129    newShortcut.setScope(pAction->shortcutScope());
    125130    newShortcut.setDescription(pAction->name());
    126     newShortcut.setSequence(pAction->defaultShortcut(pActionPool->type()));
    127     newShortcut.setDefaultSequence(pAction->defaultShortcut(pActionPool->type()));
     131    const QKeySequence &defaultSequence = pAction->defaultShortcut(pActionPool->type());
     132    newShortcut.setSequences(QList<QKeySequence>() << defaultSequence);
     133    newShortcut.setDefaultSequence(defaultSequence);
    128134    return newShortcut;
    129135}
     
    144150        if (!m_shortcuts.contains(strShortcutKey))
    145151            continue;
    146         /* Assign overridden sequence to the shortcut: */
    147         m_shortcuts[strShortcutKey].setSequence(overrides[strShortcutKey]);
     152        /* Assign overridden sequences to the shortcut: */
     153        m_shortcuts[strShortcutKey].setSequences(QList<QKeySequence>() << overrides[strShortcutKey]);
    148154    }
    149155    /* Save overrides: */
     
    172178            /* Copy the description from the action to the shortcut: */
    173179            existingShortcut.setDescription(pAction->name());
    174             /* Copy the sequence from the shortcut to the action: */
    175             pAction->setShortcut(existingShortcut.sequence());
     180            /* Copy the sequences from the shortcut to the action: */
     181            pAction->setShortcuts(existingShortcut.sequences());
    176182            pAction->retranslateUi();
    177             /* Copy the default sequence from the action to the shortcut: */
     183            /* Copy default sequence from the action to the shortcut: */
    178184            existingShortcut.setDefaultSequence(pAction->defaultShortcut(pActionPool->type()));
    179185        }
     
    183189            /* Create corresponding shortcut: */
    184190            UIShortcut &newShortcut = m_shortcuts[strShortcutKey];
    185             /* Copy the action's default to both the shortcut & the action: */
    186             newShortcut.setSequence(pAction->defaultShortcut(pActionPool->type()));
    187             newShortcut.setDefaultSequence(pAction->defaultShortcut(pActionPool->type()));
    188             pAction->setShortcut(newShortcut.sequence());
     191            /* Copy the action's default sequence to both the shortcut & the action: */
     192            const QKeySequence &defaultSequence = pAction->defaultShortcut(pActionPool->type());
     193            newShortcut.setSequences(QList<QKeySequence>() << defaultSequence);
     194            newShortcut.setDefaultSequence(defaultSequence);
     195            pAction->setShortcuts(newShortcut.sequences());
    189196            pAction->retranslateUi();
    190197            /* Copy the description from the action to the shortcut: */
     
    291298                           UIShortcut(QString(),
    292299                                      QApplication::translate("UIActionPool", "Popup Menu"),
    293                                       QString("Home"), QString("Home")));
     300                                      QList<QKeySequence>() << QString("Home"),
     301                                      QString("Home")));
    294302    }
    295303}
     
    328336        /* Modify map with composed key/value: */
    329337        if (!m_shortcuts.contains(strShortcutKey))
    330             m_shortcuts.insert(strShortcutKey, UIShortcut(QString(), QString(), strShortcutSequence, QString()));
     338            m_shortcuts.insert(strShortcutKey,
     339                               UIShortcut(QString(),
     340                                          QString(),
     341                                          QList<QKeySequence>() << strShortcutSequence,
     342                                          QString()));
    331343        else
    332344        {
     
    334346            UIShortcut &shortcut = m_shortcuts[strShortcutKey];
    335347            /* Check if corresponding shortcut overridden by value: */
    336             if (shortcut.toString().compare(strShortcutSequence, Qt::CaseInsensitive) != 0)
     348            if (shortcut.primaryToPortableText().compare(strShortcutSequence, Qt::CaseInsensitive) != 0)
    337349            {
    338350                /* Shortcut unassigned? */
    339351                if (strShortcutSequence.compare("None", Qt::CaseInsensitive) == 0)
    340                     shortcut.setSequence(QKeySequence());
     352                    shortcut.setSequences(QList<QKeySequence>());
    341353                /* Or reassigned? */
    342354                else
    343                     shortcut.setSequence(QKeySequence(strShortcutSequence));
     355                    shortcut.setSequences(QList<QKeySequence>() << strShortcutSequence);
    344356            }
    345357        }
     
    370382        const UIShortcut &shortcut = m_shortcuts[strShortcutKey];
    371383        /* Check if the sequence for that shortcut differs from default: */
    372         if (shortcut.sequence() == shortcut.defaultSequence())
     384        if (shortcut.sequences().contains(shortcut.defaultSequence()))
    373385            continue;
    374386        /* Add the shortcut sequence into overrides list: */
    375387        overrides << QString("%1=%2").arg(QString(strShortcutKey).remove(strShortcutPrefix),
    376                                           shortcut.sequence().toString());
     388                                          shortcut.primaryToPortableText());
    377389    }
    378390    /* Save overrides into the extra-data: */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIShortcutPool.h

    r76581 r82186  
    4545        : m_strScope(QString())
    4646        , m_strDescription(QString())
    47         , m_sequence(QKeySequence())
     47        , m_sequences(QList<QKeySequence>())
    4848        , m_defaultSequence(QKeySequence())
    4949    {}
    5050    /** Constructs shortcut descriptor.
    51       * @param  strScope         Brings the shortcut scope.
    52       * @param  strDescription   Brings the shortcut description.
    53       * @param  sequence         Brings the shortcut sequence.
    54       * @param  defaultSequence  Brings the default shortcut sequence. */
     51      * @param  strScope          Brings the shortcut scope.
     52      * @param  strDescription    Brings the shortcut description.
     53      * @param  sequences         Brings the shortcut sequences.
     54      * @param  defaultSequence   Brings the default shortcut sequence. */
    5555    UIShortcut(const QString &strScope,
    5656               const QString &strDescription,
    57                const QKeySequence &sequence,
     57               const QList<QKeySequence> &sequences,
    5858               const QKeySequence &defaultSequence)
    5959        : m_strScope(strScope)
    6060        , m_strDescription(strDescription)
    61         , m_sequence(sequence)
     61        , m_sequences(sequences)
    6262        , m_defaultSequence(defaultSequence)
    6363    {}
     
    7373    const QString &description() const;
    7474
    75     /** Defines the shortcut @a sequence. */
    76     void setSequence(const QKeySequence &sequence);
    77     /** Returns the shortcut sequence. */
    78     const QKeySequence &sequence() const;
     75    /** Defines the shortcut @a sequences. */
     76    void setSequences(const QList<QKeySequence> &sequences);
     77    /** Returns the shortcut sequences. */
     78    const QList<QKeySequence> &sequences() const;
    7979
    8080    /** Defines the default shortcut @a sequence. */
     
    8383    const QKeySequence &defaultSequence() const;
    8484
    85     /** Converts shortcut sequence to string. */
    86     QString toString() const;
     85    /** Converts primary shortcut sequence to native text. */
     86    QString primaryToNativeText() const;
     87    /** Converts primary shortcut sequence to portable text. */
     88    QString primaryToPortableText() const;
    8789
    8890private:
    8991
    9092    /** Holds the shortcut scope. */
    91     QString      m_strScope;
     93    QString              m_strScope;
    9294    /** Holds the shortcut description. */
    93     QString      m_strDescription;
    94     /** Holds the shortcut sequence. */
    95     QKeySequence m_sequence;
     95    QString              m_strDescription;
     96    /** Holds the shortcut sequences. */
     97    QList<QKeySequence>  m_sequences;
    9698    /** Holds the default shortcut sequence. */
    97     QKeySequence m_defaultSequence;
     99    QKeySequence         m_defaultSequence;
    98100};
    99101
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIKeyboardHandlerFullscreen.cpp

    r76606 r82186  
    5454                QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
    5555                /* Process Host+Home for menu popup: */
    56                 if (isHostKeyPressed() && QKeySequence(pKeyEvent->key()) == gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequence())
     56                if (   isHostKeyPressed()
     57                    && gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequences().contains(QKeySequence(pKeyEvent->key())))
    5758                {
    5859                    /* Post request to show popup-menu: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp

    r81964 r82186  
    7878            gShortcutPool->shortcut(actionPool()->shortcutsExtraDataID(),
    7979                                    actionPool()->action(UIActionIndexRT_M_View_T_Fullscreen)->shortcutExtraDataID());
    80     const QString strHotKey = QString("Host+%1").arg(shortcut.toString());
     80    const QString strHotKey = QString("Host+%1").arg(shortcut.primaryToPortableText());
    8181    if (!msgCenter().confirmGoingFullscreen(strHotKey))
    8282        return false;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIKeyboardHandlerNormal.cpp

    r76606 r82186  
    6666                QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
    6767                /* Process Host+Home as menu-bar activator: */
    68                 if (isHostKeyPressed() && QKeySequence(pKeyEvent->key()) == gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequence())
     68                if (   isHostKeyPressed()
     69                    && gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequences().contains(QKeySequence(pKeyEvent->key())))
    6970                {
    7071                    /* Trying to get menu-bar: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIKeyboardHandlerScale.cpp

    r76606 r82186  
    6161                QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
    6262                /* Process Host+Home for menu popup: */
    63                 if (isHostKeyPressed() && QKeySequence(pKeyEvent->key()) == gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequence())
     63                if (   isHostKeyPressed()
     64                    && gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequences().contains(QKeySequence(pKeyEvent->key())))
    6465                {
    6566                    /* Post request to show popup-menu: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp

    r82008 r82186  
    5454            gShortcutPool->shortcut(actionPool()->shortcutsExtraDataID(),
    5555                                    actionPool()->action(UIActionIndexRT_M_View_T_Scale)->shortcutExtraDataID());
    56     const QString strHotKey = QString("Host+%1").arg(shortcut.toString());
     56    const QString strHotKey = QString("Host+%1").arg(shortcut.primaryToPortableText());
    5757    if (!msgCenter().confirmGoingScale(strHotKey))
    5858        return false;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIKeyboardHandlerSeamless.cpp

    r76606 r82186  
    6161                QKeyEvent *pKeyEvent = static_cast<QKeyEvent*>(pEvent);
    6262                /* Process Host+Home for menu popup: */
    63                 if (isHostKeyPressed() && QKeySequence(pKeyEvent->key()) == gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequence())
     63                if (   isHostKeyPressed()
     64                    && gShortcutPool->shortcut(GUI_Input_MachineShortcuts, QString("PopupMenu")).sequences().contains(QKeySequence(pKeyEvent->key())))
    6465                {
    6566                    /* Post request to show popup-menu: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp

    r82008 r82186  
    7676            gShortcutPool->shortcut(actionPool()->shortcutsExtraDataID(),
    7777                                    actionPool()->action(UIActionIndexRT_M_View_T_Seamless)->shortcutExtraDataID());
    78     const QString strHotKey = QString("Host+%1").arg(shortcut.toString());
     78    const QString strHotKey = QString("Host+%1").arg(shortcut.primaryToPortableText());
    7979    if (!msgCenter().confirmGoingSeamless(strHotKey))
    8080        return false;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.cpp

    r80881 r82186  
    927927                                                      shortcut.scope(),
    928928                                                      UICommon::removeAccelMark(shortcut.description()),
    929                                                       shortcut.sequence().toString(QKeySequence::NativeText),
     929                                                      shortcut.primaryToNativeText(),
    930930                                                      shortcut.defaultSequence().toString(QKeySequence::NativeText));
    931931    }
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