VirtualBox

Changeset 45162 in vbox


Ignore:
Timestamp:
Mar 25, 2013 11:35:01 AM (12 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
84485
Message:

FE/Qt: QIDialog cleanup (part 1).

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

Legend:

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

    r44528 r45162  
    77
    88/*
    9  * Copyright (C) 2008-2012 Oracle Corporation
     9 * Copyright (C) 2008-2013 Oracle Corporation
    1010 *
    1111 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818 */
    1919
    20 /* VBox includes */
     20/* GUI includes: */
    2121#include "QIDialog.h"
    2222#include "VBoxGlobal.h"
     
    2525#endif /* Q_WS_MAC */
    2626
    27 QIDialog::QIDialog (QWidget *aParent /* = 0 */, Qt::WindowFlags aFlags /* = 0 */)
    28     : QDialog (aParent, aFlags)
    29     , mPolished (false)
     27QIDialog::QIDialog(QWidget *pParent /* = 0 */, Qt::WindowFlags flags /* = 0 */)
     28    : QDialog(pParent, flags)
     29    , m_fPolished(false)
    3030{
    3131}
    3232
    33 void QIDialog::showEvent (QShowEvent * /* aEvent */)
     33QIDialog::~QIDialog()
     34{
     35}
     36
     37void QIDialog::showEvent(QShowEvent * /* pEvent */)
    3438{
    3539    /* Two thinks to do for fixed size dialogs on MacOS X:
     
    4246    {
    4347        adjustSize();
    44         setFixedSize (size());
     48        setFixedSize(size());
    4549#ifdef Q_WS_MAC
    4650        ::darwinSetShowsResizeIndicator (this, false);
     
    4852    }
    4953
    50     /* Polishing border */
    51     if (mPolished)
     54    /* Polishing: */
     55    if (m_fPolished)
    5256        return;
    53     mPolished = true;
     57    m_fPolished = true;
    5458
    55     /* Explicit widget centering relatively to it's parent
    56      * if any or desktop if parent is missed. */
    57     VBoxGlobal::centerWidget (this, parentWidget(), false);
     59    /* Explicit centering according to our parent: */
     60    VBoxGlobal::centerWidget(this, parentWidget(), false);
    5861}
    5962
    60 int QIDialog::exec (bool aShow /* = true */)
     63int QIDialog::exec(bool fShow /* = true */)
    6164{
    62     /* Reset the result code */
    63     setResult (QDialog::Rejected);
     65    /* Reset the result-code: */
     66    setResult(QDialog::Rejected);
    6467
    65     bool wasDeleteOnClose = testAttribute (Qt::WA_DeleteOnClose);
    66     setAttribute (Qt::WA_DeleteOnClose, false);
     68    bool fWasDeleteOnClose = testAttribute(Qt::WA_DeleteOnClose);
     69    setAttribute(Qt::WA_DeleteOnClose, false);
    6770#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500
    6871    /* After 4.5 Qt changed the behavior of Sheets for the window/application
     
    7275     * the modal mode window, but be application modal in any case. */
    7376    Qt::WindowModality winModality = windowModality();
    74     bool wasSetWinModality = testAttribute (Qt::WA_SetWindowModality);
     77    bool wasSetWinModality = testAttribute(Qt::WA_SetWindowModality);
    7578    if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
    7679    {
    77         setWindowModality (Qt::WindowModal);
    78         setAttribute (Qt::WA_SetWindowModality, false);
     80        setWindowModality(Qt::WindowModal);
     81        setAttribute(Qt::WA_SetWindowModality, false);
    7982    }
    8083#endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */
    81     /* The dialog has to modal in any case. Save the current modality to
    82      * restore it later. */
    83     bool wasShowModal = testAttribute (Qt::WA_ShowModal);
    84     setAttribute (Qt::WA_ShowModal, true);
     84    /* The dialog has to modal in any case.
     85     * Save the current modality to restore it later. */
     86    bool wasShowModal = testAttribute(Qt::WA_ShowModal);
     87    setAttribute(Qt::WA_ShowModal, true);
    8588
    86     /* Create a local event loop */
     89    /* Create a local event-loop: */
    8790    QEventLoop eventLoop;
    88     mEventLoop = &eventLoop;
    89     /* Show the window if requested */
    90     if (aShow)
     91    m_pEventLoop = &eventLoop;
     92
     93    /* Show ourself if requested: */
     94    if (fShow)
    9195        show();
    92     /* A guard to ourself for the case we destroy ourself. */
     96
     97    /* Guard ourself for the case
     98     * we destroyed ourself in our event-loop: */
    9399    QPointer<QIDialog> guard = this;
    94     /* Start the event loop. This blocks. */
     100
     101    /* Start the blocking event-loop: */
    95102    eventLoop.exec();
    96     /* Are we valid anymore? */
     103
     104    /* Are we still valid? */
    97105    if (guard.isNull())
    98106        return QDialog::Rejected;
    99     mEventLoop = 0;
    100     /* Save the result code in case we delete ourself */
    101     QDialog::DialogCode res = (QDialog::DialogCode)result();
     107
     108    m_pEventLoop = 0;
     109
     110    /* Save the result-code early (we can delete ourself on close): */
     111    QDialog::DialogCode resultCode = (QDialog::DialogCode)result();
     112
    102113#if defined(Q_WS_MAC) && QT_VERSION >= 0x040500
    103     /* Restore old modality mode */
     114    /* Restore old modality mode: */
    104115    if ((windowFlags() & Qt::Sheet) == Qt::Sheet)
    105116    {
    106         setWindowModality (winModality);
    107         setAttribute (Qt::WA_SetWindowModality, wasSetWinModality);
     117        setWindowModality(winModality);
     118        setAttribute(Qt::WA_SetWindowModality, wasSetWinModality);
    108119    }
    109120#endif /* defined(Q_WS_MAC) && QT_VERSION >= 0x040500 */
     121
    110122    /* Set the old show modal attribute */
    111123    setAttribute (Qt::WA_ShowModal, wasShowModal);
    112     /* Delete us in the case we should do so on close */
    113     if (wasDeleteOnClose)
     124    /* Delete ourself if we should do that on close: */
     125    if (fWasDeleteOnClose)
    114126        delete this;
    115     /* Return the final result */
    116     return res;
     127
     128    /* Return the result-code: */
     129    return resultCode;
    117130}
    118131
    119 void QIDialog::setVisible (bool aVisible)
     132void QIDialog::setVisible(bool fVisible)
    120133{
    121     QDialog::setVisible (aVisible);
    122     /* Exit from the event loop if there is any and we are changing our state
    123      * from visible to invisible. */
    124     if (mEventLoop && !aVisible)
    125         mEventLoop->exit();
     134    /* Call to base-class: */
     135    QDialog::setVisible(fVisible);
     136
     137    /* Exit from the event-loop if
     138     * 1. there is any and
     139     * 2. we are changing our state from visible to invisible: */
     140    if (m_pEventLoop && !fVisible)
     141        m_pEventLoop->exit();
    126142}
    127143
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIDialog.h

    r44528 r45162  
    22 *
    33 * VBox frontends: Qt GUI ("VirtualBox"):
    4  * VirtualBox Qt extensions: QIDialog class implementation
     4 * VirtualBox Qt extensions: QIDialog class declaration
    55 */
    66
    77/*
    8  * Copyright (C) 2008-2012 Oracle Corporation
     8 * Copyright (C) 2008-2013 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#define __QIDialog_h__
    2121
    22 /* Qt includes */
     22/* Qt includes: */
    2323#include <QDialog>
    2424#include <QPointer>
    2525
    26 /* Qt forwards declarations */
     26/* Forward declarations: */
    2727class QEventLoop;
    2828
     29/* Qt dialog extension: */
    2930class QIDialog: public QDialog
    3031{
     
    3233
    3334public:
    34     QIDialog (QWidget *aParent = 0, Qt::WindowFlags aFlags = 0);
    35     void setVisible (bool aVisible);
     35
     36    /* Constructor/destructor: */
     37    QIDialog(QWidget *pParent = 0, Qt::WindowFlags flags = 0);
     38    ~QIDialog();
     39
     40    /* API: Visibility stuff: */
     41    void setVisible(bool fVisible);
    3642
    3743public slots:
    38     int exec (bool aShow = true);
     44
     45    /* API: Exec stuff: */
     46    int exec(bool fShow = true);
    3947
    4048protected:
    41     void showEvent (QShowEvent *aEvent);
     49
     50    /* Handler: Show-event stuff: */
     51    void showEvent(QShowEvent *pEvent);
    4252
    4353private:
    44     /* Private member vars */
    45     bool mPolished;
    46     QPointer<QEventLoop> mEventLoop;
     54
     55    /* Variables: */
     56    bool m_fPolished;
     57    QPointer<QEventLoop> m_pEventLoop;
    4758};
    4859
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