148 lines
2.8 KiB
C++
Executable File
148 lines
2.8 KiB
C++
Executable File
|
|
|
|
|
|
#include "lts_progress_dialog_helper.h"
|
|
|
|
#include "lts_frameless_dialog.h"
|
|
|
|
#include <QCoreApplication>
|
|
#include <QHBoxLayout>
|
|
#include <QLabel>
|
|
#include <QProgressBar>
|
|
#include <QPushButton>
|
|
#include <QTimer>
|
|
|
|
|
|
namespace LtsWidgets
|
|
{
|
|
|
|
LtsProgressDialogHelper::LtsProgressDialogHelper(QWidget *parent)
|
|
: QObject(parent)
|
|
, m_waitDlg(nullptr)
|
|
, m_parentWidget(parent)
|
|
, m_textLabel(nullptr)
|
|
{}
|
|
|
|
|
|
LtsProgressDialogHelper::~LtsProgressDialogHelper()
|
|
{
|
|
delete m_waitDlg;
|
|
}
|
|
|
|
|
|
void LtsProgressDialogHelper::setCustomText(const QString &customText)
|
|
{
|
|
if (m_waitDlg == nullptr || m_textLabel == nullptr)
|
|
return;
|
|
|
|
if (customText.isEmpty())
|
|
m_textLabel->setText(tr("Waiting for server reply..."));
|
|
else
|
|
m_textLabel->setText(customText);
|
|
}
|
|
|
|
void LtsProgressDialogHelper::setParentWidget(QWidget *newParent)
|
|
{
|
|
m_parentWidget = newParent;
|
|
if (m_waitDlg)
|
|
{
|
|
m_waitDlg->setParent(newParent);
|
|
QTimer::singleShot(0, m_waitDlg.data(), &LtsFramelessDialog::onUpdateGeometry);
|
|
}
|
|
}
|
|
|
|
void LtsProgressDialogHelper::slotShowWaitForReplyWindow()
|
|
{
|
|
if (m_waitDlg)
|
|
m_waitDlg->deleteLater();
|
|
m_waitDlg = new LtsFramelessDialog(m_parentWidget, Behaviour::Modal);
|
|
|
|
QHBoxLayout *l = new QHBoxLayout(m_waitDlg);
|
|
|
|
QProgressBar *pb = new QProgressBar(m_waitDlg);
|
|
pb->setMaximum(0);
|
|
pb->setValue(-1);
|
|
|
|
l->addWidget(pb);
|
|
|
|
m_textLabel = new QLabel(m_waitDlg);
|
|
setCustomText();
|
|
l->addWidget(m_textLabel);
|
|
|
|
m_waitDlg->setLayout(l);
|
|
m_waitDlg->show();
|
|
m_waitDlg->raise();
|
|
|
|
|
|
}
|
|
|
|
|
|
void LtsProgressDialogHelper::slotStopWaitForReplyWindow(const ReplyResult &replyResult, const QString &replyString)
|
|
{
|
|
if (m_waitDlg == nullptr)
|
|
{
|
|
|
|
return;
|
|
}
|
|
|
|
|
|
m_waitDlg->deleteLater();
|
|
m_waitDlg = nullptr;
|
|
|
|
|
|
QString resultText = tr("Unknown result (%1)!").arg((int)replyResult);
|
|
|
|
switch (replyResult)
|
|
{
|
|
case ReplyResult::Close:
|
|
{
|
|
return;
|
|
}
|
|
|
|
case ReplyResult::Success:
|
|
{
|
|
resultText = tr("Operation was successful");
|
|
break;
|
|
}
|
|
|
|
case ReplyResult::Failure:
|
|
{
|
|
resultText = tr("Operation has failed!\nReason: '%1'").arg(replyString);
|
|
break;
|
|
}
|
|
|
|
case ReplyResult::TimeOut:
|
|
{
|
|
resultText = tr("Operation has timed out and could not be processed! Please try again later");
|
|
break;
|
|
}
|
|
}
|
|
|
|
m_waitDlg = new LtsFramelessDialog(m_parentWidget, Behaviour::Modal);
|
|
|
|
QVBoxLayout *newLayout = new QVBoxLayout(m_waitDlg);
|
|
newLayout->addWidget(new QLabel(resultText, m_waitDlg));
|
|
|
|
QPushButton *btn = new QPushButton(tr("OK"),m_waitDlg);
|
|
connect(btn, &QPushButton::clicked,
|
|
this, &LtsProgressDialogHelper::accept);
|
|
|
|
newLayout->addWidget(btn);
|
|
|
|
m_waitDlg->setLayout(newLayout);
|
|
m_waitDlg->show();
|
|
|
|
|
|
}
|
|
|
|
|
|
void LtsProgressDialogHelper::accept()
|
|
{
|
|
m_waitDlg->accept();
|
|
m_waitDlg->deleteLater();
|
|
m_waitDlg = nullptr;
|
|
emit accepted();
|
|
}
|
|
|
|
}
|