| 1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
| 2 | // |
| 3 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 4 | |
| 5 | #ifndef OUTPUTPANE_H |
| 6 | #define OUTPUTPANE_H |
| 7 | |
| 8 | #include <QPlainTextEdit> |
| 9 | |
| 10 | class OutputPanePrivate; |
| 11 | class OutputPane : public QPlainTextEdit |
| 12 | { |
| 13 | Q_OBJECT |
| 14 | public: |
| 15 | |
| 16 | enum OutputFormat { |
| 17 | NormalMessage, |
| 18 | ErrorMessage, |
| 19 | LogMessage, |
| 20 | Debug, |
| 21 | StdOut, |
| 22 | StdErr, |
| 23 | StdOutFormatSameLine, |
| 24 | StdErrFormatSameLine, |
| 25 | NumberOfFormats // Keep this entry last. |
| 26 | }; |
| 27 | |
| 28 | enum AppendMode { |
| 29 | Normal, |
| 30 | OverWrite |
| 31 | }; |
| 32 | |
| 33 | OutputPane(QWidget *parent = nullptr); |
| 34 | ~OutputPane() override; |
| 35 | |
| 36 | void clearContents(); |
| 37 | void appendText(const QString &text, OutputPane::OutputFormat format, AppendMode mode = Normal); |
| 38 | static OutputPane* instance(); |
| 39 | |
| 40 | protected: |
| 41 | void (QContextMenuEvent * event) override; |
| 42 | |
| 43 | private: |
| 44 | QString normalizeNewlines(const QString &text); |
| 45 | |
| 46 | void appendCustomText(const QString &text, AppendMode mode, const QTextCharFormat &format = QTextCharFormat()); |
| 47 | bool isScrollbarAtBottom() const; |
| 48 | QString doNewlineEnforcement(const QString &out); |
| 49 | void scrollToBottom(); |
| 50 | QList<QAction*> actionFactory(); |
| 51 | |
| 52 | OutputPanePrivate *d = nullptr; |
| 53 | }; |
| 54 | |
| 55 | #endif // OUTPUTPANE_H |
| 56 | |