mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00
MdEditor: fix zoomPage() bug after setting style sheet
This commit is contained in:
parent
2b01a4ccd0
commit
ba0660de28
@ -91,5 +91,7 @@ inline void VLineNumberArea::setForegroundColor(const QColor &p_color)
|
|||||||
inline void VLineNumberArea::setDigitWidth(int p_width)
|
inline void VLineNumberArea::setDigitWidth(int p_width)
|
||||||
{
|
{
|
||||||
m_digitWidth = p_width;
|
m_digitWidth = p_width;
|
||||||
|
m_blockCount = -1;
|
||||||
|
calculateWidth();
|
||||||
}
|
}
|
||||||
#endif // VLINENUMBERAREA_H
|
#endif // VLINENUMBERAREA_H
|
||||||
|
@ -126,17 +126,9 @@ void VMdEditor::updateFontAndPalette()
|
|||||||
// setTextColor(palette.color(QPalette::Text));
|
// setTextColor(palette.color(QPalette::Text));
|
||||||
|
|
||||||
// Only this could override the font-family set of QWidget in QSS.
|
// Only this could override the font-family set of QWidget in QSS.
|
||||||
setStyleSheet(QString("VMdEditor, VLineNumberArea {"
|
setFontAndPaletteByStyleSheet(font, palette);
|
||||||
"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());
|
updateLineNumberAreaWidth(QFontMetrics(font));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VMdEditor::beginEdit()
|
void VMdEditor::beginEdit()
|
||||||
@ -284,7 +276,6 @@ void VMdEditor::makeBlockVisible(const QTextBlock &p_block)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (y + rectHeight > height && vbar->value() < vbar->maximum()) {
|
while (y + rectHeight > height && vbar->value() < vbar->maximum()) {
|
||||||
moved = true;
|
|
||||||
vbar->setValue(vbar->value() + vbar->singleStep());
|
vbar->setValue(vbar->value() + vbar->singleStep());
|
||||||
rt = layout->blockBoundingRect(p_block);
|
rt = layout->blockBoundingRect(p_block);
|
||||||
rectHeight = (int)rt.height();
|
rectHeight = (int)rt.height();
|
||||||
@ -1207,17 +1198,20 @@ void VMdEditor::wheelEvent(QWheelEvent *p_event)
|
|||||||
|
|
||||||
void VMdEditor::zoomPage(bool p_zoomIn, int p_range)
|
void VMdEditor::zoomPage(bool p_zoomIn, int p_range)
|
||||||
{
|
{
|
||||||
int delta;
|
|
||||||
const int minSize = 2;
|
const int minSize = 2;
|
||||||
|
|
||||||
if (p_zoomIn) {
|
int delta = p_zoomIn ? p_range : -p_range;
|
||||||
delta = p_range;
|
|
||||||
zoomIn(p_range);
|
// zoomIn() and zoomOut() does not work if we set stylesheet of VMdEditor.
|
||||||
} else {
|
int ptSz = font().pointSize() + delta;
|
||||||
delta = -p_range;
|
if (ptSz < minSize) {
|
||||||
zoomOut(p_range);
|
ptSz = minSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setFontPointSizeByStyleSheet(ptSz);
|
||||||
|
|
||||||
|
emit m_object->statusMessage(QObject::tr("Set base font point size %1").arg(ptSz));
|
||||||
|
|
||||||
m_zoomDelta += delta;
|
m_zoomDelta += delta;
|
||||||
|
|
||||||
QVector<HighlightingStyle> &styles = m_pegHighlighter->getStyles();
|
QVector<HighlightingStyle> &styles = m_pegHighlighter->getStyles();
|
||||||
@ -1384,3 +1378,28 @@ void VMdEditor::setEditTab(VEditTab *p_editTab)
|
|||||||
{
|
{
|
||||||
m_editTab = p_editTab;
|
m_editTab = p_editTab;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void VMdEditor::setFontPointSizeByStyleSheet(int p_ptSize)
|
||||||
|
{
|
||||||
|
QFont ft = font();
|
||||||
|
ft.setPointSize(p_ptSize);
|
||||||
|
|
||||||
|
setFontAndPaletteByStyleSheet(ft, palette());
|
||||||
|
|
||||||
|
ensurePolished();
|
||||||
|
|
||||||
|
updateLineNumberAreaWidth(QFontMetrics(ft));
|
||||||
|
}
|
||||||
|
|
||||||
|
void VMdEditor::setFontAndPaletteByStyleSheet(const QFont &p_font, const QPalette &p_palette)
|
||||||
|
{
|
||||||
|
setStyleSheet(QString("VMdEditor, VLineNumberArea {"
|
||||||
|
"font-family: \"%1\";"
|
||||||
|
"font-size: %2pt;"
|
||||||
|
"color: %3;"
|
||||||
|
"background-color: %4; }")
|
||||||
|
.arg(p_font.family())
|
||||||
|
.arg(p_font.pointSize())
|
||||||
|
.arg(p_palette.color(QPalette::Text).name())
|
||||||
|
.arg(p_palette.color(QPalette::Base).name()));
|
||||||
|
}
|
||||||
|
@ -256,6 +256,10 @@ private:
|
|||||||
|
|
||||||
void insertImageLink(const QString &p_text, const QString &p_url);
|
void insertImageLink(const QString &p_text, const QString &p_url);
|
||||||
|
|
||||||
|
void setFontPointSizeByStyleSheet(int p_ptSize);
|
||||||
|
|
||||||
|
void setFontAndPaletteByStyleSheet(const QFont &p_font, const QPalette &p_palette);
|
||||||
|
|
||||||
PegMarkdownHighlighter *m_pegHighlighter;
|
PegMarkdownHighlighter *m_pegHighlighter;
|
||||||
|
|
||||||
VCodeBlockHighlightHelper *m_cbHighlighter;
|
VCodeBlockHighlightHelper *m_cbHighlighter;
|
||||||
|
@ -446,6 +446,7 @@ void VTextEdit::setDisplayScaleFactor(qreal p_factor)
|
|||||||
void VTextEdit::updateLineNumberAreaWidth(const QFontMetrics &p_metrics)
|
void VTextEdit::updateLineNumberAreaWidth(const QFontMetrics &p_metrics)
|
||||||
{
|
{
|
||||||
m_lineNumberArea->setDigitWidth(p_metrics.width(QLatin1Char('8')));
|
m_lineNumberArea->setDigitWidth(p_metrics.width(QLatin1Char('8')));
|
||||||
|
updateLineNumberAreaMargin();
|
||||||
}
|
}
|
||||||
|
|
||||||
void VTextEdit::dragMoveEvent(QDragMoveEvent *p_event)
|
void VTextEdit::dragMoveEvent(QDragMoveEvent *p_event)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user