comparison widgets/ProgressDialog.cpp @ 1324:13d9b422f7fe zoom

Merge from default branch
author Chris Cannam
date Mon, 17 Sep 2018 13:51:31 +0100
parents 05d12869043e
children c8a6fd3f9dff
comparison
equal deleted inserted replaced
1183:57d192e26331 1324:13d9b422f7fe
17 17
18 #include <QProgressDialog> 18 #include <QProgressDialog>
19 #include <QApplication> 19 #include <QApplication>
20 #include <QTimer> 20 #include <QTimer>
21 21
22 ProgressDialog::ProgressDialog(QString message, bool cancellable, 22 ProgressDialog::ProgressDialog(QString message,
23 int timeBeforeShow, QWidget *parent) : 23 bool cancellable,
24 int timeBeforeShow,
25 QWidget *parent,
26 Qt::WindowModality modality) :
24 m_showTimer(0), 27 m_showTimer(0),
25 m_timerElapsed(false), 28 m_timerElapsed(false),
26 m_cancelled(false) 29 m_cancelled(false)
27 { 30 {
28 m_dialog = new QProgressDialog(message, cancellable ? tr("Cancel") : 0, 31 m_dialog = new QProgressDialog(message, cancellable ? tr("Cancel") : 0,
29 0, 100, parent); 32 0, 100, parent);
33 m_dialog->setWindowModality(modality);
34
30 if (timeBeforeShow > 0) { 35 if (timeBeforeShow > 0) {
31 m_dialog->hide(); 36 m_dialog->hide();
32 m_showTimer = new QTimer; 37 m_showTimer = new QTimer;
33 connect(m_showTimer, SIGNAL(timeout()), this, SLOT(showTimerElapsed())); 38 connect(m_showTimer, SIGNAL(timeout()), this, SLOT(showTimerElapsed()));
34 m_showTimer->setSingleShot(true); 39 m_showTimer->setSingleShot(true);
95 100
96 void 101 void
97 ProgressDialog::setProgress(int percentage) 102 ProgressDialog::setProgress(int percentage)
98 { 103 {
99 if (percentage > m_dialog->value()) { 104 if (percentage > m_dialog->value()) {
100
101 m_dialog->setValue(percentage);
102
103 if (percentage >= 100 && isDefinite()) { 105 if (percentage >= 100 && isDefinite()) {
104 m_dialog->hide(); 106 m_dialog->hide();
105 } else if (m_timerElapsed && !m_dialog->isVisible()) { 107 } else if (m_timerElapsed && !m_dialog->isVisible()) {
106 emit showing(); 108 emit showing();
107 m_dialog->show(); 109 m_dialog->show();
108 m_dialog->raise(); 110 m_dialog->raise();
109 } 111 }
110 112 m_dialog->setValue(percentage); // processes event loop when modal
111 qApp->processEvents(); 113 if (!m_dialog->isModal()) qApp->processEvents();
112 } 114 }
113 } 115 }
114