mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
MdEditor: fix the font style issue
Font family may be constrained by QWidget style in qss file.
This commit is contained in:
parent
3e29a647ab
commit
0e724635b3
@ -95,9 +95,9 @@ public:
|
||||
// Reset the layout.
|
||||
void resetLayoutConfigurations();
|
||||
|
||||
QFont getMdEditFont() const;
|
||||
const QFont &getMdEditFont() const;
|
||||
|
||||
QPalette getMdEditPalette() const;
|
||||
const QPalette &getMdEditPalette() const;
|
||||
|
||||
QVector<HighlightingStyle> getMdHighlightingStyles() const;
|
||||
|
||||
@ -984,12 +984,12 @@ private:
|
||||
};
|
||||
|
||||
|
||||
inline QFont VConfigManager::getMdEditFont() const
|
||||
inline const QFont &VConfigManager::getMdEditFont() const
|
||||
{
|
||||
return mdEditFont;
|
||||
}
|
||||
|
||||
inline QPalette VConfigManager::getMdEditPalette() const
|
||||
inline const QPalette &VConfigManager::getMdEditPalette() const
|
||||
{
|
||||
return mdEditPalette;
|
||||
}
|
||||
|
@ -42,6 +42,8 @@ public:
|
||||
return QSize(calculateWidth(), 0);
|
||||
}
|
||||
|
||||
void setDigitWidth(int p_width);
|
||||
|
||||
int calculateWidth() const;
|
||||
|
||||
const QColor &getBackgroundColor() const;
|
||||
@ -86,4 +88,8 @@ inline void VLineNumberArea::setForegroundColor(const QColor &p_color)
|
||||
m_foregroundColor = p_color;
|
||||
}
|
||||
|
||||
inline void VLineNumberArea::setDigitWidth(int p_width)
|
||||
{
|
||||
m_digitWidth = p_width;
|
||||
}
|
||||
#endif // VLINENUMBERAREA_H
|
||||
|
@ -111,11 +111,27 @@ VMdEditor::VMdEditor(VFile *p_file,
|
||||
|
||||
void VMdEditor::updateFontAndPalette()
|
||||
{
|
||||
setFont(g_config->getMdEditFont());
|
||||
setPalette(g_config->getMdEditPalette());
|
||||
QFont font(g_config->getMdEditFont());
|
||||
setFont(font);
|
||||
|
||||
const QPalette &palette = g_config->getMdEditPalette();
|
||||
setPalette(palette);
|
||||
|
||||
// setPalette() won't change the foreground.
|
||||
setTextColor(g_config->getMdEditPalette().color(QPalette::Text));
|
||||
setTextColor(palette.color(QPalette::Text));
|
||||
|
||||
// Only this could override the font-family set of QWidget in QSS.
|
||||
// May be need to reset all the stylesheet?
|
||||
setStyleSheet(QString("font-family: \"%1\";"
|
||||
"font-size: %2pt;"
|
||||
"color: %3;"
|
||||
"background-color: %4;")
|
||||
.arg(font.family())
|
||||
.arg(font.pointSize())
|
||||
.arg(palette.color(QPalette::Text).name())
|
||||
.arg(palette.color(QPalette::Base).name()));
|
||||
|
||||
updateLineNumberAreaWidth(fontMetrics());
|
||||
}
|
||||
|
||||
void VMdEditor::beginEdit()
|
||||
|
@ -442,3 +442,8 @@ void VTextEdit::setDisplayScaleFactor(qreal p_factor)
|
||||
: m_defaultCursorWidth);
|
||||
getLayout()->setCursorWidth(m_defaultCursorWidth);
|
||||
}
|
||||
|
||||
void VTextEdit::updateLineNumberAreaWidth(const QFontMetrics &p_metrics)
|
||||
{
|
||||
m_lineNumberArea->setDigitWidth(p_metrics.width(QLatin1Char('8')));
|
||||
}
|
||||
|
@ -81,6 +81,8 @@ protected:
|
||||
// Return the Y offset of the content via the scrollbar.
|
||||
int contentOffsetY() const;
|
||||
|
||||
void updateLineNumberAreaWidth(const QFontMetrics &p_metrics);
|
||||
|
||||
private slots:
|
||||
// Update viewport margin to hold the line number area.
|
||||
void updateLineNumberAreaMargin();
|
||||
|
Loading…
x
Reference in New Issue
Block a user