Changeset View
Changeset View
Standalone View
Standalone View
src/render/katerenderer.cpp
Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Line(s) | 52 | KateRenderer::KateRenderer(KTextEditor::DocumentPrivate *doc, Kate::TextFolding &folding, KTextEditor::ViewPrivate *view) | |||
---|---|---|---|---|---|
54 | , m_folding(folding) | 54 | , m_folding(folding) | ||
55 | , m_view(view) | 55 | , m_view(view) | ||
56 | , m_tabWidth(m_doc->config()->tabWidth()) | 56 | , m_tabWidth(m_doc->config()->tabWidth()) | ||
57 | , m_indentWidth(m_doc->config()->indentationWidth()) | 57 | , m_indentWidth(m_doc->config()->indentationWidth()) | ||
58 | , m_caretStyle(KateRenderer::Line) | 58 | , m_caretStyle(KateRenderer::Line) | ||
59 | , m_drawCaret(true) | 59 | , m_drawCaret(true) | ||
60 | , m_showSelections(true) | 60 | , m_showSelections(true) | ||
61 | , m_showTabs(true) | 61 | , m_showTabs(true) | ||
62 | , m_showSpaces(true) | 62 | , m_showTrailingSpaces(true) | ||
63 | , m_showAllSpaces(true) | ||||
63 | , m_showNonPrintableSpaces(false) | 64 | , m_showNonPrintableSpaces(false) | ||
64 | , m_printerFriendly(false) | 65 | , m_printerFriendly(false) | ||
65 | , m_config(new KateRendererConfig(this)) | 66 | , m_config(new KateRendererConfig(this)) | ||
66 | { | 67 | { | ||
67 | updateAttributes(); | 68 | updateAttributes(); | ||
68 | 69 | | |||
69 | // initialize with a sane font height | 70 | // initialize with a sane font height | ||
70 | updateFontHeight(); | 71 | updateFontHeight(); | ||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Line(s) | |||||
113 | 114 | | |||
114 | void KateRenderer::setShowTabs(bool showTabs) | 115 | void KateRenderer::setShowTabs(bool showTabs) | ||
115 | { | 116 | { | ||
116 | m_showTabs = showTabs; | 117 | m_showTabs = showTabs; | ||
117 | } | 118 | } | ||
118 | 119 | | |||
119 | void KateRenderer::setShowTrailingSpaces(bool showSpaces) | 120 | void KateRenderer::setShowTrailingSpaces(bool showSpaces) | ||
120 | { | 121 | { | ||
121 | m_showSpaces = showSpaces; | 122 | m_showTrailingSpaces = showSpaces; | ||
123 | } | ||||
124 | | ||||
125 | void KateRenderer::setShowAllSpaces(bool showSpaces) | ||||
126 | { | ||||
127 | m_showAllSpaces = showSpaces; | ||||
122 | } | 128 | } | ||
123 | 129 | | |||
124 | void KateRenderer::setShowNonPrintableSpaces(const bool on) | 130 | void KateRenderer::setShowNonPrintableSpaces(const bool on) | ||
125 | { | 131 | { | ||
126 | m_showNonPrintableSpaces = on; | 132 | m_showNonPrintableSpaces = on; | ||
127 | } | 133 | } | ||
128 | 134 | | |||
129 | void KateRenderer::setTabWidth(int tabWidth) | 135 | void KateRenderer::setTabWidth(int tabWidth) | ||
▲ Show 20 Lines • Show All 136 Lines • ▼ Show 20 Line(s) | 258 | { | |||
266 | points[4] = QPoint(x - dist, y - dist); | 272 | points[4] = QPoint(x - dist, y - dist); | ||
267 | points[5] = QPoint(x, y); | 273 | points[5] = QPoint(x, y); | ||
268 | points[6] = QPoint(x, y); | 274 | points[6] = QPoint(x, y); | ||
269 | points[7] = QPoint(x - dist, y + dist); | 275 | points[7] = QPoint(x - dist, y + dist); | ||
270 | paint.drawLines(points, 4); | 276 | paint.drawLines(points, 4); | ||
271 | paint.setPen(penBackup); | 277 | paint.setPen(penBackup); | ||
272 | } | 278 | } | ||
273 | 279 | | |||
274 | void KateRenderer::paintTrailingSpace(QPainter &paint, qreal x, qreal y) | 280 | void KateRenderer::paintSpace(QPainter &paint, qreal x, qreal y) | ||
275 | { | 281 | { | ||
276 | QPen penBackup(paint.pen()); | 282 | QPen penBackup(paint.pen()); | ||
277 | QPen pen(config()->tabMarkerColor()); | 283 | QPen pen(config()->tabMarkerColor()); | ||
278 | 284 | | |||
279 | pen.setWidthF(m_markerSize); | 285 | pen.setWidthF(m_markerSize); | ||
280 | pen.setCapStyle(Qt::RoundCap); | 286 | pen.setCapStyle(Qt::RoundCap); | ||
281 | paint.setPen(pen); | 287 | paint.setPen(pen); | ||
282 | paint.setRenderHint(QPainter::Antialiasing, true); | 288 | paint.setRenderHint(QPainter::Antialiasing, true); | ||
Show All 21 Lines | 295 | { | |||
304 | points[4] = QPoint(x + width - width / 10, y + height / 3); | 310 | points[4] = QPoint(x + width - width / 10, y + height / 3); | ||
305 | points[5] = QPoint(x + width - width / 10, y + height / 4); | 311 | points[5] = QPoint(x + width - width / 10, y + height / 4); | ||
306 | paint.drawLines(points, 3); | 312 | paint.drawLines(points, 3); | ||
307 | paint.setPen(penBackup); | 313 | paint.setPen(penBackup); | ||
308 | } | 314 | } | ||
309 | 315 | | |||
310 | void KateRenderer::paintNonPrintableSpaces(QPainter &paint, qreal x, qreal y, const QChar &chr) | 316 | void KateRenderer::paintNonPrintableSpaces(QPainter &paint, qreal x, qreal y, const QChar &chr) | ||
311 | { | 317 | { | ||
318 | qDebug() << "xxxx" << x << y <<chr; | ||||
312 | paint.save(); | 319 | paint.save(); | ||
313 | QPen pen(config()->spellingMistakeLineColor()); | 320 | QPen pen(config()->spellingMistakeLineColor()); | ||
314 | pen.setWidthF(qMax(1.0, spaceWidth() * 0.1)); | 321 | pen.setWidthF(qMax(1.0, spaceWidth() * 0.1)); | ||
315 | paint.setPen(pen); | 322 | paint.setPen(pen); | ||
316 | paint.setRenderHint(QPainter::Antialiasing, false); | 323 | paint.setRenderHint(QPainter::Antialiasing, false); | ||
317 | 324 | | |||
318 | const int height = fontHeight(); | 325 | const int height = fontHeight(); | ||
319 | const int width = config()->fontMetrics().width(chr); | 326 | const int width = config()->fontMetrics().width(chr); | ||
▲ Show 20 Lines • Show All 398 Lines • ▼ Show 20 Line(s) | 724 | if (x > xEnd) { | |||
718 | break; | 725 | break; | ||
719 | } | 726 | } | ||
720 | paintTabstop(paint, x - xStart + spaceWidth() / 2.0, y); | 727 | paintTabstop(paint, x - xStart + spaceWidth() / 2.0, y); | ||
721 | tabIndex = text.indexOf(tabChar, tabIndex + 1); | 728 | tabIndex = text.indexOf(tabChar, tabIndex + 1); | ||
722 | } | 729 | } | ||
723 | } | 730 | } | ||
724 | 731 | | |||
725 | // draw trailing spaces | 732 | // draw trailing spaces | ||
726 | if (showTrailingSpaces()) { | 733 | if (showAllSpaces() || showTrailingSpaces()) { | ||
727 | int spaceIndex = line.endCol() - 1; | 734 | int spaceIndex = line.endCol() - 1; | ||
728 | int trailingPos = range->textLine()->lastChar(); | 735 | int trailingPos = showAllSpaces() ? 0 : range->textLine()->lastChar(); | ||
729 | if (trailingPos < 0) { | 736 | if (trailingPos < 0) { | ||
730 | trailingPos = 0; | 737 | trailingPos = 0; | ||
731 | } | 738 | } | ||
732 | if (spaceIndex >= trailingPos) { | 739 | if (spaceIndex >= trailingPos) { | ||
733 | while (spaceIndex >= line.startCol() && text.at(spaceIndex).isSpace()) { | 740 | for (; spaceIndex >= line.startCol(); --spaceIndex) { | ||
741 | if (!text.at(spaceIndex).isSpace()) { | ||||
742 | if (showTrailingSpaces()) | ||||
743 | break; | ||||
744 | else | ||||
745 | continue; | ||||
746 | } | ||||
747 | | ||||
734 | if (text.at(spaceIndex) != QLatin1Char('\t') || !showTabs()) { | 748 | if (text.at(spaceIndex) != QLatin1Char('\t') || !showTabs()) { | ||
735 | if (range->layout()->textOption().alignment() == Qt::AlignRight) { // Draw on left for RTL lines | 749 | if (range->layout()->textOption().alignment() == Qt::AlignRight) { // Draw on left for RTL lines | ||
736 | paintTrailingSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart - spaceWidth() / 2.0, y); | 750 | paintSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart - spaceWidth() / 2.0, y); | ||
737 | } else { | 751 | } else { | ||
738 | paintTrailingSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart + spaceWidth() / 2.0, y); | 752 | paintSpace(paint, line.lineLayout().cursorToX(spaceIndex) - xStart + spaceWidth() / 2.0, y); | ||
739 | } | 753 | } | ||
740 | } | 754 | } | ||
741 | --spaceIndex; | | |||
742 | } | 755 | } | ||
743 | } | 756 | } | ||
744 | } | 757 | } | ||
745 | 758 | | |||
746 | if (showNonPrintableSpaces()) { | 759 | if (showNonPrintableSpaces()) { | ||
747 | const int y = lineHeight() * i + fm.ascent(); | 760 | const int y = lineHeight() * i + fm.ascent(); | ||
748 | 761 | | |||
749 | static const QRegularExpression nonPrintableSpacesRegExp(QStringLiteral("[\\x{2000}-\\x{200F}\\x{2028}-\\x{202F}\\x{205F}-\\x{2064}\\x{206A}-\\x{206F}]")); | 762 | static const QRegularExpression nonPrintableSpacesRegExp(QStringLiteral("[\\x{2000}-\\x{200F}\\x{2028}-\\x{202F}\\x{205F}-\\x{2064}\\x{206A}-\\x{206F}]")); | ||
▲ Show 20 Lines • Show All 464 Lines • Show Last 20 Lines |