Mercurial > hg > svgui
comparison widgets/ProgressDialog.cpp @ 378:22b72f0f6a4e
* More work to abstract out interactive components used in the data library,
so that it does not need to depend on QtGui.
author | Chris Cannam |
---|---|
date | Fri, 14 Mar 2008 17:14:21 +0000 |
parents | |
children | 036b75ddcd3f |
comparison
equal
deleted
inserted
replaced
377:0bcb449d15f4 | 378:22b72f0f6a4e |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2007-2008 QMUL. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #include "ProgressDialog.h" | |
17 | |
18 #include <QProgressDialog> | |
19 #include <QApplication> | |
20 #include <QTimer> | |
21 | |
22 ProgressDialog::ProgressDialog(QString message, bool cancellable, | |
23 int timeBeforeShow, QWidget *parent) : | |
24 m_showTimer(0), | |
25 m_timerElapsed(false) | |
26 { | |
27 m_dialog = new QProgressDialog(message, cancellable ? tr("Cancel") : 0, | |
28 0, 100, parent); | |
29 if (timeBeforeShow > 0) { | |
30 m_dialog->hide(); | |
31 m_showTimer = new QTimer; | |
32 connect(m_showTimer, SIGNAL(timeout()), this, SLOT(showTimerElapsed())); | |
33 m_showTimer->setSingleShot(true); | |
34 m_showTimer->start(timeBeforeShow); | |
35 } else { | |
36 m_dialog->show(); | |
37 m_dialog->raise(); | |
38 m_timerElapsed = true; | |
39 } | |
40 | |
41 if (cancellable) { | |
42 connect(m_dialog, SIGNAL(canceled()), this, SIGNAL(cancelled())); | |
43 } | |
44 } | |
45 | |
46 ProgressDialog::~ProgressDialog() | |
47 { | |
48 delete m_showTimer; | |
49 delete m_dialog; | |
50 } | |
51 | |
52 void | |
53 ProgressDialog::setMessage(QString text) | |
54 { | |
55 m_dialog->setLabelText(text); | |
56 } | |
57 | |
58 void | |
59 ProgressDialog::showTimerElapsed() | |
60 { | |
61 m_timerElapsed = true; | |
62 delete m_showTimer; | |
63 m_showTimer = 0; | |
64 if (m_dialog->value() > 0) { | |
65 m_dialog->show(); | |
66 } | |
67 qApp->processEvents(); | |
68 } | |
69 | |
70 void | |
71 ProgressDialog::setProgress(int percentage) | |
72 { | |
73 if (percentage > m_dialog->value()) { | |
74 | |
75 m_dialog->setValue(percentage); | |
76 | |
77 if (percentage >= 100) { | |
78 delete m_showTimer; | |
79 m_showTimer = 0; | |
80 m_dialog->hide(); | |
81 } else if (m_timerElapsed && !m_dialog->isVisible()) { | |
82 m_dialog->show(); | |
83 m_dialog->raise(); | |
84 } | |
85 | |
86 qApp->processEvents(); | |
87 } | |
88 } | |
89 |