1 | #include "AddCodeReviewDialog.h" |
---|---|
2 | #include "ui_AddCodeReviewDialog.h" |
3 | |
4 | #include <GitQlientStyles.h> |
5 | |
6 | #include <QMessageBox> |
7 | |
8 | AddCodeReviewDialog::AddCodeReviewDialog(ReviewMode mode, QWidget *parent) |
9 | : QDialog(parent) |
10 | , ui(new Ui::AddCodeReviewDialog) |
11 | , mMode(mode) |
12 | { |
13 | ui->setupUi(this); |
14 | |
15 | if (!parent) |
16 | setStyleSheet(GitQlientStyles::getInstance()->getStyles()); |
17 | |
18 | switch (mode) |
19 | { |
20 | case ReviewMode::Comment: |
21 | setWindowTitle(tr("Add comment")); |
22 | break; |
23 | case ReviewMode::Approve: |
24 | setWindowTitle(tr("Approve PR")); |
25 | break; |
26 | case ReviewMode::RequestChanges: |
27 | setWindowTitle(tr("Request changes")); |
28 | default: |
29 | break; |
30 | } |
31 | |
32 | setAttribute(Qt::WA_DeleteOnClose); |
33 | } |
34 | |
35 | AddCodeReviewDialog::~AddCodeReviewDialog() |
36 | { |
37 | delete ui; |
38 | } |
39 | |
40 | void AddCodeReviewDialog::accept() |
41 | { |
42 | #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) |
43 | if (const auto text = ui->teComment->toMarkdown(); !text.isEmpty()) |
44 | #else |
45 | if (const auto text = ui->teComment->toPlainText(); !text.isEmpty()) |
46 | #endif |
47 | { |
48 | emit commentAdded(text); |
49 | QDialog::accept(); |
50 | } |
51 | else if (mMode != ReviewMode::Approve) |
52 | QMessageBox::warning(this, tr("Empty comment!"), |
53 | tr("The body cannot be empty when adding a comment or requesting changes.")); |
54 | } |
55 | |
56 | QString AddCodeReviewDialog::getText() const |
57 | { |
58 | #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) |
59 | return ui->teComment->toMarkdown(); |
60 | #else |
61 | return ui->teComment->toPlainText(); |
62 | #endif |
63 | } |
64 |