| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
lua_debugger_code_view.h
1/* lua_debugger_code_view.h
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#ifndef LUA_DEBUGGER_CODE_VIEW_H
11#define LUA_DEBUGGER_CODE_VIEW_H
12
13#include <QFont>
14#include <QObject>
15#include <QPlainTextEdit>
16#include <QtGlobal>
17
18 class QSyntaxHighlighter;
19 class QEvent;
20 class QContextMenuEvent;
21
25 class LuaDebuggerCodeView : public QPlainTextEdit
26{
27 Q_OBJECT
28
29 public:
34 LuaDebuggerCodeView(QWidget *parent = nullptr);
35
40 void lineNumberAreaPaintEvent(QPaintEvent *event);
45 qint32 lineNumberAreaWidth();
46
47 void setFilename(const QString &f) { filename = f; }
48 QString getFilename() const { return filename; }
53 void setCurrentLine(qint32 line);
55 void clearCurrentLineHighlight();
60 void moveCaretToLineStart(qint32 line);
62 void setEditorFont(const QFont &font);
64 void updateBreakpointMarkers();
66 void applyTheme();
67
68 signals:
76 void breakpointToggled(const QString &filename, qint32 line,
77 bool toggleActive);
78
97 void breakpointGutterMenuRequested(const QString &filename, qint32 line,
98 const QPoint &globalPos);
99
100 protected:
102 void resizeEvent(QResizeEvent *event) override;
104 bool eventFilter(QObject *watched, QEvent *event) override;
105
106 private slots:
108 void updateLineNumberAreaWidth(int newBlockCount);
110 void rebuildLineHighlights();
112 void updateLineNumberArea(const QRect &rect, int dy);
113
114 private:
115 QWidget *lineNumberArea;
116 QSyntaxHighlighter *syntaxHighlighter;
118 qint32 pausedExecutionLine_ = -1;
119
120 friend class LineNumberArea;
121 QString filename;
123 void applyEditorPalette();
124};
125
126 class LineNumberArea : public QWidget
127{
128 public:
133 LineNumberArea(LuaDebuggerCodeView *editor)
134 : QWidget(editor), codeEditor(editor)
135 {
136 }
137
139 QSize sizeHint() const override
140 {
141 return QSize(codeEditor->lineNumberAreaWidth(), 0);
142 }
143
144 protected:
146 void paintEvent(QPaintEvent *event) override
147 {
148 codeEditor->lineNumberAreaPaintEvent(event);
149 }
150
152 void mousePressEvent(QMouseEvent *event) override;
153
161 void contextMenuEvent(QContextMenuEvent *event) override;
162
163 private:
164 LuaDebuggerCodeView *codeEditor;
165
176 qint32 lineAtY(qint32 yPx) const;
177};
178
179#endif // LUA_DEBUGGER_CODE_VIEW_H
LineNumberArea
Definition lua_debugger_code_view.h:127
LineNumberArea::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event) override
Right-click / Ctrl-click / two-finger trackpad tap on the breakpoint gutter: always pop the Edit / Di...
Definition lua_debugger_code_view.cpp:948
LineNumberArea::paintEvent
void paintEvent(QPaintEvent *event) override
Delegate painting back to the code view.
Definition lua_debugger_code_view.h:146
LineNumberArea::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
Toggle breakpoints when the gutter is clicked.
Definition lua_debugger_code_view.cpp:873
LineNumberArea::LineNumberArea
LineNumberArea(LuaDebuggerCodeView *editor)
Construct the helper widget bound to a specific code view.
Definition lua_debugger_code_view.h:133
LineNumberArea::sizeHint
QSize sizeHint() const override
Size the gutter according to the editor's width requirements.
Definition lua_debugger_code_view.h:139
LuaDebuggerCodeView
Editable code editor supporting gutter breakpoints and highlighting.
Definition lua_debugger_code_view.h:26
LuaDebuggerCodeView::clearCurrentLineHighlight
void clearCurrentLineHighlight()
Clear the debugger paused-line highlight (caret stripe unchanged).
Definition lua_debugger_code_view.cpp:608
LuaDebuggerCodeView::setCurrentLine
void setCurrentLine(qint32 line)
Set the debugger "execution paused" line (amber bar) and move the caret to that line....
Definition lua_debugger_code_view.cpp:555
LuaDebuggerCodeView::updateBreakpointMarkers
void updateBreakpointMarkers()
Refresh breakpoint markers in the gutter area.
Definition lua_debugger_code_view.cpp:634
LuaDebuggerCodeView::resizeEvent
void resizeEvent(QResizeEvent *event) override
Update margins whenever Qt reports a size change.
Definition lua_debugger_code_view.cpp:465
LuaDebuggerCodeView::lineNumberAreaPaintEvent
void lineNumberAreaPaintEvent(QPaintEvent *event)
Paint the custom gutter that hosts line numbers and breakpoints.
Definition lua_debugger_code_view.cpp:704
LuaDebuggerCodeView::breakpointToggled
void breakpointToggled(const QString &filename, qint32 line, bool toggleActive)
Emitted when a breakpoint icon is clicked within the gutter (right margin).
LuaDebuggerCodeView::lineNumberAreaWidth
qint32 lineNumberAreaWidth()
Compute the width required for the gutter, including icons.
Definition lua_debugger_code_view.cpp:433
LuaDebuggerCodeView::moveCaretToLineStart
void moveCaretToLineStart(qint32 line)
Move the caret to the start of a line without changing the paused line (e.g. go-to-line).
Definition lua_debugger_code_view.cpp:589
LuaDebuggerCodeView::eventFilter
bool eventFilter(QObject *watched, QEvent *event) override
Forward Esc to LuaDebuggerDialog (keys go to viewport, not the dialog).
Definition lua_debugger_code_view.cpp:475
LuaDebuggerCodeView::breakpointGutterMenuRequested
void breakpointGutterMenuRequested(const QString &filename, qint32 line, const QPoint &globalPos)
Request an Edit / Disable (Enable) / Remove popup for the breakpoint at filename:line,...
LuaDebuggerCodeView::applyTheme
void applyTheme()
Re-apply theme colors from the current preference.
Definition lua_debugger_code_view.cpp:639
LuaDebuggerCodeView::setEditorFont
void setEditorFont(const QFont &font)
Apply a monospace font to both editor text and gutter.
Definition lua_debugger_code_view.cpp:619