File indexing completed on 2025-01-05 05:14:50
0001 /* 0002 SPDX-FileCopyrightText: 2020-2022 Hamed Masafi <hamed.masfi@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-3.0-or-later 0005 */ 0006 0007 #include "blamecodeview.h" 0008 0009 #include <entities/commit.h> 0010 0011 #include <KLocalizedString> 0012 #include <KSyntaxHighlighting/SyntaxHighlighter> 0013 0014 BlameCodeView::BlameCodeView(QWidget *parent) 0015 : CodeEditor(parent) 0016 { 0017 setReadOnly(true); 0018 } 0019 0020 const Git::BlameData &BlameCodeView::blameData() const 0021 { 0022 return mBlameData; 0023 } 0024 0025 void BlameCodeView::setBlameData(const Git::BlameData &newBlameData) 0026 { 0027 BlockType type{Odd}; 0028 const QVector<QColor> colors{QColor(200, 150, 150, 100), QColor(150, 200, 150, 100)}; 0029 int currentColor{0}; 0030 mBlameData = newBlameData; 0031 QString lastCommit; 0032 for (const auto &blame : newBlameData) { 0033 const QString commitHash = blame.log ? blame.log->commitHash() : QString(); 0034 0035 if (lastCommit != commitHash) { 0036 currentColor = (currentColor + 1) % colors.size(); 0037 type = type == Odd ? Even : Odd; 0038 } 0039 0040 auto data = new BlockData{-1, nullptr, type}; 0041 data->extraText = blame.log ? blame.log->committer()->name() : i18n("Uncommited"); 0042 data->data = blame.log ? blame.log : nullptr; 0043 0044 append(blame.code, type, data); 0045 lastCommit = commitHash; 0046 } 0047 } 0048 0049 #include "moc_blamecodeview.cpp"