VirtualBox

Changeset 92490 in vbox


Ignore:
Timestamp:
Nov 18, 2021 9:58:58 AM (3 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10141. Managing escape key in viso creator dialog.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMainDialog.cpp

    r91109 r92490  
    4444    , m_fPolished(false)
    4545    , m_iResult(QDialog::Rejected)
     46    , m_fRejectByEscape(true)
    4647{
    4748    /* Install event-filter: */
     
    269270        case Qt::Key_Escape:
    270271        {
    271             if (pEvent->modifiers() == Qt::NoModifier)
     272            if (pEvent->modifiers() == Qt::NoModifier && m_fRejectByEscape)
    272273            {
    273274                reject();
     
    330331    hide();
    331332}
     333
     334void QIMainDialog::setRejectByEscape(bool fRejectByEscape)
     335{
     336    m_fRejectByEscape = fRejectByEscape;
     337}
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMainDialog.h

    r87718 r92490  
    9191    QPushButton *searchDefaultButton() const;
    9292
     93    /** Sets reject-by-escape-key flag. */
     94    void setRejectByEscape(bool fRejectByEscape);
     95
    9396protected slots:
    9497
     
    121124    /** Holds dialog's size-grip. */
    122125    QPointer<QSizeGrip>    m_pSizeGrip;
     126    /** Holds reject by escape flag. When true pressing escape rejects the dialog. Default is true.*/
     127    bool m_fRejectByEscape;
    123128};
    124129
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.cpp

    r92478 r92490  
    446446void UIVisoCreatorWidget::manageEscapeShortCut()
    447447{
    448     // /* Take the escape key from m_pButtonBox and from the panels in case treeview(s) in
    449     //    host and/or content browser is open. We use the escape key to close those first: */
    450     // if ((m_pHostBrowser && m_pHostBrowser->isTreeViewVisible()) ||
    451     //     (m_pVISOContentBrowser && m_pVISOContentBrowser->isTreeViewVisible()))
    452     // {
    453     //     if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel))
    454     //         m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence());
    455     //     for (int i = 0; i < m_visiblePanelsList.size(); ++i)
    456     //         m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence());
    457     //     return;
    458     // }
    459 
    460     // /* if there are no visible panels then assign esc. key to cancel button of the button box: */
    461     // if (m_visiblePanelsList.isEmpty())
    462     // {
    463     //     if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel))
    464     //         m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence(Qt::Key_Escape));
    465     //     return;
    466     // }
    467     // if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel))
    468     //     m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence());
     448    /* Take the escape key from m_pButtonBox and from the panels in case treeview(s) in
     449       host and/or content browser is open. We use the escape key to close those first: */
     450    if ((m_pHostBrowser && m_pHostBrowser->isTreeViewVisible()) ||
     451        (m_pVISOContentBrowser && m_pVISOContentBrowser->isTreeViewVisible()))
     452    {
     453        emit sigSetCancelButtonShortCut(QKeySequence());
     454        for (int i = 0; i < m_visiblePanelsList.size(); ++i)
     455            m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence());
     456        return;
     457    }
     458
     459    /* if there are no visible panels then assign esc. key to cancel button of the button box: */
     460    if (m_visiblePanelsList.isEmpty())
     461    {
     462        emit sigSetCancelButtonShortCut(QKeySequence(Qt::Key_Escape));
     463        return;
     464    }
     465    emit sigSetCancelButtonShortCut(QKeySequence());
    469466
    470467    /* Just loop thru the visible panel list and set the esc key to the
    471468       panel which made visible latest */
    472     // for (int i = 0; i < m_visiblePanelsList.size() - 1; ++i)
    473     //     m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence());
    474     // m_visiblePanelsList.back()->setCloseButtonShortCut(QKeySequence(Qt::Key_Escape));
     469    for (int i = 0; i < m_visiblePanelsList.size() - 1; ++i)
     470        m_visiblePanelsList[i]->setCloseButtonShortCut(QKeySequence());
     471    m_visiblePanelsList.back()->setCloseButtonShortCut(QKeySequence(Qt::Key_Escape));
    475472}
    476473
     
    518515    , m_pActionPool(pActionPool)
    519516{
     517    /* Make sure that the base class does not close this dialog upon pressing escape.
     518       we manage escape key here with special casing: */
     519    setRejectByEscape(false);
    520520    prepareWidgets();
    521521    prepareConnections();
     
    569569        menuBar()->addMenu(m_pVisoCreatorWidget->menu());
    570570        pMainLayout->addWidget(m_pVisoCreatorWidget);
     571        connect(m_pVisoCreatorWidget, &UIVisoCreatorWidget::sigSetCancelButtonShortCut,
     572                this, &UIVisoCreatorDialog::sltSetCancelButtonShortCut);
    571573    }
    572574
     
    575577    {
    576578        m_pButtonBox->setStandardButtons(QDialogButtonBox::Help | QDialogButtonBox::Cancel | QDialogButtonBox::Ok);
    577         m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
     579        m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(QKeySequence(Qt::Key_Escape));
    578580        pMainLayout->addWidget(m_pButtonBox);
    579581
     
    610612        m_pButtonBox->button(QDialogButtonBox::Help)->setToolTip(UIVisoCreatorWidget::tr("Opens the help browser and navigates to the related section"));
    611613}
     614
     615void UIVisoCreatorDialog::sltSetCancelButtonShortCut(QKeySequence keySequence)
     616{
     617    if (m_pButtonBox && m_pButtonBox->button(QDialogButtonBox::Cancel))
     618        m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(keySequence);
     619}
  • trunk/src/VBox/Frontends/VirtualBox/src/medium/viso/UIVisoCreator.h

    r92478 r92490  
    4949{
    5050    Q_OBJECT;
     51
     52signals:
     53
     54    void sigSetCancelButtonShortCut(QKeySequence keySequence);
    5155
    5256public:
     
    184188    void    setCurrentPath(const QString &strPath);
    185189
     190private slots:
     191
     192    void sltSetCancelButtonShortCut(QKeySequence keySequence);
     193
    186194private:
    187195    void prepareWidgets();
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