svgui  1.9
ProgressDialog.cpp
Go to the documentation of this file.
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  m_cancelled(false)
27 {
28  m_dialog = new QProgressDialog(message, cancellable ? tr("Cancel") : 0,
29  0, 100, parent);
30  if (timeBeforeShow > 0) {
31  m_dialog->hide();
32  m_showTimer = new QTimer;
33  connect(m_showTimer, SIGNAL(timeout()), this, SLOT(showTimerElapsed()));
34  m_showTimer->setSingleShot(true);
35  m_showTimer->start(timeBeforeShow);
36  } else {
37  m_dialog->show();
38  m_dialog->raise();
39  m_timerElapsed = true;
40  }
41 
42  if (cancellable) {
43  connect(m_dialog, SIGNAL(canceled()), this, SLOT(canceled()));
44  }
45 }
46 
48 {
49  delete m_showTimer;
50  delete m_dialog;
51 }
52 
53 bool
55 {
56  return (m_dialog->maximum() > 0);
57 }
58 
59 void
61 {
62  if (definite) m_dialog->setMaximum(100);
63  else m_dialog->setMaximum(0);
64 }
65 
66 void
68 {
69  m_dialog->setLabelText(text);
70 }
71 
72 void
74 {
75  m_cancelled = true;
76  emit cancelled();
77 }
78 
79 bool
81 {
82  return m_cancelled;
83 }
84 
85 void
87 {
88  m_timerElapsed = true;
89  if (m_dialog->value() > 0) {
90  emit showing();
91  m_dialog->show();
92  }
93  qApp->processEvents();
94 }
95 
96 void
98 {
99  if (percentage > m_dialog->value()) {
100 
101  m_dialog->setValue(percentage);
102 
103  if (percentage >= 100 && isDefinite()) {
104  m_dialog->hide();
105  } else if (m_timerElapsed && !m_dialog->isVisible()) {
106  emit showing();
107  m_dialog->show();
108  m_dialog->raise();
109  }
110 
111  qApp->processEvents();
112  }
113 }
114 
virtual bool isDefinite() const
virtual void setMessage(QString text)
ProgressDialog(QString message, bool cancellable, int timeBeforeShow=0, QWidget *parent=0)
virtual void showTimerElapsed()
QProgressDialog * m_dialog
virtual void setProgress(int percentage)
QTimer * m_showTimer
virtual void setDefinite(bool definite)
virtual bool wasCancelled() const
virtual ~ProgressDialog()