| 90 | } |
| 91 | |
| 92 | void BasicEditor::lineNumberAreaPaintEvent(QPaintEvent *event) |
| 93 | { |
| 94 | QPainter painter(lineNumberArea); |
| 95 | painter.fillRect(event->rect(), Qt::lightGray); |
| 96 | painter.setPen(Qt::black); |
| 97 | |
| 98 | QTextBlock block = firstVisibleBlock(); |
| 99 | int blockNumber = block.blockNumber(); |
| 100 | int top = static_cast<int>(blockBoundingGeometry(block).translated(contentOffset()).top()); |
| 101 | int bottom = top + static_cast<int>(blockBoundingRect(block).height()); |
| 102 | |
| 103 | while (block.isValid() && top <= event->rect().bottom()) { |
| 104 | if (block.isVisible() && bottom >= event->rect().top()) { |
| 105 | QString number = QString::number(blockNumber + 1); |
| 106 | painter.drawText(-2, top, lineNumberArea->width(), fontMetrics().height(), Qt::AlignRight, number); |
| 107 | } |
| 108 | block = block.next(); |
| 109 | top = bottom; |
| 110 | bottom = top + static_cast<int>(blockBoundingRect(block).height()); |
| 111 | ++blockNumber; |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | /* Highlighter */ |
| 116 | |