From 06ee23aff9c28ee634bcec45931da0da34e0efb3 Mon Sep 17 00:00:00 2001 From: hongjinchuan Date: Fri, 1 Sep 2023 13:45:03 +0800 Subject: [PATCH] feat: complete dialog box common library 1. add question dialog log: complete common library --- assets/translations/en_US.ts | 70 ++++++++++-------- assets/translations/zh_CN.ts | 72 +++++++++++-------- debian/changelog | 5 ++ src/common/dialog/contextdialog.cpp | 31 +++++++- src/common/dialog/contextdialog.h | 7 ++ .../mainframe/binarytoolsconfigview.cpp | 45 +++++++----- src/plugins/template/wizard/detailwidget.cpp | 2 +- 7 files changed, 152 insertions(+), 80 deletions(-) create mode 100644 debian/changelog diff --git a/assets/translations/en_US.ts b/assets/translations/en_US.ts index 9cc61a922..013e3bf8f 100644 --- a/assets/translations/en_US.ts +++ b/assets/translations/en_US.ts @@ -45,47 +45,47 @@ BinaryToolsConfigView - + Add - + Delete - + Rename - + Combine - + Binary configuration: - + command combination: - + Use Combination Command - + Warning - + Please select working directory. @@ -100,83 +100,83 @@ - + Delete Configuration? - + Do you really want to delete the command <b>%1</b>? - + Rename... - + New name for command <b>%1</b>: - + Command: - + Tool arguments: - + Input your arguments. - + Executable: - - + + Browse... - + Working directory: - + Envrioment: Base environment for this command configuration. - + &Append - + &Delete - + &Reset - + Select Executabel Path - + Select Working Directory @@ -782,6 +782,11 @@ The dap port is not ready, please retry. DetailWidget + + + Browse... + + Choose path @@ -2371,14 +2376,21 @@ storage: %2 - OK + + Ok + Cancel + + + No + + Build Steps @@ -2412,14 +2424,14 @@ storage: %2 QPushButton - + Ok - + Cancel diff --git a/assets/translations/zh_CN.ts b/assets/translations/zh_CN.ts index 8330ef517..99aaf70fd 100644 --- a/assets/translations/zh_CN.ts +++ b/assets/translations/zh_CN.ts @@ -45,47 +45,47 @@ BinaryToolsConfigView - + Add 添加 - + Delete 删除 - + Rename 重命名 - + Combine 组合 - + Binary configuration: 运行配置: - + command combination: 命令组合: - + Use Combination Command 使用组合命令 - + Warning 警告 - + Please select working directory. 请选择工作目录。 @@ -100,83 +100,83 @@ 命令名称: - + Delete Configuration? 删除配置? - + Do you really want to delete the command <b>%1</b>? 确定要删除<b>%1</b>吗? - + Rename... 重命名... - + New name for command <b>%1</b>: <b>%1</b>的新名称: - + Command: 命令: - + Tool arguments: 工具参数: - + Input your arguments. 请输入参数. - + Executable: 可执行文件: - - + + Browse... 浏览... - + Working directory: 工作目录: - + Envrioment: Base environment for this command configuration. 当前命令的配置环境。 - + &Append 添加(&A) - + &Delete 删除(&D) - + &Reset 重置(&R) - + Select Executabel Path 选择执行路径 - + Select Working Directory 选择工作目录 @@ -806,6 +806,11 @@ dap端口未就绪,请重试。 DetailWidget + + + Browse... + 浏览... + Choose path @@ -2406,14 +2411,21 @@ storage: %2 - OK - 确定 + + Ok + + Cancel 取消 + + + No + + Build Steps @@ -2447,14 +2459,14 @@ storage: %2 QPushButton - + Ok 确定 - + Cancel 取消 diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 000000000..a2d7fc972 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,5 @@ +deepin-unioncode (1.1.19) unstable; urgency=medium + + * + + -- MAINTAINER Fri, 01 Sep 2023 14:49:15 +0800 diff --git a/src/common/dialog/contextdialog.cpp b/src/common/dialog/contextdialog.cpp index 44a6f6731..0657168d7 100644 --- a/src/common/dialog/contextdialog.cpp +++ b/src/common/dialog/contextdialog.cpp @@ -25,8 +25,8 @@ void ContextDialog::okCancel(QString text, QString title, messageBox.setWindowTitle(title); messageBox.setText(text); messageBox.setIcon(icon); - messageBox.setStandardButtons(QMessageBox::Ok|QMessageBox::Cancel); - messageBox.button(QMessageBox::Ok)->setText(QObject::tr("OK")); + messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + messageBox.button(QMessageBox::Ok)->setText(QObject::tr("Ok")); messageBox.button(QMessageBox::Cancel)->setText(QObject::tr("Cancel")); if (okCallBack) QObject::connect(messageBox.button(QMessageBox::Ok), @@ -49,13 +49,38 @@ void ContextDialog::ok(QString text, QString title, messageBox.setText(text); messageBox.setIcon(icon); messageBox.setStandardButtons(QMessageBox::Ok); - messageBox.button(QMessageBox::Ok)->setText(QObject::tr("OK")); + messageBox.button(QMessageBox::Ok)->setText(QObject::tr("Ok")); if (okCallBack) QObject::connect(messageBox.button(QMessageBox::Ok), &QAbstractButton::clicked, okCallBack); messageBox.exec(); } +void ContextDialog::question(QString text, QString title, QMessageBox::Icon icon, std::function okCallBack, std::function noCallBack, std::function cancelCallBack) +{ + if (text.isEmpty()) + return; + + QMessageBox messageBox; + messageBox.setWindowTitle(title); + messageBox.setText(text); + messageBox.setIcon(icon); + messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::No | QMessageBox::Cancel); + messageBox.button(QMessageBox::Ok)->setText(QObject::tr("Ok")); + messageBox.button(QMessageBox::No)->setText(QObject::tr("No")); + messageBox.button(QMessageBox::Cancel)->setText(QObject::tr("Cancel")); + if (okCallBack) + QObject::connect(messageBox.button(QMessageBox::Ok), + &QAbstractButton::clicked, okCallBack); + if (noCallBack) + QObject::connect(messageBox.button(QMessageBox::No), + &QAbstractButton::clicked, noCallBack); + if (cancelCallBack) + QObject::connect(messageBox.button(QMessageBox::Cancel), + &QAbstractButton::clicked, cancelCallBack); + messageBox.exec(); +} + void ContextDialog::singleChoice(QSet infos, QString windowTitle, QString choiceTitle, std::function okCallBack, diff --git a/src/common/dialog/contextdialog.h b/src/common/dialog/contextdialog.h index 0d1e0281f..5e819e377 100644 --- a/src/common/dialog/contextdialog.h +++ b/src/common/dialog/contextdialog.h @@ -31,6 +31,13 @@ class ContextDialog final QMessageBox::Icon icon = QMessageBox::Critical, std::function okCallBack = nullptr); + static void question(QString text, + QString title = "Question", + QMessageBox::Icon icon = QMessageBox::Question, + std::function okCallBack = nullptr, + std::function noCallBack = nullptr, + std::function cancelCallBack = nullptr); + static void singleChoice(QSet infos, QString windowTitle = "Infos Selection", QString choiceTitle = "Single Choice", diff --git a/src/plugins/binarytools/mainframe/binarytoolsconfigview.cpp b/src/plugins/binarytools/mainframe/binarytoolsconfigview.cpp index a5f044ff6..933ee97f5 100644 --- a/src/plugins/binarytools/mainframe/binarytoolsconfigview.cpp +++ b/src/plugins/binarytools/mainframe/binarytoolsconfigview.cpp @@ -8,6 +8,7 @@ #include "common/widget/collapsewidget.h" #include "common/util/custompaths.h" +#include "common/dialog/contextdialog.h" #include #include @@ -237,7 +238,7 @@ void BinaryToolsConfigView::currentConfigChanged(const QString &text) void BinaryToolsConfigView::initializeCombo() { QString fileName = CustomPaths::global(CustomPaths::Flags::Configures) - + QDir::separator() + QString("binarytool.support"); + + QDir::separator() + QString("binarytool.support"); QFile file(fileName); if (file.open(QIODevice::ReadOnly)) { QByteArray data = file.readAll(); @@ -285,10 +286,9 @@ void BinaryToolsConfigView::addCompatConfig() return; bool ok; - QInputDialog inputDialog; - QString name = inputDialog.getText(this, tr("Add new command"), - tr("New command name:"), - QLineEdit::Normal, "", &ok); + QString name = QInputDialog::getText(this, tr("Add new command"), + tr("New command name:"), + QLineEdit::Normal, "", &ok); if (!ok) return; @@ -297,12 +297,24 @@ void BinaryToolsConfigView::addCompatConfig() void BinaryToolsConfigView::deleteCompatConfig() { - QMessageBox msgBox(QMessageBox::Question, tr("Delete Configuration?"), - tr("Do you really want to delete the command %1?").arg(d->nameLabel->text()), - QMessageBox::Yes|QMessageBox::No, this); - msgBox.setDefaultButton(QMessageBox::No); - msgBox.setEscapeButton(QMessageBox::No); - if (msgBox.exec() == QMessageBox::No) + bool doSave = false, doCancle = false; + auto ok = [&](bool checked) { + Q_UNUSED(checked); + doSave = true; + }; + auto no = [&](bool checked) { + Q_UNUSED(checked); + doSave = false; + }; + auto cancel = [&](bool checked) { + Q_UNUSED(checked); + }; + + ContextDialog::question(tr("Delete Configuration?"), + tr("Do you really want to delete the command %1?").arg(d->nameLabel->text()), + QMessageBox::Question, + ok, no, cancel); + if (!doSave || doCancle) return; QStringList allCommand = qvariant_cast(d->settings->getValue(ALL_COMMAND)); @@ -321,12 +333,11 @@ void BinaryToolsConfigView::deleteCompatConfig() void BinaryToolsConfigView::renameCompatConfig() { bool ok; - QInputDialog inputDialog; - QString name = inputDialog.getText(this, tr("Rename..."), - tr("New name for command %1:"). - arg(d->runComandCombo->currentText()), - QLineEdit::Normal, - d->runComandCombo->currentText(), &ok); + QString name = QInputDialog::getText(this, tr("Rename..."), + tr("New name for command %1:"). + arg(d->runComandCombo->currentText()), + QLineEdit::Normal, + d->runComandCombo->currentText(), &ok); if (!ok) return; diff --git a/src/plugins/template/wizard/detailwidget.cpp b/src/plugins/template/wizard/detailwidget.cpp index c1583d2bc..0fc83a64a 100644 --- a/src/plugins/template/wizard/detailwidget.cpp +++ b/src/plugins/template/wizard/detailwidget.cpp @@ -70,7 +70,7 @@ DetailWidget::DetailWidget(const QString &templatePath, QWidget *parent) lineEdit->setFixedSize(300, 30); lineEdit->setReadOnly(true); - QPushButton *browse = new QPushButton("Browse..."); + QPushButton *browse = new QPushButton(tr("Browse...")); browse->setFixedSize(100, 30); hLayout->addWidget(browse, 0, Qt::AlignRight); hLayout->setStretchFactor(browse, 1);