From af836c41e4e295346421a9d9259908fb66bb4d00 Mon Sep 17 00:00:00 2001 From: xiaoming <2014500726@smail.xtu.edu.cn> Date: Thu, 19 Sep 2024 10:30:52 +0800 Subject: [PATCH] Add reconfirm when closing the floating window Signed-off-by: xiaoming <2014500726@smail.xtu.edu.cn> --- CHANGELOG.md | 2 ++ docs/changelog.md | 1 + src/mainwindow.cpp | 9 +++------ src/mainwindow.h | 29 +++++++++++++++++++++++++++++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 40eac649..16ac3c9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ en-US: - Add record script feature - Add recently loaded script feature - Add disable plugin command line option +- Add reconfirm when closing the floating window - Improve the default path of recording logs, etc. to the last saved path - Improve the appearance of the session tabs - Fix the small probability memory leak problem @@ -22,6 +23,7 @@ zh-CN: - 增加记录脚本功能 - 增加最近加载的脚本功能 - 增加禁用插件命令行选项 +- 增加浮动窗口关闭时二次确认 - 改进记录日志等默认路径为上次保存路径 - 改进会话标签外观 - 修复可能存在的小概率内存泄漏问题 diff --git a/docs/changelog.md b/docs/changelog.md index db396054..bc4c068c 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,7 @@ - Add record script feature - Add recently loaded script feature - Add disable plugin command line option +- Add reconfirm when closing the floating window - Improve the default path of recording logs, etc. to the last saved path - Improve the appearance of the session tabs - Fix the small probability memory leak problem diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index c4489ac2..4ea1afdb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1375,10 +1375,7 @@ void CentralWidget::terminalWidgetContextMenuBase(QMenu *menu,SessionsWindow *te } void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) { - QDialog *dialog = new QDialog(this); - dialog->setWindowFlags(Qt::Window); - dialog->resize(800,480); - dialog->setLayout(new QVBoxLayout); + FloatingTab *dialog = new FloatingTab(this); MainWidgetGroup *group = new MainWidgetGroup(MainWidgetGroup::FLOATING,dialog); mainWidgetGroupList.append(group); int newGroup = mainWidgetGroupList.count()-1; @@ -1402,7 +1399,7 @@ void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) { menu->addAction(floatBackAction); connect(floatBackAction,&QAction::triggered,this,[=](){ moveToAnotherTab(newGroup,0,1); - dialog->close(); + dialog->forceClose(); }); if(menu->isEmpty()) { delete menu; @@ -1423,7 +1420,7 @@ void CentralWidget::floatingWindow(MainWidgetGroup *g, int index) { SessionsWindow *sessionsWindow = widget->property("session").value(); sessionsWindow->proxySendData(data); }); - connect(dialog, &QDialog::finished, this, [=](int result){ + connect(dialog, &FloatingTab::finished, this, [=](int result){ MainWidgetGroup *group = mainWidgetGroupList.at(newGroup); stopSession(group,1,true); mainWidgetGroupList.removeAt(newGroup); diff --git a/src/mainwindow.h b/src/mainwindow.h index da1ea19a..132a8ff6 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -74,6 +74,35 @@ extern QString HASH_TAG; extern QString SHORT_HASH_TAG; extern QDateTime START_TIME; +class FloatingTab : public QDialog { + Q_OBJECT +public: + explicit FloatingTab(QWidget *parent = nullptr) : QDialog(parent) { + setWindowFlags(Qt::Window); + resize(800,480); + setLayout(new QVBoxLayout); + } + void forceClose(void) { + doNotAskClose = true; + close(); + } +protected: + void closeEvent(QCloseEvent *event) override { + if(doNotAskClose) { + QDialog::closeEvent(event); + } else { + QMessageBox::StandardButton ret = QMessageBox::question(this, tr("Close"),tr("Do you want to close this window?"),QMessageBox::Yes|QMessageBox::No); + if(ret == QMessageBox::Yes) { + event->accept(); + } else { + event->ignore(); + } + } + } +private: + bool doNotAskClose = false; +}; + QT_BEGIN_NAMESPACE namespace Ui { class CentralWidget; } QT_END_NAMESPACE