MCPcopy Create free account
hub / github.com/KDE/kate / DiffEditor

Method DiffEditor

apps/lib/diff/diffeditor.cpp:49–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49DiffEditor::DiffEditor(DiffParams::Flags f, QWidget *parent)
50 : QPlainTextEdit(parent)
51 , m_lineNumArea(new LineNumArea(this))
52 , m_diffWidget(static_cast<DiffWidget *>(parent))
53 , m_flags(f)
54 , m_openLineNumAEnabled(false)
55 , m_openLineNumBEnabled(false)
56{
57 setFrameStyle(QFrame::NoFrame);
58
59 auto updateEditorColors = [this](KTextEditor::Editor *e) {
60 if (!e)
61 return;
62 using namespace KSyntaxHighlighting;
63 auto theme = e->theme();
64 auto bg = QColor::fromRgba(theme.editorColor(Theme::EditorColorRole::BackgroundColor));
65 auto fg = QColor::fromRgba(theme.textColor(Theme::TextStyle::Normal));
66 auto sel = QColor::fromRgba(theme.editorColor(Theme::EditorColorRole::TextSelection));
67 hunkSeparatorColor = QColor::fromRgba(theme.textColor(Theme::TextStyle::Keyword));
68 auto pal = palette();
69 pal.setColor(QPalette::Base, bg);
70 pal.setColor(QPalette::Text, fg);
71 // set a small alpha to be able to see the red/green bg
72 // with selection
73 if (fg.alpha() == 255) {
74 sel.setAlphaF(0.8f);
75 }
76 pal.setColor(QPalette::Highlight, sel);
77 pal.setColor(QPalette::HighlightedText, fg);
78 setFont(Utils::editorFont());
79 setPalette(pal);
80
81 updateDiffColors(bg.lightness() < 127);
82 };
83 connect(KTextEditor::Editor::instance(), &KTextEditor::Editor::configChanged, this, updateEditorColors);
84 updateEditorColors(KTextEditor::Editor::instance());
85
86 connect(verticalScrollBar(), &QScrollBar::valueChanged, this, [this] {
87 m_lineNumArea->update();
88 });
89 connect(this, &QPlainTextEdit::cursorPositionChanged, this, [this] {
90 m_lineNumArea->update();
91 });
92 connect(document(), &QTextDocument::blockCountChanged, this, &DiffEditor::updateLineNumberAreaWidth);
93 connect(this, &QPlainTextEdit::updateRequest, this, &DiffEditor::updateLineNumberArea);
94
95 setReadOnly(true);
96
97 m_timeLine.setDuration(1000);
98 m_timeLine.setFrameRange(0, 250);
99 connect(&m_timeLine, &QTimeLine::frameChanged, this, [this](int) {
100 if (!m_animateTextRect.isNull()) {
101 viewport()->update(m_animateTextRect);
102 }
103 });
104 connect(&m_timeLine, &QTimeLine::finished, this, [this] {
105 auto r = m_animateTextRect;
106 m_animateTextRect = QRect();

Callers

nothing calls this directly

Calls 3

editorFontFunction · 0.85
isNullMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected