Merge pull request #1329 from Ryex/fix/progress_dialog_centering
fix(progress dialog): if there is a parent center on creation
This commit is contained in:
commit
67d473aab7
@ -67,9 +67,9 @@ ProgressDialog::ProgressDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Pr
|
|||||||
ui->taskProgressScrollArea->setHidden(true);
|
ui->taskProgressScrollArea->setHidden(true);
|
||||||
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||||
setAttribute(Qt::WidgetAttribute::WA_QuitOnClose, true);
|
setAttribute(Qt::WidgetAttribute::WA_QuitOnClose, true);
|
||||||
setSkipButton(false);
|
|
||||||
changeProgress(0, 100);
|
changeProgress(0, 100);
|
||||||
updateSize();
|
updateSize(true);
|
||||||
|
setSkipButton(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressDialog::setSkipButton(bool present, QString label)
|
void ProgressDialog::setSkipButton(bool present, QString label)
|
||||||
@ -95,7 +95,7 @@ ProgressDialog::~ProgressDialog()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProgressDialog::updateSize()
|
void ProgressDialog::updateSize(bool recenterParent)
|
||||||
{
|
{
|
||||||
QSize lastSize = this->size();
|
QSize lastSize = this->size();
|
||||||
QPoint lastPos = this->pos();
|
QPoint lastPos = this->pos();
|
||||||
@ -112,13 +112,20 @@ void ProgressDialog::updateSize()
|
|||||||
adjustSize();
|
adjustSize();
|
||||||
|
|
||||||
QSize newSize = this->size();
|
QSize newSize = this->size();
|
||||||
// if the current window is too small
|
// if the current window is a different size
|
||||||
if ((lastSize != newSize) && (lastSize.height() < newSize.height()))
|
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
|
// center on old position after resize
|
||||||
QPoint newPos(lastPos.x() + (sizeDiff.width() / 2), lastPos.y() + (sizeDiff.height() / 2));
|
QSize sizeDiff = lastSize - newSize; // last size was smaller, the results should be negative
|
||||||
this->move(newPos);
|
auto newX = std::max(0, lastPos.x() + (sizeDiff.width() / 2));
|
||||||
|
auto newY = std::max(0, lastPos.y() + (sizeDiff.height() / 2));
|
||||||
|
this->move(newX, newY);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ public:
|
|||||||
explicit ProgressDialog(QWidget *parent = 0);
|
explicit ProgressDialog(QWidget *parent = 0);
|
||||||
~ProgressDialog();
|
~ProgressDialog();
|
||||||
|
|
||||||
void updateSize();
|
void updateSize(bool recenterParent = false);
|
||||||
|
|
||||||
int execWithTask(Task* task);
|
int execWithTask(Task* task);
|
||||||
int execWithTask(std::unique_ptr<Task> &&task);
|
int execWithTask(std::unique_ptr<Task> &&task);
|
||||||
|
Loading…
Reference in New Issue
Block a user