Syntax highlighter: Highlight C and C++ comments.
[kdbg.git] / kdbg / sourcewnd.h
blobd217eb3cf37e2c482aa862acb3fab522a873e7ef
1 // $Id$
3 // Copyright by Johannes Sixt
4 // This file is under GPL, the GNU General Public Licence
6 #ifndef SOURCEWND_H
7 #define SOURCEWND_H
9 #include <qpixmap.h>
10 #include <qtextedit.h>
11 #include <qsyntaxhighlighter.h>
12 #include <vector>
13 #include "dbgdriver.h"
15 // forward declarations
16 class KDebugger;
17 struct DbgAddr;
19 class SourceWindow : public QTextEdit
21 Q_OBJECT
22 public:
23 SourceWindow(const char* fileName, QWidget* parent, const char* name);
24 ~SourceWindow();
26 bool loadFile();
27 void reloadFile();
28 bool fileNameMatches(const QString& other);
29 void scrollTo(int lineNo, const DbgAddr& address);
30 const QString& fileName() const { return m_fileName; }
31 void updateLineItems(const KDebugger* dbg);
32 void setPC(bool set, int lineNo, const DbgAddr& address, int frameNo);
33 enum FindDirection { findForward = 1, findBackward = -1 };
34 void find(const QString& text, bool caseSensitive, FindDirection dir);
35 bool wordAtPoint(const QPoint& p, QString& word, QRect& r);
36 /**
37 * Translates row number (zero-based) to zero-based source line number.
38 * If sourceRow is non-zero, it is filled with the source code row
39 * belonging to the line number.
41 int rowToLine(int row, int* sourceRow = 0);
42 /** Translates zero-based source line number to row number (zero-based) */
43 int lineToRow(int line);
44 /** Is the row disassembled? */
45 bool isRowExpanded(int row);
46 /** Does the row show disassembled code? */
47 bool isRowDisassCode(int row);
49 /** lineNo is zero-based */
50 void disassembled(int lineNo, const QList<DisassembledCode>& disass);
52 void activeLine(int& lineNo, DbgAddr& address);
54 protected:
55 virtual void drawFrame(QPainter* p);
56 virtual bool eventFilter(QObject* watched, QEvent* e);
57 virtual void contextMenuEvent(QContextMenuEvent* e);
58 virtual void mousePressEvent(QMouseEvent* ev);
59 virtual void keyPressEvent(QKeyEvent* ev);
60 virtual void paletteChange(const QPalette&);
61 void expandRow(int row);
62 void collapseRow(int row);
63 void scrollToRow(int row);
64 /** translates (0-based) line number plus a code address into a row number */
65 int lineToRow(int row, const DbgAddr& address);
67 void actionExpandRow(int row);
68 void actionCollapseRow(int row);
70 signals:
71 void clickedLeft(const QString&, int, const DbgAddr& address, bool);
72 void clickedMid(const QString&, int, const DbgAddr& address);
73 void disassemble(const QString&, int);
74 void expanded(int lineNo); /* source lineNo has been expanded */
75 void collapsed(int lineNo); /* source lineNo has been collapsed */
76 void lineChanged();
77 public slots:
78 void setTabWidth(int numChars);
79 void cursorChanged(int row);
81 protected:
82 QString m_fileName;
83 enum LineItem { liPC = 1, liPCup = 2,
84 liBP = 4, liBPdisabled = 8, liBPtemporary = 16,
85 liBPconditional = 32, liBPorphan = 64,
86 liBPany = liBP|liBPdisabled|liBPtemporary|liBPconditional|liBPorphan
89 struct SourceLine {
90 QString code; /* a line of text */
91 std::vector<QString> disass; /* its disassembled code */
92 std::vector<DbgAddr> disassAddr; /* the addresses thereof */
93 bool canDisass; /* if line can be disassembled */
94 SourceLine() : canDisass(true) { }
95 int findAddressRowOffset(const DbgAddr& address) const;
97 std::vector<SourceLine> m_sourceCode;
99 std::vector<int> m_rowToLine; //!< The source line number for each row
100 std::vector<uchar> m_lineItems; //!< Icons displayed on the line
101 QPixmap m_pcinner; /* PC at innermost frame */
102 QPixmap m_pcup; /* PC at frame up the stack */
103 QPixmap m_brkena; /* enabled breakpoint */
104 QPixmap m_brkdis; /* disabled breakpoint */
105 QPixmap m_brktmp; /* temporary breakpoint marker */
106 QPixmap m_brkcond; /* conditional breakpoint marker */
107 QPixmap m_brkorph; /* orphaned breakpoint marker */
108 int m_curRow; //!< The highlighted row
109 int m_widthItems; //!< The width of the item column
110 int m_widthPlus; //!< The width of the expander column
113 class HighlightCpp : public QSyntaxHighlighter
115 SourceWindow* m_srcWnd;
117 public:
118 HighlightCpp(SourceWindow* srcWnd);
119 virtual int highlightParagraph(const QString& text, int state);
122 #endif // SOURCEWND_H