折叠按钮修改,转码页面优化
|
|
@ -5,9 +5,15 @@
|
||||||
!python_bindings/**
|
!python_bindings/**
|
||||||
!src/
|
!src/
|
||||||
!src/**
|
!src/**
|
||||||
|
!resources/
|
||||||
|
!resources/**
|
||||||
!*.bat
|
!*.bat
|
||||||
!*.rc
|
!*.rc
|
||||||
!*.prp
|
!*.prp
|
||||||
!*.cpp
|
!*.cpp
|
||||||
!*.qrc
|
!*.qrc
|
||||||
!.gitignore
|
!*.h
|
||||||
|
!*.pro
|
||||||
|
!*.md
|
||||||
|
!.gitignore
|
||||||
|
!.gitkeep
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,24 @@
|
||||||
|
# 图标设置说明
|
||||||
|
|
||||||
|
## 已完成配置
|
||||||
|
|
||||||
|
1. **应用程序窗口图标** - 已设置为 `resources/icons/转码工具.svg`
|
||||||
|
2. **资源文件** - 图标已添加到 `resources.qrc`
|
||||||
|
|
||||||
|
## Windows 可执行程序图标(可选)
|
||||||
|
|
||||||
|
如需设置 Windows 可执行文件的图标(任务栏、文件管理器显示的图标),需要:
|
||||||
|
|
||||||
|
### 方法 1:使用在线工具转换
|
||||||
|
1. 将 `resources/images/转码工具.png` 转换为 `.ico` 格式
|
||||||
|
2. 推荐尺寸:包含 16x16, 32x32, 48x48, 256x256 等多种尺寸
|
||||||
|
3. 保存为 `app.ico` 并放在项目根目录
|
||||||
|
4. `app.rc` 已配置引用 `app.ico`
|
||||||
|
|
||||||
|
### 方法 2:使用 ImageMagick 转换
|
||||||
|
```bash
|
||||||
|
magick convert 转码工具.png -define icon:auto-resize=256,128,96,64,48,32,16 app.ico
|
||||||
|
```
|
||||||
|
|
||||||
|
### 重新编译
|
||||||
|
设置好图标后重新编译项目即可。
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
QT += core gui widgets
|
||||||
|
|
||||||
|
TARGET = Uft30ChangeCode
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
DEFINES += QT_DEPRECATED_WARNINGS
|
||||||
|
|
||||||
|
SOURCES += main.cpp \
|
||||||
|
src/mainwindow/mainwindow.cpp \
|
||||||
|
src/pythonrunner/PythonRunner.cpp \
|
||||||
|
src/pages/about/aboutpage.cpp \
|
||||||
|
src/pages/batchconvert/batchconvertpage.cpp \
|
||||||
|
src/pages/functionsearch/functionsearchpage.cpp \
|
||||||
|
src/pages/help/helppage.cpp \
|
||||||
|
src/pages/settings/settingspage.cpp
|
||||||
|
|
||||||
|
HEADERS += src/mainwindow/mainwindow.h \
|
||||||
|
src/pythonrunner/PythonRunner.h \
|
||||||
|
src/pages/about/aboutpage.h \
|
||||||
|
src/pages/batchconvert/batchconvertpage.h \
|
||||||
|
src/pages/functionsearch/functionsearchpage.h \
|
||||||
|
src/pages/help/helppage.h \
|
||||||
|
src/pages/settings/settingspage.h
|
||||||
|
|
||||||
|
RESOURCES += resources.qrc
|
||||||
|
|
||||||
|
CONFIG += c++17
|
||||||
|
CONFIG += debug_and_release
|
||||||
|
|
||||||
|
QMAKE_CXXFLAGS += -Wall -Wextra
|
||||||
|
QMAKE_LFLAGS += -fno-use-linker-plugin
|
||||||
|
|
||||||
|
INCLUDEPATH += src
|
||||||
|
INCLUDEPATH += 3rd/ElaWidgetTools/include
|
||||||
|
|
||||||
|
win32 {
|
||||||
|
LIBS += -L$$PWD/3rd/ElaWidgetTools/lib -lElaWidgetTools
|
||||||
|
LIBS += -ld3d11 -ldxgi
|
||||||
|
RC_FILE = app.rc
|
||||||
|
}
|
||||||
|
|
||||||
|
DESTDIR = $$PWD/bin
|
||||||
|
OBJECTS_DIR = $$PWD/build
|
||||||
|
MOC_DIR = $$PWD/build
|
||||||
|
RCC_DIR = $$PWD/build
|
||||||
|
|
||||||
|
|
||||||
2
app.rc
|
|
@ -1 +1 @@
|
||||||
IDI_ICON1 ICON DISCARDABLE "app.ico"
|
IDI_ICON1 ICON DISCARDABLE "resources/images/ChangeCode.ico"
|
||||||
4
main.cpp
|
|
@ -1,12 +1,14 @@
|
||||||
#include "src/mainwindow/mainwindow.h"
|
#include "src/mainwindow/mainwindow.h"
|
||||||
#include "ElaApplication.h"
|
#include "ElaApplication.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QIcon>
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
QApplication a(argc, argv);
|
QApplication a(argc, argv);
|
||||||
|
a.setWindowIcon(QIcon(":resources/images/ChangeCode.png"));
|
||||||
eApp->init();
|
eApp->init();
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
w.show();
|
w.showMaximized();
|
||||||
return a.exec();
|
return a.exec();
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,10 @@
|
||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
|
<file>resources/images/ChangeCode.png</file>
|
||||||
|
<file>resources/images/delect.png</file>
|
||||||
|
<file>resources/images/zhedie_left.png</file>
|
||||||
|
<file>resources/images/zhedie_right.png</file>
|
||||||
|
<file>resources/images/max.png</file>
|
||||||
|
<file>resources/images/min.png</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
# 资源目录
|
||||||
|
|
||||||
|
此目录用于存放项目使用的图标、图片等资源文件。
|
||||||
|
|
||||||
|
## 目录结构
|
||||||
|
|
||||||
|
```
|
||||||
|
resources/
|
||||||
|
├── icons/ # 图标文件
|
||||||
|
└── images/ # 图片文件
|
||||||
|
```
|
||||||
|
|
||||||
|
## 添加新资源
|
||||||
|
|
||||||
|
1. 将资源文件放入对应目录
|
||||||
|
2. 更新 resources.qrc 文件添加资源引用
|
||||||
|
3. 重新编译项目
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
# 此文件用于保持icons目录在Git仓库中
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
# 此文件用于保持images目录在Git仓库中
|
||||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 8.0 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 3.4 KiB |
|
After Width: | Height: | Size: 2.8 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
After Width: | Height: | Size: 3.0 KiB |
|
|
@ -2,6 +2,7 @@
|
||||||
#include "ElaIcon.h"
|
#include "ElaIcon.h"
|
||||||
#include "ElaText.h"
|
#include "ElaText.h"
|
||||||
#include "ElaTheme.h"
|
#include "ElaTheme.h"
|
||||||
|
#include "ElaToolButton.h"
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
|
@ -16,10 +17,15 @@
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
|
#include <QTimer>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
MainWindow::MainWindow(QWidget *parent)
|
MainWindow::MainWindow(QWidget *parent)
|
||||||
: ElaWindow(parent)
|
: ElaWindow(parent)
|
||||||
, m_pythonRunner(new PythonRunner(this))
|
, m_pythonRunner(new PythonRunner(this))
|
||||||
|
, m_iconsSet(false)
|
||||||
|
, m_navigationButton(nullptr)
|
||||||
|
, m_isNavigationExpanded(true)
|
||||||
{
|
{
|
||||||
initWindow();
|
initWindow();
|
||||||
initContent();
|
initContent();
|
||||||
|
|
@ -52,6 +58,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||||
connect(m_pythonRunner, &PythonRunner::started, [this]() {
|
connect(m_pythonRunner, &PythonRunner::started, [this]() {
|
||||||
m_batchLogEdit->append("转换任务已启动...");
|
m_batchLogEdit->append("转换任务已启动...");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 延迟查找并更新导航按钮(等待窗口完全显示后)
|
||||||
|
QTimer::singleShot(100, this, &MainWindow::updateNavigationButtonIcon);
|
||||||
}
|
}
|
||||||
|
|
||||||
MainWindow::~MainWindow()
|
MainWindow::~MainWindow()
|
||||||
|
|
@ -61,10 +70,14 @@ MainWindow::~MainWindow()
|
||||||
void MainWindow::initWindow()
|
void MainWindow::initWindow()
|
||||||
{
|
{
|
||||||
setWindowTitle("UFT30 Change Code");
|
setWindowTitle("UFT30 Change Code");
|
||||||
setWindowIcon(QIcon(":/Resource/Image/Cirno.jpg"));
|
setWindowIcon(QIcon(":/resources/images/ChangeCode.png"));
|
||||||
resize(900, 600);
|
resize(900, 600);
|
||||||
setUserInfoCardTitle("UFT30");
|
setUserInfoCardVisible(false);
|
||||||
setUserInfoCardSubTitle("Change Code Tool");
|
|
||||||
|
// 隐藏返回和前进按钮
|
||||||
|
|
||||||
|
setWindowButtonFlag(ElaAppBarType::RouteBackButtonHint, false);
|
||||||
|
setWindowButtonFlag(ElaAppBarType::RouteForwardButtonHint, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initContent()
|
void MainWindow::initContent()
|
||||||
|
|
@ -73,7 +86,7 @@ void MainWindow::initContent()
|
||||||
QString aboutKey;
|
QString aboutKey;
|
||||||
QString settingKey;
|
QString settingKey;
|
||||||
addPageNode("转码业务", createBatchConvertPage(), ElaIconType::FileCode);
|
addPageNode("转码业务", createBatchConvertPage(), ElaIconType::FileCode);
|
||||||
addPageNode("功能搜索", createFunctionSearchPage(), ElaIconType::MagnifyingGlass);
|
//addPageNode("功能搜索", createFunctionSearchPage(), ElaIconType::MagnifyingGlass);
|
||||||
addFooterNode("帮助", createHelpPage(), helpKey, 0, ElaIconType::CircleQuestion);
|
addFooterNode("帮助", createHelpPage(), helpKey, 0, ElaIconType::CircleQuestion);
|
||||||
addFooterNode("关于", createAboutPage(), aboutKey, 0, ElaIconType::User);
|
addFooterNode("关于", createAboutPage(), aboutKey, 0, ElaIconType::User);
|
||||||
addFooterNode("设置", createSettingsPage(), settingKey, 0, ElaIconType::GearComplex);
|
addFooterNode("设置", createSettingsPage(), settingKey, 0, ElaIconType::GearComplex);
|
||||||
|
|
@ -167,3 +180,83 @@ void MainWindow::onPythonRunnerError(const QString &error)
|
||||||
m_batchLogEdit->append(QString("[ERROR] %1").arg(error));
|
m_batchLogEdit->append(QString("[ERROR] %1").arg(error));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateNavigationButtonIcon()
|
||||||
|
{
|
||||||
|
// 使用资源文件中的图标
|
||||||
|
QIcon leftIcon(":/resources/images/zhedie_left.png");
|
||||||
|
|
||||||
|
if (leftIcon.isNull()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找所有 ElaToolButton
|
||||||
|
QList<ElaToolButton*> allButtons = this->findChildren<ElaToolButton*>(QString(), Qt::FindChildrenRecursively);
|
||||||
|
|
||||||
|
// 尝试查找导航按钮 - 可能在不同位置
|
||||||
|
for (int i = 0; i < allButtons.size(); i++) {
|
||||||
|
ElaToolButton* btn = allButtons[i];
|
||||||
|
QString objName = btn->objectName();
|
||||||
|
|
||||||
|
// 检查是否是导航按钮(可能的名称)
|
||||||
|
if (objName.contains("Nav", Qt::CaseInsensitive) ||
|
||||||
|
objName.contains("Menu", Qt::CaseInsensitive) ||
|
||||||
|
objName.contains("Navigation", Qt::CaseInsensitive)) {
|
||||||
|
m_navigationButton = btn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 如果没有找到有名称的导航按钮,使用第一个可见按钮
|
||||||
|
if (!m_navigationButton) {
|
||||||
|
for (ElaToolButton* btn : allButtons) {
|
||||||
|
if (btn->isVisible()) {
|
||||||
|
m_navigationButton = btn;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_navigationButton) {
|
||||||
|
m_navigationButton->setProperty("ElaIconType", "");
|
||||||
|
m_navigationButton->setIcon(leftIcon);
|
||||||
|
m_navigationButton->setIconSize(QSize(24, 24));
|
||||||
|
m_navigationButton->update();
|
||||||
|
|
||||||
|
// 先断开可能存在的连接,然后重新连接,避免多次连接
|
||||||
|
disconnect(m_navigationButton, &ElaToolButton::clicked, this, &MainWindow::onNavigationButtonClicked);
|
||||||
|
connect(m_navigationButton, &ElaToolButton::clicked, this, &MainWindow::onNavigationButtonClicked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MainWindow::eventFilter(QObject *obj, QEvent *event)
|
||||||
|
{
|
||||||
|
if (!m_iconsSet && event->type() == QEvent::Show) {
|
||||||
|
// 窗口显示后尝试设置图标
|
||||||
|
updateNavigationButtonIcon();
|
||||||
|
m_iconsSet = true;
|
||||||
|
}
|
||||||
|
return ElaWindow::eventFilter(obj, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::onNavigationButtonClicked()
|
||||||
|
{
|
||||||
|
if (!m_navigationButton) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QIcon leftIcon(":/resources/images/zhedie_left.png");
|
||||||
|
QIcon rightIcon(":/resources/images/zhedie_right.png");
|
||||||
|
|
||||||
|
// 使用状态变量来判断当前状态,而不是依赖 cacheKey
|
||||||
|
if (m_isNavigationExpanded) {
|
||||||
|
// 当前是展开状态,切换到折叠状态
|
||||||
|
m_navigationButton->setIcon(rightIcon);
|
||||||
|
m_isNavigationExpanded = false;
|
||||||
|
} else {
|
||||||
|
// 当前是折叠状态,切换到展开状态
|
||||||
|
m_navigationButton->setIcon(leftIcon);
|
||||||
|
m_isNavigationExpanded = true;
|
||||||
|
}
|
||||||
|
m_navigationButton->update();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
#define MAINWINDOW_H
|
#define MAINWINDOW_H
|
||||||
|
|
||||||
#include "ElaWindow.h"
|
#include "ElaWindow.h"
|
||||||
|
#include "ElaToolButton.h"
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
#include "src/pythonrunner/PythonRunner.h"
|
#include "src/pythonrunner/PythonRunner.h"
|
||||||
|
|
@ -34,8 +35,15 @@ private:
|
||||||
void onPythonRunnerOutput(const QString &output);
|
void onPythonRunnerOutput(const QString &output);
|
||||||
void onPythonRunnerError(const QString &error);
|
void onPythonRunnerError(const QString &error);
|
||||||
|
|
||||||
|
void updateNavigationButtonIcon();
|
||||||
|
bool eventFilter(QObject *obj, QEvent *event) override;
|
||||||
|
void onNavigationButtonClicked();
|
||||||
|
|
||||||
PythonRunner *m_pythonRunner;
|
PythonRunner *m_pythonRunner;
|
||||||
QTextEdit *m_batchLogEdit;
|
QTextEdit *m_batchLogEdit;
|
||||||
|
bool m_iconsSet;
|
||||||
|
ElaToolButton* m_navigationButton;
|
||||||
|
bool m_isNavigationExpanded;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|
@ -6,6 +6,12 @@
|
||||||
#include <QGroupBox>
|
#include <QGroupBox>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QTableWidgetItem>
|
||||||
|
#include <QHeaderView>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QInputDialog>
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QTextEdit>
|
||||||
|
|
||||||
BatchConvertPage::BatchConvertPage(QWidget *parent)
|
BatchConvertPage::BatchConvertPage(QWidget *parent)
|
||||||
: QWidget(parent)
|
: QWidget(parent)
|
||||||
|
|
@ -27,13 +33,33 @@ void BatchConvertPage::initUI()
|
||||||
QVBoxLayout *funcLayout = new QVBoxLayout(funcBox);
|
QVBoxLayout *funcLayout = new QVBoxLayout(funcBox);
|
||||||
funcLayout->setSpacing(10);
|
funcLayout->setSpacing(10);
|
||||||
|
|
||||||
QLabel *funcLabel = new QLabel("请输入需要转码的功能名称(每行一个):");
|
m_funcTable = new QTableWidget;
|
||||||
funcLayout->addWidget(funcLabel);
|
m_funcTable->setColumnCount(3);
|
||||||
|
m_funcTable->setHorizontalHeaderLabels({"UF20函数名", "是否存在", "操作"});
|
||||||
|
m_funcTable->setMinimumHeight(200);
|
||||||
|
m_funcTable->setSelectionBehavior(QAbstractItemView::SelectRows);
|
||||||
|
m_funcTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Fixed);
|
||||||
|
m_funcTable->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
|
||||||
|
m_funcTable->horizontalHeader()->setSectionResizeMode(2, QHeaderView::Fixed);
|
||||||
|
m_funcTable->horizontalHeader()->setStretchLastSection(false);
|
||||||
|
m_funcTable->setColumnWidth(2, 80);
|
||||||
|
funcLayout->addWidget(m_funcTable);
|
||||||
|
|
||||||
m_funcEdit = new QTextEdit;
|
QHBoxLayout *tableBtnLayout = new QHBoxLayout;
|
||||||
m_funcEdit->setPlaceholderText("");
|
QPushButton *addBtn = new QPushButton("添加");
|
||||||
m_funcEdit->setMinimumHeight(120);
|
addBtn->setStyleSheet("padding: 6px 20px;");
|
||||||
funcLayout->addWidget(m_funcEdit);
|
connect(addBtn, &QPushButton::clicked, this, &BatchConvertPage::onAddFunction);
|
||||||
|
QPushButton *removeBtn = new QPushButton("删除选中");
|
||||||
|
removeBtn->setStyleSheet("padding: 6px 15px;");
|
||||||
|
connect(removeBtn, &QPushButton::clicked, this, &BatchConvertPage::onRemoveFunction);
|
||||||
|
QPushButton *clearBtn = new QPushButton("清空列表");
|
||||||
|
clearBtn->setStyleSheet("padding: 6px 15px;");
|
||||||
|
connect(clearBtn, &QPushButton::clicked, this, &BatchConvertPage::onClearTable);
|
||||||
|
tableBtnLayout->addWidget(addBtn);
|
||||||
|
tableBtnLayout->addStretch();
|
||||||
|
tableBtnLayout->addWidget(removeBtn);
|
||||||
|
tableBtnLayout->addWidget(clearBtn);
|
||||||
|
funcLayout->addLayout(tableBtnLayout);
|
||||||
|
|
||||||
layout->addWidget(funcBox);
|
layout->addWidget(funcBox);
|
||||||
|
|
||||||
|
|
@ -41,11 +67,11 @@ void BatchConvertPage::initUI()
|
||||||
QPushButton *startBtn = new QPushButton("开始转换");
|
QPushButton *startBtn = new QPushButton("开始转换");
|
||||||
startBtn->setStyleSheet("background-color: #1abc9c; color: white; padding: 10px 30px; font-size: 14px; border: none; border-radius: 4px;");
|
startBtn->setStyleSheet("background-color: #1abc9c; color: white; padding: 10px 30px; font-size: 14px; border: none; border-radius: 4px;");
|
||||||
connect(startBtn, &QPushButton::clicked, this, &BatchConvertPage::onStartConvert);
|
connect(startBtn, &QPushButton::clicked, this, &BatchConvertPage::onStartConvert);
|
||||||
QPushButton *clearBtn = new QPushButton("清空");
|
QPushButton *clearLogBtn = new QPushButton("清空日志");
|
||||||
connect(clearBtn, &QPushButton::clicked, this, &BatchConvertPage::onClearLog);
|
connect(clearLogBtn, &QPushButton::clicked, this, &BatchConvertPage::onClearLog);
|
||||||
btnLayout->addStretch();
|
btnLayout->addStretch();
|
||||||
btnLayout->addWidget(startBtn);
|
btnLayout->addWidget(startBtn);
|
||||||
btnLayout->addWidget(clearBtn);
|
btnLayout->addWidget(clearLogBtn);
|
||||||
layout->addLayout(btnLayout);
|
layout->addLayout(btnLayout);
|
||||||
|
|
||||||
m_logEdit = new QTextEdit;
|
m_logEdit = new QTextEdit;
|
||||||
|
|
@ -55,6 +81,183 @@ void BatchConvertPage::initUI()
|
||||||
layout->addWidget(m_logEdit);
|
layout->addWidget(m_logEdit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BatchConvertPage::checkFunctionExists(const QString &funcName)
|
||||||
|
{
|
||||||
|
QString jsonPath = QCoreApplication::applicationDirPath() + "/uf2touft3/cust.json";
|
||||||
|
QFile file(jsonPath);
|
||||||
|
if (!file.open(QIODevice::ReadOnly)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
QByteArray data = file.readAll();
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
QString content = QString::fromUtf8(data);
|
||||||
|
return content.contains("\"" + funcName + "\"");
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatchConvertPage::updateTable()
|
||||||
|
{
|
||||||
|
m_funcTable->setRowCount(m_funcList.size());
|
||||||
|
|
||||||
|
for (int i = 0; i < m_funcList.size(); ++i) {
|
||||||
|
QString funcName = m_funcList[i];
|
||||||
|
|
||||||
|
QTableWidgetItem *nameItem = new QTableWidgetItem(funcName);
|
||||||
|
nameItem->setFlags(nameItem->flags() & ~Qt::ItemIsEditable);
|
||||||
|
m_funcTable->setItem(i, 0, nameItem);
|
||||||
|
|
||||||
|
bool exists = checkFunctionExists(funcName);
|
||||||
|
QString statusText = exists ? "是" : "否";
|
||||||
|
|
||||||
|
QTableWidgetItem *statusItem = new QTableWidgetItem(statusText);
|
||||||
|
statusItem->setFlags(statusItem->flags() & ~Qt::ItemIsEditable);
|
||||||
|
statusItem->setTextAlignment(Qt::AlignCenter);
|
||||||
|
|
||||||
|
if (exists) {
|
||||||
|
statusItem->setBackground(QColor(144, 238, 144));
|
||||||
|
statusItem->setForeground(QColor(0, 100, 0));
|
||||||
|
} else {
|
||||||
|
statusItem->setBackground(QColor(255, 182, 193));
|
||||||
|
statusItem->setForeground(QColor(139, 0, 0));
|
||||||
|
}
|
||||||
|
m_funcTable->setItem(i, 1, statusItem);
|
||||||
|
|
||||||
|
QPushButton *delBtn = new QPushButton;
|
||||||
|
delBtn->setIcon(QIcon(":/resources/images/delect.png"));
|
||||||
|
delBtn->setIconSize(QSize(20, 20));
|
||||||
|
delBtn->setStyleSheet("padding: 2px; border: none; background-color: transparent;");
|
||||||
|
delBtn->setToolTip("删除");
|
||||||
|
connect(delBtn, &QPushButton::clicked, this, [this, i]() {
|
||||||
|
onDeleteRow(i);
|
||||||
|
});
|
||||||
|
m_funcTable->setCellWidget(i, 2, delBtn);
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalWidth = m_funcTable->width();
|
||||||
|
m_funcTable->setColumnWidth(0, (totalWidth - 80) * 8 / 10);
|
||||||
|
m_funcTable->setColumnWidth(1, (totalWidth - 80) * 2 / 10);
|
||||||
|
m_funcTable->setColumnWidth(2, 80);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatchConvertPage::resizeEvent(QResizeEvent *event)
|
||||||
|
{
|
||||||
|
QWidget::resizeEvent(event);
|
||||||
|
if (m_funcTable) {
|
||||||
|
int totalWidth = m_funcTable->width();
|
||||||
|
m_funcTable->setColumnWidth(0, (totalWidth - 80) * 8 / 10);
|
||||||
|
m_funcTable->setColumnWidth(1, (totalWidth - 80) * 2 / 10);
|
||||||
|
m_funcTable->setColumnWidth(2, 80);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatchConvertPage::onDeleteRow(int row)
|
||||||
|
{
|
||||||
|
if (row >= 0 && row < m_funcList.size()) {
|
||||||
|
m_funcList.removeAt(row);
|
||||||
|
updateTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatchConvertPage::onAddFunction()
|
||||||
|
{
|
||||||
|
QDialog dialog(this);
|
||||||
|
dialog.setWindowTitle("添加UF20函数");
|
||||||
|
dialog.resize(400, 250);
|
||||||
|
|
||||||
|
QVBoxLayout *layout = new QVBoxLayout(&dialog);
|
||||||
|
|
||||||
|
QTextEdit *textEdit = new QTextEdit;
|
||||||
|
textEdit->setPlaceholderText("每行输入一个函数名");
|
||||||
|
layout->addWidget(textEdit);
|
||||||
|
|
||||||
|
QHBoxLayout *btnLayout = new QHBoxLayout;
|
||||||
|
QPushButton *okBtn = new QPushButton("确定");
|
||||||
|
QPushButton *cancelBtn = new QPushButton("取消");
|
||||||
|
btnLayout->addStretch();
|
||||||
|
btnLayout->addWidget(okBtn);
|
||||||
|
btnLayout->addWidget(cancelBtn);
|
||||||
|
layout->addLayout(btnLayout);
|
||||||
|
|
||||||
|
connect(okBtn, &QPushButton::clicked, &dialog, &QDialog::accept);
|
||||||
|
connect(cancelBtn, &QPushButton::clicked, &dialog, &QDialog::reject);
|
||||||
|
|
||||||
|
if (dialog.exec() != QDialog::Accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString text = textEdit->toPlainText().trimmed();
|
||||||
|
if (text.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QStringList funcNames = text.split('\n', Qt::SkipEmptyParts);
|
||||||
|
int addedCount = 0;
|
||||||
|
int existCount = 0;
|
||||||
|
|
||||||
|
for (const QString &name : funcNames) {
|
||||||
|
QString trimmedName = name.trimmed();
|
||||||
|
if (trimmedName.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (m_funcList.contains(trimmedName)) {
|
||||||
|
existCount++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
m_funcList.append(trimmedName);
|
||||||
|
addedCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existCount > 0) {
|
||||||
|
QMessageBox::information(this, "提示",
|
||||||
|
QString("成功添加 %1 个函数,%2 个函数已存在").arg(addedCount).arg(existCount));
|
||||||
|
} else if (addedCount > 0) {
|
||||||
|
QMessageBox::information(this, "提示",
|
||||||
|
QString("成功添加 %1 个函数").arg(addedCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatchConvertPage::onRemoveFunction()
|
||||||
|
{
|
||||||
|
QList<QTableWidgetItem*> selectedItems = m_funcTable->selectedItems();
|
||||||
|
if (selectedItems.isEmpty()) {
|
||||||
|
QMessageBox::warning(this, "提示", "请先选中要删除的行!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<int> rowsToRemove;
|
||||||
|
for (QTableWidgetItem *item : selectedItems) {
|
||||||
|
int row = item->row();
|
||||||
|
if (!rowsToRemove.contains(row)) {
|
||||||
|
rowsToRemove.append(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::sort(rowsToRemove.begin(), rowsToRemove.end(), std::greater<int>());
|
||||||
|
for (int row : rowsToRemove) {
|
||||||
|
m_funcList.removeAt(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateTable();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BatchConvertPage::onClearTable()
|
||||||
|
{
|
||||||
|
if (m_funcList.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMessageBox::StandardButton reply;
|
||||||
|
reply = QMessageBox::question(this, "确认清空", "确定要清空所有函数吗?",
|
||||||
|
QMessageBox::Yes | QMessageBox::No);
|
||||||
|
if (reply == QMessageBox::Yes) {
|
||||||
|
m_funcList.clear();
|
||||||
|
updateTable();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool BatchConvertPage::saveToCustJson(const QStringList &funcList)
|
bool BatchConvertPage::saveToCustJson(const QStringList &funcList)
|
||||||
{
|
{
|
||||||
QString jsonPath = QCoreApplication::applicationDirPath() + "/uf2touft3/cust.json";
|
QString jsonPath = QCoreApplication::applicationDirPath() + "/uf2touft3/cust.json";
|
||||||
|
|
@ -111,23 +314,8 @@ bool BatchConvertPage::saveToCustJson(const QStringList &funcList)
|
||||||
|
|
||||||
void BatchConvertPage::onStartConvert()
|
void BatchConvertPage::onStartConvert()
|
||||||
{
|
{
|
||||||
QString funcText = m_funcEdit->toPlainText().trimmed();
|
if (m_funcList.isEmpty()) {
|
||||||
if (funcText.isEmpty()) {
|
m_logEdit->append("请先添加需要转码的函数!");
|
||||||
m_logEdit->append("请输入需要转码的功能名称!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QStringList funcs = funcText.split('\n', Qt::SkipEmptyParts);
|
|
||||||
QStringList trimmedFuncs;
|
|
||||||
for (const QString &func : funcs) {
|
|
||||||
QString trimmed = func.trimmed();
|
|
||||||
if (!trimmed.isEmpty()) {
|
|
||||||
trimmedFuncs.append(trimmed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (trimmedFuncs.isEmpty()) {
|
|
||||||
m_logEdit->append("请输入有效的功能名称!");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,11 +323,11 @@ void BatchConvertPage::onStartConvert()
|
||||||
m_logEdit->append("正在写入 cust.json ...");
|
m_logEdit->append("正在写入 cust.json ...");
|
||||||
m_logEdit->append("功能列表:");
|
m_logEdit->append("功能列表:");
|
||||||
|
|
||||||
for (const QString &func : trimmedFuncs) {
|
for (const QString &func : m_funcList) {
|
||||||
m_logEdit->append(" - " + func + ".service_design");
|
m_logEdit->append(" - " + func + ".service_design");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (saveToCustJson(trimmedFuncs)) {
|
if (saveToCustJson(m_funcList)) {
|
||||||
m_logEdit->append("[OK] cust.json 写入成功!");
|
m_logEdit->append("[OK] cust.json 写入成功!");
|
||||||
} else {
|
} else {
|
||||||
m_logEdit->append("[FAIL] cust.json 写入失败!");
|
m_logEdit->append("[FAIL] cust.json 写入失败!");
|
||||||
|
|
@ -155,4 +343,4 @@ void BatchConvertPage::onClearLog()
|
||||||
{
|
{
|
||||||
m_logEdit->clear();
|
m_logEdit->clear();
|
||||||
m_logEdit->append("转码工具已准备就绪...");
|
m_logEdit->append("转码工具已准备就绪...");
|
||||||
}
|
}
|
||||||
|
|
@ -4,6 +4,8 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <QTextEdit>
|
#include <QTextEdit>
|
||||||
|
#include <QTableWidget>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
class BatchConvertPage : public QWidget
|
class BatchConvertPage : public QWidget
|
||||||
{
|
{
|
||||||
|
|
@ -21,13 +23,21 @@ signals:
|
||||||
private slots:
|
private slots:
|
||||||
void onStartConvert();
|
void onStartConvert();
|
||||||
void onClearLog();
|
void onClearLog();
|
||||||
|
void onAddFunction();
|
||||||
|
void onRemoveFunction();
|
||||||
|
void onClearTable();
|
||||||
|
void onDeleteRow(int row);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void initUI();
|
void initUI();
|
||||||
bool saveToCustJson(const QStringList &funcList);
|
bool saveToCustJson(const QStringList &funcList);
|
||||||
|
bool checkFunctionExists(const QString &funcName);
|
||||||
|
void updateTable();
|
||||||
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
|
|
||||||
QTextEdit *m_funcEdit;
|
QTableWidget *m_funcTable;
|
||||||
QTextEdit *m_logEdit;
|
QTextEdit *m_logEdit;
|
||||||
|
QStringList m_funcList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BATCHCONVERTPAGE_H
|
#endif // BATCHCONVERTPAGE_H
|
||||||