Changeset 43857 in vbox
- Timestamp:
- Nov 12, 2012 12:40:08 PM (12 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
r43855 r43857 47 47 int cMinDuration /* = 2000 */, 48 48 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: */ 57 58 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); 60 64 61 65 #ifdef Q_WS_MAC … … 69 73 ::darwinSetShowsResizeIndicator(this, false); 70 74 if (pImage) 71 p Layout0->setContentsMargins(30, 15, 30, 15);75 pMainLayout->setContentsMargins(30, 15, 30, 15); 72 76 else 73 p Layout0->setContentsMargins(6, 6, 6, 6);74 #else 77 pMainLayout->setContentsMargins(6, 6, 6, 6); 78 #else /* Q_WS_MAC */ 75 79 NOREF(fSheetOnDarwin); 76 #endif /* Q_WS_MAC */ 77 80 #endif /* !Q_WS_MAC */ 81 82 /* Create image: */ 78 83 if (pImage) 79 84 { 80 m_pImageLbl = new Q ILabel(this);85 m_pImageLbl = new QLabel(this); 81 86 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: */ 89 91 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 99 92 if (m_cOperations > 1) 100 93 m_pDescriptionLbl->setText(QString(m_spcszOpDescTpl) … … 104 97 m_pDescriptionLbl->setText(QString("%1 ...") 105 98 .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: */ 109 106 m_fCancelEnabled = m_progress.GetCancelable(); 110 107 m_pCancelBtn = new UIMiniCancelButton(this); 111 108 m_pCancelBtn->setEnabled(m_fCancelEnabled); 112 109 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: */ 116 113 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: */ 123 132 retranslateUi(); 124 133 125 134 /* The progress dialog will be shown automatically after 126 135 * the duration is over if progress is not finished yet. */ 127 QTimer::singleShot(cMinDuration, this, SLOT(s howDialog()));136 QTimer::singleShot(cMinDuration, this, SLOT(sltShowDialog())); 128 137 } 129 138 … … 154 163 * We don't do this on the Mac, cause regarding the design rules of 155 164 * Apple there is no busy window behavior. A window should always be 156 * responsive and i s itin our case (We show the progress dialog bar). */165 * responsive and it is in our case (We show the progress dialog bar). */ 157 166 #ifndef Q_WS_MAC 158 167 if (m_fCancelEnabled) … … 181 190 { 182 191 if (m_fCancelEnabled) 183 cancelOperation();184 } 185 186 void UIProgressDialog::timerEvent(QTimerEvent 192 sltCancelOperation(); 193 } 194 195 void UIProgressDialog::timerEvent(QTimerEvent* /* pEvent */) 187 196 { 188 197 /* We should hide progress-dialog … … 201 210 if (!m_fEnded && (!m_progress.isOk() || m_progress.GetCompleted())) 202 211 { 203 /* Progress finished */212 /* Progress finished: */ 204 213 if (m_progress.isOk()) 205 214 { 206 m_p rogressBar->setValue(100);215 m_pProgressBar->setValue(100); 207 216 done(Accepted); 208 217 } 209 /* Progress is not valid */218 /* Progress is not valid: */ 210 219 else 211 220 done(Rejected); 212 221 213 /* Request to exit loop */222 /* Request to exit loop: */ 214 223 m_fEnded = true; 215 224 return; … … 218 227 if (!m_progress.GetCanceled()) 219 228 { 220 /* Update the progress dialog */229 /* Update the progress dialog: */ 221 230 /* First ETA */ 222 231 long newTime = m_progress.GetTimeRemaining(); … … 271 280 m_pEtaLbl->clear(); 272 281 273 /* Then operation text if changed */282 /* Then operation text if changed: */ 274 283 ulong newOp = m_progress.GetOperation() + 1; 275 284 if (newOp != m_iCurrentOperation) … … 280 289 .arg(m_iCurrentOperation).arg(m_cOperations)); 281 290 } 282 m_p rogressBar->setValue(m_progress.GetPercent());291 m_pProgressBar->setValue(m_progress.GetPercent()); 283 292 284 293 /* Then cancel button: */ … … 293 302 { 294 303 if (m_fCancelEnabled) 295 cancelOperation();304 sltCancelOperation(); 296 305 else 297 306 pEvent->ignore(); 298 307 } 299 308 300 void UIProgressDialog::s howDialog()309 void UIProgressDialog::sltShowDialog() 301 310 { 302 311 /* We should not show progress-dialog … … 309 318 } 310 319 311 void UIProgressDialog:: cancelOperation()320 void UIProgressDialog::sltCancelOperation() 312 321 { 313 322 m_pCancelBtn->setEnabled(false); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIProgressDialog.h
r43104 r43857 6 6 7 7 /* 8 * Copyright (C) 2009-201 0Oracle Corporation8 * Copyright (C) 2009-2012 Oracle Corporation 9 9 * 10 10 * This file is part of VirtualBox Open Source Edition (OSE), as … … 20 20 #define __UIProgressDialog_h__ 21 21 22 /* Qtincludes: */22 /* GUI includes: */ 23 23 #include "QIDialog.h" 24 #include "QIWithRetranslateUI.h" 24 25 25 26 /* Forward declarations: */ 26 27 class QProgressBar; 28 class QLabel; 27 29 class QILabel; 28 30 class UIMiniCancelButton; … … 42 44 * destroyed. 43 45 */ 44 class UIProgressDialog: protected QI Dialog46 class UIProgressDialog: protected QIWithRetranslateUI2<QIDialog> 45 47 { 46 48 Q_OBJECT; … … 48 50 public: 49 51 52 /* Constructor/destructor: */ 50 53 UIProgressDialog(CProgress &progress, const QString &strTitle, 51 54 QPixmap *pImage = 0, bool fSheetOnDarwin = false, … … 53 56 ~UIProgressDialog(); 54 57 58 /* API: Run stuff: */ 55 59 int run(int aRefreshInterval); 56 bool cancelEnabled() const { return m_fCancelEnabled; }57 60 58 61 protected: 59 62 60 virtual void retranslateUi(); 63 /* Helper: Translate stuff: */ 64 void retranslateUi(); 61 65 62 virtual void reject(); 66 /* Helper: Cancel stuff: */ 67 void reject(); 63 68 69 /* Handlers: Event processing stuff: */ 64 70 virtual void timerEvent(QTimerEvent *pEvent); 65 71 virtual void closeEvent(QCloseEvent *pEvent); … … 67 73 private slots: 68 74 69 void showDialog(); 70 void cancelOperation(); 75 /* Handlers: */ 76 void sltShowDialog(); 77 void sltCancelOperation(); 71 78 72 79 private: 73 80 74 /* Private member vars*/81 /* Variables: */ 75 82 CProgress &m_progress; 76 Q ILabel *m_pImageLbl;83 QLabel *m_pImageLbl; 77 84 QILabel *m_pDescriptionLbl; 85 QProgressBar *m_pProgressBar; 86 UIMiniCancelButton *m_pCancelBtn; 78 87 QILabel *m_pEtaLbl; 88 bool m_fCancelEnabled; 79 89 QString m_strCancel; 80 QProgressBar *m_progressBar;81 UIMiniCancelButton *m_pCancelBtn;82 bool m_fCancelEnabled;83 90 const ulong m_cOperations; 84 91 ulong m_iCurrentOperation;
Note:
See TracChangeset
for help on using the changeset viewer.