MCPcopy Create free account
hub / github.com/KDE/kdiff3 / prepareTextLayout

Method prepareTextLayout

src/difftextwindow.cpp:1008–1074  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1006};
1007
1008void DiffTextWindowData::prepareTextLayout(QTextLayout& textLayout, qint32 visibleTextWidth)
1009{
1010 QTextOption textOption;
1011
1012 textOption.setTabStopDistance(QFontMetricsF(m_pDiffTextWindow->font()).horizontalAdvance(' ') * gOptions->tabSize());
1013
1014 if(gOptions->m_bShowWhiteSpaceCharacters)
1015 textOption.setFlags(QTextOption::ShowTabsAndSpaces);
1016 if(gOptions->m_bRightToLeftLanguage)
1017
1018 {
1019 textOption.setAlignment(Qt::AlignRight); // only relevant for multi line text layout
1020 }
1021 if(visibleTextWidth >= 0)
1022 textOption.setWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
1023
1024 textLayout.setTextOption(textOption);
1025
1026 if(gOptions->m_bShowWhiteSpaceCharacters)
1027 {
1028 // This additional format is only necessary for the tab arrow
1029 QVector<QTextLayout::FormatRange> formats;
1030 QTextLayout::FormatRange formatRange;
1031 formatRange.start = 0;
1032 formatRange.length = SafeInt<qint32>(textLayout.text().length());
1033 formatRange.format.setFont(m_pDiffTextWindow->font());
1034 formats.append(formatRange);
1035 textLayout.setFormats(formats);
1036 }
1037 textLayout.beginLayout();
1038
1039 qint32 leading = m_pDiffTextWindow->fontMetrics().leading();
1040 qint32 height = 0;
1041 //TODO: Fix after line number area is converted to a QWidget.
1042 qint32 fontWidth = m_pDiffTextWindow->fontMetrics().horizontalAdvance('0');
1043 qint32 xOffset = leftInfoWidth() * fontWidth - m_horizScrollOffset;
1044 qint32 textWidth = visibleTextWidth;
1045 if(textWidth < 0)
1046 textWidth = m_pDiffTextWindow->width() - xOffset;
1047
1048 qint32 indentation = 0;
1049 while(true)
1050 {
1051 QTextLine line = textLayout.createLine();
1052 if(!line.isValid())
1053 break;
1054
1055 height += leading;
1056 if(visibleTextWidth >= 0)
1057 {
1058 line.setLineWidth(visibleTextWidth - indentation);
1059 line.setPosition(QPointF(indentation, height));
1060 height += qCeil(line.height());
1061 }
1062 else // only one line
1063 {
1064 line.setPosition(QPointF(indentation, height));
1065 break;

Callers 3

getMaxTextWidthMethod · 0.80
convertToLinePosMethod · 0.80
recalcWordWrapHelperMethod · 0.80

Calls 5

tabSizeMethod · 0.80
setFontMethod · 0.80
appendMethod · 0.80
widthMethod · 0.80
isValidMethod · 0.45

Tested by

no test coverage detected