| 36 | } |
| 37 | |
| 38 | SimpleCommitForm::SimpleCommitForm(QWidget* parent) |
| 39 | : QWidget(parent) |
| 40 | , m_commitBtn(new QPushButton(i18n("Commit"))) |
| 41 | , m_summaryEdit(new QLineEdit) |
| 42 | , m_messageEdit(new QTextEdit) |
| 43 | , m_inlineError(new KMessageWidget) |
| 44 | , m_disabled(false) |
| 45 | { |
| 46 | QHBoxLayout* _hlayout = new QHBoxLayout(); |
| 47 | _hlayout->setSpacing(0); |
| 48 | _hlayout->addWidget(m_summaryEdit); |
| 49 | _hlayout->addWidget(m_commitBtn); |
| 50 | |
| 51 | QVBoxLayout* _vlayout = new QVBoxLayout(this); |
| 52 | _vlayout->setSpacing(2); |
| 53 | _vlayout->setContentsMargins(0, 0, 0, 0); |
| 54 | _vlayout->addWidget(m_inlineError); |
| 55 | _vlayout->addLayout(_hlayout); |
| 56 | _vlayout->addWidget(m_messageEdit); |
| 57 | |
| 58 | m_inlineError->setHidden(true); |
| 59 | m_inlineError->setMessageType(KMessageWidget::Error); |
| 60 | m_inlineError->setCloseButtonVisible(true); |
| 61 | m_inlineError->setWordWrap(true); |
| 62 | |
| 63 | auto monospace = QFontDatabase::systemFont(QFontDatabase::FixedFont); |
| 64 | monospace.setStyleHint(QFont::TypeWriter); |
| 65 | m_messageEdit->setPlaceholderText(i18n("Extended commit description")); |
| 66 | m_messageEdit->setMinimumHeight(30); |
| 67 | m_messageEdit->setFont(monospace); |
| 68 | m_messageEdit->setWordWrapMode(QTextOption::WordWrap); |
| 69 | m_messageEdit->setLineWrapMode(QTextEdit::FixedColumnWidth); |
| 70 | m_messageEdit->setLineWrapColumnOrWidth(80); |
| 71 | |
| 72 | QAction* summaryLen = new QAction(this); |
| 73 | m_summaryEdit->setPlaceholderText(i18n("Commit summary")); |
| 74 | m_summaryEdit->addAction(summaryLen, QLineEdit::TrailingPosition); |
| 75 | m_summaryEdit->setFont(monospace); |
| 76 | |
| 77 | auto colors = KColorScheme(); |
| 78 | |
| 79 | summaryLen->setIcon(textIcon(QString::number(0), colors.foreground(KColorScheme::NormalText).color(), |
| 80 | colors.background(KColorScheme::NormalBackground).color())); |
| 81 | connect(m_summaryEdit, &QLineEdit::textChanged, this, [=] { |
| 82 | int sz = m_summaryEdit->text().size(); |
| 83 | |
| 84 | // Disable the commit button if the message is empty |
| 85 | if (sz == 0) { |
| 86 | m_commitBtn->setDisabled(true); |
| 87 | if (!m_disabled) |
| 88 | m_commitBtn->setToolTip(i18n("To commit changes, please write a commit message first")); |
| 89 | } else if (!m_disabled) { |
| 90 | m_commitBtn->setToolTip( |
| 91 | i18n("Commit changes to <b>%1</b> on branch <b>%2</b>", m_projectName, m_branchName)); |
| 92 | m_commitBtn->setDisabled(false); |
| 93 | } |
| 94 | |
| 95 | // Determine the summary background color based on the length |
nothing calls this directly
no test coverage detected