VirtualBox

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


Ignore:
Timestamp:
Mar 28, 2023 11:43:51 AM (22 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6669: Advance UINativeWizard interface to support non-modal way of running wizards.

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

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/UINativeWizard.cpp

    r98103 r99194  
    9393                               WizardMode enmMode /* = WizardMode_Auto */,
    9494                               const QString &strHelpTag /* = QString() */)
    95     : QIWithRetranslateUI<QDialog>(pParent)
     95    : QIWithRetranslateUI2<QDialog>(pParent, Qt::Window)
    9696    , m_enmType(enmType)
    9797    , m_enmMode(enmMode == WizardMode_Auto ? gEDataManager->modeForWizardType(m_enmType) : enmMode)
    9898    , m_strHelpHashtag(strHelpTag)
    9999    , m_iLastIndex(-1)
     100    , m_fClosed(false)
    100101    , m_pLabelPixmap(0)
    101102    , m_pLayoutRight(0)
     
    136137
    137138    /* Call to base-class: */
    138     return QIWithRetranslateUI<QDialog>::exec();
     139    return QIWithRetranslateUI2<QDialog>::exec();
     140}
     141
     142void UINativeWizard::show()
     143{
     144    /* Init wizard: */
     145    init();
     146
     147    /* Call to base-class: */
     148    return QIWithRetranslateUI2<QDialog>::show();
    139149}
    140150
     
    241251    pButtonCancel->setText(tr("&Cancel"));
    242252    pButtonCancel->setToolTip(tr("Cancel wizard execution."));
     253}
     254
     255void UINativeWizard::keyPressEvent(QKeyEvent *pEvent)
     256{
     257    /* Different handling depending on current modality: */
     258    const Qt::WindowModality enmModality = windowHandle()->modality();
     259
     260    /* For non-modal case: */
     261    if (enmModality == Qt::NonModal)
     262    {
     263        /* Special pre-processing for some keys: */
     264        switch (pEvent->key())
     265        {
     266            case Qt::Key_Escape:
     267            {
     268                close();
     269                return;
     270            }
     271            default:
     272                break;
     273        }
     274    }
     275
     276    /* Call to base-class: */
     277    return QIWithRetranslateUI2<QDialog>::keyPressEvent(pEvent);
     278}
     279
     280void UINativeWizard::closeEvent(QCloseEvent *pEvent)
     281{
     282    /* Different handling depending on current modality: */
     283    const Qt::WindowModality enmModality = windowHandle()->modality();
     284
     285    /* For non-modal case: */
     286    if (enmModality == Qt::NonModal)
     287    {
     288        /* Ignore event initially: */
     289        pEvent->ignore();
     290
     291        /* Tell the listener to close us (once): */
     292        if (!m_fClosed)
     293        {
     294            m_fClosed = true;
     295            emit sigClose(m_enmType);
     296        }
     297
     298        return;
     299    }
     300
     301    /* Call to base-class: */
     302    QIWithRetranslateUI2<QDialog>::closeEvent(pEvent);
    243303}
    244304
     
    513573                        this, &UINativeWizard::sltNext);
    514574                connect(wizardButton(WizardButtonType_Cancel), &QPushButton::clicked,
    515                         this, &UINativeWizard::reject);
     575                        this, &UINativeWizard::close);
    516576            }
    517577
  • trunk/src/VBox/Frontends/VirtualBox/src/wizards/UINativeWizard.h

    r98103 r99194  
    8383
    8484/** QDialog extension with advanced functionality emulating QWizard behavior. */
    85 class SHARED_LIBRARY_STUFF UINativeWizard : public QIWithRetranslateUI<QDialog>
     85class SHARED_LIBRARY_STUFF UINativeWizard : public QIWithRetranslateUI2<QDialog>
    8686{
    8787    Q_OBJECT;
     88
     89signals:
     90
     91    /** Notifies listeners about dialog should be closed. */
     92    void sigClose(WizardType enmType);
    8893
    8994public:
     
    113118      * @note You shouldn't have to override it! */
    114119    virtual int exec() /* final */;
     120    /** Shows wizard in non-mode.
     121      * @note You shouldn't have to override it! */
     122    virtual void show() /* final */;
    115123
    116124protected:
     
    141149    /** Handles translation event. */
    142150    virtual void retranslateUi() RT_OVERRIDE;
     151
     152    /** Handles key-press @a pEvent. */
     153    virtual void keyPressEvent(QKeyEvent *pEvent) RT_OVERRIDE;
     154    /** Handles close @a pEvent. */
     155    virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;
    143156
    144157    /** Performs wizard-specific cleanup in case of wizard-mode change
     
    199212    /** Holds the set of invisible pages. */
    200213    QSet<int>   m_invisiblePages;
     214    /** Holds whether the dialod had emitted signal to be closed. */
     215    bool        m_fClosed;
    201216
    202217    /** Holds the pixmap label instance. */
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