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 <Issue.h>
27#include <GitServerCache.h>
28#include <document.h>
29
30#include <QFrame>
31#include <QMutex>
32
33namespace GitServer
34{
35struct Issue;
36struct PullRequest;
37struct Comment;
38struct Review;
39struct CodeReview;
40}
41
42class QLabel;
43class QVBoxLayout;
44class QNetworkAccessManager;
45class QHBoxLayout;
46class QScrollArea;
47class QTextEdit;
48
49class HighlightningFrame : public QFrame
50{
51 Q_OBJECT
52 Q_PROPERTY(QColor color READ color WRITE setColor)
53
54public:
55 explicit HighlightningFrame(QWidget *parent = nullptr);
56
57 void setColor(QColor color);
58 QColor color();
59};
60
61class PrCommentsList : public QFrame
62{
63 Q_OBJECT
64
65signals:
66 void frameReviewLink(GitServer::PullRequest pr, const QMap<int, int> &links);
67
68public:
69 enum class Config
70 {
71 Issues,
72 PullRequests
73 };
74
75 explicit PrCommentsList(const QSharedPointer<GitServerCache> &gitServerCache, QWidget *parent = nullptr);
76 ~PrCommentsList();
77
78 void loadData(Config config, int issueNumber);
79 void highlightComment(int frameId);
80 void addGlobalComment();
81
82private:
83 QMutex mMutex;
84 QSharedPointer<GitServerCache> mGitServerCache = nullptr;
85 QNetworkAccessManager *mManager = nullptr;
86 QFrame *mCommentsFrame = nullptr;
87 QVBoxLayout *mIssuesLayout = nullptr;
88 QFrame *mIssuesFrame = nullptr;
89 QFrame *mInputFrame = nullptr;
90 QTextEdit *mInputTextEdit = nullptr;
91 Config mConfig {};
92 QScrollArea *mScroll = nullptr;
93 bool mLoaded = false;
94 int mIssueNumber = -1;
95 QMap<int, QFrame *> mComments {};
96 QMap<int, int> mFrameLinks {};
97 inline static int mCommentId = 0;
98 Document m_content;
99 QVector<Document *> m_commentContents;
100
101 void processComments(const GitServer::Issue &issue);
102 QLabel *createHeadline(const QDateTime &dt, const QString &prefix = QString());
103 void onReviewsReceived();
104 QLayout *createBubbleForComment(const GitServer::Comment &comment);
105 QLayout *createBubbleForReview(const GitServer::Review &review);
106 QVector<QLayout *> createBubbleForCodeReview(int reviewId, QVector<GitServer::CodeReview> &comments);
107 void addReplyToCodeReview(int commentId, const QString &message);
108};
109