From 81344771dd03fd844daeedcbf3545103db3898c0 Mon Sep 17 00:00:00 2001 From: Eran Mizrahi Date: Wed, 13 Dec 2017 09:49:09 +0200 Subject: Locked dialog fixes (fix mainwindow modalness; use normal window to fix parentless scenario) --- src/lockeddialog.cpp | 46 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 11 deletions(-) (limited to 'src/lockeddialog.cpp') diff --git a/src/lockeddialog.cpp b/src/lockeddialog.cpp index 519abd5b..09538a0f 100644 --- a/src/lockeddialog.cpp +++ b/src/lockeddialog.cpp @@ -25,14 +25,29 @@ along with Mod Organizer. If not, see . #include #include // for Qt::FramelessWindowHint, etc -LockedDialog::LockedDialog(QWidget *parent, const QString &text, bool unlockButton) +LockedDialog::LockedDialog(QWidget *parent, bool unlockByButton) : QDialog(parent) , ui(new Ui::LockedDialog) - , m_UnlockClicked(false) + , m_Unlocked(false) + , m_allowClose(!unlockByButton) { ui->setupUi(this); - this->setWindowFlags(this->windowFlags() | Qt::ToolTip | Qt::FramelessWindowHint); + // Supposedly the Qt::CustomizeWindowHint should use a customized window + // allowing us to select if there is a close button. In practice this doesn't + // seem to work. We will ignore pressing the close button if unlockByButton == true + Qt::WindowFlags flags = + this->windowFlags() | Qt::CustomizeWindowHint | Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint; + if (!unlockByButton) + flags |= Qt::WindowCloseButtonHint; + this->setWindowFlags(flags); + + if (!unlockByButton) + { + ui->unlockButton->hide(); + ui->verticalLayout->addItem( + new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding)); + } if (parent != nullptr) { QPoint position = parent->mapToGlobal(QPoint(parent->width() / 2, parent->height() / 2)); @@ -40,13 +55,6 @@ LockedDialog::LockedDialog(QWidget *parent, const QString &text, bool unlockButt position.ry() -= this->height() / 2; move(position); } - - if (text.length() > 0) { - ui->label->setText(text); - } - if (!unlockButton) { - ui->unlockButton->hide(); - } } LockedDialog::~LockedDialog() @@ -74,5 +82,21 @@ void LockedDialog::resizeEvent(QResizeEvent *event) void LockedDialog::on_unlockButton_clicked() { - m_UnlockClicked = true; + unlock(); +} + +void LockedDialog::reject() +{ + if (m_allowClose) + unlock(); +} + +bool LockedDialog::unlockForced() { + return m_Unlocked; +} + +void LockedDialog::unlock() { + m_Unlocked = true; + ui->label->setText("unlocking may take a few seconds"); + ui->unlockButton->setEnabled(false); } -- cgit v1.3.1