VirtualBox

Changeset 68998 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
Oct 6, 2017 9:49:05 AM (7 years ago)
Author:
vboxsync
Message:

FE/Qt: bugref:8674: A bit of rework for UIProgressDialog (part 1): Doxy/comments.

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

Legend:

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

    r68435 r68998  
    55
    66/*
    7  * Copyright (C) 2006-2016 Oracle Corporation
     7 * Copyright (C) 2006-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    6767    /* Create main layout: */
    6868    QHBoxLayout *pMainLayout = new QHBoxLayout(this);
    69 
     69    /* Configure layout: */
    7070#ifdef VBOX_WS_MAC
    7171    ::darwinSetHidesAllTitleButtons(this);
     
    7474    else
    7575        pMainLayout->setContentsMargins(6, 6, 6, 6);
    76 #endif /* VBOX_WS_MAC */
    77 
    78     /* Create image: */
     76#endif
     77
     78    /* If there is image: */
    7979    if (pImage)
    8080    {
     81        /* Create image label: */
    8182        m_pImageLbl = new QLabel(this);
     83        /* Configure label: */
    8284        m_pImageLbl->setPixmap(*pImage);
     85        /* Add into layout: */
    8386        pMainLayout->addWidget(m_pImageLbl);
    8487    }
    8588
    86     /* Create description: */
     89    /* Create description label: */
    8790    m_pDescriptionLbl = new QILabel(this);
     91    /* Configure label: */
    8892    if (m_cOperations > 1)
    8993        m_pDescriptionLbl->setText(QString(m_spcszOpDescTpl)
    90                                    .arg(m_progress.GetOperationDescription())
    91                                    .arg(m_iCurrentOperation).arg(m_cOperations));
     94                                           .arg(m_progress.GetOperationDescription())
     95                                           .arg(m_iCurrentOperation).arg(m_cOperations));
    9296    else
    9397        m_pDescriptionLbl->setText(QString("%1 ...")
    94                                    .arg(m_progress.GetOperationDescription()));
     98                                           .arg(m_progress.GetOperationDescription()));
    9599
    96100    /* Create progress-bar: */
    97101    m_pProgressBar = new QProgressBar(this);
     102    /* Configure progress-bar: */
    98103    m_pProgressBar->setMaximum(100);
    99104    m_pProgressBar->setValue(0);
     
    102107    m_fCancelEnabled = m_progress.GetCancelable();
    103108    m_pCancelBtn = new UIMiniCancelButton(this);
     109    /* Configure cancel button: */
    104110    m_pCancelBtn->setEnabled(m_fCancelEnabled);
    105111    m_pCancelBtn->setFocusPolicy(Qt::ClickFocus);
     
    111117    /* Create proggress layout: */
    112118    QHBoxLayout *pProgressLayout = new QHBoxLayout;
     119    /* Configure layout: */
    113120    pProgressLayout->setMargin(0);
     121    /* Add into layout: */
    114122    pProgressLayout->addWidget(m_pProgressBar, 0, Qt::AlignVCenter);
    115123    pProgressLayout->addWidget(m_pCancelBtn, 0, Qt::AlignVCenter);
     
    117125    /* Create description layout: */
    118126    QVBoxLayout *pDescriptionLayout = new QVBoxLayout;
     127    /* Configure layout: */
    119128    pDescriptionLayout->setMargin(0);
     129    /* Add stretch: */
    120130    pDescriptionLayout->addStretch(1);
     131    /* Add into layout: */
    121132    pDescriptionLayout->addWidget(m_pDescriptionLbl, 0, Qt::AlignHCenter);
    122133    pDescriptionLayout->addLayout(pProgressLayout);
    123134    pDescriptionLayout->addWidget(m_pEtaLbl, 0, Qt::AlignLeft | Qt::AlignVCenter);
     135    /* Add stretch: */
    124136    pDescriptionLayout->addStretch(1);
     137    /* Add into layout: */
    125138    pMainLayout->addLayout(pDescriptionLayout);
    126139
     
    137150    /* Wait for CProgress to complete: */
    138151    m_progress.WaitForCompletion(-1);
     152
    139153    /* Call the timer event handling delegate: */
    140154    handleTimerEvent();
     
    152166    if (m_progress.isOk())
    153167    {
    154         /* Start refresh timer */
     168        /* Start refresh timer: */
    155169        int id = startTimer(cRefreshInterval);
    156170
     
    180194        }
    181195
    182         /* Kill refresh timer */
     196        /* Kill refresh timer: */
    183197        killTimer(id);
    184198
     
    269283    }
    270284
     285    /* Update the progress dialog: */
    271286    if (!m_progress.GetCanceled())
    272287    {
    273         /* Update the progress dialog: */
    274         /* First ETA */
     288        /* Update ETA: */
    275289        long newTime = m_progress.GetTimeRemaining();
    276290        long seconds;
     
    324338            m_pEtaLbl->clear();
    325339
    326         /* Then operation text if changed: */
     340        /* Then operation text (if changed): */
    327341        ulong newOp = m_progress.GetOperation() + 1;
    328342        if (newOp != m_iCurrentOperation)
     
    333347                                       .arg(m_iCurrentOperation).arg(m_cOperations));
    334348        }
     349        /* Update operation percentage: */
    335350        m_pProgressBar->setValue(m_progress.GetPercent());
    336351
     
    343358                               m_progress.GetOperation() + 1, m_progress.GetPercent());
    344359    }
     360    /* Mark progress canceled if so: */
    345361    else
    346362        m_pEtaLbl->setText(m_strCancel);
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h

    r62493 r68998  
    55
    66/*
    7  * Copyright (C) 2009-2016 Oracle Corporation
     7 * Copyright (C) 2009-2017 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    3030class CProgress;
    3131
    32 /**
    33  * A QProgressDialog enhancement that allows to:
    34  *
    35  * 1) prevent closing the dialog when it has no cancel button;
    36  * 2) effectively track the IProgress object completion (w/o using
    37  *    IProgress::waitForCompletion() and w/o blocking the UI thread in any other
    38  *    way for too long).
    39  *
    40  * @note The CProgress instance is passed as a non-const reference to the
    41  *       constructor (to memorize COM errors if they happen), and therefore must
    42  *       not be destroyed before the created UIProgressDialog instance is
    43  *       destroyed.
    44  */
     32
     33/** QProgressDialog enhancement that allows to:
     34  * 1) prevent closing the dialog when it has no cancel button;
     35  * 2) effectively track the IProgress object completion (w/o using
     36  *    IProgress::waitForCompletion() and w/o blocking the UI thread in any other way for too long).
     37  * @note The CProgress instance is passed as a non-const reference to the constructor (to memorize COM errors if they happen),
     38  *       and therefore must not be destroyed before the created UIProgressDialog instance is destroyed. */
    4539class UIProgressDialog: public QIWithRetranslateUI2<QIDialog>
    4640{
     
    4943public:
    5044
    51     /** Constructor. */
     45    /** Constructs progress-dialog passing @a pParent to the base-class.
     46      * @param  progress   Brings the progress reference.
     47      * @param  strTitle      Brings the progress-dialog title.
     48      * @param  pImage        Brings the progress-dialog image.
     49      * @param  cMinDuration  Brings the minimum duration before the progress-dialog is shown. */
    5250    UIProgressDialog(CProgress &progress, const QString &strTitle,
    5351                     QPixmap *pImage = 0, int cMinDuration = 2000, QWidget *pParent = 0);
    54     /** Destructor. */
     52    /** Destructs progress-dialog. */
    5553    ~UIProgressDialog();
    5654
    57     /* API: Run stuff: */
     55    /** Executes the progress-dialog within its loop with passed @a iRefreshInterval. */
    5856    int run(int aRefreshInterval);
    5957
     
    6159
    6260    /** Notifies listeners about wrapped CProgress change.
    63       * @param iOperations  holds the number of operations CProgress have,
    64       * @param strOperation holds the description of the current CProgress operation,
    65       * @param iOperation   holds the index of the current CProgress operation,
    66       * @param iPercent     holds the percentage of the current CProgress operation. */
     61      * @param  iOperations   Brings the number of operations CProgress have.
     62      * @param  strOperation  Brings the description of the current CProgress operation.
     63      * @param  iOperation    Brings the index of the current CProgress operation.
     64      * @param  iPercent      Brings the percentage of the current CProgress operation. */
    6765    void sigProgressChange(ulong iOperations, QString strOperation,
    6866                           ulong iOperation, ulong iPercent);
     
    7068public slots:
    7169
    72     /* Handler: Show stuff: */
     70    /** Shows progress-dialog if it's not yet shown. */
    7371    void show();
    7472
    7573protected:
    7674
    77     /* Helper: Translate stuff: */
     75    /** Handles translation event. */
    7876    void retranslateUi();
    7977
    80     /* Helper: Cancel stuff: */
     78    /** Rejects dialog. */
    8179    void reject();
    8280
    83     /* Handlers: Event processing stuff: */
     81    /** Handles timer @a pEvent. */
    8482    virtual void timerEvent(QTimerEvent *pEvent);
     83    /** Handles close @a pEvent. */
    8584    virtual void closeEvent(QCloseEvent *pEvent);
    8685
    8786private slots:
    8887
    89     /* Handler: Cancel stuff: */
     88    /** Handles request to cancel operation. */
    9089    void sltCancelOperation();
    9190
    9291private:
    9392
    94     /** Timer event handling delegate. */
     93    /** Performes timer event handling. */
    9594    void handleTimerEvent();
    9695
    97     /* Variables: */
     96    /** Holds the progress reference. */
    9897    CProgress &m_progress;
    99     QLabel *m_pImageLbl;
    100     QILabel *m_pDescriptionLbl;
    101     QProgressBar *m_pProgressBar;
     98
     99    /** Holds the image label instance. */
     100    QLabel             *m_pImageLbl;
     101    /** Holds the description label instance. */
     102    QILabel            *m_pDescriptionLbl;
     103    /** Holds the progress-bar instance. */
     104    QProgressBar       *m_pProgressBar;
     105    /** Holds the cancel button instance. */
    102106    UIMiniCancelButton *m_pCancelBtn;
    103     QILabel *m_pEtaLbl;
    104     bool m_fCancelEnabled;
    105     QString m_strCancel;
    106     const ulong m_cOperations;
    107     ulong m_iCurrentOperation;
    108     bool m_fEnded;
     107    /** Holds the ETA label instance. */
     108    QILabel            *m_pEtaLbl;
    109109
     110    /** Holds whether progress cancel is enabled. */
     111    bool         m_fCancelEnabled;
     112    /** Holds the translated canceling tag. */
     113    QString      m_strCancel;
     114    /** Holds the amount of operations. */
     115    const ulong  m_cOperations;
     116    /** Holds the number of current operation. */
     117    ulong        m_iCurrentOperation;
     118    /** Holds whether the progress has ended. */
     119    bool         m_fEnded;
     120
     121    /** Holds the operation description template. */
    110122    static const char *m_spcszOpDescTpl;
    111123};
     124
    112125
    113126/** QObject reimplementation allowing to effectively track the CProgress object completion
     
    124137
    125138    /** Notifies listeners about wrapped CProgress change.
    126       * @param iOperations  holds the number of operations CProgress have,
    127       * @param strOperation holds the description of the current CProgress operation,
    128       * @param iOperation   holds the index of the current CProgress operation,
    129       * @param iPercent     holds the percentage of the current CProgress operation. */
     139      * @param  iOperations   Brings the number of operations CProgress have.
     140      * @param  strOperation  Brings the description of the current CProgress operation.
     141      * @param  iOperation    Brings the index of the current CProgress operation.
     142      * @param  iPercent      Brings the percentage of the current CProgress operation. */
    130143    void sigProgressChange(ulong iOperations, QString strOperation,
    131144                           ulong iOperation, ulong iPercent);
     
    137150public:
    138151
    139     /** Constructor passing @a pParent to the base-class.
    140       * @param progress holds the CProgress to be wrapped. */
     152    /** Constructs progress handler passing @a pParent to the base-class.
     153      * @param  progress  Brings the progress reference. */
    141154    UIProgress(CProgress &progress, QObject *pParent = 0);
    142155
    143     /** Starts the UIProgress by entering the personal event-loop.
    144       * @param iRefreshInterval holds the refresh interval to check
    145       *                         for the CProgress updates with. */
     156    /** Executes the progress-handler within its loop with passed @a iRefreshInterval. */
    146157    void run(int iRefreshInterval);
    147158
    148159private:
    149160
    150     /** Timer @a pEvent reimplementation. */
     161    /** Handles timer @a pEvent. */
    151162    virtual void timerEvent(QTimerEvent *pEvent);
    152163
    153     /** Holds the wrapped CProgress reference. */
     164    /** Holds the progress reference. */
    154165    CProgress &m_progress;
    155     /** Holds the number of operations wrapped CProgress have. */
    156     const ulong m_cOperations;
    157     /** Holds whether the UIProgress ended. */
    158     bool m_fEnded;
    159166
    160     /** Holds the personal event-loop. */
     167    /** Holds the amount of operations. */
     168    const ulong  m_cOperations;
     169    /** Holds whether the progress has ended. */
     170    bool         m_fEnded;
     171
     172    /** Holds the personal event-loop instance. */
    161173    QPointer<QEventLoop> m_pEventLoop;
    162174};
    163175
    164 #endif /* __UIProgressDialog_h__ */
     176#endif /* !__UIProgressDialog_h__ */
    165177
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