File indexing completed on 2024-04-28 04:38:52

0001 /*
0002     SPDX-FileCopyrightText: 2020 Jonathan L. Verner <jonathan.verner@matfyz.cz>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KDEVPLATFORM_PLUGIN_SIMPLE_COMMIT_FORM_H
0008 #define KDEVPLATFORM_PLUGIN_SIMPLE_COMMIT_FORM_H
0009 
0010 #include <QWidget>
0011 
0012 class QLineEdit;
0013 class QPushButton;
0014 class QTextEdit;
0015 class QToolButton;
0016 class KMessageWidget;
0017 
0018 /**
0019  * A widget for preparing the commit message. It has
0020  *
0021  *  - an (initially hidden) KMessageWidget to show potential errors
0022  *  - a lineedit for editing the commit message summary
0023  *    (the first line of the commit message);
0024  *  - a textedit for editing the rest of the commit message
0025  *  - a button for committing
0026  *
0027  * Also, the lineedit shows the number of characters in the summary
0028  * on the right and, if it is >= 80, indicates this with a red background.
0029  */
0030 class SimpleCommitForm : public QWidget
0031 {
0032     Q_OBJECT
0033 
0034 public:
0035     SimpleCommitForm(QWidget* parent = nullptr);
0036 
0037     /**
0038      * @returns the current value of the commit message summary.
0039      */
0040     QString summary() const;
0041 
0042     /**
0043      * Sets the current value of the commit message summary.
0044      */
0045     void setSummary(const QString& txt);
0046 
0047     /**
0048      * @param wrapAtColumn if >0, the returned message is wrapped so that
0049      * it fits into the specified number of columns.
0050      *
0051      * @returns the current value of the extended commit message.
0052      *
0053      * @note: The wrapping is done very simplistically. Whenever a line
0054      * is encountered which is longer then @ref:wrapAtColumn, the first
0055      * space character at position > @ref:wrapAtColumn is replaced by
0056      * a new-line character '\n'.
0057      */
0058     QString extendedDescription(int wrapAtColumn = -1) const;
0059 
0060     /**
0061      * Sets the current value of the commit extended commit message.
0062      */
0063     void setExtendedDescription(const QString& txt);
0064 
0065 public Q_SLOTS:
0066 
0067     /**
0068      * Disables the commit button.
0069      */
0070     void disableCommitButton();
0071 
0072     /**
0073      * Enables the commit button.
0074      */
0075     void enableCommitButton();
0076 
0077     /**
0078      * Enable input in the commit form.
0079      */
0080     void enable();
0081 
0082     /**
0083      * Disable input in the commit form
0084      * (used e.g. while a commit job is in progress)
0085      */
0086     void disable();
0087 
0088     /**
0089      * Clear the commit form (summary & description)
0090      *
0091      * @note: Also hides the inline error message if shown.
0092      */
0093     void clear();
0094 
0095     /**
0096      * Sets the project name where changes will be
0097      * committed, so that it can be displayed in the
0098      * form (currently in some tooltips).
0099      */
0100     void setProjectName(const QString& projName);
0101 
0102     /**
0103      * Sets the branch name, where changes will be
0104      * committed, so that it can be displayed in the
0105      * form (currently in some tooltips).
0106      */
0107     void setBranchName(const QString& branchName);
0108 
0109     /**
0110      * Shows an error message using the inline KMessageWidget
0111      *
0112      * (Use e.g. when git commit fails)
0113      */
0114     void showError(const QString& error);
0115 
0116     /**
0117      * Hides the inline error message if shown.
0118      */
0119     void clearError();
0120 
0121 
0122 Q_SIGNALS:
0123 
0124     /**
0125      * Emmitted when the user presses the commit button
0126      */
0127     void committed();
0128 
0129 private:
0130     QPushButton* m_commitBtn;
0131     QLineEdit* m_summaryEdit;
0132     QTextEdit* m_messageEdit;
0133     KMessageWidget* m_inlineError;
0134 
0135     /**
0136      * true if the commit button is disabled by calling disable();
0137      *
0138      * We use this to track disable/enable requests; We can't use the
0139      * button state for this, since we also internally disable the button
0140      * if the commit message is empty
0141      */
0142     bool m_disabled;
0143 
0144     QString m_projectName;     /**< The project to which changes will be committed */
0145     QString m_branchName;      /**< The branch on which changes will be committed */
0146 };
0147 
0148 #endif