| 67 | } |
| 68 | |
| 69 | void QLineNumberArea::paintEvent(QPaintEvent *event) |
| 70 | { |
| 71 | QPainter painter(this); |
| 72 | painter.setLayoutDirection(Qt::LeftToRight); |
| 73 | |
| 74 | // Clearing rect to update |
| 75 | painter.fillRect(event->rect(), |
| 76 | m_syntaxStyle->getFormat("Text").background().color()); |
| 77 | |
| 78 | auto blockNumber = m_codeEditParent->getFirstVisibleBlock(); |
| 79 | auto block = m_codeEditParent->document()->findBlockByNumber(blockNumber); |
| 80 | auto top = (int)m_codeEditParent->document() |
| 81 | ->documentLayout() |
| 82 | ->blockBoundingRect(block) |
| 83 | .translated(0, -m_codeEditParent->verticalScrollBar()->value()) |
| 84 | .top(); |
| 85 | auto bottom = top |
| 86 | + (int)m_codeEditParent->document() |
| 87 | ->documentLayout() |
| 88 | ->blockBoundingRect(block) |
| 89 | .height(); |
| 90 | |
| 91 | auto currentLine |
| 92 | = m_syntaxStyle->getFormat("CurrentLineNumber").foreground().color(); |
| 93 | auto otherLines = m_syntaxStyle->getFormat("LineNumber").foreground().color(); |
| 94 | |
| 95 | painter.setFont(m_codeEditParent->font()); |
| 96 | |
| 97 | while (block.isValid() && top <= event->rect().bottom()) |
| 98 | { |
| 99 | if (block.isVisible() && bottom >= event->rect().top()) |
| 100 | { |
| 101 | QString number = QString::number(blockNumber + 1); |
| 102 | |
| 103 | auto isCurrentLine |
| 104 | = m_codeEditParent->textCursor().blockNumber() == blockNumber; |
| 105 | painter.setPen(isCurrentLine ? currentLine : otherLines); |
| 106 | |
| 107 | painter.drawText(-5, top, sizeHint().width(), |
| 108 | m_codeEditParent->fontMetrics().height(), Qt::AlignRight, |
| 109 | number); |
| 110 | } |
| 111 | |
| 112 | block = block.next(); |
| 113 | top = bottom; |
| 114 | bottom = top |
| 115 | + (int)m_codeEditParent->document() |
| 116 | ->documentLayout() |
| 117 | ->blockBoundingRect(block) |
| 118 | .height(); |
| 119 | ++blockNumber; |
| 120 | } |
| 121 | } |
nothing calls this directly
no test coverage detected