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/ilockedwaitingforprocess.h | 2 +- src/lockeddialog.cpp | 46 ++++++++++++++++++++++++++++++++---------- src/lockeddialog.h | 11 +++++++--- src/lockeddialog.ui | 42 +++++++++++++++++++++++++++++++++++--- src/mainwindow.cpp | 3 ++- src/organizercore.cpp | 2 +- 6 files changed, 86 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/ilockedwaitingforprocess.h b/src/ilockedwaitingforprocess.h index 6a4267d4..5bf1f1ca 100644 --- a/src/ilockedwaitingforprocess.h +++ b/src/ilockedwaitingforprocess.h @@ -6,7 +6,7 @@ class QString; class ILockedWaitingForProcess { public: - virtual bool unlockClicked() = 0; + virtual bool unlockForced() = 0; virtual void setProcessName(QString const &) = 0; }; 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); } diff --git a/src/lockeddialog.h b/src/lockeddialog.h index 8803efae..82a15a93 100644 --- a/src/lockeddialog.h +++ b/src/lockeddialog.h @@ -45,7 +45,7 @@ class LockedDialog : public QDialog, public ILockedWaitingForProcess Q_OBJECT public: - explicit LockedDialog(QWidget *parent = 0, const QString &text = "", bool unlockButton = true); + explicit LockedDialog(QWidget *parent = 0, bool unlockByButton = false); ~LockedDialog(); /** @@ -53,7 +53,7 @@ public: * * @return true if the user clicked the unlock button **/ - bool unlockClicked() override { return m_UnlockClicked; } + bool unlockForced() override; /** * @brief set the name of the process being run @@ -65,13 +65,18 @@ protected: virtual void resizeEvent(QResizeEvent *event); + virtual void reject(); + private slots: void on_unlockButton_clicked(); private: + void unlock(); + Ui::LockedDialog *ui; - bool m_UnlockClicked; + bool m_Unlocked; + bool m_allowClose; }; #endif // LOCKEDDIALOG_H diff --git a/src/lockeddialog.ui b/src/lockeddialog.ui index 2175f8ac..0ec2e467 100644 --- a/src/lockeddialog.ui +++ b/src/lockeddialog.ui @@ -11,7 +11,7 @@ - Locked + Running virtualized processes @@ -30,7 +30,19 @@ - + + + + Qt::Vertical + + + + 10 + + + + + @@ -48,13 +60,37 @@ - + + + + Qt::Vertical + + + + 10 + + + + + Unlock + + + + Qt::Vertical + + + + 10 + + + + diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 632b64e9..1e1a4558 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1471,7 +1471,8 @@ ILockedWaitingForProcess* MainWindow::lock() ++m_LockCount; return m_LockDialog; } - m_LockDialog = new LockedDialog(qApp->activeWindow()); + m_LockDialog = new LockedDialog(this, true); + m_LockDialog->setModal(true); m_LockDialog->show(); setEnabled(false); m_LockDialog->setEnabled(true); //What's the point otherwise? diff --git a/src/organizercore.cpp b/src/organizercore.cpp index 5601afa7..1f42bf95 100644 --- a/src/organizercore.cpp +++ b/src/organizercore.cpp @@ -1350,7 +1350,7 @@ bool OrganizerCore::waitForProcessCompletion(HANDLE handle, LPDWORD exitCode, IL break; } - if (uilock && uilock->unlockClicked()) { + if (uilock && uilock->unlockForced()) { uiunlocked = true; break; } -- cgit v1.3.1