CustomMarkdownHighlighter.cpp

customapplicationstyle.cpp两个文件
main
Sunyuxuan 7 months ago
parent e7ada2435c
commit aac1b687b8

@ -6,8 +6,9 @@ CustomMarkdownHighlighter::CustomMarkdownHighlighter(QTextDocument *parent,
: MarkdownHighlighter(parent, highlightingOptions)
{
setListsColor(QColor(35, 131, 226)); // accent color
//设置列表颜色为蓝色,即特定的强调色
_formats[static_cast<HighlighterState>(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<HighlighterState>(i)].setFontPointSize(size);
}
qreal codeBlockFontSize = fontSize - 4;
_formats[static_cast<HighlighterState>(HighlighterState::InlineCodeBlock)].setFontPointSize(
codeBlockFontSize);
//改变块间距
}
void CustomMarkdownHighlighter::setListsColor(QColor color)
{
_formats[static_cast<HighlighterState>(HighlighterState::CheckBoxUnChecked)].setForeground(
color);
//设置未选中的复选框
_formats[static_cast<HighlighterState>(HighlighterState::CheckBoxChecked)].setForeground(
QColor(90, 113, 140));
//设置已选中的复选框
_formats[static_cast<HighlighterState>(HighlighterState::List)].setForeground(color);
//设置列表前景颜色
_formats[static_cast<HighlighterState>(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>(HighlighterState::InlineCodeBlock)].setBackground(

@ -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) { }
//初始化主题,默认主题为浅色

@ -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;
};

Loading…
Cancel
Save