diff options
author | Simon Rettberg | 2024-04-30 09:28:41 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-04-30 09:28:41 +0200 |
commit | 688a0887a38e5b4ff96d72772d27fc7616cd3d51 (patch) | |
tree | fef0d6955052a61029fc8162e9ea0d82f61c95e4 /src | |
parent | Inischl commit (diff) | |
download | cowgui-688a0887a38e5b4ff96d72772d27fc7616cd3d51.tar.gz cowgui-688a0887a38e5b4ff96d72772d27fc7616cd3d51.tar.xz cowgui-688a0887a38e5b4ff96d72772d27fc7616cd3d51.zip |
Stay on top, ignore close events
Diffstat (limited to 'src')
-rw-r--r-- | src/gui.cpp | 16 | ||||
-rw-r--r-- | src/gui.h | 4 |
2 files changed, 19 insertions, 1 deletions
diff --git a/src/gui.cpp b/src/gui.cpp index e27086a..02925ad 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -11,6 +11,7 @@ #include <QJsonDocument> #include <QJsonObject> #include <QJsonArray> +#include <QCloseEvent> static QString STATE_COPYING("COPYING"); // Still busy copying original file, new chunks are only accepted in already copied range static QString STATE_WAITING_FOR_UPLOAD_DONE("WAITING_FOR_UPLOAD_DONE"); // Copying done, just waiting for new chunks until client signals that it's done @@ -27,13 +28,14 @@ Gui::Gui(const char *urlbase, const char *uuid, QWidget *parent) , _urlAbort(QString(urlbase).append("abort/").append(uuid)) , _urlFinish(QString(urlbase).append("finish/").append(uuid)) , _denyInteraction(false) + , _allowClose(false) , _tmrStatus(new QTimer(this)) , _status(nullptr) { _nam->setAutoDeleteReplies(true); _nam->setTransferTimeout(5000); setupUi(); - auto flags = windowFlags(); + auto flags = windowFlags() | Qt::WindowStaysOnTopHint; setWindowFlags(flags & ~(Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint)); _tmrStatus->start(2500); QObject::connect(_tmrStatus, &QTimer::timeout, [this]() { @@ -154,6 +156,7 @@ void Gui::updateButtons() void Gui::pushedCancel(bool) { if (_remoteState == STATE_ERROR) { + _allowClose = true; this->close(); return; } @@ -181,6 +184,7 @@ void Gui::pushedCancel(bool) _remoteState = STATE_ERROR; QMessageBox::information(this, tr("Ergebnis"), msg); QTimer::singleShot(2000, [this]() { + _allowClose = true; this->close(); }); } @@ -190,6 +194,7 @@ void Gui::pushedCancel(bool) void Gui::pushedOk(bool) { if (_remoteState == STATE_COMPLETELY_DONE || _remoteState == STATE_PROCESSING) { + _allowClose = true; this->close(); return; } @@ -215,3 +220,12 @@ void Gui::pushedOk(bool) } }); } + +void Gui::closeEvent(QCloseEvent *e) +{ + if (_allowClose) { + QDialog::closeEvent(e); + } else { + e->ignore(); + } +} @@ -19,6 +19,9 @@ public: explicit Gui(const char *urlbase, const char *uuid, QWidget *parent = nullptr); ~Gui(); +protected: + virtual void closeEvent(QCloseEvent *event) override; + private slots: void pushedCancel(bool pushed); void pushedOk(bool pushed); @@ -32,6 +35,7 @@ private: QString _remoteState; QString _urlStatus, _urlAbort, _urlFinish; bool _denyInteraction; + bool _allowClose; QPushButton *_btnAbort, *_btnOk; QTimer *_tmrStatus; QHash<QString, Progress*> _items; |