comparison widgets/ProgressDialog.cpp @ 410:33b7f5e54d60

* Merge revisions 1041 to 1130 from sv-rdf-import branch
author Chris Cannam
date Thu, 18 Sep 2008 12:09:32 +0000
parents 036b75ddcd3f
children b68f3162b5a8
comparison
equal deleted inserted replaced
409:feeb48f7478a 410:33b7f5e54d60
20 #include <QTimer> 20 #include <QTimer>
21 21
22 ProgressDialog::ProgressDialog(QString message, bool cancellable, 22 ProgressDialog::ProgressDialog(QString message, bool cancellable,
23 int timeBeforeShow, QWidget *parent) : 23 int timeBeforeShow, QWidget *parent) :
24 m_showTimer(0), 24 m_showTimer(0),
25 m_timerElapsed(false) 25 m_timerElapsed(false),
26 m_cancelled(false)
26 { 27 {
27 m_dialog = new QProgressDialog(message, cancellable ? tr("Cancel") : 0, 28 m_dialog = new QProgressDialog(message, cancellable ? tr("Cancel") : 0,
28 0, 100, parent); 29 0, 100, parent);
29 if (timeBeforeShow > 0) { 30 if (timeBeforeShow > 0) {
30 m_dialog->hide(); 31 m_dialog->hide();
37 m_dialog->raise(); 38 m_dialog->raise();
38 m_timerElapsed = true; 39 m_timerElapsed = true;
39 } 40 }
40 41
41 if (cancellable) { 42 if (cancellable) {
42 connect(m_dialog, SIGNAL(canceled()), this, SIGNAL(cancelled())); 43 connect(m_dialog, SIGNAL(canceled()), this, SLOT(canceled()));
43 } 44 }
44 } 45 }
45 46
46 ProgressDialog::~ProgressDialog() 47 ProgressDialog::~ProgressDialog()
47 { 48 {
48 delete m_showTimer; 49 delete m_showTimer;
49 delete m_dialog; 50 delete m_dialog;
50 } 51 }
51 52
53 bool
54 ProgressDialog::isDefinite() const
55 {
56 return (m_dialog->maximum() > 0);
57 }
58
59 void
60 ProgressDialog::setDefinite(bool definite)
61 {
62 if (definite) m_dialog->setMaximum(100);
63 else m_dialog->setMaximum(0);
64 }
65
52 void 66 void
53 ProgressDialog::setMessage(QString text) 67 ProgressDialog::setMessage(QString text)
54 { 68 {
55 m_dialog->setLabelText(text); 69 m_dialog->setLabelText(text);
56 } 70 }
57 71
58 void 72 void
73 ProgressDialog::canceled()
74 {
75 m_cancelled = true;
76 emit cancelled();
77 }
78
79 bool
80 ProgressDialog::wasCancelled() const
81 {
82 return m_cancelled;
83 }
84
85 void
59 ProgressDialog::showTimerElapsed() 86 ProgressDialog::showTimerElapsed()
60 { 87 {
61 m_timerElapsed = true; 88 m_timerElapsed = true;
62 if (m_dialog->value() > 0) { 89 if (m_dialog->value() > 0) {
90 emit showing();
63 m_dialog->show(); 91 m_dialog->show();
64 } 92 }
65 qApp->processEvents(); 93 qApp->processEvents();
66 } 94 }
67 95
70 { 98 {
71 if (percentage > m_dialog->value()) { 99 if (percentage > m_dialog->value()) {
72 100
73 m_dialog->setValue(percentage); 101 m_dialog->setValue(percentage);
74 102
75 if (percentage >= 100) { 103 if (percentage >= 100 && isDefinite()) {
76 m_dialog->hide(); 104 m_dialog->hide();
77 } else if (m_timerElapsed && !m_dialog->isVisible()) { 105 } else if (m_timerElapsed && !m_dialog->isVisible()) {
106 emit showing();
78 m_dialog->show(); 107 m_dialog->show();
79 m_dialog->raise(); 108 m_dialog->raise();
80 } 109 }
81 110
82 qApp->processEvents(); 111 qApp->processEvents();