| 1 | #pragma once |
| 2 | |
| 3 | /**************************************************************************************** |
| 4 | ** GitQlient is an application to manage and operate one or several Git repositories. With |
| 5 | ** GitQlient you will be able to add commits, branches and manage all the options Git provides. |
| 6 | ** Copyright (C) 2021 Francesc Martinez |
| 7 | ** |
| 8 | ** LinkedIn: www.linkedin.com/in/cescmm/ |
| 9 | ** Web: www.francescmm.com |
| 10 | ** |
| 11 | ** This program is free software; you can redistribute it and/or |
| 12 | ** modify it under the terms of the GNU Lesser General Public |
| 13 | ** License as published by the Free Software Foundation; either |
| 14 | ** version 2 of the License, or (at your option) any later version. |
| 15 | ** |
| 16 | ** This program is distributed in the hope that it will be useful, |
| 17 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | ** Lesser General Public License for more details. |
| 20 | ** |
| 21 | ** You should have received a copy of the GNU Lesser General Public |
| 22 | ** License along with this library; if not, write to the Free Software |
| 23 | ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 | ***************************************************************************************/ |
| 25 | |
| 26 | #include <IDiffWidget.h> |
| 27 | |
| 28 | #include <QSyntaxHighlighter> |
| 29 | |
| 30 | class QPlainTextEdit; |
| 31 | class QPushButton; |
| 32 | |
| 33 | /*! |
| 34 | \brief The FullDiffWidget class is an overload class inherited from QTextEdit that process the output from a diff for a |
| 35 | full commit diff. It includes a highlighter for the lines that are added, removed and to differentiate where a file |
| 36 | diff chuck starts. |
| 37 | |
| 38 | */ |
| 39 | class FullDiffWidget : public IDiffWidget |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | public: |
| 44 | /*! |
| 45 | \brief Default constructor. |
| 46 | |
| 47 | \param git The git object to perform Git operations. |
| 48 | \param parent The parent widget if needed. |
| 49 | */ |
| 50 | explicit FullDiffWidget(const QSharedPointer<GitBase> &git, QSharedPointer<GitCache> cache, |
| 51 | QWidget *parent = nullptr); |
| 52 | |
| 53 | /*! |
| 54 | \brief Reloads the current diff in case the user loaded the work in progress as base commit. |
| 55 | |
| 56 | */ |
| 57 | bool reload() override; |
| 58 | /*! |
| 59 | \brief Loads a diff for a specific commit SHA respect another commit SHA. |
| 60 | |
| 61 | \param sha The base commit SHA. |
| 62 | \param diffToSha The commit SHA to compare to. |
| 63 | \param diffData The diff data returned by the git command. |
| 64 | \return True if there is a diff to load, otherwise false. |
| 65 | */ |
| 66 | void loadDiff(const QString &sha, const QString &diffToSha, const QString &diffData); |
| 67 | |
| 68 | private: |
| 69 | QPushButton *mGoPrevious = nullptr; |
| 70 | QPushButton *mGoNext = nullptr; |
| 71 | QString mPreviousDiffText; |
| 72 | QPlainTextEdit *mDiffWidget = nullptr; |
| 73 | QVector<int> mFilePositions; |
| 74 | |
| 75 | class DiffHighlighter : public QSyntaxHighlighter |
| 76 | { |
| 77 | public: |
| 78 | DiffHighlighter(QTextDocument *document); |
| 79 | void highlightBlock(const QString &text) override; |
| 80 | }; |
| 81 | |
| 82 | DiffHighlighter *diffHighlighter = nullptr; |
| 83 | |
| 84 | /*! |
| 85 | \brief Method that processes the data from the Git diff command. |
| 86 | |
| 87 | \param fileChunk The file chuck to compare. |
| 88 | */ |
| 89 | void processData(const QString &fileChunk); |
| 90 | /** |
| 91 | * @brief moveChunkUp Moves to the previous diff chunk. |
| 92 | */ |
| 93 | void moveChunkUp(); |
| 94 | /** |
| 95 | * @brief moveChunkDown Moves to the following diff chunk. |
| 96 | */ |
| 97 | void moveChunkDown(); |
| 98 | }; |
| 99 | |