Files
hfut-bishe/client/gui/dialogs/CancelableTaskDialog.cpp
2026-04-07 20:55:30 +08:00

51 lines
1.3 KiB
C++

#include "dialogs/CancelableTaskDialog.h"
#include <QBoxLayout>
#include <QLabel>
#include <QProgressBar>
#include <QPushButton>
CancelableTaskDialog::CancelableTaskDialog(const QString& title,
const QString& message,
QWidget* parent)
: QDialog(parent) {
setWindowTitle(title);
setModal(true);
setMinimumWidth(420);
auto* root = new QVBoxLayout(this);
root->setContentsMargins(14, 14, 14, 14);
root->setSpacing(10);
m_label = new QLabel(message, this);
m_label->setWordWrap(true);
root->addWidget(m_label);
m_bar = new QProgressBar(this);
m_bar->setRange(0, 0); // 不定进度
root->addWidget(m_bar);
auto* row = new QHBoxLayout();
row->addStretch(1);
m_btnCancel = new QPushButton(QStringLiteral("取消"), this);
row->addWidget(m_btnCancel);
root->addLayout(row);
connect(m_btnCancel, &QPushButton::clicked, this, &CancelableTaskDialog::onCancel);
}
void CancelableTaskDialog::setMessage(const QString& message) {
if (m_label) {
m_label->setText(message);
}
}
void CancelableTaskDialog::onCancel() {
if (m_canceled) {
return;
}
m_canceled = true;
emit canceled();
}