Use QString parameters instead of const char* in some more places.
[kdbg.git] / kdbg / sourcewnd.h
blobbab0b5aafec799b3bfcc9b5c81bf6afaf98e8e22
1 /*
2 * Copyright Johannes Sixt
3 * This file is licensed under the GNU General Public License Version 2.
4 * See the file COPYING in the toplevel directory of the source directory.
5 */
7 #ifndef SOURCEWND_H
8 #define SOURCEWND_H
10 #include <qpixmap.h>
11 #include <qtextedit.h>
12 #include <qsyntaxhighlighter.h>
13 #include <vector>
14 #include "dbgdriver.h"
16 // forward declarations
17 class KDebugger;
18 struct DbgAddr;
20 class SourceWindow : public QTextEdit
22 Q_OBJECT
23 public:
24 SourceWindow(const QString& fileName, QWidget* parent, const char* name);
25 ~SourceWindow();
27 bool loadFile();
28 void reloadFile();
29 bool fileNameMatches(const QString& other);
30 void scrollTo(int lineNo, const DbgAddr& address);
31 const QString& fileName() const { return m_fileName; }
32 void updateLineItems(const KDebugger* dbg);
33 void setPC(bool set, int lineNo, const DbgAddr& address, int frameNo);
34 enum FindDirection { findForward = 1, findBackward = -1 };
35 void find(const QString& text, bool caseSensitive, FindDirection dir);
36 bool wordAtPoint(const QPoint& p, QString& word, QRect& r);
37 /**
38 * Translates row number (zero-based) to zero-based source line number.
39 * If sourceRow is non-zero, it is filled with the source code row
40 * belonging to the line number.
42 int rowToLine(int row, int* sourceRow = 0);
43 /** Translates zero-based source line number to row number (zero-based) */
44 int lineToRow(int line);
45 /** Is the row disassembled? */
46 bool isRowExpanded(int row);
47 /** Does the row show disassembled code? */
48 bool isRowDisassCode(int row);
50 /** lineNo is zero-based */
51 void disassembled(int lineNo, const std::list<DisassembledCode>& disass);
53 void activeLine(int& lineNo, DbgAddr& address);
55 protected:
56 virtual void drawFrame(QPainter* p);
57 virtual bool eventFilter(QObject* watched, QEvent* e);
58 virtual void contextMenuEvent(QContextMenuEvent* e);
59 virtual void mousePressEvent(QMouseEvent* ev);
60 virtual void keyPressEvent(QKeyEvent* ev);
61 virtual void paletteChange(const QPalette&);
62 void expandRow(int row);
63 void collapseRow(int row);
64 void scrollToRow(int row);
65 /** translates (0-based) line number plus a code address into a row number */
66 int lineToRow(int row, const DbgAddr& address);
68 void actionExpandRow(int row);
69 void actionCollapseRow(int row);
71 signals:
72 void clickedLeft(const QString&, int, const DbgAddr& address, bool);
73 void clickedMid(const QString&, int, const DbgAddr& address);
74 void disassemble(const QString&, int);
75 void expanded(int lineNo); /* source lineNo has been expanded */
76 void collapsed(int lineNo); /* source lineNo has been collapsed */
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 QFont m_lineNoFont; //!< The font used to draw line numbers
109 int m_curRow; //!< The highlighted row
110 int m_widthItems; //!< The width of the item column
111 int m_widthPlus; //!< The width of the expander column
112 int m_widthLineNo; //!< The width of the line number columns
115 class HighlightCpp : public QSyntaxHighlighter
117 SourceWindow* m_srcWnd;
119 public:
120 HighlightCpp(SourceWindow* srcWnd);
121 virtual int highlightParagraph(const QString& text, int state);
124 #endif // SOURCEWND_H