File indexing completed on 2024-05-05 04:39:53

0001 /*
0002     SPDX-FileCopyrightText: 2003 John Birch <jbb@kdevelop.org>
0003     SPDX-FileCopyrightText: 2007 Hamish Rodda <rodda@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #ifndef _GDBOUTPUTWIDGET_H_
0009 #define _GDBOUTPUTWIDGET_H_
0010 
0011 #include "dbgglobal.h"
0012 
0013 #include <QPlainTextEdit>
0014 #include <QTimer>
0015 #include <QStringList>
0016 
0017 namespace KDevelop {
0018 class IDebugSession;
0019 }
0020 
0021 class KHistoryComboBox;
0022 class QToolButton;
0023 
0024 namespace KDevMI
0025 {
0026 namespace GDB
0027 {
0028 
0029 class GDBController;
0030 class CppDebuggerPlugin;
0031 
0032 class GDBOutputWidget : public QWidget
0033 {
0034     Q_OBJECT
0035 
0036 public:
0037     explicit GDBOutputWidget(CppDebuggerPlugin* plugin, QWidget *parent=nullptr );
0038     ~GDBOutputWidget() override;
0039 
0040     void savePartialProjectSession();
0041     void restorePartialProjectSession();
0042 
0043     bool showInternalCommands() const;
0044 
0045 public Q_SLOTS:
0046     void clear();
0047 
0048     void slotInternalCommandStdout(const QString& line);
0049     void slotUserCommandStdout(const QString& line);
0050     void slotReceivedStderr(const char* line);
0051     void slotStateChanged(DBGStateFlags oldStatus, DBGStateFlags newStatus);
0052 
0053     void slotGDBCmd();
0054 
0055     void flushPending();
0056 
0057     void copyAll();
0058     void toggleShowInternalCommands();
0059 
0060 private Q_SLOTS:
0061     void currentSessionChanged(KDevelop::IDebugSession *session);
0062     void updateColors();
0063 
0064 protected:
0065     void focusInEvent(QFocusEvent *e) override;
0066     void contextMenuEvent(QContextMenuEvent* e) override;
0067 
0068 Q_SIGNALS:
0069     void requestRaise();
0070     void userGDBCmd(const QString &cmd);
0071     void breakInto();
0072 
0073 private:
0074     void newStdoutLine(const QString& line, bool internal);
0075 
0076     /** Arranges for 'line' to be shown to the user.
0077         Adds 'line' to pendingOutput_ and makes sure
0078         updateTimer_ is running. */
0079     void showLine(const QString& line);
0080 
0081     /** Makes 'l' no longer than 'max_size' by
0082         removing excessive elements from the top.
0083     */
0084     void trimList(QStringList& l, int max_size);
0085 
0086     GDBController* m_controller;
0087     KHistoryComboBox*  m_userGDBCmdEditor;
0088     QToolButton*    m_Interrupt;
0089     QPlainTextEdit*      m_gdbView;
0090 
0091     bool m_cmdEditorHadFocus;
0092 
0093     void setShowInternalCommands(bool);
0094     friend class OutputText;
0095 
0096     /** The output from user commands only and from
0097         all commands. We keep it here so that if we switch
0098         "Show internal commands" on, we can show previous 
0099         internal commands. 
0100     */
0101     QStringList m_userCommands_, m_allCommands;
0102     /** Same output, without any fancy formatting.  Keeping it
0103         here because I can't find any way to extract raw text,
0104         without formatting, out of QTextEdit except for
0105         selecting everything and calling 'copy()'. The latter
0106         approach is just ugly.  */
0107     QStringList m_userCommandsRaw, m_allCommandsRaw;
0108 
0109 
0110     /** For performance reasons, we don't immediately add new text
0111         to QTExtEdit. Instead we add it to pendingOutput_ and 
0112         flush it on timer.
0113     */
0114     QString m_pendingOutput;
0115     QTimer m_updateTimer;
0116 
0117     bool m_showInternalCommands;
0118 
0119     int m_maxLines;
0120 
0121     QColor m_gdbColor;
0122     QColor m_errorColor;
0123 };
0124 
0125 class OutputTextEdit : public QPlainTextEdit
0126 {
0127     Q_OBJECT
0128 
0129 public:
0130     explicit OutputTextEdit(GDBOutputWidget* parent);
0131 
0132 protected:
0133     void contextMenuEvent(QContextMenuEvent* event) override;
0134 };
0135 
0136 } // end of namespace GDB
0137 } // end of namespace KDevMI
0138 
0139 #endif