qt/LedOK/base/waitingdlg.cpp

51 lines
1.4 KiB
C++
Raw Normal View History

2022-08-25 18:37:24 +08:00
#include "waitingdlg.h"
#include <QBoxLayout>
#include <QTimerEvent>
2022-10-27 15:07:45 +08:00
WaitingDlg::WaitingDlg(QWidget *parent, QString text, QString sucText) : BaseDlg{parent}, sucText(sucText) {
2022-08-25 18:37:24 +08:00
setAttribute(Qt::WA_DeleteOnClose);
setModal(true);
auto pal = palette();
pal.setBrush(QPalette::Window, QColor(0xdddddd));
setPalette(pal);
auto vBox = new QVBoxLayout(this);
vBox->addStretch();
mIndicator = new CustomProgressIndicator(this);
mIndicator->setDisplayModel(1);
mIndicator->setColor(QColor(0x0088dd));
mIndicator->startAnimation();
vBox->addWidget(mIndicator, 0, Qt::AlignCenter);
vBox->addStretch();
fdText = new QLabel(text);
fdText->setAlignment(Qt::AlignCenter);
auto font = fdText->font();
font.setPixelSize(18);
font.setBold(true);
fdText->setFont(font);
pal = fdText->palette();
pal.setBrush(QPalette::WindowText, QColor(0x0088dd));
fdText->setPalette(pal);
vBox->addWidget(fdText);
vBox->addStretch();
}
void WaitingDlg::timerEvent(QTimerEvent *event) {
if(closeTimerId==event->timerId()) {
killTimer(closeTimerId);
closeTimerId = 0;
close();
} else BaseDlg::timerEvent(event);
}
void WaitingDlg::success() {
2022-10-27 15:07:45 +08:00
fdText->setText(sucText.isEmpty() ? tr("Success") : sucText);
2022-08-25 18:37:24 +08:00
mIndicator->setBackground(":/res/success.png");
mIndicator->stopAnimation();
closeTimerId = startTimer(800);
}