#include "waitingdialog.h" #include "QBoxLayout" #include WaitingDialog::WaitingDialog(QWidget *parent) : QDialog(parent) { m_ProgressBar = NULL; m_ProgressBar = new QProgressBar(this); m_CurrentValue = m_MaxValue = m_UpdateInterval = 0; m_ProgressBar->setRange(0, 100); connect(&m_Timer, SIGNAL(timeout()), this, SLOT(UpdateSlot())); m_ProgressBar->setTextVisible(false); QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(m_ProgressBar); setLayout(layout); } WaitingDialog::~WaitingDialog() { if (m_ProgressBar) { delete m_ProgressBar; m_ProgressBar = NULL; } } void WaitingDialog::Start(int interval /*= 100*/, int maxValue /*= 100*/) { m_UpdateInterval = interval; m_MaxValue = maxValue; m_CurrentValue = 0; if (m_Timer.isActive()) m_Timer.stop(); m_Timer.start(m_UpdateInterval); m_ProgressBar->setRange(0, m_MaxValue); m_ProgressBar->setValue(0); } void WaitingDialog::Stop() { m_Timer.stop(); } void WaitingDialog::UpdateSlot() { m_CurrentValue++; if (m_CurrentValue == m_MaxValue) m_CurrentValue = 0; m_ProgressBar->setValue(m_CurrentValue); }