1#include <CodeReviewComment.h>
2
3#include <Comment.h>
4#include <AvatarHelper.h>
5#include <previewpage.h>
6#include <GitQlientSettings.h>
7
8#include <QVBoxLayout>
9#include <QTextEdit>
10#include <QLabel>
11#include <QLocale>
12//#include <QWebEngineView>
13//#include <QWebChannel>
14
15CodeReviewComment::CodeReviewComment(const GitServer::CodeReview &review, QWidget *parent)
16 : QFrame(parent)
17{
18 const auto creator = createHeadline(review.creation, QString("<b>%1</b><br/>").arg(review.creator.name));
19 creator->setObjectName("CodeReviewAuthor");
20 creator->setAlignment(Qt::AlignCenter);
21
22 const auto avatarLayout = new QVBoxLayout();
23 avatarLayout->setContentsMargins(QMargins());
24 avatarLayout->setSpacing(0);
25 avatarLayout->addStretch();
26 avatarLayout->addWidget(createAvatar(review.creator.name, review.creator.avatar, QSize(20, 20)));
27 avatarLayout->addSpacing(5);
28 avatarLayout->addWidget(creator);
29 avatarLayout->addStretch();
30
31// GitQlientSettings settings("");
32// const auto colorSchema = settings.globalValue("colorSchema", "dark").toString();
33// const auto style = colorSchema == "dark" ? QString::fromUtf8("dark") : QString::fromUtf8("bright");
34
35// QPointer<QWebEngineView> body = new QWebEngineView();
36// PreviewPage *page = new PreviewPage(this);
37// body->setPage(page);
38
39// QWebChannel *channel = new QWebChannel(this);
40// channel->registerObject(QStringLiteral("content"), &m_content);
41// page->setWebChannel(channel);
42
43// body->setUrl(QUrl(QString("qrc:/resources/index_%1.html").arg(style)));
44// body->setFixedHeight(20);
45
46// connect(page, &PreviewPage::contentsSizeChanged, this, [body](const QSizeF size) {
47// if (body)
48// body->setFixedHeight(size.height());
49// });
50
51 m_content.setText(review.body);
52
53 const auto frame = new QFrame();
54 frame->setObjectName("CodeReviewComment");
55
56 const auto innerLayout = new QVBoxLayout(frame);
57 innerLayout->setContentsMargins(10, 10, 10, 10);
58// innerLayout->addWidget(body);
59
60 const auto layout = new QHBoxLayout(this);
61 layout->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
62 layout->setContentsMargins(QMargins());
63 layout->setSpacing(20);
64 layout->addLayout(avatarLayout);
65 layout->addWidget(frame);
66}
67
68QLabel *CodeReviewComment::createHeadline(const QDateTime &dt, const QString &prefix)
69{
70 const auto days = dt.daysTo(QDateTime::currentDateTime());
71 const auto whenText = days <= 30 ? days != 0 ? tr(" %1 days ago").arg(days) : tr(" today")
72 : tr(" on %1").arg(dt.date().toString(QLocale().dateFormat(QLocale::ShortFormat)));
73
74 const auto label = prefix.isEmpty() ? new QLabel(whenText) : new QLabel(prefix + whenText);
75 label->setToolTip(dt.toString(QLocale().dateTimeFormat(QLocale::ShortFormat)));
76
77 return label;
78}
79