refine line number area

This commit is contained in:
Le Tan 2017-07-11 19:47:43 +08:00
parent ba84489c68
commit 0d0f6d4e47
3 changed files with 37 additions and 8 deletions

View File

@ -908,15 +908,44 @@ void VEdit::lineNumberAreaPaintEvent(QPaintEvent *p_event)
const int curBlockNumber = textCursor().block().blockNumber(); const int curBlockNumber = textCursor().block().blockNumber();
const bool relative = vconfig.getEditorLineNumber() == 2; const bool relative = vconfig.getEditorLineNumber() == 2;
const QString &fg = vconfig.getEditorLineNumberFg(); const QString &fg = vconfig.getEditorLineNumberFg();
painter.setPen(fg);
while (block.isValid() && top <= eventBtm) { while (block.isValid() && top <= eventBtm) {
if (block.isVisible() && bottom >= eventTop) { if (block.isVisible() && bottom >= eventTop) {
QString number = QString::number(relative ? blockNumber - curBlockNumber bool currentLine = false;
: blockNumber + 1); int number = blockNumber + 1;
painter.setPen(fg); if (relative) {
painter.drawText(0, top + 2, number = blockNumber - curBlockNumber;
if (number == 0) {
currentLine = true;
number = blockNumber + 1;
} else if (number < 0) {
number = -number;
}
} else if (blockNumber == curBlockNumber) {
currentLine = true;
}
QString numberStr = QString::number(number);
if (currentLine) {
QFont font = painter.font();
font.setBold(true);
painter.setFont(font);
}
painter.drawText(0,
top + 2,
m_lineNumberArea->width(), m_lineNumberArea->width(),
digitHeight, Qt::AlignRight, number); digitHeight,
Qt::AlignRight,
numberStr);
if (currentLine) {
QFont font = painter.font();
font.setBold(false);
painter.setFont(font);
}
} }
block = block.next(); block = block.next();
@ -999,7 +1028,7 @@ int LineNumberArea::calculateWidth() const
++digits; ++digits;
} }
int width = 2 + m_digitWidth * digits; int width = m_digitWidth * digits;
const_cast<LineNumberArea *>(this)->m_width = width; const_cast<LineNumberArea *>(this)->m_width = width;
return m_width; return m_width;

View File

@ -231,7 +231,7 @@ public:
m_document(p_editor->document()), m_document(p_editor->document()),
m_width(0), m_blockCount(-1) m_width(0), m_blockCount(-1)
{ {
m_digitWidth = m_editor->fontMetrics().width(QLatin1Char('9')); m_digitWidth = m_editor->fontMetrics().width(QLatin1Char('1'));
m_digitHeight = m_editor->fontMetrics().height(); m_digitHeight = m_editor->fontMetrics().height();
} }

View File

@ -163,7 +163,7 @@ void VNotebookSelector::update()
bool VNotebookSelector::newNotebook() bool VNotebookSelector::newNotebook()
{ {
QString info(tr("Please type the name of the notebook and " QString info(tr("Please type the name of the notebook and "
"choose an existing folder as Root Folder of the notebook.")); "choose a folder as the Root Folder of the notebook."));
info += "\n"; info += "\n";
info += tr("The root folder should be used EXCLUSIVELY by VNote and " info += tr("The root folder should be used EXCLUSIVELY by VNote and "
"it is recommended to be EMPTY."); "it is recommended to be EMPTY.");