Chris@378: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@378: Chris@378: /* Chris@378: Sonic Visualiser Chris@378: An audio file viewer and annotation editor. Chris@378: Centre for Digital Music, Queen Mary, University of London. Chris@378: This file copyright 2007-2008 QMUL. Chris@378: Chris@378: This program is free software; you can redistribute it and/or Chris@378: modify it under the terms of the GNU General Public License as Chris@378: published by the Free Software Foundation; either version 2 of the Chris@378: License, or (at your option) any later version. See the file Chris@378: COPYING included with this distribution for more information. Chris@378: */ Chris@378: Chris@378: #include "ProgressDialog.h" Chris@378: Chris@378: #include Chris@378: #include Chris@378: #include Chris@378: Chris@378: ProgressDialog::ProgressDialog(QString message, bool cancellable, Chris@378: int timeBeforeShow, QWidget *parent) : Chris@378: m_showTimer(0), Chris@378: m_timerElapsed(false) Chris@378: { Chris@378: m_dialog = new QProgressDialog(message, cancellable ? tr("Cancel") : 0, Chris@378: 0, 100, parent); Chris@378: if (timeBeforeShow > 0) { Chris@378: m_dialog->hide(); Chris@378: m_showTimer = new QTimer; Chris@378: connect(m_showTimer, SIGNAL(timeout()), this, SLOT(showTimerElapsed())); Chris@378: m_showTimer->setSingleShot(true); Chris@378: m_showTimer->start(timeBeforeShow); Chris@378: } else { Chris@378: m_dialog->show(); Chris@378: m_dialog->raise(); Chris@378: m_timerElapsed = true; Chris@378: } Chris@378: Chris@378: if (cancellable) { Chris@378: connect(m_dialog, SIGNAL(canceled()), this, SIGNAL(cancelled())); Chris@378: } Chris@378: } Chris@378: Chris@378: ProgressDialog::~ProgressDialog() Chris@378: { Chris@378: delete m_showTimer; Chris@378: delete m_dialog; Chris@378: } Chris@378: Chris@378: void Chris@378: ProgressDialog::setMessage(QString text) Chris@378: { Chris@378: m_dialog->setLabelText(text); Chris@378: } Chris@378: Chris@378: void Chris@378: ProgressDialog::showTimerElapsed() Chris@378: { Chris@378: m_timerElapsed = true; Chris@378: if (m_dialog->value() > 0) { Chris@378: m_dialog->show(); Chris@378: } Chris@378: qApp->processEvents(); Chris@378: } Chris@378: Chris@378: void Chris@378: ProgressDialog::setProgress(int percentage) Chris@378: { Chris@378: if (percentage > m_dialog->value()) { Chris@378: Chris@378: m_dialog->setValue(percentage); Chris@378: Chris@378: if (percentage >= 100) { Chris@378: m_dialog->hide(); Chris@378: } else if (m_timerElapsed && !m_dialog->isVisible()) { Chris@378: m_dialog->show(); Chris@378: m_dialog->raise(); Chris@378: } Chris@378: Chris@378: qApp->processEvents(); Chris@378: } Chris@378: } Chris@378: