annotate widgets/ProgressDialog.cpp @ 634:4fa3951bbb05 tonioni

different colours, some minor changes, mainly debugging cerrs
author matthiasm
date Fri, 19 Apr 2013 15:37:27 +0100
parents 33b7f5e54d60
children b68f3162b5a8
rev   line source
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@410 25 m_timerElapsed(false),
Chris@410 26 m_cancelled(false)
Chris@378 27 {
Chris@378 28 m_dialog = new QProgressDialog(message, cancellable ? tr("Cancel") : 0,
Chris@378 29 0, 100, parent);
Chris@378 30 if (timeBeforeShow > 0) {
Chris@378 31 m_dialog->hide();
Chris@378 32 m_showTimer = new QTimer;
Chris@378 33 connect(m_showTimer, SIGNAL(timeout()), this, SLOT(showTimerElapsed()));
Chris@378 34 m_showTimer->setSingleShot(true);
Chris@378 35 m_showTimer->start(timeBeforeShow);
Chris@378 36 } else {
Chris@378 37 m_dialog->show();
Chris@378 38 m_dialog->raise();
Chris@378 39 m_timerElapsed = true;
Chris@378 40 }
Chris@378 41
Chris@378 42 if (cancellable) {
Chris@410 43 connect(m_dialog, SIGNAL(canceled()), this, SLOT(canceled()));
Chris@378 44 }
Chris@378 45 }
Chris@378 46
Chris@378 47 ProgressDialog::~ProgressDialog()
Chris@378 48 {
Chris@378 49 delete m_showTimer;
Chris@378 50 delete m_dialog;
Chris@378 51 }
Chris@378 52
Chris@410 53 bool
Chris@410 54 ProgressDialog::isDefinite() const
Chris@410 55 {
Chris@410 56 return (m_dialog->maximum() > 0);
Chris@410 57 }
Chris@410 58
Chris@410 59 void
Chris@410 60 ProgressDialog::setDefinite(bool definite)
Chris@410 61 {
Chris@410 62 if (definite) m_dialog->setMaximum(100);
Chris@410 63 else m_dialog->setMaximum(0);
Chris@410 64 }
Chris@410 65
Chris@378 66 void
Chris@378 67 ProgressDialog::setMessage(QString text)
Chris@378 68 {
Chris@378 69 m_dialog->setLabelText(text);
Chris@378 70 }
Chris@378 71
Chris@378 72 void
Chris@410 73 ProgressDialog::canceled()
Chris@410 74 {
Chris@410 75 m_cancelled = true;
Chris@410 76 emit cancelled();
Chris@410 77 }
Chris@410 78
Chris@410 79 bool
Chris@410 80 ProgressDialog::wasCancelled() const
Chris@410 81 {
Chris@410 82 return m_cancelled;
Chris@410 83 }
Chris@410 84
Chris@410 85 void
Chris@378 86 ProgressDialog::showTimerElapsed()
Chris@378 87 {
Chris@378 88 m_timerElapsed = true;
Chris@378 89 if (m_dialog->value() > 0) {
Chris@410 90 emit showing();
Chris@378 91 m_dialog->show();
Chris@378 92 }
Chris@378 93 qApp->processEvents();
Chris@378 94 }
Chris@378 95
Chris@378 96 void
Chris@378 97 ProgressDialog::setProgress(int percentage)
Chris@378 98 {
Chris@378 99 if (percentage > m_dialog->value()) {
Chris@378 100
Chris@378 101 m_dialog->setValue(percentage);
Chris@378 102
Chris@410 103 if (percentage >= 100 && isDefinite()) {
Chris@378 104 m_dialog->hide();
Chris@378 105 } else if (m_timerElapsed && !m_dialog->isVisible()) {
Chris@410 106 emit showing();
Chris@378 107 m_dialog->show();
Chris@378 108 m_dialog->raise();
Chris@378 109 }
Chris@378 110
Chris@378 111 qApp->processEvents();
Chris@378 112 }
Chris@378 113 }
Chris@378 114