mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 05:49:53 +08:00
support font family settings in editor style
Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
parent
eb5b6a6276
commit
2adbd7c409
@ -52,7 +52,7 @@ void WorkerThread::resizeBuffer(int newCap)
|
||||
void WorkerThread::prepareAndStart(const char *data)
|
||||
{
|
||||
Q_ASSERT(data);
|
||||
int len = strlen(data);
|
||||
int len = int(strlen(data));
|
||||
if (len >= capacity) {
|
||||
resizeBuffer(qMax(2 * capacity, len + 1));
|
||||
}
|
||||
@ -245,6 +245,7 @@ void HGMarkdownHighlighter::handleContentsChange(int position, int charsRemoved,
|
||||
if (charsRemoved == 0 && charsAdded == 0)
|
||||
return;
|
||||
|
||||
position;
|
||||
timer->stop();
|
||||
timer->start();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
# Created by Le Tan (tamlokveer@gmail.com)
|
||||
|
||||
editor
|
||||
font-family: Georgia, Palatino, Arial, serif
|
||||
font-family: Microsoft YaHei, WenQuanYi Micro Hei, Droid Sans, SimSun, Georgia, Palatino, Arial, serif
|
||||
|
||||
H1
|
||||
foreground: 111111
|
||||
|
@ -95,5 +95,7 @@ void VConfigManager::updateMarkdownEditStyle()
|
||||
VStyleParser parser;
|
||||
parser.parseMarkdownStyle(styleStr);
|
||||
mdHighlightingStyles = parser.fetchMarkdownStyles(baseEditFont);
|
||||
mdEditPalette = parser.fetchMarkdownEditorStyles(baseEditPalette);
|
||||
mdEditPalette = baseEditPalette;
|
||||
mdEditFont = baseEditFont;
|
||||
parser.fetchMarkdownEditorStyles(mdEditPalette, mdEditFont);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public:
|
||||
|
||||
QFont baseEditFont;
|
||||
QPalette baseEditPalette;
|
||||
QFont mdEditFont;
|
||||
QPalette mdEditPalette;
|
||||
QVector<HighlightingStyle> mdHighlightingStyles;
|
||||
|
||||
|
@ -6,9 +6,11 @@
|
||||
VEdit::VEdit(VNoteFile *noteFile, QWidget *parent)
|
||||
: QTextEdit(parent), noteFile(noteFile)
|
||||
{
|
||||
setFont(VConfigInst->baseEditFont);
|
||||
if (noteFile->docType == DocType::Markdown) {
|
||||
setPalette(VConfigInst->mdEditPalette);
|
||||
setFont(VConfigInst->mdEditFont);
|
||||
} else {
|
||||
setFont(VConfigInst->baseEditFont);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ QTextCharFormat VStyleParser::QTextCharFormatFromAttrs(pmh_style_attribute *attr
|
||||
if (!finalFamily.isEmpty()) {
|
||||
format.setFontFamily(finalFamily);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case pmh_attr_type_font_style:
|
||||
{
|
||||
@ -128,10 +128,8 @@ QVector<HighlightingStyle> VStyleParser::fetchMarkdownStyles(const QFont &baseFo
|
||||
return styles;
|
||||
}
|
||||
|
||||
QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) const
|
||||
void VStyleParser::fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const
|
||||
{
|
||||
QPalette palette(basePalette);
|
||||
|
||||
// editor
|
||||
pmh_style_attribute *editorStyles = markdownStyles->editor_styles;
|
||||
while (editorStyles) {
|
||||
@ -146,6 +144,16 @@ QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) co
|
||||
QColorFromPmhAttr(editorStyles->value->argb_color));
|
||||
break;
|
||||
|
||||
case pmh_attr_type_font_family:
|
||||
{
|
||||
QString familyList(editorStyles->value->font_family);
|
||||
QString finalFamily = filterAvailableFontFamily(familyList);
|
||||
if (!finalFamily.isEmpty()) {
|
||||
font.setFamily(finalFamily);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
qWarning() << "warning: unimplemented editor attr type:" << editorStyles->type;
|
||||
}
|
||||
@ -177,8 +185,6 @@ QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) co
|
||||
}
|
||||
selStyles = selStyles->next;
|
||||
}
|
||||
|
||||
return palette;
|
||||
}
|
||||
|
||||
// @familyList is a comma separated string
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
|
||||
void parseMarkdownStyle(const QString &styleStr);
|
||||
QVector<HighlightingStyle> fetchMarkdownStyles(const QFont &baseFont) const;
|
||||
QPalette fetchMarkdownEditorStyles(const QPalette &basePalette) const;
|
||||
void fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const;
|
||||
|
||||
private:
|
||||
QColor QColorFromPmhAttr(pmh_attr_argb_color *attr) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user