Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: segfault in progress dialog #1302

Merged
merged 5 commits into from
Jul 8, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 23 additions & 12 deletions launcher/ui/dialogs/ProgressDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

#include "ProgressDialog.h"
#include <QPoint>
#include "ui_ProgressDialog.h"

#include <limits>
Expand Down Expand Up @@ -68,6 +69,7 @@ ProgressDialog::ProgressDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Pr
setAttribute(Qt::WidgetAttribute::WA_QuitOnClose, true);
setSkipButton(false);
changeProgress(0, 100);
updateSize();
}

void ProgressDialog::setSkipButton(bool present, QString label)
Expand Down Expand Up @@ -96,22 +98,29 @@ ProgressDialog::~ProgressDialog()
void ProgressDialog::updateSize()
{
QSize lastSize = this->size();
QSize qSize = QSize(480, minimumSizeHint().height());

QPoint lastPos = this->pos();
int minHeight = ui->globalStatusDetailsLabel->minimumSize().height() + (ui->verticalLayout->spacing() * 2);
minHeight += ui->globalProgressBar->minimumSize().height() + ui->verticalLayout->spacing();
if (!ui->taskProgressScrollArea->isHidden())
minHeight += ui->taskProgressScrollArea->minimumSizeHint().height() + ui->verticalLayout->spacing();
if (ui->skipButton->isVisible())
minHeight += ui->skipButton->height() + ui->verticalLayout->spacing();
minHeight = std::max(minHeight, 60);
QSize minSize = QSize(480, minHeight);

setMinimumSize(minSize);
adjustSize();

QSize newSize = this->size();
// if the current window is too small
if ((lastSize != qSize) && (lastSize.height() < qSize.height()))
if ((lastSize != newSize) && (lastSize.height() < newSize.height()))
{
resize(qSize);

// keep the dialog in the center after a resize
this->move(
this->parentWidget()->x() + (this->parentWidget()->width() - this->width()) / 2,
this->parentWidget()->y() + (this->parentWidget()->height() - this->height()) / 2
);
QSize sizeDiff = lastSize - newSize; // last size was smaller, the results should be negative
// center on old position after resize
QPoint newPos(lastPos.x() + (sizeDiff.width() / 2), lastPos.y() + (sizeDiff.height() / 2));
this->move(newPos);
}

setMinimumSize(qSize);

}

int ProgressDialog::execWithTask(Task* task)
Expand Down Expand Up @@ -201,7 +210,9 @@ void ProgressDialog::onTaskSucceeded()
void ProgressDialog::changeStatus(const QString& status)
{
ui->globalStatusLabel->setText(task->getStatus());
ui->globalStatusLabel->adjustSize();
ui->globalStatusDetailsLabel->setText(task->getDetails());
ui->globalStatusDetailsLabel->adjustSize();

updateSize();
}
Expand Down