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