mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 22:09:52 +08:00

- Caculate font height every time on painting line number area; - Support specifying multiple fonts in font-family in qss; - Add margin for "li ol" in CSS;
41 lines
1001 B
C++
41 lines
1001 B
C++
#include "vlinenumberarea.h"
|
|
|
|
#include <QPaintEvent>
|
|
#include <QTextDocument>
|
|
|
|
VLineNumberArea::VLineNumberArea(VTextEditWithLineNumber *p_editor,
|
|
const QTextDocument *p_document,
|
|
int p_digitWidth,
|
|
QWidget *p_parent)
|
|
: QWidget(p_parent),
|
|
m_editor(p_editor),
|
|
m_document(p_document),
|
|
m_width(0),
|
|
m_blockCount(-1),
|
|
m_digitWidth(p_digitWidth),
|
|
m_foregroundColor("black"),
|
|
m_backgroundColor("grey")
|
|
{
|
|
}
|
|
|
|
int VLineNumberArea::calculateWidth() const
|
|
{
|
|
int bc = m_document->blockCount();
|
|
if (m_blockCount == bc) {
|
|
return m_width;
|
|
}
|
|
|
|
const_cast<VLineNumberArea *>(this)->m_blockCount = bc;
|
|
int digits = 1;
|
|
int max = qMax(1, m_blockCount);
|
|
while (max >= 10) {
|
|
max /= 10;
|
|
++digits;
|
|
}
|
|
|
|
int width = m_digitWidth * (digits + 1);
|
|
const_cast<VLineNumberArea *>(this)->m_width = width;
|
|
|
|
return m_width;
|
|
}
|