Changeset View
Changeset View
Standalone View
Standalone View
src/render/katerenderer.cpp
Show All 25 Lines | |||||
26 | #include "katedocument.h" | 26 | #include "katedocument.h" | ||
27 | #include "kateconfig.h" | 27 | #include "kateconfig.h" | ||
28 | #include "katehighlight.h" | 28 | #include "katehighlight.h" | ||
29 | #include "kateview.h" | 29 | #include "kateview.h" | ||
30 | #include "katerenderrange.h" | 30 | #include "katerenderrange.h" | ||
31 | #include "katetextlayout.h" | 31 | #include "katetextlayout.h" | ||
32 | #include "katebuffer.h" | 32 | #include "katebuffer.h" | ||
33 | 33 | | |||
34 | #include "ktexteditor/inlinenoteinterface.h" | ||||
35 | | ||||
34 | #include "katepartdebug.h" | 36 | #include "katepartdebug.h" | ||
35 | 37 | | |||
38 | #include <QFont> | ||||
36 | #include <QPainter> | 39 | #include <QPainter> | ||
37 | #include <QTextLine> | 40 | #include <QTextLine> | ||
38 | #include <QStack> | 41 | #include <QStack> | ||
39 | #include <QBrush> | 42 | #include <QBrush> | ||
40 | #include <QRegularExpression> | 43 | #include <QRegularExpression> | ||
41 | #include <QtMath> // qCeil | 44 | #include <QtMath> // qCeil | ||
42 | 45 | | |||
43 | static const QChar tabChar(QLatin1Char('\t')); | 46 | static const QChar tabChar(QLatin1Char('\t')); | ||
▲ Show 20 Lines • Show All 709 Lines • ▼ Show 20 Line(s) | 755 | if (x > xEnd) { | |||
753 | break; | 756 | break; | ||
754 | } | 757 | } | ||
755 | 758 | | |||
756 | paintNonPrintableSpaces(paint, x - xStart, y, text[charIndex]); | 759 | paintNonPrintableSpaces(paint, x - xStart, y, text[charIndex]); | ||
757 | } | 760 | } | ||
758 | } | 761 | } | ||
759 | } | 762 | } | ||
760 | 763 | | |||
764 | // Draw inline notes | ||||
765 | auto inlineNotes = m_doc->inlineNotes(range->line()); | ||||
766 | foreach (const KTextEditor::InlineNote *inlineNote, inlineNotes) { | ||||
767 | int column = inlineNote->column(); | ||||
768 | int viewLine = range->viewLineForColumn(column); | ||||
769 | | ||||
770 | // Determine the position where to paint the note. | ||||
771 | // We start by getting the x coordinate of cursor placed to the column. | ||||
brauch: indent | |||||
772 | qreal x = range->viewLine(viewLine).lineLayout().cursorToX(column) - xStart; | ||||
773 | int textLength = range->length(); | ||||
Please use const for variables that do not change anymore: const int textLength = ... dhaumann: Please use const for variables that do not change anymore:
const int textLength = ... | |||||
774 | if (column == 0 || column < textLength) { | ||||
775 | // If the note is inside text or at the beginning, then there is a hole in the text where the | ||||
776 | // note should be painted and the cursor gets placed at the right side of it. So we have to | ||||
777 | // subtract the width of the note to get to left side of the hole. | ||||
brauch: indent | |||||
778 | x -= inlineNote->width(lineHeight(), currentFontMetrics()); | ||||
779 | } else { | ||||
780 | // If the note is outside the text, then the X coordinate is located at the end of the line. | ||||
781 | // Add appropriate amount of spaces to reach the required column. | ||||
782 | x += spaceWidth() * (column - textLength); | ||||
783 | } | ||||
784 | | ||||
785 | qreal y = lineHeight() * viewLine; | ||||
786 | | ||||
787 | // Paint the note | ||||
788 | paint.save(); | ||||
789 | paint.translate(x, y); | ||||
790 | inlineNote->paint(lineHeight(), currentFontMetrics(), currentFont(), paint); | ||||
791 | paint.restore(); | ||||
792 | } | ||||
793 | | ||||
761 | // draw word-wrap-honor-indent filling | 794 | // draw word-wrap-honor-indent filling | ||
762 | if ((range->viewLineCount() > 1) && range->shiftX() && (range->shiftX() > xStart)) { | 795 | if ((range->viewLineCount() > 1) && range->shiftX() && (range->shiftX() > xStart)) { | ||
763 | if (backgroundBrushSet) | 796 | if (backgroundBrushSet) | ||
764 | paint.fillRect(0, lineHeight(), range->shiftX() - xStart, lineHeight() * (range->viewLineCount() - 1), | 797 | paint.fillRect(0, lineHeight(), range->shiftX() - xStart, lineHeight() * (range->viewLineCount() - 1), | ||
765 | backgroundBrush); | 798 | backgroundBrush); | ||
766 | paint.fillRect(0, lineHeight(), range->shiftX() - xStart, lineHeight() * (range->viewLineCount() - 1), | 799 | paint.fillRect(0, lineHeight(), range->shiftX() - xStart, lineHeight() * (range->viewLineCount() - 1), | ||
767 | QBrush(config()->wordWrapMarkerColor(), Qt::Dense4Pattern)); | 800 | QBrush(config()->wordWrapMarkerColor(), Qt::Dense4Pattern)); | ||
768 | } | 801 | } | ||
▲ Show 20 Lines • Show All 233 Lines • ▼ Show 20 Line(s) | 1001 | { | |||
1002 | } else { | 1035 | } else { | ||
1003 | opt.setAlignment(Qt::AlignLeft); | 1036 | opt.setAlignment(Qt::AlignLeft); | ||
1004 | opt.setTextDirection(Qt::LeftToRight); | 1037 | opt.setTextDirection(Qt::LeftToRight); | ||
1005 | } | 1038 | } | ||
1006 | 1039 | | |||
1007 | l->setTextOption(opt); | 1040 | l->setTextOption(opt); | ||
1008 | 1041 | | |||
1009 | // Syntax highlighting, inbuilt and arbitrary | 1042 | // Syntax highlighting, inbuilt and arbitrary | ||
1010 | l->setAdditionalFormats(decorationsForLine(textLine, lineLayout->line())); | 1043 | QList<QTextLayout::FormatRange> decorations = decorationsForLine(textLine, lineLayout->line()); | ||
1044 | | ||||
1045 | int firstLineOffset = 0; | ||||
1046 | | ||||
1047 | auto inlineNotes = m_doc->inlineNotes(lineLayout->line()); | ||||
1048 | foreach (const KTextEditor::InlineNote *inlineNote, inlineNotes) { | ||||
1049 | int column = inlineNote->column(); | ||||
1050 | int width = inlineNote->width(lineHeight(), currentFontMetrics()); | ||||
1051 | | ||||
1052 | // Make space for every inline note. | ||||
1053 | // If it is on column 0 (at the beginning of the line), we must offset the first line. | ||||
1054 | // If it is inside the text, we use absolute letter spacing to create space for it between the two letters. | ||||
1055 | // If it is outside of the text, we don't have to make space for it. | ||||
1056 | if (column == 0) { | ||||
1057 | firstLineOffset = width; | ||||
1058 | } else if (column < l->text().length()) { | ||||
1059 | QTextCharFormat text_char_format; | ||||
1060 | text_char_format.setFontLetterSpacing(width); | ||||
1061 | text_char_format.setFontLetterSpacingType(QFont::AbsoluteSpacing); | ||||
1062 | decorations.append(QTextLayout::FormatRange { column - 1, 1, text_char_format }); | ||||
1063 | } | ||||
1064 | } | ||||
1065 | | ||||
1066 | l->setAdditionalFormats(decorations); | ||||
1011 | 1067 | | |||
1012 | // Begin layouting | 1068 | // Begin layouting | ||
1013 | l->beginLayout(); | 1069 | l->beginLayout(); | ||
1014 | 1070 | | |||
1015 | int height = 0; | 1071 | int height = 0; | ||
1016 | int shiftX = 0; | 1072 | int shiftX = 0; | ||
1017 | 1073 | | |||
1018 | bool needShiftX = (maxwidth != -1) | 1074 | bool needShiftX = (maxwidth != -1) | ||
Show All 9 Lines | 1077 | forever { | |||
1028 | if (maxwidth > 0) | 1084 | if (maxwidth > 0) | ||
1029 | { | 1085 | { | ||
1030 | line.setLineWidth(maxwidth); | 1086 | line.setLineWidth(maxwidth); | ||
1031 | } | 1087 | } | ||
1032 | 1088 | | |||
1033 | // we include the leading, this must match the ::updateFontHeight code! | 1089 | // we include the leading, this must match the ::updateFontHeight code! | ||
1034 | line.setLeadingIncluded(true); | 1090 | line.setLeadingIncluded(true); | ||
1035 | 1091 | | |||
1036 | line.setPosition(QPoint(line.lineNumber() ? shiftX : 0, height)); | 1092 | line.setPosition(QPoint(line.lineNumber() ? shiftX : firstLineOffset, height)); | ||
1037 | 1093 | | |||
1038 | if (needShiftX && line.width() > 0) | 1094 | if (needShiftX && line.width() > 0) | ||
1039 | { | 1095 | { | ||
1040 | needShiftX = false; | 1096 | needShiftX = false; | ||
1041 | // Determine x offset for subsequent-lines-of-paragraph indenting | 1097 | // Determine x offset for subsequent-lines-of-paragraph indenting | ||
1042 | int pos = textLine->nextNonSpaceChar(0); | 1098 | int pos = textLine->nextNonSpaceChar(0); | ||
1043 | 1099 | | |||
1044 | if (pos > 0) { | 1100 | if (pos > 0) { | ||
▲ Show 20 Lines • Show All 107 Lines • Show Last 20 Lines |
indent