帮助页面修改
This commit is contained in:
+192
-39
@@ -1,7 +1,15 @@
|
||||
#include "helppage.h"
|
||||
#include <QHBoxLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QLabel>
|
||||
#include <QTextEdit>
|
||||
#include <QTextBrowser>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
#include <QDir>
|
||||
#include <QRegularExpression>
|
||||
#include <QStandardItemModel>
|
||||
#include <QModelIndex>
|
||||
#include "ElaTreeView.h"
|
||||
|
||||
HelpPage::HelpPage(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@@ -15,48 +23,193 @@ HelpPage::~HelpPage()
|
||||
|
||||
void HelpPage::initUI()
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
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("<h1>使用帮助</h1>");
|
||||
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("概述");
|
||||
}
|
||||
|
||||
QLabel *title = new QLabel("<h1>使用帮助</h1>");
|
||||
layout->addWidget(title);
|
||||
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帮助文档加载失败,请检查资源文件。";
|
||||
}
|
||||
}
|
||||
|
||||
QTextEdit *helpText = new QTextEdit;
|
||||
helpText->setReadOnly(true);
|
||||
helpText->setStyleSheet("background-color: white;");
|
||||
helpText->setHtml(R"(
|
||||
<h2>批量转码工具</h2>
|
||||
<p>批量转码工具用于将指定目录下的多个文件从一种编码格式转换为另一种编码格式。</p>
|
||||
<ul>
|
||||
<li><strong>源目录:</strong> 选择包含待转换文件的目录</li>
|
||||
<li><strong>目标目录:</strong> 选择转换后文件的保存目录</li>
|
||||
<li><strong>文件过滤:</strong> 设置要转换的文件类型,如 *.txt</li>
|
||||
<li><strong>源编码:</strong> 选择源文件的编码格式</li>
|
||||
<li><strong>目标编码:</strong> 选择目标编码格式</li>
|
||||
</ul>
|
||||
void HelpPage::updateContent(const QString §ion)
|
||||
{
|
||||
QString htmlContent = markdownToHtml(extractSection(section));
|
||||
m_contentBrowser->setHtml(htmlContent);
|
||||
}
|
||||
|
||||
<h2>非LS转码工具</h2>
|
||||
<p>非LS转码工具用于在LS和非LS格式之间进行转换。</p>
|
||||
<ul>
|
||||
<li><strong>非LS转LS:</strong> 将非LS格式转换为LS格式</li>
|
||||
<li><strong>LS转非LS:</strong> 将LS格式转换为非LS格式</li>
|
||||
</ul>
|
||||
QString HelpPage::extractSection(const QString §ionName)
|
||||
{
|
||||
QStringList lines = m_helpContent.split("\n");
|
||||
QString sectionContent;
|
||||
bool inSection = false;
|
||||
|
||||
<h2>支持的编码格式</h2>
|
||||
<ul>
|
||||
<li>GBK</li>
|
||||
<li>GB2312</li>
|
||||
<li>UTF-8</li>
|
||||
<li>UTF-16</li>
|
||||
<li>ASCII</li>
|
||||
</ul>
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
<h2>注意事项</h2>
|
||||
<ul>
|
||||
<li>转换前请备份重要文件</li>
|
||||
<li>确保有足够的磁盘空间</li>
|
||||
<li>大文件转换可能需要较长时间</li>
|
||||
</ul>
|
||||
)");
|
||||
layout->addWidget(helpText);
|
||||
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 += "<br>";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (trimmedLine.startsWith("### ")) {
|
||||
if (inList) {
|
||||
html += "</ul>";
|
||||
inList = false;
|
||||
}
|
||||
html += "<h3>" + trimmedLine.mid(4) + "</h3>";
|
||||
} else if (trimmedLine.startsWith("#### ")) {
|
||||
if (inList) {
|
||||
html += "</ul>";
|
||||
inList = false;
|
||||
}
|
||||
html += "<h4>" + trimmedLine.mid(5) + "</h4>";
|
||||
} else if (trimmedLine.startsWith("- ")) {
|
||||
if (!inList) {
|
||||
html += "<ul style='margin-top: 4px; margin-bottom: 4px; padding-left: 20px;'>";
|
||||
inList = true;
|
||||
}
|
||||
QString text = trimmedLine.mid(2);
|
||||
text.replace(QRegularExpression("\\*\\*(.+?)\\*\\*"), "<strong>\\1</strong>");
|
||||
html += "<li style='margin-bottom: 2px;'>" + text + "</li>";
|
||||
} else if (trimmedLine.startsWith("```")) {
|
||||
if (inList) {
|
||||
html += "</ul>";
|
||||
inList = false;
|
||||
}
|
||||
continue;
|
||||
} else {
|
||||
if (inList) {
|
||||
html += "</ul>";
|
||||
inList = false;
|
||||
}
|
||||
QString text = trimmedLine;
|
||||
text.replace(QRegularExpression("\\*\\*(.+?)\\*\\*"), "<strong>\\1</strong>");
|
||||
html += "<p style='margin-top: 4px; margin-bottom: 4px;'>" + text + "</p>";
|
||||
}
|
||||
}
|
||||
|
||||
if (inList) {
|
||||
html += "</ul>";
|
||||
}
|
||||
|
||||
return html;
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
#define HELPPAGE_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QStackedWidget>
|
||||
#include <QLabel>
|
||||
#include <QTextBrowser>
|
||||
#include "ElaTreeView.h"
|
||||
|
||||
class HelpPage : public QWidget
|
||||
{
|
||||
@@ -13,6 +17,18 @@ public:
|
||||
|
||||
private:
|
||||
void initUI();
|
||||
void initTreeView();
|
||||
void initContentPages();
|
||||
void loadHelpFile();
|
||||
void updateContent(const QString §ion);
|
||||
QString extractSection(const QString §ionName);
|
||||
QString markdownToHtml(const QString &markdown);
|
||||
|
||||
ElaTreeView* m_treeView;
|
||||
QStackedWidget* m_stackedWidget;
|
||||
QLabel* m_titleLabel;
|
||||
QTextBrowser* m_contentBrowser;
|
||||
QString m_helpContent;
|
||||
};
|
||||
|
||||
#endif // HELPPAGE_H
|
||||
Reference in New Issue
Block a user