support font family settings in editor style

Signed-off-by: Le Tan <tamlokveer@gmail.com>
This commit is contained in:
Le Tan 2016-10-13 23:09:20 +08:00
parent eb5b6a6276
commit 2adbd7c409
7 changed files with 23 additions and 11 deletions

View File

@ -52,7 +52,7 @@ void WorkerThread::resizeBuffer(int newCap)
void WorkerThread::prepareAndStart(const char *data) void WorkerThread::prepareAndStart(const char *data)
{ {
Q_ASSERT(data); Q_ASSERT(data);
int len = strlen(data); int len = int(strlen(data));
if (len >= capacity) { if (len >= capacity) {
resizeBuffer(qMax(2 * capacity, len + 1)); resizeBuffer(qMax(2 * capacity, len + 1));
} }
@ -245,6 +245,7 @@ void HGMarkdownHighlighter::handleContentsChange(int position, int charsRemoved,
if (charsRemoved == 0 && charsAdded == 0) if (charsRemoved == 0 && charsAdded == 0)
return; return;
position;
timer->stop(); timer->stop();
timer->start(); timer->start();
} }

View File

@ -2,7 +2,7 @@
# Created by Le Tan (tamlokveer@gmail.com) # Created by Le Tan (tamlokveer@gmail.com)
editor editor
font-family: Georgia, Palatino, Arial, serif font-family: Microsoft YaHei, WenQuanYi Micro Hei, Droid Sans, SimSun, Georgia, Palatino, Arial, serif
H1 H1
foreground: 111111 foreground: 111111

View File

@ -95,5 +95,7 @@ void VConfigManager::updateMarkdownEditStyle()
VStyleParser parser; VStyleParser parser;
parser.parseMarkdownStyle(styleStr); parser.parseMarkdownStyle(styleStr);
mdHighlightingStyles = parser.fetchMarkdownStyles(baseEditFont); mdHighlightingStyles = parser.fetchMarkdownStyles(baseEditFont);
mdEditPalette = parser.fetchMarkdownEditorStyles(baseEditPalette); mdEditPalette = baseEditPalette;
mdEditFont = baseEditFont;
parser.fetchMarkdownEditorStyles(mdEditPalette, mdEditFont);
} }

View File

@ -25,6 +25,7 @@ public:
QFont baseEditFont; QFont baseEditFont;
QPalette baseEditPalette; QPalette baseEditPalette;
QFont mdEditFont;
QPalette mdEditPalette; QPalette mdEditPalette;
QVector<HighlightingStyle> mdHighlightingStyles; QVector<HighlightingStyle> mdHighlightingStyles;

View File

@ -6,9 +6,11 @@
VEdit::VEdit(VNoteFile *noteFile, QWidget *parent) VEdit::VEdit(VNoteFile *noteFile, QWidget *parent)
: QTextEdit(parent), noteFile(noteFile) : QTextEdit(parent), noteFile(noteFile)
{ {
setFont(VConfigInst->baseEditFont);
if (noteFile->docType == DocType::Markdown) { if (noteFile->docType == DocType::Markdown) {
setPalette(VConfigInst->mdEditPalette); setPalette(VConfigInst->mdEditPalette);
setFont(VConfigInst->mdEditFont);
} else {
setFont(VConfigInst->baseEditFont);
} }
} }

View File

@ -77,8 +77,8 @@ QTextCharFormat VStyleParser::QTextCharFormatFromAttrs(pmh_style_attribute *attr
if (!finalFamily.isEmpty()) { if (!finalFamily.isEmpty()) {
format.setFontFamily(finalFamily); format.setFontFamily(finalFamily);
} }
}
break; break;
}
case pmh_attr_type_font_style: case pmh_attr_type_font_style:
{ {
@ -128,10 +128,8 @@ QVector<HighlightingStyle> VStyleParser::fetchMarkdownStyles(const QFont &baseFo
return styles; return styles;
} }
QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) const void VStyleParser::fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const
{ {
QPalette palette(basePalette);
// editor // editor
pmh_style_attribute *editorStyles = markdownStyles->editor_styles; pmh_style_attribute *editorStyles = markdownStyles->editor_styles;
while (editorStyles) { while (editorStyles) {
@ -146,6 +144,16 @@ QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) co
QColorFromPmhAttr(editorStyles->value->argb_color)); QColorFromPmhAttr(editorStyles->value->argb_color));
break; 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: default:
qWarning() << "warning: unimplemented editor attr type:" << editorStyles->type; qWarning() << "warning: unimplemented editor attr type:" << editorStyles->type;
} }
@ -177,8 +185,6 @@ QPalette VStyleParser::fetchMarkdownEditorStyles(const QPalette &basePalette) co
} }
selStyles = selStyles->next; selStyles = selStyles->next;
} }
return palette;
} }
// @familyList is a comma separated string // @familyList is a comma separated string

View File

@ -22,7 +22,7 @@ public:
void parseMarkdownStyle(const QString &styleStr); void parseMarkdownStyle(const QString &styleStr);
QVector<HighlightingStyle> fetchMarkdownStyles(const QFont &baseFont) const; QVector<HighlightingStyle> fetchMarkdownStyles(const QFont &baseFont) const;
QPalette fetchMarkdownEditorStyles(const QPalette &basePalette) const; void fetchMarkdownEditorStyles(QPalette &palette, QFont &font) const;
private: private:
QColor QColorFromPmhAttr(pmh_attr_argb_color *attr) const; QColor QColorFromPmhAttr(pmh_attr_argb_color *attr) const;