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(progress dialog): if there is a parent center on creation #1329

Merged
merged 1 commit into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
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
23 changes: 15 additions & 8 deletions launcher/ui/dialogs/ProgressDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ ProgressDialog::ProgressDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Pr
ui->taskProgressScrollArea->setHidden(true);
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
setAttribute(Qt::WidgetAttribute::WA_QuitOnClose, true);
setSkipButton(false);
changeProgress(0, 100);
updateSize();
updateSize(true);
setSkipButton(false);
}

void ProgressDialog::setSkipButton(bool present, QString label)
Expand All @@ -95,7 +95,7 @@ ProgressDialog::~ProgressDialog()
delete ui;
}

void ProgressDialog::updateSize()
void ProgressDialog::updateSize(bool recenterParent)
{
QSize lastSize = this->size();
QPoint lastPos = this->pos();
Expand All @@ -112,13 +112,20 @@ void ProgressDialog::updateSize()
adjustSize();

QSize newSize = this->size();
// if the current window is too small
if ((lastSize != newSize) && (lastSize.height() < newSize.height()))
// if the current window is a different size
auto parent = this->parentWidget();
if (recenterParent && parent) {
auto newX = std::max(0, parent->x() + ((parent->width() - newSize.width()) / 2));
auto newY = std::max(0, parent->y() + ((parent->height() - newSize.height()) / 2));
this->move(newX, newY);
}
else if (lastSize != newSize)
{
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);
QSize sizeDiff = lastSize - newSize; // last size was smaller, the results should be negative
auto newX = std::max(0, lastPos.x() + (sizeDiff.width() / 2));
auto newY = std::max(0, lastPos.y() + (sizeDiff.height() / 2));
this->move(newX, newY);
}

}
Expand Down
2 changes: 1 addition & 1 deletion launcher/ui/dialogs/ProgressDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ProgressDialog : public QDialog
explicit ProgressDialog(QWidget *parent = 0);
~ProgressDialog();

void updateSize();
void updateSize(bool recenterParent = false);

int execWithTask(Task* task);
int execWithTask(std::unique_ptr<Task> &&task);
Expand Down