| 195 | } |
| 196 | |
| 197 | void ProblemInlineNoteProvider::paintInlineNote(const KTextEditor::InlineNote& note, QPainter& painter, |
| 198 | Qt::LayoutDirection direction) const |
| 199 | { |
| 200 | // TODO: https://commits.kde.org/ktexteditor/1ee470de9aea37979836dd3e381cce7bc26344d7 added the third parameter - |
| 201 | // direction - to KTextEditor::InlineNoteProvider::paintInlineNote(). Should the new argument be used here somehow? |
| 202 | Q_UNUSED(direction); |
| 203 | |
| 204 | InlineNoteLayout layout; |
| 205 | doInlineNoteLayout(note, &layout); |
| 206 | |
| 207 | const int line = note.position().line(); |
| 208 | const auto prob = m_problemForLine[note.position().line()]; |
| 209 | QFont font = note.font(); |
| 210 | font.setItalic(true); |
| 211 | painter.setFont(font); |
| 212 | const KTextEditor::View* view = note.view(); |
| 213 | // NOTE cursorToCoordinate is relative to (0,0) of the view widget so we have to subtract the x |
| 214 | // value of the start of the line from it. However it returns also -1 for cursors that have no |
| 215 | // actual text so we subtract the width of the margin column(s) from the available width |
| 216 | const int viewWidth = view->textAreaRect().width(); |
| 217 | const int textAreaStart = view->cursorToCoordinate(KTextEditor::Cursor(line, 0)).x(); |
| 218 | const int marginWidth = view->cursorToCoordinate(KTextEditor::Cursor(line, marginColumns)).x() - textAreaStart; |
| 219 | const int nonTextSize = layout.descriptionX + layout.rightMargin; |
| 220 | const int lineEnd = view->cursorToCoordinate(KTextEditor::Cursor(line, note.position().column() - marginColumns)).x() - textAreaStart; |
| 221 | const int availableTextWidth = viewWidth - marginWidth - lineEnd - nonTextSize; |
| 222 | QString text = painter.fontMetrics().elidedText(prob->description(), Qt::ElideRight, availableTextWidth); |
| 223 | QIcon icon = IProblem::iconForSeverity(prob->severity()); |
| 224 | // QFontMetrics doesn't provide results that are good enough for painting so we use QPainter::boundingRect here |
| 225 | QRect boundingRect = painter.boundingRect(QRect(layout.descriptionX, 0, 0, 0), Qt::AlignLeft, text); |
| 226 | const auto colors = severityColors(prob->severity()); |
| 227 | // background |
| 228 | painter.setBrush(colors.background); |
| 229 | painter.setPen(Qt::NoPen); |
| 230 | painter.drawRect(boundingRect.adjusted(-(layout.descriptionX), 0, layout.rightMargin, 0)); |
| 231 | // borderline |
| 232 | painter.setBrush(colors.foreground); |
| 233 | painter.drawRect(QRect(0, 0, noteBorderWidth, note.lineHeight())); |
| 234 | // icpn |
| 235 | icon.paint(&painter, layout.iconX, iconTopBottomMargin, layout.iconSize, layout.iconSize, Qt::AlignCenter); |
| 236 | // text |
| 237 | painter.setPen(colors.foreground); |
| 238 | painter.drawText(boundingRect, Qt::AlignLeft, text); |
| 239 | } |
| 240 | |
| 241 | #include "moc_probleminlinenoteprovider.cpp" |
nothing calls this directly
no test coverage detected