V20251117-2.2.1
优化退出交互。
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@
|
||||
#include <QDir>
|
||||
|
||||
#pragma execution_character_set("utf-8")
|
||||
const std::string softwareVersion = "20251116-2.2.0";
|
||||
const std::string softwareVersion = "20251117-2.2.1";
|
||||
const std::string euiJsonVersion = "1.0.6";
|
||||
#define globalDatabasePth "./sqlDatabase/eui_db.db" //全局数据库路径
|
||||
#define saveImgEnable 1
|
||||
|
||||
@@ -41,9 +41,6 @@ public:
|
||||
};
|
||||
const int topBarHeight = 40;
|
||||
const int buttonWidth = 50;
|
||||
void registerQuitFunc(std::function<void()> quitFunc) {
|
||||
quitFunction = quitFunc;
|
||||
}
|
||||
topMenuBar(QMainWindow* mainWindowIN,appConfig* configIN = nullptr,QWidget* parent = nullptr)
|
||||
: QWidget(parent), config(configIN), mainWindow(mainWindowIN){
|
||||
|
||||
@@ -146,7 +143,9 @@ public:
|
||||
"QPushButton:hover { background-color: rgb(%1); }").arg(sColor_Red)); // 设置透明背景和悬停时的背景色
|
||||
exitButton->setFixedHeight(topBarHeight);
|
||||
exitButton->setFixedWidth(buttonWidth);
|
||||
QObject::connect(exitButton, &QPushButton::clicked, this, &topMenuBar::QuitCheck); // 点击退出按钮退出应用程序
|
||||
//QObject::connect(exitButton, &QPushButton::clicked, this, &topMenuBar::QuitCheck); // 点击退出按钮退出应用程序
|
||||
connect(exitButton, &QPushButton::clicked, mainWindow, &QWidget::close);
|
||||
|
||||
}
|
||||
public slots:
|
||||
void toggleMaximize(toggleMaximizeEnum toggleMaximizeEnumIn = reverse) {
|
||||
@@ -171,32 +170,11 @@ public slots:
|
||||
break;
|
||||
}
|
||||
}
|
||||
void QuitCheck() {
|
||||
//跳出确认窗口
|
||||
QMessageBox::StandardButton reply;
|
||||
reply = QMessageBox::question(mainWindow,
|
||||
QString::fromStdString(Translation::getInstance().translate("Exit Confirmation")),
|
||||
QString::fromStdString(Translation::getInstance().translate("Do you want to exit the application?")),
|
||||
QMessageBox::Yes | QMessageBox::No);
|
||||
if (reply == QMessageBox::Yes) {
|
||||
Quit(); // 确认退出
|
||||
}
|
||||
else {
|
||||
// 取消退出
|
||||
qDebug() << "用户取消了退出操作";
|
||||
}
|
||||
}
|
||||
void Quit() {
|
||||
qDebug() << "退出应用程序";
|
||||
quitFunction();
|
||||
config->saveSettingJson();
|
||||
QApplication::quit(); // 退出应用程序
|
||||
}
|
||||
private:
|
||||
QMainWindow* mainWindow;
|
||||
QPushButton* maximizeRestoreButton;
|
||||
appConfig* config;
|
||||
std::function<void()> quitFunction;
|
||||
|
||||
};
|
||||
class leftMenuBar : public QWidget {
|
||||
public:
|
||||
@@ -265,7 +243,7 @@ public:
|
||||
nlohmann::ordered_json& _jsonIn = nlohmann::ordered_json());
|
||||
~MainWindow();
|
||||
void registerQuitFunc(std::function<void()> quitFunc) {
|
||||
topBar->registerQuitFunc(quitFunc);
|
||||
quitFunction = quitFunc;
|
||||
}
|
||||
|
||||
//主要控件
|
||||
@@ -436,6 +414,58 @@ signals:
|
||||
void recvPixmapImageWidgetSignal(showImgPack*);
|
||||
void signal_summaryData_addData(QString window, double data);
|
||||
protected:
|
||||
std::function<void()> quitFunction;
|
||||
void closeEvent(QCloseEvent* event){
|
||||
|
||||
QDialog dialog(this);
|
||||
dialog.setWindowTitle(TR("Exit Confirmation"));
|
||||
dialog.setModal(true);
|
||||
|
||||
QVBoxLayout layout(&dialog);
|
||||
|
||||
int countdown = 15;
|
||||
QLabel label(QString(TR("Please enter Y to exit (will cancel after %1 sec)")).arg(countdown));
|
||||
QLineEdit edit;
|
||||
edit.setPlaceholderText(TR("Enter Y or y"));
|
||||
|
||||
QPushButton btnOk(TR("OK"));
|
||||
|
||||
layout.addWidget(&label);
|
||||
layout.addWidget(&edit);
|
||||
layout.addWidget(&btnOk);
|
||||
|
||||
dialog.setLayout(&layout);
|
||||
|
||||
QTimer timer;
|
||||
timer.setInterval(1000);
|
||||
|
||||
QObject::connect(&timer, &QTimer::timeout, [&]() {
|
||||
countdown--;
|
||||
label.setText(QString(TR("Please enter Y to exit (will cancel after %1 sec)")).arg(countdown));
|
||||
|
||||
if (countdown <= 0) {
|
||||
dialog.reject(); // 超时关闭对话框
|
||||
}
|
||||
});
|
||||
|
||||
timer.start();
|
||||
|
||||
QObject::connect(&btnOk, &QPushButton::clicked, [&]() {dialog.accept(); });
|
||||
|
||||
int ret = dialog.exec();
|
||||
if (ret == QDialog::Accepted &&(edit.text() == "Y" || edit.text() == "y")){
|
||||
qDebug() << "退出应用程序";
|
||||
quitFunction();
|
||||
config->saveSettingJson();
|
||||
event->accept();
|
||||
}
|
||||
else {
|
||||
event->ignore();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void mouseDoubleClickEvent(QMouseEvent* event) override {
|
||||
if (event->pos().y() < topBar->topBarHeight)
|
||||
return
|
||||
|
||||
@@ -266,6 +266,26 @@
|
||||
"us-EN": "Exit Confirmation",
|
||||
"zh-CN": "退出确认"
|
||||
},
|
||||
"Exiting...": {
|
||||
"ms-MY": "Keluar...",
|
||||
"us-EN": "Exiting...",
|
||||
"zh-CN": "正在退出..."
|
||||
},
|
||||
"Exiting, please wait": {
|
||||
"ms-MY": "Keluar, sila tunggu sebentar",
|
||||
"us-EN": "Exiting, please wait",
|
||||
"zh-CN": "退出中,请稍后"
|
||||
},
|
||||
"Please enter Y to exit (will cancel after %1 sec)": {
|
||||
"ms-MY": "Sila masukkan Y untuk keluar (akan batal selepas %1 saat)",
|
||||
"us-EN": "Please enter Y to exit (will cancel after %1 sec)",
|
||||
"zh-CN": "请输入 Y 以退出(%1 秒后取消)"
|
||||
},
|
||||
"Enter Y or y": {
|
||||
"ms-MY": "Masukkan Y atau y",
|
||||
"us-EN": "Enter Y or y",
|
||||
"zh-CN": "输入 Y 或 y"
|
||||
},
|
||||
"Export": {
|
||||
"ms-MY": "Eksport",
|
||||
"us-EN": "Export",
|
||||
|
||||
Reference in New Issue
Block a user