Changeset 68998 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Oct 6, 2017 9:49:05 AM (7 years ago)
- 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 5 5 6 6 /* 7 * Copyright (C) 2006-201 6Oracle Corporation7 * Copyright (C) 2006-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 67 67 /* Create main layout: */ 68 68 QHBoxLayout *pMainLayout = new QHBoxLayout(this); 69 69 /* Configure layout: */ 70 70 #ifdef VBOX_WS_MAC 71 71 ::darwinSetHidesAllTitleButtons(this); … … 74 74 else 75 75 pMainLayout->setContentsMargins(6, 6, 6, 6); 76 #endif /* VBOX_WS_MAC */77 78 /* Createimage: */76 #endif 77 78 /* If there is image: */ 79 79 if (pImage) 80 80 { 81 /* Create image label: */ 81 82 m_pImageLbl = new QLabel(this); 83 /* Configure label: */ 82 84 m_pImageLbl->setPixmap(*pImage); 85 /* Add into layout: */ 83 86 pMainLayout->addWidget(m_pImageLbl); 84 87 } 85 88 86 /* Create description : */89 /* Create description label: */ 87 90 m_pDescriptionLbl = new QILabel(this); 91 /* Configure label: */ 88 92 if (m_cOperations > 1) 89 93 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)); 92 96 else 93 97 m_pDescriptionLbl->setText(QString("%1 ...") 94 .arg(m_progress.GetOperationDescription()));98 .arg(m_progress.GetOperationDescription())); 95 99 96 100 /* Create progress-bar: */ 97 101 m_pProgressBar = new QProgressBar(this); 102 /* Configure progress-bar: */ 98 103 m_pProgressBar->setMaximum(100); 99 104 m_pProgressBar->setValue(0); … … 102 107 m_fCancelEnabled = m_progress.GetCancelable(); 103 108 m_pCancelBtn = new UIMiniCancelButton(this); 109 /* Configure cancel button: */ 104 110 m_pCancelBtn->setEnabled(m_fCancelEnabled); 105 111 m_pCancelBtn->setFocusPolicy(Qt::ClickFocus); … … 111 117 /* Create proggress layout: */ 112 118 QHBoxLayout *pProgressLayout = new QHBoxLayout; 119 /* Configure layout: */ 113 120 pProgressLayout->setMargin(0); 121 /* Add into layout: */ 114 122 pProgressLayout->addWidget(m_pProgressBar, 0, Qt::AlignVCenter); 115 123 pProgressLayout->addWidget(m_pCancelBtn, 0, Qt::AlignVCenter); … … 117 125 /* Create description layout: */ 118 126 QVBoxLayout *pDescriptionLayout = new QVBoxLayout; 127 /* Configure layout: */ 119 128 pDescriptionLayout->setMargin(0); 129 /* Add stretch: */ 120 130 pDescriptionLayout->addStretch(1); 131 /* Add into layout: */ 121 132 pDescriptionLayout->addWidget(m_pDescriptionLbl, 0, Qt::AlignHCenter); 122 133 pDescriptionLayout->addLayout(pProgressLayout); 123 134 pDescriptionLayout->addWidget(m_pEtaLbl, 0, Qt::AlignLeft | Qt::AlignVCenter); 135 /* Add stretch: */ 124 136 pDescriptionLayout->addStretch(1); 137 /* Add into layout: */ 125 138 pMainLayout->addLayout(pDescriptionLayout); 126 139 … … 137 150 /* Wait for CProgress to complete: */ 138 151 m_progress.WaitForCompletion(-1); 152 139 153 /* Call the timer event handling delegate: */ 140 154 handleTimerEvent(); … … 152 166 if (m_progress.isOk()) 153 167 { 154 /* Start refresh timer */168 /* Start refresh timer: */ 155 169 int id = startTimer(cRefreshInterval); 156 170 … … 180 194 } 181 195 182 /* Kill refresh timer */196 /* Kill refresh timer: */ 183 197 killTimer(id); 184 198 … … 269 283 } 270 284 285 /* Update the progress dialog: */ 271 286 if (!m_progress.GetCanceled()) 272 287 { 273 /* Update the progress dialog: */ 274 /* First ETA */ 288 /* Update ETA: */ 275 289 long newTime = m_progress.GetTimeRemaining(); 276 290 long seconds; … … 324 338 m_pEtaLbl->clear(); 325 339 326 /* Then operation text if changed: */340 /* Then operation text (if changed): */ 327 341 ulong newOp = m_progress.GetOperation() + 1; 328 342 if (newOp != m_iCurrentOperation) … … 333 347 .arg(m_iCurrentOperation).arg(m_cOperations)); 334 348 } 349 /* Update operation percentage: */ 335 350 m_pProgressBar->setValue(m_progress.GetPercent()); 336 351 … … 343 358 m_progress.GetOperation() + 1, m_progress.GetPercent()); 344 359 } 360 /* Mark progress canceled if so: */ 345 361 else 346 362 m_pEtaLbl->setText(m_strCancel); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h
r62493 r68998 5 5 6 6 /* 7 * Copyright (C) 2009-201 6Oracle Corporation7 * Copyright (C) 2009-2017 Oracle Corporation 8 8 * 9 9 * This file is part of VirtualBox Open Source Edition (OSE), as … … 30 30 class CProgress; 31 31 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. */ 45 39 class UIProgressDialog: public QIWithRetranslateUI2<QIDialog> 46 40 { … … 49 43 public: 50 44 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. */ 52 50 UIProgressDialog(CProgress &progress, const QString &strTitle, 53 51 QPixmap *pImage = 0, int cMinDuration = 2000, QWidget *pParent = 0); 54 /** Destruct or. */52 /** Destructs progress-dialog. */ 55 53 ~UIProgressDialog(); 56 54 57 /* API: Run stuff:*/55 /** Executes the progress-dialog within its loop with passed @a iRefreshInterval. */ 58 56 int run(int aRefreshInterval); 59 57 … … 61 59 62 60 /** 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. */ 67 65 void sigProgressChange(ulong iOperations, QString strOperation, 68 66 ulong iOperation, ulong iPercent); … … 70 68 public slots: 71 69 72 /* Handler: Show stuff:*/70 /** Shows progress-dialog if it's not yet shown. */ 73 71 void show(); 74 72 75 73 protected: 76 74 77 /* Helper: Translate stuff:*/75 /** Handles translation event. */ 78 76 void retranslateUi(); 79 77 80 /* Helper: Cancel stuff:*/78 /** Rejects dialog. */ 81 79 void reject(); 82 80 83 /* Handlers: Event processing stuff:*/81 /** Handles timer @a pEvent. */ 84 82 virtual void timerEvent(QTimerEvent *pEvent); 83 /** Handles close @a pEvent. */ 85 84 virtual void closeEvent(QCloseEvent *pEvent); 86 85 87 86 private slots: 88 87 89 /* Handler: Cancel stuff:*/88 /** Handles request to cancel operation. */ 90 89 void sltCancelOperation(); 91 90 92 91 private: 93 92 94 /** Timer event handling delegate. */93 /** Performes timer event handling. */ 95 94 void handleTimerEvent(); 96 95 97 /* Variables:*/96 /** Holds the progress reference. */ 98 97 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. */ 102 106 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; 109 109 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. */ 110 122 static const char *m_spcszOpDescTpl; 111 123 }; 124 112 125 113 126 /** QObject reimplementation allowing to effectively track the CProgress object completion … … 124 137 125 138 /** 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. */ 130 143 void sigProgressChange(ulong iOperations, QString strOperation, 131 144 ulong iOperation, ulong iPercent); … … 137 150 public: 138 151 139 /** Construct or 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. */ 141 154 UIProgress(CProgress &progress, QObject *pParent = 0); 142 155 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. */ 146 157 void run(int iRefreshInterval); 147 158 148 159 private: 149 160 150 /** Timer @a pEvent reimplementation. */161 /** Handles timer @a pEvent. */ 151 162 virtual void timerEvent(QTimerEvent *pEvent); 152 163 153 /** Holds the wrapped CProgress reference. */164 /** Holds the progress reference. */ 154 165 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;159 166 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. */ 161 173 QPointer<QEventLoop> m_pEventLoop; 162 174 }; 163 175 164 #endif /* __UIProgressDialog_h__ */176 #endif /* !__UIProgressDialog_h__ */ 165 177
Note:
See TracChangeset
for help on using the changeset viewer.