#include "dialogs/CancelableTaskDialog.h" #include #include #include #include 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(); }