KTextEditor
katerenderer.cpp
42KateRenderer::KateRenderer(KTextEditor::DocumentPrivate *doc, Kate::TextFolding &folding, KTextEditor::ViewPrivate *view)
181void KateRenderer::paintTextLineBackground(QPainter &paint, KateLineLayout *layout, int currentViewLine, int xStart, int xEnd)
231 const bool currentLineHasSelection = m_view && m_view->selection() && m_view->selectionRange().overlapsLine(layout->line());
243 paint.fillRect(0, lineHeight() * currentViewLine, xEnd - xStart, lineHeight(), currentLineColor);
341static KTextEditor::Range cursorAtBracket(KTextEditor::ViewPrivate *view, const KateLineLayout *range, int spaceWidth, KTextEditor::Cursor c, int &bracketXPos)
355 static constexpr QChar brackets[] = {QLatin1Char('{'), QLatin1Char('}'), QLatin1Char('('), QLatin1Char(')')};
436QList<QTextLayout::FormatRange> KateRenderer::decorationsForLine(const Kate::TextLine &textLine, int line, bool selectionsOnly) const
440 auto rangesWithAttributes = m_doc->buffer().rangesForLine(line, m_printerFriendly ? nullptr : m_view, true);
457 currentRange.addRange(KTextEditor::Range(KTextEditor::Cursor(line, al[i].offset), al[i].length), specificAttribute(al[i].attributeValue));
467 // sort all ranges, we want that the most specific ranges win during rendering, multiple equal ranges are kind of random, still better than old smart
481 if (KTextEditor::Attribute::Ptr attributeMouseIn = attribute->dynamicAttribute(KTextEditor::Attribute::ActivateMouseIn)) {
488 if (KTextEditor::Attribute::Ptr attributeCaretIn = attribute->dynamicAttribute(KTextEditor::Attribute::ActivateCaretIn)) {
500 if ((m_view && selectionsOnly && showSelections() && m_view->selection()) || (m_view && m_view->blockSelection())) {
512 backgroundAttribute->setForeground(attribute(KSyntaxHighlighting::Theme::TextStyle::Normal)->selectedForeground().color());
527 // Calculate the range which we need to iterate in order to get the highlighting for just this line
536 KTextEditor::Range rangeNeeded = m_view->selectionRange() & KTextEditor::Range(line, 0, line + 1, 0);
548 const KTextEditor::Range selectionRange = shoudlClearBackground ? m_view->selectionRange() : KTextEditor::Range::invalid();
587 if (shoudlClearBackground && selectionRange.contains(currentPosition) && fr.format.hasProperty(QTextFormat::BackgroundBrush)) {
606void KateRenderer::assignSelectionBrushesFromAttribute(QTextLayout::FormatRange &target, const KTextEditor::Attribute &attribute)
715 paint.drawLine(0, (lineHeight() * range->viewLineCount()) - 2, xEnd - xStart, (lineHeight() * range->viewLineCount()) - 2);
720 m_view && m_view->selection() && showSelections() && m_view->selectionRange().overlapsLine(range->line()) && !flags.testFlag(SkipDrawLineSelection);
721 // Draw selection in block selection mode. We need 2 kinds of selections that QTextLayout::draw can't render:
725 int selectionStartColumn = m_doc->fromVirtualColumn(range->line(), m_doc->toVirtualColumn(m_view->selectionRange().start()));
726 int selectionEndColumn = m_doc->fromVirtualColumn(range->line(), m_doc->toVirtualColumn(m_view->selectionRange().end()));
731 int selectionStartX = (selectionStartColumn > lastLine.startCol()) ? cursorToX(lastLine, selectionStartColumn, true) : 0;
733 paint.fillRect(QRect(selectionStartX - xStart, (int)lastLine.lineLayout().y(), selectionEndX - selectionStartX, lineHeight()),
740 paint.fillRect(QRect(selectionX - xStart, (int)selectionLine.lineLayout().y(), selectStickWidth, lineHeight()), selectionBrush);
763 return sr.overlapsLine(line) && sr.overlapsColumn(fr.start) && fr.format.background().color() == c;
778 range->layout()->draw(&paint, QPoint(-xStart, 0), QList<QTextLayout::FormatRange>{}, textClipRect);
788 if (!m_currentBracketRange.boundaryAtCursor(*cursor) && m_currentBracketRange.end() != cur && m_currentBracketRange.start() != cur) {
789 m_currentBracketRange = cursorAtBracket(view(), range, spaceWidth(), *cursor, m_currentBracketX);
839 const int trailingPos = showSpaces() == KateDocumentConfig::All ? 0 : qMax(range->textLine().lastChar(), 0);
915 QStringLiteral("[\\x{0000}-\\x{0008}\\x{000A}-\\x{001F}\\x{2000}-\\x{200F}\\x{2028}-\\x{202F}\\x{205F}-\\x{2064}\\x{206A}-\\x{206F}]"));
916 QRegularExpressionMatchIterator i = nonPrintableSpacesRegExp.globalMatch(text, line.lineLayout().xToCursor(xStart));
933 if (drawSelection && !m_view->blockSelection() && m_view->selectionRange().start() < line.start()
935 paint.fillRect(0, lineHeight() * i, range->shiftX - xStart, lineHeight(), QBrush(config()->selectionColor()));
939 paint.fillRect(0, lineHeight() * i, range->shiftX - xStart, lineHeight(), QBrush(config()->wordWrapMarkerColor(), Qt::Dense4Pattern));
947 auto mIt = std::lower_bound(secCursors.begin(), secCursors.end(), range->line(), [](const KTextEditor::ViewPrivate::SecondaryCursor &l, int line) {
978 int _x = qreal(m_doc->config()->wordWrapAt()) * fm.horizontalAdvance(QLatin1Char('x')) - xStart;
1024 inlineNote.provider()->paintInlineNote(inlineNote, paint, isRTL ? Qt::RightToLeft : Qt::LeftToRight);
1030static void drawCursor(const QTextLayout &layout, QPainter *p, const QPointF &pos, int cursorPosition, int width, const int height)
1050void KateRenderer::paintCaret(KTextEditor::Cursor cursor, KateLineLayout *range, QPainter &paint, int xStart, int xEnd)
1130 drawCursor(*range->layout(), &paint, QPoint(-xStart - width, 0), cursor.column(), caretWidth, lineHeight());
1226 // https://github.com/qt/qtbase/blob/5.12/src/gui/text/qtextlayout.cpp (line 2270 at the moment) where the text height is set as:
1298 if (isLineRightToLeft(textLine.text()) || (view()->dynWordWrap() && view()->forceRTLDirection())) {
1316 QList<QTextLayout::FormatRange> decorations = decorationsForLine(textLine, lineLayout->line());
1353 // If it is inside the text, we use absolute letter spacing to create space for it between the two letters.
1362 decorations.append(QTextLayout::FormatRange{.start = column - 1, .length = 1, .format = text_char_format});
1374 bool needShiftX = (maxwidth != -1) && m_view && (m_view->config()->dynWordWrapAlignIndent() > 0);
1391 line.setPosition(QPoint(line.lineNumber() ? shiftX : firstLineOffset, height - line.ascent() + m_fontAscent));
1463int KateRenderer::cursorToX(const KateTextLayout &range, const KTextEditor::Cursor pos, bool returnPastLine) const
1482KTextEditor::Cursor KateRenderer::xToCursor(const KateTextLayout &range, int x, bool returnPastLine) const
1504void KateRenderer::paintSelection(QPaintDevice *d, int startLine, int xStart, int endLine, int xEnd, int viewWidth, qreal scale)
1522 QRect endRect(mainRect.bottomLeft().x() + xEnd, mainRect.bottomRight().y() - lineHeight, mainRect.width() - xEnd, lineHeight);
QRgb textColor(TextStyle style) const
QExplicitlySharedDataPointer< Attribute > Ptr
Shared data pointer for Attribute.
Definition attribute.h:56
constexpr int column() const noexcept
Retrieve the column on which this cursor is situated.
Definition cursor.h:192
constexpr int line() const noexcept
Retrieve the line on which this cursor is situated.
Definition cursor.h:174
Backend of KTextEditor::Document related public KTextEditor interfaces.
Definition katedocument.h:68
virtual void paintInlineNote(const InlineNote ¬e, QPainter &painter, Qt::LayoutDirection direction) const =0
Paint the note into the line.
InlineNoteProvider * provider() const
The provider which created this note.
Definition ktexteditor.cpp:317
const Cursor toCursor() const
Convert this clever cursor into a dumb one.
Definition movingcursor.h:266
An object representing a section of text, from one Cursor to another.
Definition include/ktexteditor/range.h:49
constexpr Cursor end() const noexcept
Get the end position of this range.
Definition include/ktexteditor/range.h:163
constexpr Cursor start() const noexcept
Get the start position of this range.
Definition include/ktexteditor/range.h:153
static constexpr Range invalid() noexcept
Returns an invalid range.
Definition include/ktexteditor/range.h:121
constexpr bool containsLine(int line) const noexcept
Returns true if this range wholly encompasses line.
Definition include/ktexteditor/range.h:347
constexpr bool contains(Range range) const noexcept
Check whether the this range wholly encompasses range.
Definition include/ktexteditor/range.h:323
constexpr bool overlapsLine(int line) const noexcept
Check whether the range overlaps at least part of line.
Definition include/ktexteditor/range.h:383
constexpr bool boundaryAtCursor(Cursor cursor) const noexcept
Check whether cursor is located at either of the start() or end() boundaries.
Definition include/ktexteditor/range.h:412
KSyntaxHighlighting::Theme theme() const
Get the current active theme of this view.
Definition ktexteditor.cpp:179
Internal data container for KTextEditor::InlineNote interface.
Definition inlinenotedata.h:25
void increaseFontSizes(qreal step=1.0) const
Change to a different font (soon to be font set?)
Definition katerenderer.cpp:145
void setShowTabs(bool showTabs)
Set whether a mark should be painted to help identifying tabs.
Definition katerenderer.cpp:101
bool showNonPrintableSpaces() const
Definition katerenderer.h:189
KateRenderer(KTextEditor::DocumentPrivate *doc, Kate::TextFolding &folding, KTextEditor::ViewPrivate *view=nullptr)
Style of Caret.
Definition katerenderer.cpp:42
void setShowSelections(bool showSelections)
Set whether the view's selections should be shown.
Definition katerenderer.cpp:140
const AttributePtr & attribute(uint pos) const
This takes an in index, and returns all the attributes for it.
Definition katerenderer.cpp:73
KTextEditor::caretStyles caretStyle() const
The style of the caret (text cursor) to be painted.
Definition katerenderer.h:136
void setDrawCaret(bool drawCaret)
Set whether the caret (text cursor) will be drawn.
Definition katerenderer.cpp:91
static bool isLineRightToLeft(QStringView str)
This is a smaller QString::isRightToLeft().
Definition katerenderer.cpp:1426
int cursorToX(const KateTextLayout &range, int col, bool returnPastLine=false) const
Returns the x position of cursor col on the line range.
Definition katerenderer.cpp:1458
KTextEditor::Cursor xToCursor(const KateTextLayout &range, int x, bool returnPastLine=false) const
Returns the real cursor which is occupied by the specified x value, or that closest to it.
Definition katerenderer.cpp:1482
void setPrinterFriendly(bool printerFriendly)
Configure this renderer to paint in a printer-friendly fashion.
Definition katerenderer.cpp:172
KTextEditor::ViewPrivate * view() const
Returns the view to which this renderer is bound.
Definition katerenderer.h:106
void setShowSpaces(KateDocumentConfig::WhitespaceRendering showSpaces)
Set which spaces should be rendered.
Definition katerenderer.cpp:106
QList< QTextLayout::FormatRange > decorationsForLine(const Kate::TextLine &textLine, int line, bool selectionsOnly=false) const
The ultimate decoration creation function.
Definition katerenderer.cpp:436
KateDocumentConfig::WhitespaceRendering showSpaces() const
Definition katerenderer.h:176
bool drawCaret() const
Determine whether the caret (text cursor) will be drawn.
Definition katerenderer.h:121
@ SkipDrawLineSelection
Skip drawing the line selection This is useful when we are drawing the draggable pixmap for drag even...
Definition katerenderer.h:342
@ SkipDrawFirstInvisibleLineUnderlined
Skip drawing the dashed underline at the start of a folded block of text?
Definition katerenderer.h:337
void setShowNonPrintableSpaces(const bool showNonPrintableSpaces)
Set whether box should be drawn around non-printable spaces.
Definition katerenderer.cpp:111
void setCaretOverrideColor(const QColor &color)
Set a brush with which to override drawing of the caret.
Definition katerenderer.cpp:1499
void setCaretStyle(KTextEditor::caretStyles style)
Set the style of caret to be painted.
Definition katerenderer.cpp:96
KTextEditor::DocumentPrivate * doc() const
Returns the document to which this renderer is bound.
Definition katerenderer.h:89
void setShowIndentLines(bool showLines)
Set whether a guide should be painted to help identifying indent lines.
Definition katerenderer.cpp:126
void updateAttributes()
update the highlighting attributes (for example after an hl change or after hl config changed)
Definition katerenderer.cpp:68
void layoutLine(KateLineLayout *line, int maxwidth=-1, bool cacheLayout=false) const
Text width & height calculation functions...
Definition katerenderer.cpp:1259
void paintSelection(QPaintDevice *d, int startLine, int xStart, int endLine, int xEnd, int viewWidth, qreal scale=1.0)
Paints a range of text into d.
Definition katerenderer.cpp:1504
void paintTextLineBackground(QPainter &paint, KateLineLayout *layout, int currentViewLine, int xStart, int xEnd)
Paint the background of a line.
Definition katerenderer.cpp:181
void paintTextLine(QPainter &paint, KateLineLayout *range, int xStart, int xEnd, const QRectF &textClipRect=QRectF(), const KTextEditor::Cursor *cursor=nullptr, PaintTextLineFlags flags=PaintTextLineFlags())
This is the ultimate function to perform painting of a text line.
Definition katerenderer.cpp:685
This class represents one visible line of text; with dynamic wrapping, many KateTextLayouts can be ne...
Definition katetextlayout.h:21
int endCol(bool indicateEOL=false) const
Return the end column of this text line.
Definition katetextlayout.cpp:136
QList< TextRange * > rangesForLine(int line, KTextEditor::View *view, bool rangesWithAttributeOnly) const
Return the ranges which affect the given line.
Definition katetextbuffer.h:501
Class representing the folding information for a TextBuffer.
Definition katetextfolding.h:33
const QString & text() const
Accessor to the text contained in this line.
Definition katetextline.h:89
const QList< Attribute > & attributesList() const
Accessor to attributes.
Definition katetextline.h:333
int indentDepth(int tabWidth) const
Returns the indentation depth with each tab expanded into tabWidth characters.
Definition katetextline.cpp:59
int lastChar() const
Returns the position of the last non-whitespace character.
Definition katetextline.cpp:17
int nextNonSpaceChar(int pos) const
Find the position of the next char that is not a space.
Definition katetextline.cpp:22
const KTextEditor::MovingCursor & end() const override
Retrieve end cursor of this range, read-only.
Definition katetextrange.h:173
const KTextEditor::Attribute::Ptr & attribute() const override
Gets the active Attribute for this range.
Definition katetextrange.h:240
const KTextEditor::MovingCursor & start() const override
Retrieve start cursor of this range, read-only.
Definition katetextrange.h:155
Q_SCRIPTABLE Q_NOREPLY void start()
QAction * end(const QObject *recvr, const char *slot, QObject *parent)
The KTextEditor namespace contains all the public API that is required to use the KTextEditor compone...
Definition katetextblock.h:18
DirL
bool isSpace(char32_t ucs4)
int alpha() const const
int blue() const const
int green() const const
bool isValid() const const
int red() const const
void setAlpha(int alpha)
void setAlphaF(float alpha)
void setRgb(QRgb rgb)
QFlags< T > & setFlag(Enum flag, bool on)
bool testFlag(Enum flag) const const
AbsoluteSpacing
Bold
qreal pointSizeF() const const
void setPointSizeF(qreal pointSize)
qreal ascent() const const
QRectF boundingRect(QChar ch) const const
qreal descent() const const
qreal horizontalAdvance(QChar ch) const const
qreal strikeOutPos() const const
void append(QList< T > &&value)
iterator begin()
iterator end()
iterator erase(const_iterator begin, const_iterator end)
int height() const const
int width() const const
RasterOpModes
bool hasFeature(PaintEngineFeatures feature) const const
CompositionMode
Antialiasing
CompositionMode compositionMode() const const
void drawLine(const QLine &line)
void drawLines(const QLine *lines, int lineCount)
void drawPoints(const QPoint *points, int pointCount)
void fillPath(const QPainterPath &path, const QBrush &brush)
void fillRect(const QRect &rectangle, QGradient::Preset preset)
QPaintEngine * paintEngine() const const
const QPen & pen() const const
RenderHints renderHints() const const
void restore()
void save()
void scale(qreal sx, qreal sy)
void setClipRegion(const QRegion ®ion, Qt::ClipOperation operation)
void setCompositionMode(CompositionMode mode)
void setPen(Qt::PenStyle style)
void setRenderHint(RenderHint hint, bool on)
void setRenderHints(RenderHints hints, bool on)
void translate(const QPoint &offset)
void addRect(const QRectF &rectangle)
QBrush brush() const const
void setColor(const QColor &color)
void setCosmetic(bool cosmetic)
void setDashOffset(qreal offset)
void setDashPattern(const QList< qreal > &pattern)
void setStyle(Qt::PenStyle style)
void setWidth(int width)
int x() const const
int y() const const
bool isNull() const const
qreal x() const const
QPoint bottomLeft() const const
QPoint bottomRight() const const
int width() const const
qreal width() const const
QRegularExpressionMatchIterator globalMatch(QStringView subjectView, qsizetype offset, MatchType matchType, MatchOptions matchOptions) const const
qsizetype capturedStart(QStringView name) const const
bool hasNext() const const
QRegularExpressionMatch next()
bool contains(const QSet< T > &other) const const
bool empty() const const
const QChar at(qsizetype position) const const
qsizetype indexOf(QChar ch, qsizetype from, Qt::CaseSensitivity cs) const const
qsizetype length() const const
AlignRight
NoBrush
RightToLeft
RoundCap
DashLine
QTextStream & left(QTextStream &stream)
QTextStream & right(QTextStream &stream)
void setFontLetterSpacing(qreal spacing)
void setFontLetterSpacingType(QFont::SpacingType letterSpacingType)
BackgroundBrush
void beginLayout()
QTextLine createLine()
void draw(QPainter *p, const QPointF &pos, const QList< FormatRange > &selections, const QRectF &clip) const const
void endLayout()
QList< FormatRange > formats() const const
QTextLine lineForTextPosition(int pos) const const
QPointF position() const const
void setCacheEnabled(bool enable)
void setFont(const QFont &font)
void setFormats(const QList< FormatRange > &formats)
void setText(const QString &string)
void setTextOption(const QTextOption &option)
QString text() const const
const QTextOption & textOption() const const
qreal ascent() const const
qreal cursorToX(int *cursorPos, Edge edge) const const
bool isValid() const const
int lineNumber() const const
void setLeadingIncluded(bool included)
void setLineWidth(qreal width)
void setPosition(const QPointF &pos)
qreal width() const const
int xToCursor(qreal x, CursorPosition cpos) const const
qreal y() const const
IncludeTrailingSpaces
WrapAnywhere
Qt::Alignment alignment() const const
Flags flags() const const
void setAlignment(Qt::Alignment alignment)
void setFlags(Flags flags)
void setTabStopDistance(qreal tabStopDistance)
void setTextDirection(Qt::LayoutDirection direction)
void setWrapMode(WrapMode mode)
Qt::LayoutDirection textDirection() const const
const T * constData() const const
bool isEmpty() const const
reverse_iterator rbegin()
reverse_iterator rend()
qsizetype size() const const
layoutDirection
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:53:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:53:44 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.