VirtualBox

Changeset 97390 in vbox


Ignore:
Timestamp:
Nov 3, 2022 4:56:57 PM (2 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:6669: Heavy rework for Properties/Settings dialogs allowing to get rid of unwanted dialog modality; Keep in mind that we are NOT applying any settings on-the-fly in any case.

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

Legend:

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

    r97388 r97390  
    639639    sltCloseManagerWindow(UIToolType_Cloud);
    640640    sltCloseManagerWindow(UIToolType_CloudConsole);
     641    sltCloseSettingsDialog();
     642    sltClosePreferencesDialog();
    641643}
    642644
     
    974976    m_fFirstMediumEnumerationHandled = true;
    975977
    976     /* Lock the action preventing cascade calls: */
    977     UIQObjectPropertySetter guardBlock(actionPool()->action(UIActionIndex_M_Application_S_Preferences), "opened", true);
    978     connect(&guardBlock, &UIQObjectPropertySetter::sigAboutToBeDestroyed,
    979             this, &UIVirtualBoxManager::sltHandleUpdateActionAppearanceRequest);
    980     updateActionsAppearance();
    981 
    982     /* Use the "safe way" to open stack of Mac OS X Sheets: */
    983     QWidget *pDialogParent = windowManager().realParentWindow(this);
    984     UISafePointerSettingsDialogGlobal pDialog = new UISettingsDialogGlobal(pDialogParent);
    985     windowManager().registerNewParent(pDialog, pDialogParent);
    986 
    987     /* Execute dialog: */
    988     pDialog->execute();
    989     delete pDialog;
     978    /* Create instance if not yet created: */
     979    if (!m_settings.contains(UISettingsDialog::DialogType_Global))
     980    {
     981        m_settings[UISettingsDialog::DialogType_Global] = new UISettingsDialogGlobal(this);
     982        connect(m_settings[UISettingsDialog::DialogType_Global], &UISettingsDialogGlobal::sigClose,
     983                this, &UIVirtualBoxManager::sltClosePreferencesDialog);
     984        m_settings.value(UISettingsDialog::DialogType_Global)->load();
     985    }
     986
     987    /* Expose instance: */
     988    UIDesktopWidgetWatchdog::restoreWidget(m_settings.value(UISettingsDialog::DialogType_Global));
     989}
     990
     991void UIVirtualBoxManager::sltClosePreferencesDialog()
     992{
     993    /* Remove instance if exist: */
     994    delete m_settings.take(UISettingsDialog::DialogType_Global);
    990995}
    991996
     
    10841089            m_fFirstMediumEnumerationHandled = true;
    10851090
    1086             /* Use the "safe way" to open stack of Mac OS X Sheets: */
    1087             QWidget *pDialogParent = windowManager().realParentWindow(this);
    1088             UISafePointerSettingsDialogMachine pDialog = new UISettingsDialogMachine(pDialogParent,
    1089                                                                                      uID.isNull() ? pItem->id() : uID,
    1090                                                                                      strCategory, strControl, actionPool());
    1091             windowManager().registerNewParent(pDialog, pDialogParent);
    1092 
    1093             /* Execute dialog: */
    1094             pDialog->execute();
    1095             delete pDialog;
     1091            /* Create instance if not yet created: */
     1092            if (!m_settings.contains(UISettingsDialog::DialogType_Machine))
     1093            {
     1094                m_settings[UISettingsDialog::DialogType_Machine] = new UISettingsDialogMachine(this,
     1095                                                                                               uID.isNull() ? pItem->id() : uID,
     1096                                                                                               strCategory,
     1097                                                                                               strControl,
     1098                                                                                               actionPool());
     1099                connect(m_settings[UISettingsDialog::DialogType_Machine], &UISettingsDialogGlobal::sigClose,
     1100                        this, &UIVirtualBoxManager::sltCloseSettingsDialog);
     1101                m_settings.value(UISettingsDialog::DialogType_Machine)->load();
     1102            }
     1103
     1104            /* Expose instance: */
     1105            UIDesktopWidgetWatchdog::restoreWidget(m_settings.value(UISettingsDialog::DialogType_Machine));
    10961106        }
    10971107    }
     
    11091119        delete pDialog;
    11101120    }
     1121}
     1122
     1123void UIVirtualBoxManager::sltCloseSettingsDialog()
     1124{
     1125    /* Remove instance if exist: */
     1126    delete m_settings.take(UISettingsDialog::DialogType_Machine);
    11111127}
    11121128
  • trunk/src/VBox/Frontends/VirtualBox/src/manager/UIVirtualBoxManager.h

    r97388 r97390  
    4141#include "UICommon.h"
    4242#include "UIExtraDataDefs.h"
     43#include "UISettingsDialog.h"
    4344
    4445/* Forward declarations: */
     
    198199        /** Handles call to open Preferences dialog. */
    199200        void sltOpenPreferencesDialog();
     201        /** Handles call to close Preferences dialog. */
     202        void sltClosePreferencesDialog();
    200203
    201204        /** Handles call to exit application. */
     
    224227        /** Handles call to open Settings dialog the default way. */
    225228        void sltOpenSettingsDialogDefault() { sltOpenSettingsDialog(); }
     229        /** Handles call to close Settings dialog. */
     230        void sltCloseSettingsDialog();
    226231
    227232        /** Handles call to open Clone Machine wizard. */
     
    491496    QMap<UIToolType, QIManagerDialog*>  m_managers;
    492497
     498    /** Holds the map of various settings dialogs. */
     499    QMap<UISettingsDialog::DialogType, UISettingsDialog*>  m_settings;
     500
    493501    /** Holds the instance of UIVMLogViewerDialog. */
    494502    QIManagerDialog   *m_pLogViewerDialog;
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp

    r97389 r97390  
    4747#include "UICommon.h"
    4848#include "UIConverter.h"
     49#include "UIDesktopWidgetWatchdog.h"
    4950#include "UIExtraDataManager.h"
    5051#include "UIFileManagerDialog.h"
     
    15561557        return;
    15571558
    1558     /* Check that we do NOT handling that already: */
    1559     if (actionPool()->action(UIActionIndex_M_Application_S_Preferences)->data().toBool())
    1560         return;
    1561     /* Remember that we handling that already: */
    1562     actionPool()->action(UIActionIndex_M_Application_S_Preferences)->setData(true);
    1563 
    1564     /* Create and execute global settings window: */
    1565     QPointer<UISettingsDialogGlobal> pDialog = new UISettingsDialogGlobal(activeMachineWindow(),
    1566                                                                           strCategory, strControl);
    1567     pDialog->execute();
    1568     if (pDialog)
    1569         delete pDialog;
    1570 
    1571     /* Remember that we do NOT handling that already: */
    1572     actionPool()->action(UIActionIndex_M_Application_S_Preferences)->setData(false);
     1559    /* Create instance if not yet created: */
     1560    if (!m_settings.contains(UISettingsDialog::DialogType_Global))
     1561    {
     1562        m_settings[UISettingsDialog::DialogType_Global] = new UISettingsDialogGlobal(activeMachineWindow(),
     1563                                                                                     strCategory,
     1564                                                                                     strControl);
     1565        connect(m_settings[UISettingsDialog::DialogType_Global], &UISettingsDialogGlobal::sigClose,
     1566                this, &UIMachineLogic::sltClosePreferencesDialog);
     1567        m_settings.value(UISettingsDialog::DialogType_Global)->load();
     1568    }
     1569
     1570    /* Expose instance: */
     1571    UIDesktopWidgetWatchdog::restoreWidget(m_settings.value(UISettingsDialog::DialogType_Global));
     1572}
     1573
     1574void UIMachineLogic::sltClosePreferencesDialog()
     1575{
     1576    /* Remove instance if exist: */
     1577    delete m_settings.take(UISettingsDialog::DialogType_Global);
    15731578}
    15741579
     
    16111616        return;
    16121617
    1613     /* Create VM settings window on the heap!
    1614      * Its necessary to allow QObject hierarchy cleanup to delete this dialog if necessary: */
    1615     QPointer<UISettingsDialogMachine> pDialog = new UISettingsDialogMachine(activeMachineWindow(),
    1616                                                                             machine().GetId(),
    1617                                                                             strCategory, strControl, actionPool());
    1618     /* Executing VM settings window.
    1619      * This blocking function calls for the internal event-loop to process all further events,
    1620      * including event which can delete the dialog itself. */
    1621     pDialog->execute();
    1622     /* Delete dialog if its still valid: */
    1623     if (pDialog)
    1624         delete pDialog;
     1618    /* Create instance if not yet created: */
     1619    if (!m_settings.contains(UISettingsDialog::DialogType_Machine))
     1620    {
     1621        m_settings[UISettingsDialog::DialogType_Machine] = new UISettingsDialogMachine(activeMachineWindow(),
     1622                                                                                       machine().GetId(),
     1623                                                                                       strCategory,
     1624                                                                                       strControl,
     1625                                                                                       actionPool());
     1626        connect(m_settings[UISettingsDialog::DialogType_Machine], &UISettingsDialogGlobal::sigClose,
     1627                this, &UIMachineLogic::sltCloseSettingsDialog);
     1628        m_settings.value(UISettingsDialog::DialogType_Machine)->load();
     1629    }
     1630
     1631    /* Expose instance: */
     1632    UIDesktopWidgetWatchdog::restoreWidget(m_settings.value(UISettingsDialog::DialogType_Machine));
     1633}
     1634
     1635void UIMachineLogic::sltCloseSettingsDialog()
     1636{
     1637    /* Remove instance if exist: */
     1638    delete m_settings.take(UISettingsDialog::DialogType_Machine);
    16251639
    16261640    /* We can't rely on MediumChange events as they are not yet properly implemented within Main.
     
    27672781    sltCloseSoftKeyboard();
    27682782    sltSwitchKeyboardLedsToPreviousLeds();
     2783    sltCloseSettingsDialog();
     2784    sltClosePreferencesDialog();
    27692785}
    27702786
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h

    r97389 r97390  
    3535#include "QIWithRetranslateUI.h"
    3636#include "UIExtraDataDefs.h"
     37#include "UISettingsDialog.h"
    3738
    3839/* COM includes: */
     
    264265    void sltOpenPreferencesDialog(const QString &strCategory = QString(), const QString &strControl = QString());
    265266    void sltOpenPreferencesDialogDefault() { sltOpenPreferencesDialog(); }
     267    void sltClosePreferencesDialog();
    266268    void sltClose();
    267269
     
    269271    void sltOpenSettingsDialog(const QString &strCategory = QString(), const QString &strControl = QString());
    270272    void sltOpenSettingsDialogDefault() { sltOpenSettingsDialog(); }
     273    void sltCloseSettingsDialog();
    271274    void sltTakeSnapshot();
    272275    void sltShowInformationDialog();
     
    447450    bool m_fIsHidLedsSyncEnabled;
    448451
     452    /** Holds the map of settings dialogs. */
     453    QMap<UISettingsDialog::DialogType, UISettingsDialog*>  m_settings;
     454
    449455    /** Holds the log viewer dialog instance. */
    450456    QIManagerDialog       *m_pLogViewerDialog;
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp

    r97383 r97390  
    4040#include "UICommon.h"
    4141#include "UIConverter.h"
     42#include "UIDesktopWidgetWatchdog.h"
    4243#include "UIIconPool.h"
    4344#include "UIMessageCenter.h"
     
    6061
    6162UISettingsDialog::UISettingsDialog(QWidget *pParent)
    62     : QIWithRetranslateUI<QIMainDialog>(pParent)
     63    : QIWithRetranslateUI<QMainWindow>(pParent)
    6364    , m_pSelector(0)
    6465    , m_pStack(0)
    6566    , m_enmConfigurationAccessLevel(ConfigurationAccessLevel_Null)
    6667    , m_pSerializeProcess(0)
     68    , m_fPolished(false)
    6769    , m_fSerializationIsInProgress(false)
    6870    , m_fSerializationClean(true)
     71    , m_fClosed(false)
    6972    , m_pStatusBar(0)
    7073    , m_pProcessBar(0)
     
    97100}
    98101
    99 void UISettingsDialog::execute()
    100 {
    101     /* Load data: */
    102     load();
    103 
    104     /* Execute dialog: */
    105     exec();
    106 }
    107 
    108102void UISettingsDialog::accept()
    109103{
     
    114108    if (m_fSerializationClean)
    115109    {
    116         /* Call to base-class: */
    117         QIWithRetranslateUI<QIMainDialog>::accept();
     110        /* Tell the listener to close us (once): */
     111        if (!m_fClosed)
     112        {
     113            m_fClosed = true;
     114            emit sigClose();
     115        }
    118116    }
    119117}
     
    122120{
    123121    if (!isSerializationInProgress())
    124         QIWithRetranslateUI<QIMainDialog>::reject();
     122        close();
    125123}
    126124
     
    222220    /* Ignore objects which are NOT widgets: */
    223221    if (!pObject->isWidgetType())
    224         return QIMainDialog::eventFilter(pObject, pEvent);
     222        return QMainWindow::eventFilter(pObject, pEvent);
    225223
    226224    /* Ignore widgets which window is NOT settings window: */
    227225    QWidget *pWidget = static_cast<QWidget*>(pObject);
    228226    if (pWidget->window() != this)
    229         return QIMainDialog::eventFilter(pObject, pEvent);
     227        return QMainWindow::eventFilter(pObject, pEvent);
    230228
    231229    /* Process different event-types: */
     
    255253
    256254    /* Base-class processing: */
    257     return QIMainDialog::eventFilter(pObject, pEvent);
     255    return QMainWindow::eventFilter(pObject, pEvent);
    258256}
    259257
     
    281279}
    282280
    283 void UISettingsDialog::polishEvent(QShowEvent *pEvent)
     281void UISettingsDialog::showEvent(QShowEvent *pEvent)
     282{
     283    /* Polish stuff: */
     284    if (!m_fPolished)
     285    {
     286        m_fPolished = true;
     287        polishEvent(pEvent);
     288    }
     289
     290    /* Call to base-class: */
     291    QIWithRetranslateUI<QMainWindow>::showEvent(pEvent);
     292}
     293
     294void UISettingsDialog::polishEvent(QShowEvent*)
    284295{
    285296    /* Check what's the minimum selector size: */
     
    339350#endif /* VBOX_WS_MAC */
    340351
    341     /* Call to base-class: */
    342     QIWithRetranslateUI<QIMainDialog>::polishEvent(pEvent);
     352    /* Explicit centering according to our parent: */
     353    UIDesktopWidgetWatchdog::centerWidget(this, parentWidget(), false);
    343354}
    344355
    345356void UISettingsDialog::closeEvent(QCloseEvent *pEvent)
    346357{
     358    /* Ignore event initially: */
     359    pEvent->ignore();
     360
    347361    /* Check whether there are unsaved settings
    348362     * which will be lost in such case: */
     
    350364        || msgCenter().confirmSettingsDiscarding(this))
    351365    {
    352         /* Call to base-class: */
    353         QIWithRetranslateUI<QIMainDialog>::closeEvent(pEvent);
    354     }
    355     else
    356     {
    357         /* Otherwise ignore this: */
    358         pEvent->ignore();
     366        /* Tell the listener to close us (once): */
     367        if (!m_fClosed)
     368        {
     369            m_fClosed = true;
     370            emit sigClose();
     371        }
    359372    }
    360373}
     
    714727    if (m_pButtonBox)
    715728    {
    716         m_pButtonBox->button(QDialogButtonBox::Ok)->setDefault(true);
    717 
    718729        /* Create status-bar: */
    719730        m_pStatusBar = new QStackedWidget;
     
    821832                                                 QDialogButtonBox::NoButton);
    822833#endif
     834                m_pButtonBox->button(QDialogButtonBox::Ok)->setShortcut(Qt::Key_Return);
     835                m_pButtonBox->button(QDialogButtonBox::Cancel)->setShortcut(Qt::Key_Escape);
    823836                connect(m_pButtonBox, &QIDialogButtonBox::rejected, this, &UISettingsDialog::close);
    824837                connect(m_pButtonBox, &QIDialogButtonBox::accepted, this, &UISettingsDialog::accept);
  • trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h

    r97384 r97390  
    3333
    3434/* Qt includes: */
     35#include <QMainWindow>
    3536#include <QPointer>
    3637#include <QVariant>
    3738
    3839/* GUI includes: */
    39 #include "QIMainDialog.h"
    4040#include "QIWithRetranslateUI.h"
    4141#include "UISettingsDefs.h"
     
    5959using namespace UISettingsDefs;
    6060
    61 /** QIMainDialog subclass used as
     61/** QMainWindow subclass used as
    6262  * base dialog class for both Global Preferences & Machine Settings
    6363  * dialogs, which encapsulates most of their common functionality. */
    64 class SHARED_LIBRARY_STUFF UISettingsDialog : public QIWithRetranslateUI<QIMainDialog>
     64class SHARED_LIBRARY_STUFF UISettingsDialog : public QIWithRetranslateUI<QMainWindow>
    6565{
    6666    Q_OBJECT;
     67
     68signals:
     69
     70    /** Notifies listeners about dialog should be closed. */
     71    void sigClose();
    6772
    6873public:
     
    7984    virtual DialogType dialogType() const = 0;
    8085
    81     /** Performs modal dialog call. */
    82     void execute();
     86    /** Loads the dialog data. */
     87    virtual void load() = 0;
     88    /** Saves the dialog data. */
     89    virtual void save() = 0;
    8390
    8491protected slots:
     
    108115    /** Handles translation event. */
    109116    virtual void retranslateUi() RT_OVERRIDE;
     117    /** Handles show @a pEvent. */
     118    virtual void showEvent(QShowEvent *pEvent) RT_OVERRIDE;
    110119    /** Handles first show @a pEvent. */
    111     virtual void polishEvent(QShowEvent *pEvent) RT_OVERRIDE;
     120    virtual void polishEvent(QShowEvent *pEvent);
    112121    /** Handles close @a pEvent. */
    113122    virtual void closeEvent(QCloseEvent *pEvent) RT_OVERRIDE;
     
    117126    /** Saves the dialog @a data. */
    118127    void saveData(QVariant &data);
    119 
    120     /** Loads the dialog data. */
    121     virtual void load() = 0;
    122     /** Saves the dialog data. */
    123     virtual void save() = 0;
    124128
    125129    /** Returns configuration access level. */
     
    199203    UISettingsSerializer *m_pSerializeProcess;
    200204
     205    /** Holds whether dialog is polished. */
     206    bool  m_fPolished;
    201207    /** Holds whether the serialization is in progress. */
    202208    bool  m_fSerializationIsInProgress;
    203209    /** Holds whether there were no serialization errors. */
    204210    bool  m_fSerializationClean;
     211    /** Holds whether the dialod had emitted signal to be closed. */
     212    bool  m_fClosed;
    205213
    206214    /** Holds the status-bar widget 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