VirtualBox

Changeset 45192 in vbox


Ignore:
Timestamp:
Mar 26, 2013 1:37:41 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: Top-level modal-window manager integration, some cleanup.

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

Legend:

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

    r44528 r45192  
    4545    : QIWithRetranslateUI<QIDialog>(pParent)
    4646{
    47 #ifdef Q_WS_MAC
    48     /* Check if Mac Sheet is allowed: */
    49     if (vboxGlobal().isSheetWindowAllowed(pParent))
    50     {
    51         vboxGlobal().setSheetWindowUsed(pParent, true);
    52         setWindowFlags(Qt::Sheet);
    53     }
    54 #endif /* Q_WS_MAC */
    55 
    5647    /* Apply UI decorations */
    5748    Ui::VBoxTakeSnapshotDlg::setupUi(this);
     
    9990}
    10091
    101 VBoxTakeSnapshotDlg::~VBoxTakeSnapshotDlg()
    102 {
    103 #ifdef Q_WS_MAC
    104     /* Check if Mac Sheet was used: */
    105     if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
    106         vboxGlobal().setSheetWindowUsed(parentWidget(), false);
    107 #endif /* Q_WS_MAC */
    108 }
    109 
    11092void VBoxTakeSnapshotDlg::retranslateUi()
    11193{
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxTakeSnapshotDlg.h

    r44528 r45192  
    3535
    3636    VBoxTakeSnapshotDlg(QWidget *pParent, const CMachine &machine);
    37     ~VBoxTakeSnapshotDlg();
    3837
    3938protected:
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialog.cpp

    r45166 r45192  
    2121#include "QIDialog.h"
    2222#include "VBoxGlobal.h"
    23 #ifdef Q_WS_MAC
    24 # include "VBoxUtils.h"
    25 #endif /* Q_WS_MAC */
    2623
    2724QIDialog::QIDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags flags /* = 0 */)
     
    2926    , m_fPolished(false)
    3027{
     28    /* No need to count that window as important for application,
     29     * it will NOT be taken into account when other top-level windows will be closed: */
     30    setAttribute(Qt::WA_QuitOnClose, false);
    3131}
    3232
     
    5353
    5454    /* Should we delete ourself on close in theory? */
    55     bool fWasDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
     55    bool fOldDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
     56    /* For the exec() time, set this attribute to 'false': */
    5657    setAttribute(Qt::WA_DeleteOnClose, false);
    5758
    58 #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500
    59     /* After 4.5 Qt changed the behavior of Sheets for the window/application
    60      * modal case. See "New Ways of Using Dialogs" in
    61      * http://doc.trolltech.com/qq/QtQuarterly30.pdf why. We want the old
    62      * behavior back, where all modal windows where shown as sheets. So make
    63      * the modal mode window, but be application modal in any case. */
    64     Qt::WindowModality winModality = windowModality();
    65     bool wasSetWinModality = testAttribute(Qt::WA_SetWindowModality);
    66     if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
    67     {
    68         setWindowModality(Qt::WindowModal);
    69         setAttribute(Qt::WA_SetWindowModality, false);
    70     }
    71 #endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */
    72     /* The dialog has to modal in any case.
    73      * Save the current modality to restore it later. */
    74     bool wasShowModal = testAttribute(Qt::WA_ShowModal);
    75     setAttribute(Qt::WA_ShowModal, true);
     59    /* Which is the current window-modality? */
     60    Qt::WindowModality oldModality = windowModality();
     61    /* For the exec() time, set this attribute to 'window-modal': */
     62    setWindowModality(Qt::WindowModal);
    7663
    7764    /* Show ourself if requested: */
     
    10188    QDialog::DialogCode resultCode = (QDialog::DialogCode)result();
    10289
    103 #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500
    104     /* Restore old modality mode: */
    105     if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
    106     {
    107         setWindowModality(winModality);
    108         setAttribute(Qt::WA_SetWindowModality, wasSetWinModality);
    109     }
    110 #endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */
    111     /* Set the old show modal attribute: */
    112     setAttribute (Qt::WA_ShowModal, wasShowModal);
     90    /* Return old modality: */
     91    setWindowModality(oldModality);
    11392
     93    /* Reset attribute to previous value: */
     94    setAttribute(Qt::WA_DeleteOnClose, fOldDeleteOnClose);
    11495    /* Delete ourself if we should do that on close: */
    115     if (fWasDeleteOnClose)
     96    if (fOldDeleteOnClose)
    11697        delete this;
    11798
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.cpp

    r43104 r45192  
    5959    , mWasPolished (false)
    6060{
    61 #ifdef Q_WS_MAC
    62     /* Check if Mac Sheet is allowed: */
    63     if (vboxGlobal().isSheetWindowAllowed(aParent))
    64     {
    65         vboxGlobal().setSheetWindowUsed(aParent, true);
    66         setWindowFlags(Qt::Sheet);
    67     }
    68 #endif /* Q_WS_MAC */
    69 
    7061    setWindowTitle (aCaption);
    7162    /* Necessary to later find some of the message boxes */
     
    174165    /* this call is a must -- it initializes mFlagCB and mSpacer */
    175166    setDetailsShown (false);
    176 }
    177 
    178 QIMessageBox::~QIMessageBox()
    179 {
    180 #ifdef Q_WS_MAC
    181     /* Check if Mac Sheet was used: */
    182     if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
    183         vboxGlobal().setSheetWindowUsed(parentWidget(), false);
    184 #endif /* Q_WS_MAC */
    185167}
    186168
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIMessageBox.h

    r44528 r45192  
    7777                  Icon aIcon, int aButton0, int aButton1 = 0, int aButton2 = 0,
    7878                  QWidget *aParent = 0, const char *aName = 0, bool aModal = TRUE);
    79     ~QIMessageBox();
    8079
    8180    QString buttonText (int aButton) const;
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp

    r45184 r45192  
    3737#include "UINetworkManagerDialog.h"
    3838#include "UIConverter.h"
     39#include "UIModalWindowManager.h"
    3940#ifdef VBOX_OSE
    4041# include "UIDownloaderUserManual.h"
     
    220221
    221222    /* Create message-box: */
    222     QPointer<QIMessageBox> pBox = new QIMessageBox(title, strMessage, icon, button1, button2,
    223                                                    button3, pParent, pcszAutoConfirmId);
     223    QWidget *pBoxParent = mwManager().realParentWindow(pParent);
     224    QPointer<QIMessageBox> pBox = new QIMessageBox(title, strMessage, icon,
     225                                                   button1, button2, button3,
     226                                                   pBoxParent, pcszAutoConfirmId);
     227    mwManager().registerNewParent(pBox, pBoxParent);
    224228
    225229    /* Configure message-box: */
     
    344348
    345349    /* Create message-box: */
     350    QWidget *pBoxParent = mwManager().realParentWindow(pParent);
    346351    QPointer<QIMessageBox> pBox = new QIMessageBox(strTitle, strMessage, icon,
    347                                                    iButton1, iButton2, iButton3, pParent);
     352                                                   iButton1, iButton2, iButton3, pBoxParent);
     353    mwManager().registerNewParent(pBox, pBoxParent);
    348354
    349355    /* Configure box: */
     
    407413                                              int cMinDuration /* = 2000 */)
    408414{
     415    /* Prepare pixmap: */
    409416    QPixmap *pPixmap = 0;
    410417    if (!strImage.isEmpty())
    411418        pPixmap = new QPixmap(strImage);
    412419
    413     UIProgressDialog progressDlg(progress, strTitle, pPixmap, fSheetOnDarwin, cMinDuration, pParent ? pParent : mainWindowShown());
     420    /* Create progress-dialog: */
     421    QWidget *pDlgParent = mwManager().realParentWindow(pParent);
     422    QPointer<UIProgressDialog> pProgressDlg = new UIProgressDialog(progress, strTitle, pPixmap, fSheetOnDarwin, cMinDuration, pDlgParent);
     423    mwManager().registerNewParent(pProgressDlg, pDlgParent);
     424
    414425    /* Run the dialog with the 350 ms refresh interval. */
    415     progressDlg.run(350);
    416 
     426    pProgressDlg->run(350);
     427
     428    /* Make sure progress-dialog still valid: */
     429    if (!pProgressDlg)
     430        return false;
     431
     432    /* Delete progress-dialog: */
     433    delete pProgressDlg;
     434
     435    /* Cleanup pixmap: */
    417436    if (pPixmap)
    418437        delete pPixmap;
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp

    r45167 r45192  
    38443844}
    38453845#endif /* VBOX_WITH_CRHGSMI */
    3846 
    3847 #ifdef Q_WS_MAC
    3848 bool VBoxGlobal::isSheetWindowAllowed(QWidget *pParent) const
    3849 {
    3850     /* Disallow for null parent: */
    3851     if (!pParent)
    3852         return false;
    3853 
    3854     /* Make sure Mac Sheet is not used for the same parent now. */
    3855     if (sheetWindowUsed(pParent))
    3856         return false;
    3857 
    3858     /* No sheets for fullscreen/seamless now.
    3859      * Firstly it looks ugly and secondly in some cases it is broken. */
    3860     if (!(qobject_cast<UIMachineWindowFullscreen*>(pParent) ||
    3861           qobject_cast<UIMachineWindowSeamless*>(pParent)))
    3862         return true;
    3863 
    3864     return false;
    3865 }
    3866 
    3867 void VBoxGlobal::setSheetWindowUsed(QWidget *pParent, bool fUsed)
    3868 {
    3869     /* Ignore null parent: */
    3870     if (!pParent)
    3871         return;
    3872 
    3873     if (fUsed)
    3874     {
    3875         AssertMsg(!m_sheets.contains(pParent), ("Trying to use Mac Sheet for parent which already has one!"));
    3876         if (m_sheets.contains(pParent))
    3877             return;
    3878     }
    3879     else
    3880     {
    3881         AssertMsg(m_sheets.contains(pParent), ("Trying to cancel use Mac Sheet for parent which has no one!"));
    3882         if (!m_sheets.contains(pParent))
    3883             return;
    3884     }
    3885 
    3886     if (fUsed)
    3887         m_sheets.insert(pParent);
    3888     else
    3889         m_sheets.remove(pParent);
    3890 }
    3891 
    3892 bool VBoxGlobal::sheetWindowUsed(QWidget *pParent) const
    3893 {
    3894     return m_sheets.contains(pParent);
    3895 }
    3896 #endif /* Q_WS_MAC */
    38973846
    38983847/* static */
  • trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h

    r45054 r45192  
    384384    static quint64 required3DWddmOffscreenVideoMemory(const QString &strGuestOSTypeId, int cMonitors = 1);
    385385#endif /* VBOX_WITH_CRHGSMI */
    386 
    387 #ifdef Q_WS_MAC
    388     bool isSheetWindowAllowed(QWidget *pParent) const;
    389     void setSheetWindowUsed(QWidget *pParent, bool fUsed);
    390     bool sheetWindowUsed(QWidget *pParent) const;
    391 #endif /* Q_WS_MAC */
    392386
    393387    /* Returns full medium-format name for the given base medium-format name: */
     
    550544    bool mSettingsPwSet;
    551545
    552 #ifdef Q_WS_MAC
    553     QSet<QWidget*> m_sheets;
    554 #endif /* Q_WS_MAC */
    555 
    556546    friend VBoxGlobal &vboxGlobal();
    557547};
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r45167 r45192  
    5252#include "UIVMLogViewer.h"
    5353#include "UIConverter.h"
     54#include "UIModalWindowManager.h"
    5455#ifdef Q_WS_MAC
    5556# include "DockIconPreview.h"
     
    988989
    989990    /* Create take-snapshot dialog: */
    990     QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(activeMachineWindow(), machine);
     991    QWidget *pDlgParent = mwManager().realParentWindow(activeMachineWindow());
     992    QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(pDlgParent, machine);
     993    mwManager().registerNewParent(pDlg, pDlgParent);
    991994
    992995    /* Assign corresponding icon: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp

    r45168 r45192  
    3838#include "UIVMCloseDialog.h"
    3939#include "UIConverter.h"
     40#include "UIModalWindowManager.h"
    4041
    4142/* COM includes: */
     
    273274
    274275            /* Prepare close-dialog: */
    275             UIVMCloseDialog *pDlg = new UIVMCloseDialog(this);
     276            QWidget *pDlgParent = mwManager().realParentWindow(this);
     277            UIVMCloseDialog *pDlg = new UIVMCloseDialog(pDlgParent);
     278            mwManager().registerNewParent(pDlg, pDlgParent);
    276279
    277280            /* Assign close-dialog pixmap: */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIVMCloseDialog.cpp

    r44528 r45192  
    3636    : QIWithRetranslateUI<QIDialog>(pParent)
    3737{
    38 #ifdef Q_WS_MAC
    39     /* Check if Mac Sheet is allowed: */
    40     if (vboxGlobal().isSheetWindowAllowed(pParent))
    41     {
    42         vboxGlobal().setSheetWindowUsed(pParent, true);
    43         setWindowFlags(Qt::Sheet);
    44     }
    45 #endif /* Q_WS_MAC */
    46 
    4738    /* Apply UI decorations */
    4839    Ui::UIVMCloseDialog::setupUi(this);
     
    6253}
    6354
    64 UIVMCloseDialog::~UIVMCloseDialog()
    65 {
    66 #ifdef Q_WS_MAC
    67     /* Check if Mac Sheet was used: */
    68     if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
    69         vboxGlobal().setSheetWindowUsed(parentWidget(), false);
    70 #endif /* Q_WS_MAC */
    71 }
    72 
    7355void UIVMCloseDialog::retranslateUi()
    7456{
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIVMCloseDialog.h

    r44528 r45192  
    3232
    3333    UIVMCloseDialog(QWidget *pParent);
    34     ~UIVMCloseDialog();
    3534
    3635protected:
  • trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSnapshotsWgt.cpp

    r44528 r45192  
    4040#include "UIVirtualBoxEventHandler.h"
    4141#include "UIConverter.h"
     42#include "UIModalWindowManager.h"
    4243
    4344/* COM includes: */
     
    816817        {
    817818            /* Create take-snapshot dialog: */
    818             QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(this, mMachine);
     819            QWidget *pDlgParent = mwManager().realParentWindow(this);
     820            QPointer<VBoxTakeSnapshotDlg> pDlg = new VBoxTakeSnapshotDlg(pDlgParent, mMachine);
     821            mwManager().registerNewParent(pDlg, pDlgParent);
    819822
    820823            /* Assign corresponding icon: */
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.cpp

    r43857 r45192  
    77
    88/*
    9  * Copyright (C) 2006-2012 Oracle Corporation
     9 * Copyright (C) 2006-2013 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3232#include "UISpecialControls.h"
    3333#include "VBoxGlobal.h"
     34#include "UIModalWindowManager.h"
    3435#ifdef Q_WS_MAC
    3536# include "VBoxUtils-darwin.h"
     
    6465
    6566#ifdef Q_WS_MAC
    66     /* Check if Mac Sheet is allowed: */
    67     if (fSheetOnDarwin && vboxGlobal().isSheetWindowAllowed(pParent))
    68     {
    69         vboxGlobal().setSheetWindowUsed(pParent, true);
    70         setWindowFlags(Qt::Sheet);
    71     }
    7267    ::darwinSetHidesAllTitleButtons(this);
    73     ::darwinSetShowsResizeIndicator(this, false);
    7468    if (pImage)
    7569        pMainLayout->setContentsMargins(30, 15, 30, 15);
    7670    else
    7771        pMainLayout->setContentsMargins(6, 6, 6, 6);
    78 #else /* Q_WS_MAC */
     72#endif /* Q_WS_MAC */
    7973    NOREF(fSheetOnDarwin);
    80 #endif /* !Q_WS_MAC */
    8174
    8275    /* Create image: */
     
    135128     * the duration is over if progress is not finished yet. */
    136129    QTimer::singleShot(cMinDuration, this, SLOT(sltShowDialog()));
    137 }
    138 
    139 UIProgressDialog::~UIProgressDialog()
    140 {
    141 #ifdef Q_WS_MAC
    142     /* Check if Mac Sheet was used: */
    143     if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
    144         vboxGlobal().setSheetWindowUsed(parentWidget(), false);
    145 #endif /* Q_WS_MAC */
    146130}
    147131
     
    200184     * modal dialog prevents our event-loop from
    201185     * being exit overlapping 'this'. */
    202     if (m_fEnded && !isHidden())
     186    if (m_fEnded && !isHidden() && mwManager().isWindowOnTheTopOfTheModalWindowStack(this))
    203187    {
    204188        hide();
     
    210194    if (!m_fEnded && (!m_progress.isOk() || m_progress.GetCompleted()))
    211195    {
    212         /* Progress finished: */
    213         if (m_progress.isOk())
     196        /* Is this progress-dialog a top-level modal-dialog now? */
     197        if (mwManager().isWindowOnTheTopOfTheModalWindowStack(this))
    214198        {
    215             m_pProgressBar->setValue(100);
    216             done(Accepted);
     199            /* Progress finished: */
     200            if (m_progress.isOk())
     201            {
     202                m_pProgressBar->setValue(100);
     203                done(Accepted);
     204            }
     205            /* Progress is not valid: */
     206            else
     207                done(Rejected);
     208
     209            /* Request to exit loop: */
     210            m_fEnded = true;
     211            return;
    217212        }
    218         /* Progress is not valid: */
    219         else
    220             done(Rejected);
    221 
    222         /* Request to exit loop: */
    223         m_fEnded = true;
     213        /* Else we should wait until all the subsequent
     214         * top-level modal-dialog(s) will be dismissed: */
    224215        return;
    225216    }
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h

    r43857 r45192  
    66
    77/*
    8  * Copyright (C) 2009-2012 Oracle Corporation
     8 * Copyright (C) 2009-2013 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4444 *       destroyed.
    4545 */
    46 class UIProgressDialog: protected QIWithRetranslateUI2<QIDialog>
     46class UIProgressDialog: public QIWithRetranslateUI2<QIDialog>
    4747{
    4848    Q_OBJECT;
     
    5454                     QPixmap *pImage = 0, bool fSheetOnDarwin = false,
    5555                     int cMinDuration = 2000, QWidget *pParent = 0);
    56     ~UIProgressDialog();
    5756
    5857    /* API: Run stuff: */
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