VirtualBox

Changeset 68999 in vbox


Ignore:
Timestamp:
Oct 6, 2017 10:06:04 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8674: A bit of rework for UIProgressDialog (part 2): Renaming variables and reworking widget creation cascade.

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

Legend:

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

    r68998 r68999  
    5454                                   QWidget *pParent /* = 0 */)
    5555    : QIWithRetranslateUI2<QIDialog>(pParent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint)
    56     , m_progress(progress)
    57     , m_pImageLbl(0)
     56    , m_comProgress(progress)
     57    , m_pLabelImage(0)
     58    , m_pLabelDescription(0)
     59    , m_pProgressBar(0)
     60    , m_pButtonCancel(0)
     61    , m_pLabelEta(0)
    5862    , m_fCancelEnabled(false)
    59     , m_cOperations(m_progress.GetOperationCount())
    60     , m_iCurrentOperation(m_progress.GetOperation() + 1)
     63    , m_cOperations(m_comProgress.GetOperationCount())
     64    , m_uCurrentOperation(m_comProgress.GetOperation() + 1)
    6165    , m_fEnded(false)
    6266{
    6367    /* Setup dialog: */
    64     setWindowTitle(QString("%1: %2").arg(strTitle, m_progress.GetDescription()));
     68    setWindowTitle(QString("%1: %2").arg(strTitle, m_comProgress.GetDescription()));
    6569    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     70#ifdef VBOX_WS_MAC
     71    ::darwinSetHidesAllTitleButtons(this);
     72#endif
    6673
    6774    /* Create main layout: */
    6875    QHBoxLayout *pMainLayout = new QHBoxLayout(this);
    69     /* Configure layout: */
     76    {
     77        /* Configure layout: */
    7078#ifdef VBOX_WS_MAC
    71     ::darwinSetHidesAllTitleButtons(this);
    72     if (pImage)
    73         pMainLayout->setContentsMargins(30, 15, 30, 15);
    74     else
    75         pMainLayout->setContentsMargins(6, 6, 6, 6);
     79        if (pImage)
     80            pMainLayout->setContentsMargins(30, 15, 30, 15);
     81        else
     82            pMainLayout->setContentsMargins(6, 6, 6, 6);
    7683#endif
    7784
    78     /* If there is image: */
    79     if (pImage)
    80     {
    81         /* Create image label: */
    82         m_pImageLbl = new QLabel(this);
    83         /* Configure label: */
    84         m_pImageLbl->setPixmap(*pImage);
    85         /* Add into layout: */
    86         pMainLayout->addWidget(m_pImageLbl);
    87     }
    88 
    89     /* Create description label: */
    90     m_pDescriptionLbl = new QILabel(this);
    91     /* Configure label: */
    92     if (m_cOperations > 1)
    93         m_pDescriptionLbl->setText(QString(m_spcszOpDescTpl)
    94                                            .arg(m_progress.GetOperationDescription())
    95                                            .arg(m_iCurrentOperation).arg(m_cOperations));
    96     else
    97         m_pDescriptionLbl->setText(QString("%1 ...")
    98                                            .arg(m_progress.GetOperationDescription()));
    99 
    100     /* Create progress-bar: */
    101     m_pProgressBar = new QProgressBar(this);
    102     /* Configure progress-bar: */
    103     m_pProgressBar->setMaximum(100);
    104     m_pProgressBar->setValue(0);
    105 
    106     /* Create cancel button: */
    107     m_fCancelEnabled = m_progress.GetCancelable();
    108     m_pCancelBtn = new UIMiniCancelButton(this);
    109     /* Configure cancel button: */
    110     m_pCancelBtn->setEnabled(m_fCancelEnabled);
    111     m_pCancelBtn->setFocusPolicy(Qt::ClickFocus);
    112     connect(m_pCancelBtn, SIGNAL(clicked()), this, SLOT(sltCancelOperation()));
    113 
    114     /* Create estimation label: */
    115     m_pEtaLbl = new QILabel(this);
    116 
    117     /* Create proggress layout: */
    118     QHBoxLayout *pProgressLayout = new QHBoxLayout;
    119     /* Configure layout: */
    120     pProgressLayout->setMargin(0);
    121     /* Add into layout: */
    122     pProgressLayout->addWidget(m_pProgressBar, 0, Qt::AlignVCenter);
    123     pProgressLayout->addWidget(m_pCancelBtn, 0, Qt::AlignVCenter);
    124 
    125     /* Create description layout: */
    126     QVBoxLayout *pDescriptionLayout = new QVBoxLayout;
    127     /* Configure layout: */
    128     pDescriptionLayout->setMargin(0);
    129     /* Add stretch: */
    130     pDescriptionLayout->addStretch(1);
    131     /* Add into layout: */
    132     pDescriptionLayout->addWidget(m_pDescriptionLbl, 0, Qt::AlignHCenter);
    133     pDescriptionLayout->addLayout(pProgressLayout);
    134     pDescriptionLayout->addWidget(m_pEtaLbl, 0, Qt::AlignLeft | Qt::AlignVCenter);
    135     /* Add stretch: */
    136     pDescriptionLayout->addStretch(1);
    137     /* Add into layout: */
    138     pMainLayout->addLayout(pDescriptionLayout);
     85        /* If there is image: */
     86        if (pImage)
     87        {
     88            /* Create image label: */
     89            m_pLabelImage = new QLabel;
     90            {
     91                /* Configure label: */
     92                m_pLabelImage->setPixmap(*pImage);
     93
     94                /* Add into layout: */
     95                pMainLayout->addWidget(m_pLabelImage);
     96            }
     97        }
     98
     99        /* Create description layout: */
     100        QVBoxLayout *pDescriptionLayout = new QVBoxLayout;
     101        {
     102            /* Configure layout: */
     103            pDescriptionLayout->setMargin(0);
     104
     105            /* Add stretch: */
     106            pDescriptionLayout->addStretch(1);
     107
     108            /* Create description label: */
     109            m_pLabelDescription = new QILabel;
     110            {
     111                /* Configure label: */
     112                if (m_cOperations > 1)
     113                    m_pLabelDescription->setText(QString(m_spcszOpDescTpl)
     114                                                 .arg(m_comProgress.GetOperationDescription())
     115                                                 .arg(m_uCurrentOperation).arg(m_cOperations));
     116                else
     117                    m_pLabelDescription->setText(QString("%1 ...")
     118                                                 .arg(m_comProgress.GetOperationDescription()));
     119
     120                /* Add into layout: */
     121                pDescriptionLayout->addWidget(m_pLabelDescription, 0, Qt::AlignHCenter);
     122            }
     123
     124            /* Create proggress layout: */
     125            QHBoxLayout *pProgressLayout = new QHBoxLayout;
     126            {
     127                /* Configure layout: */
     128                pProgressLayout->setMargin(0);
     129
     130                /* Create progress-bar: */
     131                m_pProgressBar = new QProgressBar;
     132                {
     133                    /* Configure progress-bar: */
     134                    m_pProgressBar->setMaximum(100);
     135                    m_pProgressBar->setValue(0);
     136
     137                    /* Add into layout: */
     138                    pProgressLayout->addWidget(m_pProgressBar, 0, Qt::AlignVCenter);
     139                }
     140
     141                /* Create cancel button: */
     142                m_pButtonCancel = new UIMiniCancelButton;
     143                {
     144                    /* Configure cancel button: */
     145                    m_fCancelEnabled = m_comProgress.GetCancelable();
     146                    m_pButtonCancel->setEnabled(m_fCancelEnabled);
     147                    m_pButtonCancel->setFocusPolicy(Qt::ClickFocus);
     148                    connect(m_pButtonCancel, SIGNAL(clicked()), this, SLOT(sltCancelOperation()));
     149
     150                    /* Add into layout: */
     151                    pProgressLayout->addWidget(m_pButtonCancel, 0, Qt::AlignVCenter);
     152                }
     153
     154                /* Add into layout: */
     155                pDescriptionLayout->addLayout(pProgressLayout);
     156            }
     157
     158            /* Create estimation label: */
     159            m_pLabelEta = new QILabel;
     160            {
     161                /* Add into layout: */
     162                pDescriptionLayout->addWidget(m_pLabelEta, 0, Qt::AlignLeft | Qt::AlignVCenter);
     163            }
     164
     165            /* Add stretch: */
     166            pDescriptionLayout->addStretch(1);
     167
     168            /* Add into layout: */
     169            pMainLayout->addLayout(pDescriptionLayout);
     170        }
     171    }
    139172
    140173    /* Translate finally: */
     
    149182{
    150183    /* Wait for CProgress to complete: */
    151     m_progress.WaitForCompletion(-1);
     184    m_comProgress.WaitForCompletion(-1);
    152185
    153186    /* Call the timer event handling delegate: */
     
    157190void UIProgressDialog::retranslateUi()
    158191{
    159     m_strCancel = tr("Canceling...");
    160     m_pCancelBtn->setText(tr("&Cancel"));
    161     m_pCancelBtn->setToolTip(tr("Cancel the current operation"));
     192    m_pButtonCancel->setText(tr("&Cancel"));
     193    m_pButtonCancel->setToolTip(tr("Cancel the current operation"));
    162194}
    163195
    164196int UIProgressDialog::run(int cRefreshInterval)
    165197{
    166     if (m_progress.isOk())
     198    if (m_comProgress.isOk())
    167199    {
    168200        /* Start refresh timer: */
     
    240272void UIProgressDialog::sltCancelOperation()
    241273{
    242     m_pCancelBtn->setEnabled(false);
    243     m_progress.Cancel();
     274    m_pButtonCancel->setEnabled(false);
     275    m_comProgress.Cancel();
    244276}
    245277
     
    259291        return;
    260292
    261     if (!m_fEnded && (!m_progress.isOk() || m_progress.GetCompleted()))
     293    if (!m_fEnded && (!m_comProgress.isOk() || m_comProgress.GetCompleted()))
    262294    {
    263295        /* Is this progress-dialog a top-level modal-dialog now? */
     
    265297        {
    266298            /* Progress finished: */
    267             if (m_progress.isOk())
     299            if (m_comProgress.isOk())
    268300            {
    269301                m_pProgressBar->setValue(100);
     
    284316
    285317    /* Update the progress dialog: */
    286     if (!m_progress.GetCanceled())
     318    if (!m_comProgress.GetCanceled())
    287319    {
    288320        /* Update ETA: */
    289         long newTime = m_progress.GetTimeRemaining();
    290         long seconds;
    291         long minutes;
    292         long hours;
    293         long days;
    294 
    295         seconds  = newTime < 0 ? 0 : newTime;
    296         minutes  = seconds / 60;
    297         seconds -= minutes * 60;
    298         hours    = minutes / 60;
    299         minutes -= hours   * 60;
    300         days     = hours   / 24;
    301         hours   -= days    * 24;
    302 
    303         QString strDays = VBoxGlobal::daysToString(days);
    304         QString strHours = VBoxGlobal::hoursToString(hours);
    305         QString strMinutes = VBoxGlobal::minutesToString(minutes);
    306         QString strSeconds = VBoxGlobal::secondsToString(seconds);
    307 
    308         QString strTwoComp = tr("%1, %2 remaining", "You may wish to translate this more like \"Time remaining: %1, %2\"");
    309         QString strOneComp = tr("%1 remaining", "You may wish to translate this more like \"Time remaining: %1\"");
    310 
    311         if      (days > 1 && hours > 0)
    312             m_pEtaLbl->setText(strTwoComp.arg(strDays).arg(strHours));
    313         else if (days > 1)
    314             m_pEtaLbl->setText(strOneComp.arg(strDays));
    315         else if (days > 0 && hours > 0)
    316             m_pEtaLbl->setText(strTwoComp.arg(strDays).arg(strHours));
    317         else if (days > 0 && minutes > 5)
    318             m_pEtaLbl->setText(strTwoComp.arg(strDays).arg(strMinutes));
    319         else if (days > 0)
    320             m_pEtaLbl->setText(strOneComp.arg(strDays));
    321         else if (hours > 2)
    322             m_pEtaLbl->setText(strOneComp.arg(strHours));
    323         else if (hours > 0 && minutes > 0)
    324             m_pEtaLbl->setText(strTwoComp.arg(strHours).arg(strMinutes));
    325         else if (hours > 0)
    326             m_pEtaLbl->setText(strOneComp.arg(strHours));
    327         else if (minutes > 2)
    328             m_pEtaLbl->setText(strOneComp.arg(strMinutes));
    329         else if (minutes > 0 && seconds > 5)
    330             m_pEtaLbl->setText(strTwoComp.arg(strMinutes).arg(strSeconds));
    331         else if (minutes > 0)
    332             m_pEtaLbl->setText(strOneComp.arg(strMinutes));
    333         else if (seconds > 5)
    334             m_pEtaLbl->setText(strOneComp.arg(strSeconds));
    335         else if (seconds > 0)
    336             m_pEtaLbl->setText(tr("A few seconds remaining"));
     321        const long iNewTime = m_comProgress.GetTimeRemaining();
     322        long iSeconds;
     323        long iMinutes;
     324        long iHours;
     325        long iDays;
     326
     327        iSeconds  = iNewTime < 0 ? 0 : iNewTime;
     328        iMinutes  = iSeconds / 60;
     329        iSeconds -= iMinutes * 60;
     330        iHours    = iMinutes / 60;
     331        iMinutes -= iHours   * 60;
     332        iDays     = iHours   / 24;
     333        iHours   -= iDays    * 24;
     334
     335        const QString strDays = VBoxGlobal::daysToString(iDays);
     336        const QString strHours = VBoxGlobal::hoursToString(iHours);
     337        const QString strMinutes = VBoxGlobal::minutesToString(iMinutes);
     338        const QString strSeconds = VBoxGlobal::secondsToString(iSeconds);
     339
     340        const QString strTwoComp = tr("%1, %2 remaining", "You may wish to translate this more like \"Time remaining: %1, %2\"");
     341        const QString strOneComp = tr("%1 remaining", "You may wish to translate this more like \"Time remaining: %1\"");
     342
     343        if      (iDays > 1 && iHours > 0)
     344            m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strHours));
     345        else if (iDays > 1)
     346            m_pLabelEta->setText(strOneComp.arg(strDays));
     347        else if (iDays > 0 && iHours > 0)
     348            m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strHours));
     349        else if (iDays > 0 && iMinutes > 5)
     350            m_pLabelEta->setText(strTwoComp.arg(strDays).arg(strMinutes));
     351        else if (iDays > 0)
     352            m_pLabelEta->setText(strOneComp.arg(strDays));
     353        else if (iHours > 2)
     354            m_pLabelEta->setText(strOneComp.arg(strHours));
     355        else if (iHours > 0 && iMinutes > 0)
     356            m_pLabelEta->setText(strTwoComp.arg(strHours).arg(strMinutes));
     357        else if (iHours > 0)
     358            m_pLabelEta->setText(strOneComp.arg(strHours));
     359        else if (iMinutes > 2)
     360            m_pLabelEta->setText(strOneComp.arg(strMinutes));
     361        else if (iMinutes > 0 && iSeconds > 5)
     362            m_pLabelEta->setText(strTwoComp.arg(strMinutes).arg(strSeconds));
     363        else if (iMinutes > 0)
     364            m_pLabelEta->setText(strOneComp.arg(strMinutes));
     365        else if (iSeconds > 5)
     366            m_pLabelEta->setText(strOneComp.arg(strSeconds));
     367        else if (iSeconds > 0)
     368            m_pLabelEta->setText(tr("A few seconds remaining"));
    337369        else
    338             m_pEtaLbl->clear();
     370            m_pLabelEta->clear();
    339371
    340372        /* Then operation text (if changed): */
    341         ulong newOp = m_progress.GetOperation() + 1;
    342         if (newOp != m_iCurrentOperation)
     373        ulong uNewOp = m_comProgress.GetOperation() + 1;
     374        if (uNewOp != m_uCurrentOperation)
    343375        {
    344             m_iCurrentOperation = newOp;
    345             m_pDescriptionLbl->setText(QString(m_spcszOpDescTpl)
    346                                        .arg(m_progress.GetOperationDescription())
    347                                        .arg(m_iCurrentOperation).arg(m_cOperations));
     376            m_uCurrentOperation = uNewOp;
     377            m_pLabelDescription->setText(QString(m_spcszOpDescTpl)
     378                                       .arg(m_comProgress.GetOperationDescription())
     379                                       .arg(m_uCurrentOperation).arg(m_cOperations));
    348380        }
    349381        /* Update operation percentage: */
    350         m_pProgressBar->setValue(m_progress.GetPercent());
     382        m_pProgressBar->setValue(m_comProgress.GetPercent());
    351383
    352384        /* Then cancel button: */
    353         m_fCancelEnabled = m_progress.GetCancelable();
    354         m_pCancelBtn->setEnabled(m_fCancelEnabled);
     385        m_fCancelEnabled = m_comProgress.GetCancelable();
     386        m_pButtonCancel->setEnabled(m_fCancelEnabled);
    355387
    356388        /* Notify listeners about the operation progress update: */
    357         emit sigProgressChange(m_cOperations, m_progress.GetOperationDescription(),
    358                                m_progress.GetOperation() + 1, m_progress.GetPercent());
     389        emit sigProgressChange(m_cOperations, m_comProgress.GetOperationDescription(),
     390                               m_comProgress.GetOperation() + 1, m_comProgress.GetPercent());
    359391    }
    360392    /* Mark progress canceled if so: */
    361393    else
    362         m_pEtaLbl->setText(m_strCancel);
     394        m_pLabelEta->setText(tr("Canceling..."));
    363395}
    364396
     
    366398UIProgress::UIProgress(CProgress &progress, QObject *pParent /* = 0 */)
    367399    : QObject(pParent)
    368     , m_progress(progress)
    369     , m_cOperations(m_progress.GetOperationCount())
     400    , m_comProgress(progress)
     401    , m_cOperations(m_comProgress.GetOperationCount())
    370402    , m_fEnded(false)
    371403{
     
    375407{
    376408    /* Make sure the CProgress still valid: */
    377     if (!m_progress.isOk())
     409    if (!m_comProgress.isOk())
    378410        return;
    379411
     
    411443
    412444    /* If progress had failed or finished: */
    413     if (!m_progress.isOk() || m_progress.GetCompleted())
     445    if (!m_comProgress.isOk() || m_comProgress.GetCompleted())
    414446    {
    415447        /* Notify listeners about the operation progress error: */
    416         if (!m_progress.isOk() || m_progress.GetResultCode() != 0)
    417             emit sigProgressError(UIErrorString::formatErrorInfo(m_progress));
     448        if (!m_comProgress.isOk() || m_comProgress.GetResultCode() != 0)
     449            emit sigProgressError(UIErrorString::formatErrorInfo(m_comProgress));
    418450
    419451        /* Exit from the event-loop if there is any: */
     
    429461
    430462    /* If CProgress was not yet canceled: */
    431     if (!m_progress.GetCanceled())
     463    if (!m_comProgress.GetCanceled())
    432464    {
    433465        /* Notify listeners about the operation progress update: */
    434         emit sigProgressChange(m_cOperations, m_progress.GetOperationDescription(),
    435                                m_progress.GetOperation() + 1, m_progress.GetPercent());
    436     }
    437 }
    438 
     466        emit sigProgressChange(m_cOperations, m_comProgress.GetOperationDescription(),
     467                               m_comProgress.GetOperation() + 1, m_comProgress.GetPercent());
     468    }
     469}
     470
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h

    r68998 r68999  
    1616 */
    1717
    18 #ifndef __UIProgressDialog_h__
    19 #define __UIProgressDialog_h__
     18#ifndef ___UIProgressDialog_h___
     19#define ___UIProgressDialog_h___
    2020
    2121/* GUI includes: */
     
    3737  * @note The CProgress instance is passed as a non-const reference to the constructor (to memorize COM errors if they happen),
    3838  *       and therefore must not be destroyed before the created UIProgressDialog instance is destroyed. */
    39 class UIProgressDialog: public QIWithRetranslateUI2<QIDialog>
     39class UIProgressDialog : public QIWithRetranslateUI2<QIDialog>
    4040{
    4141    Q_OBJECT;
     
    4444
    4545    /** Constructs progress-dialog passing @a pParent to the base-class.
    46       * @param  progress   Brings the progress reference.
     46      * @param  comProgress   Brings the progress reference.
    4747      * @param  strTitle      Brings the progress-dialog title.
    4848      * @param  pImage        Brings the progress-dialog image.
    4949      * @param  cMinDuration  Brings the minimum duration before the progress-dialog is shown. */
    50     UIProgressDialog(CProgress &progress, const QString &strTitle,
     50    UIProgressDialog(CProgress &comProgress, const QString &strTitle,
    5151                     QPixmap *pImage = 0, int cMinDuration = 2000, QWidget *pParent = 0);
    5252    /** Destructs progress-dialog. */
    53     ~UIProgressDialog();
     53    virtual ~UIProgressDialog() /* override */;
    5454
    5555    /** Executes the progress-dialog within its loop with passed @a iRefreshInterval. */
    56     int run(int aRefreshInterval);
     56    int run(int iRefreshInterval);
    5757
    5858signals:
     
    7474
    7575    /** Handles translation event. */
    76     void retranslateUi();
     76    virtual void retranslateUi() /* override */;
    7777
    7878    /** Rejects dialog. */
    79     void reject();
     79    virtual void reject() /* override */;
    8080
    8181    /** Handles timer @a pEvent. */
    82     virtual void timerEvent(QTimerEvent *pEvent);
     82    virtual void timerEvent(QTimerEvent *pEvent) /* override */;
    8383    /** Handles close @a pEvent. */
    84     virtual void closeEvent(QCloseEvent *pEvent);
     84    virtual void closeEvent(QCloseEvent *pEvent) /* override */;
    8585
    8686private slots:
     
    9595
    9696    /** Holds the progress reference. */
    97     CProgress &m_progress;
     97    CProgress &m_comProgress;
    9898
    9999    /** Holds the image label instance. */
    100     QLabel             *m_pImageLbl;
     100    QLabel             *m_pLabelImage;
    101101    /** Holds the description label instance. */
    102     QILabel            *m_pDescriptionLbl;
     102    QILabel            *m_pLabelDescription;
    103103    /** Holds the progress-bar instance. */
    104104    QProgressBar       *m_pProgressBar;
    105105    /** Holds the cancel button instance. */
    106     UIMiniCancelButton *m_pCancelBtn;
     106    UIMiniCancelButton *m_pButtonCancel;
    107107    /** Holds the ETA label instance. */
    108     QILabel            *m_pEtaLbl;
     108    QILabel            *m_pLabelEta;
    109109
    110110    /** Holds whether progress cancel is enabled. */
    111111    bool         m_fCancelEnabled;
    112     /** Holds the translated canceling tag. */
    113     QString      m_strCancel;
    114112    /** Holds the amount of operations. */
    115113    const ulong  m_cOperations;
    116114    /** Holds the number of current operation. */
    117     ulong        m_iCurrentOperation;
     115    ulong        m_uCurrentOperation;
    118116    /** Holds whether the progress has ended. */
    119117    bool         m_fEnded;
     
    151149
    152150    /** Constructs progress handler passing @a pParent to the base-class.
    153       * @param  progress  Brings the progress reference. */
    154     UIProgress(CProgress &progress, QObject *pParent = 0);
     151      * @param  comProgress  Brings the progress reference. */
     152    UIProgress(CProgress &comProgress, QObject *pParent = 0);
    155153
    156154    /** Executes the progress-handler within its loop with passed @a iRefreshInterval. */
     
    160158
    161159    /** Handles timer @a pEvent. */
    162     virtual void timerEvent(QTimerEvent *pEvent);
     160    virtual void timerEvent(QTimerEvent *pEvent) /* override */;
    163161
    164162    /** Holds the progress reference. */
    165     CProgress &m_progress;
     163    CProgress &m_comProgress;
    166164
    167165    /** Holds the amount of operations. */
     
    174172};
    175173
    176 #endif /* !__UIProgressDialog_h__ */
     174#endif /* !___UIProgressDialog_h___ */
    177175
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