forked from vnotex/vnote
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvlinenumberarea.cpp
More file actions
39 lines (33 loc) · 976 Bytes
/
vlinenumberarea.cpp
File metadata and controls
39 lines (33 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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;
}
const_cast<VLineNumberArea *>(this)->m_width = m_digitWidth * digits + 3;
return m_width;
}