VirtualBox

Changeset 43857 in vbox


Ignore:
Timestamp:
Nov 12, 2012 12:40:08 PM (12 years ago)
Author:
vboxsync
Message:

FE/Qt: UIProgressDialog rework/cleanup.

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

Legend:

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

    r43855 r43857  
    4747                                   int cMinDuration /* = 2000 */,
    4848                                   QWidget *pParent /* = 0 */)
    49   : QIDialog(pParent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint)
    50   , m_progress(progress)
    51   , m_pImageLbl(0)
    52   , m_fCancelEnabled(false)
    53   , m_cOperations(m_progress.GetOperationCount())
    54   , m_iCurrentOperation(m_progress.GetOperation() + 1)
    55   , m_fEnded(false)
    56 {
     49    : QIWithRetranslateUI2<QIDialog>(pParent, Qt::MSWindowsFixedSizeDialogHint | Qt::WindowTitleHint)
     50    , m_progress(progress)
     51    , m_pImageLbl(0)
     52    , m_fCancelEnabled(false)
     53    , m_cOperations(m_progress.GetOperationCount())
     54    , m_iCurrentOperation(m_progress.GetOperation() + 1)
     55    , m_fEnded(false)
     56{
     57    /* Setup dialog: */
    5758    setModal(true);
    58 
    59     QHBoxLayout *pLayout0 = new QHBoxLayout(this);
     59    setWindowTitle(QString("%1: %2").arg(strTitle, m_progress.GetDescription()));
     60    setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
     61
     62    /* Create main layout: */
     63    QHBoxLayout *pMainLayout = new QHBoxLayout(this);
    6064
    6165#ifdef Q_WS_MAC
     
    6973    ::darwinSetShowsResizeIndicator(this, false);
    7074    if (pImage)
    71         pLayout0->setContentsMargins(30, 15, 30, 15);
     75        pMainLayout->setContentsMargins(30, 15, 30, 15);
    7276    else
    73         pLayout0->setContentsMargins(6, 6, 6, 6);
    74 #else
     77        pMainLayout->setContentsMargins(6, 6, 6, 6);
     78#else /* Q_WS_MAC */
    7579    NOREF(fSheetOnDarwin);
    76 #endif /* Q_WS_MAC */
    77 
     80#endif /* !Q_WS_MAC */
     81
     82    /* Create image: */
    7883    if (pImage)
    7984    {
    80         m_pImageLbl = new QILabel(this);
     85        m_pImageLbl = new QLabel(this);
    8186        m_pImageLbl->setPixmap(*pImage);
    82         pLayout0->addWidget(m_pImageLbl);
    83     }
    84 
    85     QVBoxLayout *pLayout1 = new QVBoxLayout();
    86     pLayout1->setMargin(0);
    87     pLayout0->addLayout(pLayout1);
    88     pLayout1->addStretch(1);
     87        pMainLayout->addWidget(m_pImageLbl);
     88    }
     89
     90    /* Create description: */
    8991    m_pDescriptionLbl = new QILabel(this);
    90     pLayout1->addWidget(m_pDescriptionLbl, 0, Qt::AlignHCenter);
    91 
    92     QHBoxLayout *pLayout2 = new QHBoxLayout();
    93     pLayout2->setMargin(0);
    94     pLayout1->addLayout(pLayout2);
    95 
    96     m_progressBar = new QProgressBar(this);
    97     pLayout2->addWidget(m_progressBar, 0, Qt::AlignVCenter);
    98 
    9992    if (m_cOperations > 1)
    10093        m_pDescriptionLbl->setText(QString(m_spcszOpDescTpl)
     
    10497        m_pDescriptionLbl->setText(QString("%1 ...")
    10598                                   .arg(m_progress.GetOperationDescription()));
    106     m_progressBar->setMaximum(100);
    107     setWindowTitle(QString("%1: %2").arg(strTitle, m_progress.GetDescription()));
    108     m_progressBar->setValue(0);
     99
     100    /* Create progress-bar: */
     101    m_pProgressBar = new QProgressBar(this);
     102    m_pProgressBar->setMaximum(100);
     103    m_pProgressBar->setValue(0);
     104
     105    /* Create cancel button: */
    109106    m_fCancelEnabled = m_progress.GetCancelable();
    110107    m_pCancelBtn = new UIMiniCancelButton(this);
    111108    m_pCancelBtn->setEnabled(m_fCancelEnabled);
    112109    m_pCancelBtn->setFocusPolicy(Qt::ClickFocus);
    113     pLayout2->addWidget(m_pCancelBtn, 0, Qt::AlignVCenter);
    114     connect(m_pCancelBtn, SIGNAL(clicked()), this, SLOT(cancelOperation()));
    115 
     110    connect(m_pCancelBtn, SIGNAL(clicked()), this, SLOT(sltCancelOperation()));
     111
     112    /* Create estimation label: */
    116113    m_pEtaLbl = new QILabel(this);
    117     pLayout1->addWidget(m_pEtaLbl, 0, Qt::AlignLeft | Qt::AlignVCenter);
    118 
    119     pLayout1->addStretch(1);
    120 
    121     setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
    122 
     114
     115    /* Create proggress layout: */
     116    QHBoxLayout *pProgressLayout = new QHBoxLayout;
     117    pProgressLayout->setMargin(0);
     118    pProgressLayout->addWidget(m_pProgressBar, 0, Qt::AlignVCenter);
     119    pProgressLayout->addWidget(m_pCancelBtn, 0, Qt::AlignVCenter);
     120
     121    /* Create description layout: */
     122    QVBoxLayout *pDescriptionLayout = new QVBoxLayout;
     123    pDescriptionLayout->setMargin(0);
     124    pDescriptionLayout->addStretch(1);
     125    pDescriptionLayout->addWidget(m_pDescriptionLbl, 0, Qt::AlignHCenter);
     126    pDescriptionLayout->addLayout(pProgressLayout);
     127    pDescriptionLayout->addWidget(m_pEtaLbl, 0, Qt::AlignLeft | Qt::AlignVCenter);
     128    pDescriptionLayout->addStretch(1);
     129    pMainLayout->addLayout(pDescriptionLayout);
     130
     131    /* Translate finally: */
    123132    retranslateUi();
    124133
    125134    /* The progress dialog will be shown automatically after
    126135     * the duration is over if progress is not finished yet. */
    127     QTimer::singleShot(cMinDuration, this, SLOT(showDialog()));
     136    QTimer::singleShot(cMinDuration, this, SLOT(sltShowDialog()));
    128137}
    129138
     
    154163         * We don't do this on the Mac, cause regarding the design rules of
    155164         * Apple there is no busy window behavior. A window should always be
    156          * responsive and is it in our case (We show the progress dialog bar). */
     165         * responsive and it is in our case (We show the progress dialog bar). */
    157166#ifndef Q_WS_MAC
    158167        if (m_fCancelEnabled)
     
    181190{
    182191    if (m_fCancelEnabled)
    183         cancelOperation();
    184 }
    185 
    186 void UIProgressDialog::timerEvent(QTimerEvent * /* pEvent */)
     192        sltCancelOperation();
     193}
     194
     195void UIProgressDialog::timerEvent(QTimerEvent* /* pEvent */)
    187196{
    188197    /* We should hide progress-dialog
     
    201210    if (!m_fEnded && (!m_progress.isOk() || m_progress.GetCompleted()))
    202211    {
    203         /* Progress finished */
     212        /* Progress finished: */
    204213        if (m_progress.isOk())
    205214        {
    206             m_progressBar->setValue(100);
     215            m_pProgressBar->setValue(100);
    207216            done(Accepted);
    208217        }
    209         /* Progress is not valid */
     218        /* Progress is not valid: */
    210219        else
    211220            done(Rejected);
    212221
    213         /* Request to exit loop */
     222        /* Request to exit loop: */
    214223        m_fEnded = true;
    215224        return;
     
    218227    if (!m_progress.GetCanceled())
    219228    {
    220         /* Update the progress dialog */
     229        /* Update the progress dialog: */
    221230        /* First ETA */
    222231        long newTime = m_progress.GetTimeRemaining();
     
    271280            m_pEtaLbl->clear();
    272281
    273         /* Then operation text if changed */
     282        /* Then operation text if changed: */
    274283        ulong newOp = m_progress.GetOperation() + 1;
    275284        if (newOp != m_iCurrentOperation)
     
    280289                                       .arg(m_iCurrentOperation).arg(m_cOperations));
    281290        }
    282         m_progressBar->setValue(m_progress.GetPercent());
     291        m_pProgressBar->setValue(m_progress.GetPercent());
    283292
    284293        /* Then cancel button: */
     
    293302{
    294303    if (m_fCancelEnabled)
    295         cancelOperation();
     304        sltCancelOperation();
    296305    else
    297306        pEvent->ignore();
    298307}
    299308
    300 void UIProgressDialog::showDialog()
     309void UIProgressDialog::sltShowDialog()
    301310{
    302311    /* We should not show progress-dialog
     
    309318}
    310319
    311 void UIProgressDialog::cancelOperation()
     320void UIProgressDialog::sltCancelOperation()
    312321{
    313322    m_pCancelBtn->setEnabled(false);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h

    r43104 r43857  
    66
    77/*
    8  * Copyright (C) 2009-2010 Oracle Corporation
     8 * Copyright (C) 2009-2012 Oracle Corporation
    99 *
    1010 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    2020#define __UIProgressDialog_h__
    2121
    22 /* Qt includes: */
     22/* GUI includes: */
    2323#include "QIDialog.h"
     24#include "QIWithRetranslateUI.h"
    2425
    2526/* Forward declarations: */
    2627class QProgressBar;
     28class QLabel;
    2729class QILabel;
    2830class UIMiniCancelButton;
     
    4244 *       destroyed.
    4345 */
    44 class UIProgressDialog: protected QIDialog
     46class UIProgressDialog: protected QIWithRetranslateUI2<QIDialog>
    4547{
    4648    Q_OBJECT;
     
    4850public:
    4951
     52    /* Constructor/destructor: */
    5053    UIProgressDialog(CProgress &progress, const QString &strTitle,
    5154                     QPixmap *pImage = 0, bool fSheetOnDarwin = false,
     
    5356    ~UIProgressDialog();
    5457
     58    /* API: Run stuff: */
    5559    int run(int aRefreshInterval);
    56     bool cancelEnabled() const { return m_fCancelEnabled; }
    5760
    5861protected:
    5962
    60     virtual void retranslateUi();
     63    /* Helper: Translate stuff: */
     64    void retranslateUi();
    6165
    62     virtual void reject();
     66    /* Helper: Cancel stuff: */
     67    void reject();
    6368
     69    /* Handlers: Event processing stuff: */
    6470    virtual void timerEvent(QTimerEvent *pEvent);
    6571    virtual void closeEvent(QCloseEvent *pEvent);
     
    6773private slots:
    6874
    69     void showDialog();
    70     void cancelOperation();
     75    /* Handlers: */
     76    void sltShowDialog();
     77    void sltCancelOperation();
    7178
    7279private:
    7380
    74     /* Private member vars */
     81    /* Variables: */
    7582    CProgress &m_progress;
    76     QILabel *m_pImageLbl;
     83    QLabel *m_pImageLbl;
    7784    QILabel *m_pDescriptionLbl;
     85    QProgressBar *m_pProgressBar;
     86    UIMiniCancelButton *m_pCancelBtn;
    7887    QILabel *m_pEtaLbl;
     88    bool m_fCancelEnabled;
    7989    QString m_strCancel;
    80     QProgressBar *m_progressBar;
    81     UIMiniCancelButton *m_pCancelBtn;
    82     bool m_fCancelEnabled;
    8390    const ulong m_cOperations;
    8491    ulong m_iCurrentOperation;
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