From edb693e5af0f106444c6138957da3cac0876d80a Mon Sep 17 00:00:00 2001 From: taocong Date: Wed, 10 Jun 2026 17:11:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=85=8D=E7=BD=AE=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=BF=9D=E5=AD=98=E6=97=B6=E7=BC=96=E7=A0=81=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E9=97=AE=E9=A2=98,=E4=BF=AE=E6=94=B9=E5=85=B3?= =?UTF-8?q?=E4=BA=8E=E5=92=8C=E5=B8=AE=E5=8A=A9=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Uft30ChangeCode.pro | 16 +- build.bat | 4 +- src/components/interdialog.cpp | 116 ++++++++++ src/components/interdialog.h | 68 ++++++ src/mainwindow/mainwindow.cpp | 55 +++-- src/mainwindow/mainwindow.h | 14 +- src/pages/about/aboutdialog.cpp | 70 ++++++ src/pages/about/aboutdialog.h | 21 ++ src/pages/about/aboutpage.cpp | 41 ---- src/pages/about/aboutpage.h | 18 -- src/pages/help/helpdocpage.cpp | 26 +++ src/pages/help/{helppage.h => helpdocpage.h} | 12 +- src/pages/help/helppage.cpp | 215 ------------------- src/pages/settings/settingspage.cpp | 2 +- src/utils/configmanager.cpp | 22 +- src/utils/version.cpp | 12 ++ src/utils/version.h | 11 + 17 files changed, 399 insertions(+), 324 deletions(-) create mode 100644 src/components/interdialog.cpp create mode 100644 src/components/interdialog.h create mode 100644 src/pages/about/aboutdialog.cpp create mode 100644 src/pages/about/aboutdialog.h delete mode 100644 src/pages/about/aboutpage.cpp delete mode 100644 src/pages/about/aboutpage.h create mode 100644 src/pages/help/helpdocpage.cpp rename src/pages/help/{helppage.h => helpdocpage.h} (76%) delete mode 100644 src/pages/help/helppage.cpp create mode 100644 src/utils/version.cpp create mode 100644 src/utils/version.h diff --git a/Uft30ChangeCode.pro b/Uft30ChangeCode.pro index 6cbd7c6..ea56e69 100644 --- a/Uft30ChangeCode.pro +++ b/Uft30ChangeCode.pro @@ -8,13 +8,14 @@ DEFINES += QT_DEPRECATED_WARNINGS SOURCES += main.cpp \ src/mainwindow/mainwindow.cpp \ src/pythonrunner/PythonRunner.cpp \ - src/pages/about/aboutpage.cpp \ + src/pages/about/aboutdialog.cpp \ src/pages/batchconvert/batchconvertpage.cpp \ src/pages/functionsearch/functionsearchpage.cpp \ src/pages/functionsearch/uf20functionsearchpage.cpp \ src/pages/functionsearch/uft3functionsearchpage.cpp \ src/components/elasearchedit.cpp \ - src/pages/help/helppage.cpp \ + src/components/interdialog.cpp \ + src/pages/help/helpdocpage.cpp \ src/pages/settings/settingspage.cpp \ src/pages/metadatupdate/metadatupdatepage.cpp \ src/metadataupdate/filedb.cpp \ @@ -31,17 +32,19 @@ SOURCES += main.cpp \ src/utils/uf2configreader.cpp \ src/utils/uft3configreader.cpp \ src/utils/logmanager.cpp \ - src/utils/configmanager.cpp + src/utils/configmanager.cpp \ + src/utils/version.cpp HEADERS += src/mainwindow/mainwindow.h \ src/pythonrunner/PythonRunner.h \ - src/pages/about/aboutpage.h \ + src/pages/about/aboutdialog.h \ src/pages/batchconvert/batchconvertpage.h \ src/pages/functionsearch/functionsearchpage.h \ src/pages/functionsearch/uf20functionsearchpage.h \ src/pages/functionsearch/uft3functionsearchpage.h \ src/components/elasearchedit.h \ - src/pages/help/helppage.h \ + src/components/interdialog.h \ + src/pages/help/helpdocpage.h \ src/pages/settings/settingspage.h \ src/pages/metadatupdate/metadatupdatepage.h \ src/metadataupdate/filedb.h \ @@ -58,7 +61,8 @@ HEADERS += src/mainwindow/mainwindow.h \ src/utils/uf2configreader.h \ src/utils/uft3configreader.h \ src/utils/logmanager.h \ - src/utils/configmanager.h + src/utils/configmanager.h \ + src/utils/version.h RESOURCES += resources.qrc diff --git a/build.bat b/build.bat index 21513b6..d5c8a2a 100644 --- a/build.bat +++ b/build.bat @@ -66,8 +66,8 @@ echo [OK] qmake done echo. REM Compile -echo [4/4] Compiling Debug version... -mingw32-make debug +echo [4/4] Compiling Release version... +mingw32-make release if errorlevel 1 ( echo. echo ERROR: Compilation failed diff --git a/src/components/interdialog.cpp b/src/components/interdialog.cpp new file mode 100644 index 0000000..8364f6f --- /dev/null +++ b/src/components/interdialog.cpp @@ -0,0 +1,116 @@ +#include "interdialog.h" + +#include "ElaText.h" +#include "ElaPushButton.h" + +#include + +InterDialog::InterDialog(QWidget* parent) : ElaDialog(parent) +{ + this->setIsFixedSize(true); + this->setWindowModality(Qt::ApplicationModal); + this->setWindowButtonFlags(ElaAppBarType::CloseButtonHint); + this->setAppBarHeight(30); + + _mainLayout = new QVBoxLayout(this); + _mainLayout->setContentsMargins(10, 10, 10, 10); + + _centralWidget = new QWidget(this); + auto* centralVLayout = new QVBoxLayout(_centralWidget); + centralVLayout->setContentsMargins(0, 0, 0, 0); + _messageLabel = new ElaText("这是消息", _centralWidget); + _messageLabel->setIsWrapAnywhere(true); + centralVLayout->addWidget(_messageLabel); + + _buttonWidget = new QWidget(this); + _btnLayout = new QHBoxLayout(_buttonWidget); + _btnLayout->setContentsMargins(0, 0, 0, 0); + _btnLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Policy::Expanding, QSizePolicy::Policy::Minimum)); + + auto *defaultButton = new QPushButton(_buttonWidget); + defaultButton->setDefault(true); + defaultButton->hide(); + + _okButton = new ElaPushButton("确认", _buttonWidget); + connect(_okButton, &ElaPushButton::clicked, this, [=] + { + emit okButtonClicked(); + accept(); + }); + _okButton->setLightDefaultColor(ElaThemeColor(ElaThemeType::Light, PrimaryNormal)); + _okButton->setLightHoverColor(ElaThemeColor(ElaThemeType::Light, PrimaryHover)); + _okButton->setLightPressColor(ElaThemeColor(ElaThemeType::Light, PrimaryPress)); + _okButton->setLightTextColor(ElaThemeColor(ElaThemeType::Dark, BasicText)); + _okButton->setDarkDefaultColor(ElaThemeColor(ElaThemeType::Dark, PrimaryNormal)); + _okButton->setDarkHoverColor(ElaThemeColor(ElaThemeType::Dark, PrimaryHover)); + _okButton->setDarkPressColor(ElaThemeColor(ElaThemeType::Dark, PrimaryPress)); + _okButton->setDarkTextColor(ElaThemeColor(ElaThemeType::Light, BasicText)); + _okButton->setMinimumSize(0, 0); + _okButton->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); + _okButton->setFixedHeight(38); + _btnLayout->addWidget(_okButton); + + _cancelButton = new ElaPushButton("取消", _buttonWidget); + connect(_cancelButton, &ElaPushButton::clicked, this, [=] + { + emit cancelButtonClicked(); + reject(); + }); + _cancelButton->setMinimumSize(0, 0); + _cancelButton->setMaximumSize(QSize(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX)); + _cancelButton->setFixedHeight(38); + _btnLayout->addWidget(_cancelButton); + + _mainLayout->addWidget(_centralWidget); + _mainLayout->addWidget(_buttonWidget); + + setFocus(); +} + +InterDialog::~InterDialog() = default; + +void InterDialog::setMessage(const QString& message) +{ + if (_messageLabel) + { + _messageLabel->setText(message); + } +} + +void InterDialog::setCentralWidget(QWidget* centralWidget) +{ + _mainLayout->removeWidget(_centralWidget); + delete _messageLabel; + _messageLabel = nullptr; + delete _centralWidget; + _centralWidget = centralWidget; + QSizePolicy sizePolicy(QSizePolicy::Policy::Preferred, QSizePolicy::Policy::Expanding); + sizePolicy.setHorizontalStretch(0); + sizePolicy.setVerticalStretch(0); + sizePolicy.setHeightForWidth(centralWidget->sizePolicy().hasHeightForWidth()); + centralWidget->setSizePolicy(sizePolicy); + _mainLayout->insertWidget(0, _centralWidget); +} + +void InterDialog::setStandardButtons(const QDialogButtonBox::StandardButtons buttons) const +{ + if (buttons.testFlag(QDialogButtonBox::NoButton)) + { + _buttonWidget->setVisible(false); + } + else + { + _okButton->setVisible(buttons.testFlag(QDialogButtonBox::StandardButton::Ok)); + _cancelButton->setVisible(buttons.testFlag(QDialogButtonBox::StandardButton::Cancel)); + } +} + +void InterDialog::addFirstButton(QPushButton* button) const +{ + _btnLayout->insertWidget(1, button); +} + +void InterDialog::addLastButton(QPushButton* button) const +{ + _btnLayout->addWidget(button); +} \ No newline at end of file diff --git a/src/components/interdialog.h b/src/components/interdialog.h new file mode 100644 index 0000000..a9dbd0b --- /dev/null +++ b/src/components/interdialog.h @@ -0,0 +1,68 @@ +#ifndef METASEARCH_INTERDIALOG_H +#define METASEARCH_INTERDIALOG_H + +#include "ElaDialog.h" +#include "ElaTheme.h" +#include "ElaText.h" +#include "ElaPushButton.h" + +#include +#include +#include + + + +/** + * 带按钮栏的弹窗 + */ +class InterDialog : public ElaDialog +{ + Q_OBJECT + +public: + explicit InterDialog(QWidget* parent = nullptr); + ~InterDialog() override; + + // 设置消息 + virtual void setMessage(const QString& message); + + // 设置中心区域 + void setCentralWidget(QWidget* centralWidget); + + // 设置按钮 + void setStandardButtons(QDialogButtonBox::StandardButtons buttons) const; + + // 头部添加按钮 + void addFirstButton(QPushButton* button) const; + + // 尾部添加按钮 + void addLastButton(QPushButton* button) const; + +signals: + void okButtonClicked(); + void cancelButtonClicked(); + +protected: + // 主题 + ElaThemeType::ThemeMode _themeMode; + + // 主布局 + QVBoxLayout* _mainLayout{nullptr}; + + // 中心区域 + QWidget* _centralWidget{nullptr}; + // 中心区域文本 + ElaText* _messageLabel{nullptr}; + + // 按钮区域 + QWidget* _buttonWidget{nullptr}; + // 按钮区域布局 + QHBoxLayout* _btnLayout{nullptr}; + // 确认按钮 + ElaPushButton* _okButton{nullptr}; + // 取消按钮 + ElaPushButton* _cancelButton{nullptr}; +}; + + +#endif //METASEARCH_INTERDIALOG_H diff --git a/src/mainwindow/mainwindow.cpp b/src/mainwindow/mainwindow.cpp index 0994fe2..1d5a150 100644 --- a/src/mainwindow/mainwindow.cpp +++ b/src/mainwindow/mainwindow.cpp @@ -22,6 +22,8 @@ #include #include #include +#include +#include MainWindow::MainWindow(QWidget *parent) : ElaWindow(parent) @@ -57,6 +59,8 @@ MainWindow::MainWindow(QWidget *parent) connect(m_pythonRunner, &PythonRunner::standardOutput, this, &MainWindow::onPythonRunnerOutput); connect(m_pythonRunner, &PythonRunner::standardError, this, &MainWindow::onPythonRunnerError); + connect(this, &ElaWindow::navigationNodeClicked, this, &MainWindow::onNavigationNodeClicked); + QTimer::singleShot(100, this, &MainWindow::updateNavigationButtonIcon); } @@ -100,7 +104,7 @@ MainWindow::~MainWindow() void MainWindow::initWindow() { - setWindowTitle("UFT30 Change Code"); + setWindowTitle(QString("UFT30 Change Code %1").arg(Version::getVersionString())); setWindowIcon(QIcon(":/resources/images/ChangeCode.png")); resize(900, 600); setMinimumSize(800, 500); @@ -113,27 +117,20 @@ void MainWindow::initWindow() } void MainWindow::initContent() -{ - QString helpKey; - QString aboutKey; - QString settingKey; - QString funcSearchKey; - QString funcConvertKey; - QString metadataKey; +{ + addExpanderNode("功能转码", m_funcConvertKey, ElaIconType::FileCode); + addPageNode("业务转码", createBatchConvertPage(), m_funcConvertKey, ElaIconType::ArrowsRepeat); - addExpanderNode("功能转码", funcConvertKey, ElaIconType::FileCode); - addPageNode("业务转码", createBatchConvertPage(), funcConvertKey, ElaIconType::ArrowsRepeat); - - addExpanderNode("功能查询", funcSearchKey, ElaIconType::MagnifyingGlass); - addPageNode("UF20功能查询", createUF20FunctionSearchPage(), funcSearchKey, ElaIconType::MagnifyingGlassPlus); - addPageNode("UFT3功能查询", createUFT3FunctionSearchPage(), funcSearchKey, ElaIconType::MagnifyingGlassPlus); - expandNavigationNode(funcConvertKey); + addExpanderNode("功能查询", m_funcSearchKey, ElaIconType::MagnifyingGlass); + addPageNode("UF20功能查询", createUF20FunctionSearchPage(), m_funcSearchKey, ElaIconType::MagnifyingGlassPlus); + addPageNode("UFT3功能查询", createUFT3FunctionSearchPage(), m_funcSearchKey, ElaIconType::MagnifyingGlassPlus); + expandNavigationNode(m_funcConvertKey); - addPageNode("元数据更新", createMetadataUpdatePage(), ElaIconType::ArrowsRotate); + addPageNode("元数据更新", createMetadataUpdatePage(), m_metadataKey, ElaIconType::ArrowsRotate); - addFooterNode("帮助", createHelpPage(), helpKey, 0, ElaIconType::CircleQuestion); - addFooterNode("关于", createAboutPage(), aboutKey, 0, ElaIconType::Info); - addFooterNode("设置", createSettingsPage(), settingKey, 0, ElaIconType::GearComplex); + addFooterNode("帮助", m_helpKey, 0, ElaIconType::CircleQuestion); + addFooterNode("关于", m_aboutKey, 0, ElaIconType::Info); + addFooterNode("设置", createSettingsPage(), m_settingKey, 0, ElaIconType::GearComplex); } QWidget* MainWindow::createBatchConvertPage() @@ -162,16 +159,6 @@ QWidget* MainWindow::createUFT3FunctionSearchPage() return new UFT3FunctionSearchPage; } -QWidget* MainWindow::createHelpPage() -{ - return new HelpPage; -} - -QWidget* MainWindow::createAboutPage() -{ - return new AboutPage; -} - QWidget* MainWindow::createSettingsPage() { return new SettingsPage(); @@ -394,3 +381,13 @@ void MainWindow::onNavigationButtonClicked() } m_navigationButton->update(); } + +void MainWindow::onNavigationNodeClicked(ElaNavigationType::NavigationNodeType nodeType, QString nodeKey) +{ + Q_UNUSED(nodeType); + if (nodeKey == m_helpKey) { + QDesktopServices::openUrl(QUrl("http://10.20.163.105:6045/uft3changecode")); + } else if (nodeKey == m_aboutKey) { + std::make_unique(this)->exec(); + } +} diff --git a/src/mainwindow/mainwindow.h b/src/mainwindow/mainwindow.h index 95f7c5f..e9827fc 100644 --- a/src/mainwindow/mainwindow.h +++ b/src/mainwindow/mainwindow.h @@ -9,10 +9,11 @@ #include "src/pages/functionsearch/functionsearchpage.h" #include "src/pages/functionsearch/uf20functionsearchpage.h" #include "src/pages/functionsearch/uft3functionsearchpage.h" -#include "src/pages/help/helppage.h" -#include "src/pages/about/aboutpage.h" + +#include "src/pages/about/aboutdialog.h" #include "src/pages/settings/settingspage.h" #include "src/pages/metadatupdate/metadatupdatepage.h" +#include "src/utils/version.h" class MainWindow : public ElaWindow { @@ -30,8 +31,6 @@ private: QWidget* createFunctionSearchPage(); QWidget* createUF20FunctionSearchPage(); QWidget* createUFT3FunctionSearchPage(); - QWidget* createHelpPage(); - QWidget* createAboutPage(); QWidget* createSettingsPage(); QWidget* createMetadataUpdatePage(); @@ -46,6 +45,7 @@ private: void updateNavigationButtonIcon(); bool eventFilter(QObject *obj, QEvent *event) override; void onNavigationButtonClicked(); + void onNavigationNodeClicked(ElaNavigationType::NavigationNodeType nodeType, QString nodeKey); PythonRunner *m_pythonRunner; bool m_iconsSet; @@ -56,6 +56,12 @@ private: int m_totalFunctions; int m_currentFunctionIndex; QStringList m_functionList; + QString m_helpKey; + QString m_aboutKey; + QString m_settingKey; + QString m_funcSearchKey; + QString m_funcConvertKey; + QString m_metadataKey; }; #endif // MAINWINDOW_H \ No newline at end of file diff --git a/src/pages/about/aboutdialog.cpp b/src/pages/about/aboutdialog.cpp new file mode 100644 index 0000000..05a1087 --- /dev/null +++ b/src/pages/about/aboutdialog.cpp @@ -0,0 +1,70 @@ +#include "aboutdialog.h" + +#include "ElaImageCard.h" +#include "ElaText.h" +#include "ElaPushButton.h" + +#include +#include +#include +#include + +AboutDialog::AboutDialog(QWidget* parent) : InterDialog(parent) +{ + setFixedSize(354, 180); + setWindowTitle("关于"); + setStandardButtons(QDialogButtonBox::Ok); + + auto* centralWidget = new QWidget(this); + auto* centralLayout = new QVBoxLayout(centralWidget); + centralLayout->setContentsMargins(0, 10, 0, 10); + this->setCentralWidget(centralWidget); + + auto* pixCard = new ElaImageCard(this); + pixCard->setFixedSize(64, 64); + pixCard->setIsPreserveAspectCrop(false); + pixCard->setCardImage(QImage(":/resources/images/ChangeCode.png")); + + auto* pixCardLayout = new QVBoxLayout(); + pixCardLayout->addWidget(pixCard); + pixCardLayout->addStretch(); + + auto* nameText = new ElaText(this); + QFont nameTextFont = nameText->font(); + nameTextFont.setWeight(QFont::Bold); + nameText->setFont(nameTextFont); + nameText->setTextPixelSize(17); + nameText->setText("UFT30 ChangeCode"); + + auto* versionText = new ElaText(this); + versionText->setText(QString("版本: %1").arg(Version::getVersionString())); + versionText->setTextPixelSize(12); + + auto* dateText = new ElaText(this); + dateText->setText(QString("构建日期: %1").arg(Version::getBuildDateTime())); + dateText->setTextPixelSize(12); + + auto* textLayout = new QVBoxLayout(); + textLayout->setSpacing(10); + textLayout->addWidget(nameText); + textLayout->addWidget(versionText); + textLayout->addWidget(dateText); + textLayout->addStretch(); + + auto* downloadBtn = new ElaPushButton("下载最新", this); + connect(downloadBtn, &ElaPushButton::clicked, [] + { + QDesktopServices::openUrl(QUrl("http://10.20.163.105:6045/uft3changecode/下载.html")); + }); + addFirstButton(downloadBtn); + + auto* contentLayout = new QHBoxLayout(); + contentLayout->addSpacing(10); + contentLayout->addLayout(pixCardLayout); + contentLayout->addSpacing(15); + contentLayout->addLayout(textLayout); + + centralLayout->addLayout(contentLayout); +} + +AboutDialog::~AboutDialog() = default; \ No newline at end of file diff --git a/src/pages/about/aboutdialog.h b/src/pages/about/aboutdialog.h new file mode 100644 index 0000000..371b667 --- /dev/null +++ b/src/pages/about/aboutdialog.h @@ -0,0 +1,21 @@ +#ifndef METASEARCH_ABOUTDIALOG_H +#define METASEARCH_ABOUTDIALOG_H + +#include "components/interdialog.h" +#include "utils/version.h" + +/** + * 关于弹窗 + */ +class AboutDialog final : public InterDialog +{ + Q_OBJECT + +public: + explicit AboutDialog(QWidget *parent = nullptr); + ~AboutDialog() override; + +}; + + +#endif //METASEARCH_ABOUTDIALOG_H diff --git a/src/pages/about/aboutpage.cpp b/src/pages/about/aboutpage.cpp deleted file mode 100644 index 3000c95..0000000 --- a/src/pages/about/aboutpage.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "aboutpage.h" -#include -#include - -AboutPage::AboutPage(QWidget *parent) - : QWidget(parent) -{ - initUI(); -} - -AboutPage::~AboutPage() -{ -} - -void AboutPage::initUI() -{ - QVBoxLayout *layout = new QVBoxLayout(this); - layout->setContentsMargins(30, 30, 30, 30); - layout->setAlignment(Qt::AlignCenter); - - QLabel *logoLabel = new QLabel; - logoLabel->setStyleSheet("font-size: 48px; text-align: center;"); - logoLabel->setText("UFT30"); - layout->addWidget(logoLabel, 0, Qt::AlignCenter); - - QLabel *title = new QLabel("

UFT30 Change Code

"); - title->setAlignment(Qt::AlignCenter); - layout->addWidget(title); - - QLabel *version = new QLabel("

版本: 1.0.0

"); - version->setAlignment(Qt::AlignCenter); - layout->addWidget(version); - - QLabel *description = new QLabel("

一款强大的编码转换工具,支持批量转码和非LS格式转换。

"); - description->setAlignment(Qt::AlignCenter); - layout->addWidget(description); - - QLabel *copyright = new QLabel("

Copyright © 2024 UFT30 Team. All rights reserved.

"); - copyright->setAlignment(Qt::AlignCenter); - layout->addWidget(copyright); -} \ No newline at end of file diff --git a/src/pages/about/aboutpage.h b/src/pages/about/aboutpage.h deleted file mode 100644 index 1be500b..0000000 --- a/src/pages/about/aboutpage.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef ABOUTPAGE_H -#define ABOUTPAGE_H - -#include - -class AboutPage : public QWidget -{ - Q_OBJECT - -public: - explicit AboutPage(QWidget *parent = nullptr); - ~AboutPage(); - -private: - void initUI(); -}; - -#endif // ABOUTPAGE_H \ No newline at end of file diff --git a/src/pages/help/helpdocpage.cpp b/src/pages/help/helpdocpage.cpp new file mode 100644 index 0000000..2b274ae --- /dev/null +++ b/src/pages/help/helpdocpage.cpp @@ -0,0 +1,26 @@ +#include "helpdocpage.h" +#include +#include +#include +#include + +HelpDocPage::HelpDocPage(QWidget *parent) + : QWidget(parent) +{ + initUI(); +} + +HelpDocPage::~HelpDocPage() +{ +} + +void HelpDocPage::initUI() +{ + QVBoxLayout *layout = new QVBoxLayout(this); + layout->setContentsMargins(0, 0, 0, 0); + + QLabel *label = new QLabel("点击此处跳转帮助文档"); + label->setStyleSheet("font-size: 14px; color: #4a90d9;"); + label->setOpenExternalLinks(true); + layout->addWidget(label, 0, Qt::AlignCenter); +} \ No newline at end of file diff --git a/src/pages/help/helppage.h b/src/pages/help/helpdocpage.h similarity index 76% rename from src/pages/help/helppage.h rename to src/pages/help/helpdocpage.h index 37a2a94..47621dc 100644 --- a/src/pages/help/helppage.h +++ b/src/pages/help/helpdocpage.h @@ -1,5 +1,5 @@ -#ifndef HELPPAGE_H -#define HELPPAGE_H +#ifndef HELPDOCPAGE_H +#define HELPDOCPAGE_H #include #include @@ -7,13 +7,13 @@ #include #include "ElaTreeView.h" -class HelpPage : public QWidget +class HelpDocPage : public QWidget { Q_OBJECT public: - explicit HelpPage(QWidget *parent = nullptr); - ~HelpPage(); + explicit HelpDocPage(QWidget *parent = nullptr); + ~HelpDocPage(); private: void initUI(); @@ -31,4 +31,4 @@ private: QString m_helpContent; }; -#endif // HELPPAGE_H \ No newline at end of file +#endif // HELPDOCPAGE_H \ No newline at end of file diff --git a/src/pages/help/helppage.cpp b/src/pages/help/helppage.cpp deleted file mode 100644 index b846509..0000000 --- a/src/pages/help/helppage.cpp +++ /dev/null @@ -1,215 +0,0 @@ -#include "helppage.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ElaTreeView.h" - -HelpPage::HelpPage(QWidget *parent) - : QWidget(parent) -{ - initUI(); -} - -HelpPage::~HelpPage() -{ -} - -void HelpPage::initUI() -{ - QHBoxLayout *mainLayout = new QHBoxLayout(this); - mainLayout->setContentsMargins(10, 10, 10, 10); - mainLayout->setSpacing(10); - - initTreeView(); - initContentPages(); - - mainLayout->addWidget(m_treeView); - mainLayout->addWidget(m_stackedWidget); -} - -void HelpPage::initTreeView() -{ - m_treeView = new ElaTreeView; - m_treeView->setFixedWidth(200); - - QStandardItemModel *model = new QStandardItemModel(this); - model->setHorizontalHeaderLabels(QStringList() << "功能导航"); - - QStandardItem *overviewItem = new QStandardItem("📋 概述"); - overviewItem->setData("概述", Qt::UserRole); - model->appendRow(overviewItem); - - QStandardItem *convertItem = new QStandardItem("📦 功能转码"); - convertItem->setData("功能转码", Qt::UserRole); - QStandardItem *businessConvertItem = new QStandardItem("业务转码"); - businessConvertItem->setData("功能转码", Qt::UserRole); - convertItem->appendRow(businessConvertItem); - model->appendRow(convertItem); - - QStandardItem *searchItem = new QStandardItem("🔍 功能查询"); - searchItem->setData("功能查询", Qt::UserRole); - QStandardItem *uf20SearchItem = new QStandardItem("UF20功能查询"); - uf20SearchItem->setData("功能查询", Qt::UserRole); - QStandardItem *uft3SearchItem = new QStandardItem("UFT3功能查询"); - uft3SearchItem->setData("功能查询", Qt::UserRole); - searchItem->appendRow(uf20SearchItem); - searchItem->appendRow(uft3SearchItem); - model->appendRow(searchItem); - - QStandardItem *metadataItem = new QStandardItem("🔄 元数据更新"); - metadataItem->setData("元数据更新", Qt::UserRole); - model->appendRow(metadataItem); - - QStandardItem *settingsItem = new QStandardItem("⚙️ 设置"); - settingsItem->setData("设置", Qt::UserRole); - model->appendRow(settingsItem); - - QStandardItem *aboutItem = new QStandardItem("📖 关于"); - aboutItem->setData("关于", Qt::UserRole); - model->appendRow(aboutItem); - - QStandardItem *tipsItem = new QStandardItem("💡 使用技巧"); - tipsItem->setData("使用技巧", Qt::UserRole); - model->appendRow(tipsItem); - - m_treeView->setModel(model); - m_treeView->expand(model->index(1, 0)); - m_treeView->expand(model->index(2, 0)); - - connect(m_treeView, &QTreeView::clicked, this, [this](const QModelIndex& index) { - QString section = index.data(Qt::UserRole).toString(); - updateContent(section); - }); -} - -void HelpPage::initContentPages() -{ - m_stackedWidget = new QStackedWidget; - - QWidget *contentPage = new QWidget; - QVBoxLayout *layout = new QVBoxLayout(contentPage); - layout->setContentsMargins(30, 30, 30, 30); - - m_titleLabel = new QLabel("

使用帮助

"); - layout->addWidget(m_titleLabel); - - m_contentBrowser = new QTextBrowser; - m_contentBrowser->setReadOnly(true); - m_contentBrowser->setStyleSheet("background-color: white;"); - layout->addWidget(m_contentBrowser); - - m_stackedWidget->addWidget(contentPage); - - loadHelpFile(); - updateContent("概述"); -} - -void HelpPage::loadHelpFile() -{ - QString helpFilePath = QDir::currentPath() + "/help/help.md"; - QFile file(helpFilePath); - - if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { - QTextStream in(&file); - m_helpContent = in.readAll(); - file.close(); - } else { - m_helpContent = "# 使用帮助\n\n## 概述\n\n帮助文档加载失败,请检查资源文件。"; - } -} - -void HelpPage::updateContent(const QString §ion) -{ - QString htmlContent = markdownToHtml(extractSection(section)); - m_contentBrowser->setHtml(htmlContent); -} - -QString HelpPage::extractSection(const QString §ionName) -{ - QStringList lines = m_helpContent.split("\n"); - QString sectionContent; - bool inSection = false; - - for (const QString &line : lines) { - if (line.startsWith("## ")) { - QString title = line.mid(3).trimmed(); - if (title == sectionName) { - inSection = true; - sectionContent = line + "\n"; - } else if (inSection) { - break; - } - } else if (inSection) { - sectionContent += line + "\n"; - } - } - - return sectionContent; -} - -QString HelpPage::markdownToHtml(const QString &markdown) -{ - QStringList lines = markdown.split("\n"); - QString html; - bool inList = false; - - for (const QString &line : lines) { - QString trimmedLine = line.trimmed(); - - if (trimmedLine.isEmpty()) { - if (!inList) { - html += "
"; - } - continue; - } - - if (trimmedLine.startsWith("### ")) { - if (inList) { - html += ""; - inList = false; - } - html += "

" + trimmedLine.mid(4) + "

"; - } else if (trimmedLine.startsWith("#### ")) { - if (inList) { - html += ""; - inList = false; - } - html += "

" + trimmedLine.mid(5) + "

"; - } else if (trimmedLine.startsWith("- ")) { - if (!inList) { - html += "
    "; - inList = true; - } - QString text = trimmedLine.mid(2); - text.replace(QRegularExpression("\\*\\*(.+?)\\*\\*"), "\\1"); - html += "
  • " + text + "
  • "; - } else if (trimmedLine.startsWith("```")) { - if (inList) { - html += "
"; - inList = false; - } - continue; - } else { - if (inList) { - html += ""; - inList = false; - } - QString text = trimmedLine; - text.replace(QRegularExpression("\\*\\*(.+?)\\*\\*"), "\\1"); - html += "

" + text + "

"; - } - } - - if (inList) { - html += ""; - } - - return html; -} \ No newline at end of file diff --git a/src/pages/settings/settingspage.cpp b/src/pages/settings/settingspage.cpp index 631b467..2613502 100644 --- a/src/pages/settings/settingspage.cpp +++ b/src/pages/settings/settingspage.cpp @@ -1,4 +1,4 @@ -#include "settingspage.h" +#include "settingspage.h" #include #include #include diff --git a/src/utils/configmanager.cpp b/src/utils/configmanager.cpp index 48259df..8a5a9ec 100644 --- a/src/utils/configmanager.cpp +++ b/src/utils/configmanager.cpp @@ -106,6 +106,16 @@ bool ConfigManager::saveConfig() LogManager::instance()->log(QString("========== 保存配置文件 ==========")); LogManager::instance()->log(QString("配置文件路径: %1").arg(m_configFilePath)); + bool isUtf8 = true; + if (QFile::exists(m_configFilePath)) { + QFile readFile(m_configFilePath); + if (readFile.open(QIODevice::ReadOnly)) { + QByteArray data = readFile.readAll(); + readFile.close(); + isUtf8 = isValidUtf8(data); + } + } + QFile file(m_configFilePath); if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) { LogManager::instance()->logError(QString("无法打开配置文件进行写入: %1").arg(m_configFilePath)); @@ -117,13 +127,21 @@ bool ConfigManager::saveConfig() content += QString("[%1]\n").arg(section); for (const QString& key : m_configCache[section].keys()) { QString value = m_configCache[section][key]; - value.replace("/", "\\"); + if (section == "projectPath" && (key == "uft30" || key == "uf20" || key == "ufAcct20" || key == "createPath" || key == "uft30pub")) { + value.replace("/", "\\"); + } content += QString("%1=%2\n").arg(key).arg(value); } content += "\n"; } - file.write(content.toUtf8()); + QByteArray outData; + if (isUtf8) { + outData = content.toUtf8(); + } else { + outData = content.toLocal8Bit(); + } + file.write(outData); file.close(); LogManager::instance()->log("配置文件保存完成"); diff --git a/src/utils/version.cpp b/src/utils/version.cpp new file mode 100644 index 0000000..9ee349d --- /dev/null +++ b/src/utils/version.cpp @@ -0,0 +1,12 @@ +#include "version.h" +#include + +namespace Version { + QString getVersionString() { + return "1.0.0"; + } + + QString getBuildDateTime() { + return QDateTime::currentDateTime().toString("yyyy-MM-dd HH:mm:ss"); + } +} \ No newline at end of file diff --git a/src/utils/version.h b/src/utils/version.h new file mode 100644 index 0000000..ac57613 --- /dev/null +++ b/src/utils/version.h @@ -0,0 +1,11 @@ +#ifndef VERSION_H +#define VERSION_H + +#include + +namespace Version { + QString getVersionString(); + QString getBuildDateTime(); +} + +#endif // VERSION_H \ No newline at end of file