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

Class FormatRangeHelper

src/difftextwindow.cpp:955–1006  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

953}
954
955class FormatRangeHelper
956{
957 private:
958 QFont m_font;
959 QPen m_pen;
960 QColor m_background;
961 qint32 m_currentPos;
962
963 QVector<QTextLayout::FormatRange> m_formatRanges;
964
965 public:
966 inline operator QVector<QTextLayout::FormatRange>() { return m_formatRanges; }
967 FormatRangeHelper()
968 {
969 m_pen = QColor(Qt::black);
970 m_background = QColor(Qt::white);
971 m_currentPos = 0;
972 }
973
974 void setFont(const QFont& f)
975 {
976 m_font = f;
977 }
978
979 void setPen(const QPen& pen)
980 {
981 m_pen = pen;
982 }
983
984 void setBackground(const QColor& background)
985 {
986 m_background = background;
987 }
988
989 void next()
990 {
991 if(m_formatRanges.isEmpty() || m_formatRanges.back().format.foreground().color() != m_pen.color() || m_formatRanges.back().format.background().color() != m_background)
992 {
993 QTextLayout::FormatRange fr;
994 fr.length = 1;
995 fr.start = m_currentPos;
996 fr.format.setForeground(m_pen.color());
997 fr.format.setBackground(m_background);
998 m_formatRanges.append(fr);
999 }
1000 else
1001 {
1002 ++m_formatRanges.back().length;
1003 }
1004 ++m_currentPos;
1005 }
1006};
1007
1008void DiffTextWindowData::prepareTextLayout(QTextLayout& textLayout, qint32 visibleTextWidth)
1009{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected