From aac1b687b8ca7534926d9420c9003802850d8fcf Mon Sep 17 00:00:00 2001 From: Sunyuxuan <3107278279@qq.com> Date: Mon, 16 Dec 2024 21:11:06 +0800 Subject: [PATCH] =?UTF-8?q?CustomMarkdownHighlighter.cpp=20customapplicati?= =?UTF-8?q?onstyle.cpp=E4=B8=A4=E4=B8=AA=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/src/customMarkdownHighlighter.cpp | 12 ++++++++++-- source/src/customapplicationstyle.cpp | 8 ++++++-- source/src/customapplicationstyle.h | 3 ++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/source/src/customMarkdownHighlighter.cpp b/source/src/customMarkdownHighlighter.cpp index 1d5f43d..6f60442 100644 --- a/source/src/customMarkdownHighlighter.cpp +++ b/source/src/customMarkdownHighlighter.cpp @@ -6,8 +6,9 @@ CustomMarkdownHighlighter::CustomMarkdownHighlighter(QTextDocument *parent, : MarkdownHighlighter(parent, highlightingOptions) { setListsColor(QColor(35, 131, 226)); // accent color - + //设置列表颜色为蓝色,即特定的强调色 _formats[static_cast(HighlighterState::HorizontalRuler)].clearBackground(); + //清除水平分隔线的背景色 } void CustomMarkdownHighlighter::setHeaderColors(QColor color) @@ -30,29 +31,36 @@ void CustomMarkdownHighlighter::setFontSize(qreal fontSize) // H1 => size = fontSize * 1.6 // H6 => size = fontSize * 1.1 qreal size = fontSize * (1.6 - (i - HighlighterState::H1) * 0.1); + //启发我们可以通过一定的计算来避免存储空间的浪费,即用计算时的空间换取存储时的空间 _formats[static_cast(i)].setFontPointSize(size); } qreal codeBlockFontSize = fontSize - 4; _formats[static_cast(HighlighterState::InlineCodeBlock)].setFontPointSize( codeBlockFontSize); + //改变块间距 } void CustomMarkdownHighlighter::setListsColor(QColor color) { _formats[static_cast(HighlighterState::CheckBoxUnChecked)].setForeground( color); + //设置未选中的复选框 _formats[static_cast(HighlighterState::CheckBoxChecked)].setForeground( QColor(90, 113, 140)); + //设置已选中的复选框 _formats[static_cast(HighlighterState::List)].setForeground(color); + //设置列表前景颜色 _formats[static_cast(HighlighterState::BlockQuote)].setForeground(color); + //设置块引用前景颜色 } void CustomMarkdownHighlighter::setTheme(Theme::Value theme, QColor textColor, qreal fontSize) { + //设置标题颜色和字体大小 setHeaderColors(textColor); setFontSize(fontSize); - + //根据主题设置代码块的背景色和前景色 switch (theme) { case Theme::Light: _formats[static_cast(HighlighterState::InlineCodeBlock)].setBackground( diff --git a/source/src/customapplicationstyle.cpp b/source/src/customapplicationstyle.cpp index 3e25a4d..340ba75 100644 --- a/source/src/customapplicationstyle.cpp +++ b/source/src/customapplicationstyle.cpp @@ -7,13 +7,14 @@ void CustomApplicationStyle::drawPrimitive(PrimitiveElement element, const QStyl QPainter *painter, const QWidget *widget) const { if (element == QStyle::PE_IndicatorItemViewItemDrop) { + //此为用户拖动进来的操作流程 painter->setRenderHint(QPainter::Antialiasing, true); QColor color(207, 207, 207); QPen pen(color); pen.setWidth(2); painter->setPen(pen); - + //设置一个宽度为2的灰色画笔 if (option->rect.height() == 0) { color.setAlpha(50); painter->setBrush(color); @@ -22,7 +23,9 @@ void CustomApplicationStyle::drawPrimitive(PrimitiveElement element, const QStyl color.setAlpha(200); painter->fillRect(option->rect, color); } + //如果高度为0,透明度设置为50%,画线;否则设为不透明,填充灰色 } else { + //此为默认创建流程 QProxyStyle::drawPrimitive(element, option, painter, widget); } } @@ -31,5 +34,6 @@ void CustomApplicationStyle::setTheme(Theme::Value theme) { m_theme = theme; } - +//初始化主题 CustomApplicationStyle::CustomApplicationStyle() : m_theme(Theme::Light) { } +//初始化主题,默认主题为浅色 \ No newline at end of file diff --git a/source/src/customapplicationstyle.h b/source/src/customapplicationstyle.h index 737a5b5..e74c13c 100644 --- a/source/src/customapplicationstyle.h +++ b/source/src/customapplicationstyle.h @@ -11,8 +11,9 @@ public: void drawPrimitive(PrimitiveElement element, const QStyleOption *option, QPainter *painter, const QWidget *widget) const; + //重写绘制函数 void setTheme(Theme::Value theme); - + //存储当前的主题值 private: Theme::Value m_theme; };