MCPcopy Create free account
hub / github.com/KDE/kate / paintEvent

Method paintEvent

apps/lib/diff/difflinenumarea.cpp:102–185  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100}
101
102void LineNumArea::paintEvent(QPaintEvent *event)
103{
104 if (m_lineToNumA.empty()) {
105 return;
106 }
107 QPainter painter(this);
108
109 painter.fillRect(event->rect(), palette().color(QPalette::Active, QPalette::Window));
110
111 QTextBlock block = textEdit->firstVisibleBlock();
112 int blockNumber = block.blockNumber();
113 qreal top = textEdit->blockBoundingGeometry(block).translated(textEdit->contentOffset()).top();
114 // Maybe the top is not 0?
115 top += textEdit->viewportMargins().top();
116 qreal bottom = top;
117
118 // const QPen currentLine = m_currentLineColor;
119 const QPen otherLines = m_otherLinesColor;
120
121 QColor c = textEdit->addedColor();
122 c.setAlphaF(0.7f);
123 const QPen added = c;
124 c = textEdit->removedColor();
125 c.setAlphaF(0.7f);
126 const QPen removed = c;
127
128 LineNumColors colors{.otherLine = otherLines /*, currentLine*/, .added = added, .removed = removed};
129
130 painter.setFont(font());
131 const int w = lineNumAreaWidth();
132
133 while (block.isValid() && top <= event->rect().bottom()) {
134 top = bottom;
135 bottom = top + textEdit->blockBoundingRect(block).height();
136 if (block.isVisible() && bottom >= event->rect().top()) {
137 // Current line background
138 // const auto isCurrentLine = textEdit->textCursor().blockNumber() == blockNumber;
139 // if (isCurrentLine) {
140 // painter.fillRect(0, top, rect().width(), textEdit->fontMetrics().height(), m_currentLineBgColor);
141 // }
142
143 // Line number left
144 if (size_t(blockNumber) < m_lineToNumA.size()) {
145 int n = m_lineToNumA[blockNumber];
146 QRect numRect(0, top, w, textEdit->fontMetrics().height());
147 drawLineNumber(painter, numRect, blockNumber, n, colors);
148 }
149
150 if (!m_lineToNumB.empty()) {
151 // we are in unified mode, draw the right line number
152 if (size_t(blockNumber) < m_lineToNumB.size()) {
153 int n = m_lineToNumB[blockNumber];
154 QRect numRect(w, top, w, textEdit->fontMetrics().height());
155 drawLineNumber(painter, numRect, blockNumber, n, colors);
156 }
157 }
158
159 // Hunk fold marker

Callers

nothing calls this directly

Calls 11

lineNumAreaWidthFunction · 0.85
paintTriangleFunction · 0.85
QPointClass · 0.85
emptyMethod · 0.80
addedColorMethod · 0.80
removedColorMethod · 0.80
sizeMethod · 0.80
isHunkLineMethod · 0.80
isHunkFoldedMethod · 0.80
setFontMethod · 0.45
isValidMethod · 0.45

Tested by

no test coverage detected