File indexing completed on 2024-04-28 05:49:32

0001 /*
0002     SPDX-FileCopyrightText: 2021 Christoph Cullmann <cullmann@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <QLineEdit>
0010 #include <QPointer>
0011 #include <QTextBrowser>
0012 #include <QTimer>
0013 #include <QWidget>
0014 
0015 class KateMainWindow;
0016 class KateOutputTreeView;
0017 class QSortFilterProxyModel;
0018 
0019 /**
0020  * Widget to output stuff e.g. for plugins.
0021  */
0022 class KateOutputView : public QWidget
0023 {
0024     Q_OBJECT
0025 
0026 public:
0027     enum Column {
0028         Column_Time = 0,
0029         Column_Category,
0030         Column_LogType,
0031         Column_Body,
0032     };
0033     /**
0034      * Construct new output, we do that once per main window
0035      * @param mainWindow parent main window
0036      * @param parent parent widget (e.g. the tool view in the main window)
0037      */
0038     KateOutputView(KateMainWindow *mainWindow, QWidget *parent);
0039 
0040 private Q_SLOTS:
0041     void tabForToolViewAdded(QWidget *toolView, QWidget *tab);
0042 
0043 public Q_SLOTS:
0044     /**
0045      * Read and apply our configuration.
0046      */
0047     void readConfig();
0048 
0049     /**
0050      * slot for incoming messages
0051      * @param message incoming message we shall handle
0052      *
0053      * details of message format:
0054      *
0055      * IMPORTANT: at the moment, most stuff is key/value with strings, if the format is more finalized, one can introduce better type for more efficiency/type
0056      * safety
0057      *
0058      * message text, will be trimmed before output
0059      *
0060      *    message["text"] = i18n("your cool message")
0061      *
0062      * the text will be split in lines, all lines beside the first can be collapsed away
0063      *
0064      * message type, we support at the moment
0065      *
0066      *    message["type"] = "Error"
0067      *    message["type"] = "Warning"
0068      *    message["type"] = "Info"
0069      *    message["type"] = "Log"
0070      *
0071      * this is take from https://microsoft.github.io/language-server-protocol/specification#window_showMessage MessageType of LSP
0072      *
0073      * will lead to appropriate icons/... in the output view
0074      *
0075      * a message should have some category, like Git, LSP, ....
0076      *
0077      *    message["category"] = i18n(...)
0078      *
0079      * will be used to allow the user to filter for
0080      *
0081      * one can additionally provide a categoryIcon
0082      *
0083      *    message["categoryIcon"] = QIcon(...)
0084      *
0085      * the categoryIcon icon QVariant must contain a QIcon, nothing else!
0086      *
0087      */
0088     void slotMessage(const QVariantMap &message);
0089 
0090 private:
0091     void search();
0092     void appendLines(const QStringList &lines, const QString &token, const QTextCursor &pos = {});
0093 
0094     /**
0095      * the main window we belong to
0096      * each main window has exactly one KateOutputView
0097      */
0098     KateMainWindow *const m_mainWindow = nullptr;
0099 
0100     // The text edit used to display messages
0101     class KateOutputEdit *m_textEdit;
0102 
0103     /**
0104      * fuzzy filter line edit
0105      */
0106     QLineEdit m_filterLine;
0107 
0108     /**
0109      * When to show output view
0110      * 0 => never
0111      * 1 => on error
0112      * 2 => on warning or above
0113      * 3 => on info or above
0114      * 4 => on log or above
0115      */
0116     int m_showOutputViewForMessageType = 1;
0117 
0118     /**
0119      * history size limit, < 0 is unlimited
0120      */
0121     int m_historyLimit = -1;
0122 
0123     QPointer<QWidget> tabButton;
0124 
0125     QPointer<class NewMsgIndicator> m_fadingIndicator;
0126 
0127     QColor m_msgIndicatorColors[3];
0128 
0129     QTimer m_searchTimer;
0130 
0131     QString m_infoColor;
0132     QString m_warnColor;
0133     QString m_errColor;
0134     QString m_keywordColor;
0135 };