File indexing completed on 2024-05-05 05:05:32

0001 /*************************************************************************************
0002     Copyright (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net)
0003                   2008-2019 by Michel Ludwig (michel.ludwig@kdemail.net)
0004  *************************************************************************************/
0005 
0006 /***************************************************************************
0007  *                                                                         *
0008  *   This program is free software; you can redistribute it and/or modify  *
0009  *   it under the terms of the GNU General Public License as published by  *
0010  *   the Free Software Foundation; either version 2 of the License, or     *
0011  *   (at your option) any later version.                                   *
0012  *                                                                         *
0013  ****************************************************************************/
0014 
0015 #ifndef LOGWIDGET_H
0016 #define LOGWIDGET_H
0017 
0018 #include <QItemDelegate>
0019 #include <QTextDocument>
0020 
0021 #include <QListWidget>
0022 
0023 #include "outputinfo.h"
0024 
0025 class QString;
0026 class QPoint;
0027 
0028 class KileInfo;
0029 class QUrl;
0030 
0031 namespace KileWidget {
0032 class LogWidgetItemDelegate : public QItemDelegate
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     explicit LogWidgetItemDelegate(QObject* parent = Q_NULLPTR);
0038 
0039     virtual QSize sizeHint(const QStyleOptionViewItem& option,
0040                            const QModelIndex& index) const override;
0041 
0042 protected:
0043     virtual void paint(QPainter* painter,
0044                        const QStyleOptionViewItem& option,
0045                        const QModelIndex & index) const override;
0046 
0047     QTextDocument* constructTextDocument(const QModelIndex& index) const;
0048 };
0049 
0050 class LogWidget : public QListWidget
0051 {
0052     Q_OBJECT
0053 
0054 public:
0055     struct ProblemInformation {
0056         int type;
0057         QString message;
0058         OutputInfo outputInfo;
0059     };
0060 
0061     enum PopupType { AllPopupActions = 0, NoHideActions = 1};
0062 
0063     explicit LogWidget(PopupType popupType = AllPopupActions, QWidget *parent = Q_NULLPTR, const char *name = Q_NULLPTR);
0064     ~LogWidget();
0065 
0066     bool isShowingOutput() const;
0067 
0068 public Q_SLOTS:
0069     void highlight(const OutputInfo& info, bool startFromBottom = false);
0070 
0071     void printMessage(const QString& message);
0072     void printMessage(int type, const QString& message, const QString &tool = "Kile",
0073                       const OutputInfo& outputInfo = OutputInfo(), bool allowSelection = false,
0074                       bool scroll = true);
0075     void printProblem(int type, const QString& problem, const OutputInfo& outputInfo = OutputInfo());
0076     void printProblems(const QList<KileWidget::LogWidget::ProblemInformation>& list);
0077 
0078     void addEmptyLine();
0079 
0080     void copy();
0081 
0082     void startToolLogOutput();
0083     void endToolLogOutput();
0084 
0085 Q_SIGNALS:
0086     void showingErrorMessage(QWidget*);
0087     void outputInfoSelected(const OutputInfo&);
0088 
0089 protected:
0090     virtual void enterEvent(QEvent *event) override;
0091     virtual void leaveEvent(QEvent *event) override;
0092     virtual void mouseMoveEvent(QMouseEvent* event) override;
0093 
0094     void adaptMouseCursor(const QPoint& p);
0095     virtual void keyPressEvent(QKeyEvent *event) override;
0096 
0097     virtual void contextMenuEvent(QContextMenuEvent *event) override;
0098 
0099     void printMessageLine(int type, const QString& message, const QString &tool = "Kile",
0100                           const OutputInfo& outputInfo = OutputInfo(), bool allowSelection = false,
0101                           bool scroll = true);
0102 
0103 protected Q_SLOTS:
0104     void slotItemClicked(QListWidgetItem *item);
0105     void deselectAllItems();
0106 
0107     void toggleBadBoxHiding();
0108     void toggleWarningsHiding();
0109 
0110 private:
0111     int             m_popupType;
0112     int         m_idWarning, m_idBadBox;
0113     LogWidgetItemDelegate   *m_itemDelegate;
0114     OutputInfo      m_firstErrorMessgeInToolLog;
0115 
0116     bool containsSelectableItems() const;
0117 };
0118 }
0119 
0120 #endif