|
@ -42,18 +42,20 @@ ProgressDialog::ProgressDialog(const MessageConfig &config, QPointer<MessageResu |
|
|
layout->addWidget(_progress); |
|
|
layout->addWidget(_progress); |
|
|
|
|
|
|
|
|
//add the cancel button, in case it was requested
|
|
|
//add the cancel button, in case it was requested
|
|
|
if(config.buttons().testFlag(MessageConfig::Cancel)) { |
|
|
if(config.buttons() != MessageConfig::NoButton) { |
|
|
_btnBox = new QDialogButtonBox{this}; |
|
|
_btnBox = new QDialogButtonBox{this}; |
|
|
_btnBox->setStandardButtons(QDialogButtonBox::Cancel); //is ok, as the buttons are the same
|
|
|
_btnBox->setStandardButtons(static_cast<QDialogButtonBox::StandardButtons>(static_cast<int>(config.buttons()))); //is ok, as the buttons are the same
|
|
|
auto btnTexts = config.buttonTexts(); |
|
|
auto btns = config.buttonTexts(); |
|
|
if(btnTexts.contains(MessageConfig::Cancel)) |
|
|
for(auto it = btns.constBegin(); it != btns.constEnd(); it++){ |
|
|
_btnBox->button(QDialogButtonBox::Cancel)->setText(btnTexts.value(MessageConfig::Cancel)); |
|
|
auto sBtn = static_cast<QDialogButtonBox::StandardButton>(it.key()); |
|
|
|
|
|
Q_ASSERT(_btnBox->standardButtons().testFlag(sBtn)); //Must be the case now because of the change in MessageConfig
|
|
|
|
|
|
_btnBox->button(sBtn)->setText(it.value()); |
|
|
|
|
|
} |
|
|
layout->addWidget(_btnBox); |
|
|
layout->addWidget(_btnBox); |
|
|
// connect the box
|
|
|
// connect the box
|
|
|
connect(_btnBox, &QDialogButtonBox::clicked, |
|
|
connect(_btnBox, &QDialogButtonBox::clicked, |
|
|
this, [this](QAbstractButton *btn) { |
|
|
this, [this](QAbstractButton *btn) { |
|
|
if(_btnBox->standardButton(btn) == QDialogButtonBox::Cancel) |
|
|
tryCancel(_btnBox->standardButton(btn)); |
|
|
tryCancel(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -75,9 +77,6 @@ ProgressDialog::ProgressDialog(const MessageConfig &config, QPointer<MessageResu |
|
|
this, &ProgressDialog::setIndetem); |
|
|
this, &ProgressDialog::setIndetem); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
connect(this, &ProgressDialog::canceled, |
|
|
|
|
|
_control, &ProgressControl::requestCancel); |
|
|
|
|
|
|
|
|
|
|
|
adjustSize(); |
|
|
adjustSize(); |
|
|
DialogMaster::masterDialog(this, true, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
|
|
DialogMaster::masterDialog(this, true, Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint); |
|
|
} |
|
|
} |
|
@ -87,29 +86,25 @@ void ProgressDialog::done(int code) |
|
|
QDialog::done(code); |
|
|
QDialog::done(code); |
|
|
if(_control) |
|
|
if(_control) |
|
|
_control->notifyClosed(); |
|
|
_control->notifyClosed(); |
|
|
if(_result) { |
|
|
if(_result) |
|
|
if(_wasCanceled) |
|
|
_result->complete(_cancelAction); |
|
|
_result->complete(MessageConfig::Cancel); |
|
|
|
|
|
else |
|
|
|
|
|
_result->complete(MessageConfig::Close); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ProgressDialog::closeEvent(QCloseEvent *event) |
|
|
void ProgressDialog::closeEvent(QCloseEvent *event) |
|
|
{ |
|
|
{ |
|
|
event->ignore(); |
|
|
event->ignore(); |
|
|
tryCancel(); |
|
|
tryCancel(QDialogButtonBox::Cancel); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ProgressDialog::tryCancel() |
|
|
void ProgressDialog::tryCancel(QDialogButtonBox::StandardButton btn) |
|
|
{ |
|
|
{ |
|
|
if(!_wasCanceled && _btnBox) { |
|
|
if(_cancelAction == MessageConfig::NoButton && _btnBox) { |
|
|
_wasCanceled = true; |
|
|
_cancelAction = static_cast<MessageConfig::StandardButton>(btn); |
|
|
_btnBox->button(QDialogButtonBox::Cancel)->setEnabled(false); |
|
|
_btnBox->setEnabled(false); |
|
|
if(_control) |
|
|
if(_control) |
|
|
_control->requestCancel(); |
|
|
_control->requestCancel(_cancelAction); |
|
|
else |
|
|
else |
|
|
done(QDialogButtonBox::Cancel); |
|
|
done(btn); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|