You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB
C++

5 years ago
#include "waitingdialog.h"
#include "QBoxLayout"
#include <QProgressBar>
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);
}