|
ACAV f0ba4b7c9529
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
|
Source code viewer with line numbers and lightweight syntax highlighting. More...
#include <SourceCodeView.h>
Signals | |
| void | fileLoaded (const QString &filePath) |
| Emitted when a file is successfully loaded. | |
| void | fileLoadError (const QString &errorMessage) |
| Emitted when file loading fails. | |
| void | sourcePositionClicked (FileID fileId, unsigned line, unsigned column) |
| Emitted when user clicks in editor. | |
| void | sourceRangeSelected (FileID fileId, unsigned startLine, unsigned startColumn, unsigned endLine, unsigned endColumn) |
| Emitted when user selects a range in the editor. | |
Public Member Functions | |
| SourceCodeView (QWidget *parent=nullptr) | |
| bool | loadFile (const QString &filePath) |
| Load and display a source file. | |
| void | clearView () |
| Clear the view. | |
| void | applyFontSize (int pointSize) |
| Update font size and refresh editor metrics. | |
| QString | currentFilePath () const |
| Get the currently loaded file path. | |
| FileID | currentFileId () const |
| Get the current file ID. | |
| void | setCurrentFileId (FileID fileId) |
| Set the current file ID Should be called after loading a file. | |
| void | highlightRange (const SourceRange &range, bool moveCursor=true) |
| Highlight source range with light green background. | |
| void | clearHighlight () |
| Clear current highlight. | |
| bool | findNext (const QString &term, QTextDocument::FindFlags flags=QTextDocument::FindFlags()) |
| Find next occurrence of the term and highlight it. | |
| bool | findPrevious (const QString &term, QTextDocument::FindFlags flags=QTextDocument::FindFlags()) |
| Find previous occurrence of the term and highlight it. | |
| void | clearSearchHighlight () |
| Clear any active search highlight. | |
| int | lineNumberAreaWidth () const |
| Calculate required width for line number area. | |
| void | lineNumberAreaPaintEvent (QPaintEvent *event) |
| Paint line numbers for visible text blocks Called by LineNumberArea::paintEvent(). | |
Protected Member Functions | |
| void | resizeEvent (QResizeEvent *event) override |
| Override to resize line number area with editor. | |
| void | mousePressEvent (QMouseEvent *event) override |
| Override to detect mouse press for selection tracking. | |
| void | mouseReleaseEvent (QMouseEvent *event) override |
| Override to detect mouse selection end. | |
| void | keyPressEvent (QKeyEvent *event) override |
| Override to emit navigation on keyboard movement. | |
Source code viewer with line numbers and lightweight syntax highlighting.
This widget displays source code files in a read-only text editor with line numbers in the left margin and lightweight C/C++ syntax highlighting.
Definition at line 45 of file SourceCodeView.h.
|
explicit |
Definition at line 55 of file SourceCodeView.cpp.
| void acav::SourceCodeView::applyFontSize | ( | int | pointSize | ) |
Update font size and refresh editor metrics.
Definition at line 97 of file SourceCodeView.cpp.
References applyFontSize().
Referenced by applyFontSize().
| void acav::SourceCodeView::clearHighlight | ( | ) |
Clear current highlight.
Definition at line 217 of file SourceCodeView.cpp.
References clearHighlight().
Referenced by clearHighlight(), clearView(), and mousePressEvent().
| void acav::SourceCodeView::clearSearchHighlight | ( | ) |
Clear any active search highlight.
Definition at line 211 of file SourceCodeView.cpp.
References clearSearchHighlight().
Referenced by clearSearchHighlight(), clearView(), loadFile(), and mousePressEvent().
| void acav::SourceCodeView::clearView | ( | ) |
Clear the view.
Definition at line 141 of file SourceCodeView.cpp.
References clearHighlight(), clearSearchHighlight(), clearView(), and acav::FileManager::InvalidFileID.
Referenced by clearView().
|
inline |
Get the current file ID.
Definition at line 67 of file SourceCodeView.h.
|
inline |
Get the currently loaded file path.
Definition at line 64 of file SourceCodeView.h.
| bool acav::SourceCodeView::findNext | ( | const QString & | term, |
| QTextDocument::FindFlags | flags = QTextDocument::FindFlags() ) |
Find next occurrence of the term and highlight it.
Definition at line 201 of file SourceCodeView.cpp.
References findNext().
Referenced by findNext().
| bool acav::SourceCodeView::findPrevious | ( | const QString & | term, |
| QTextDocument::FindFlags | flags = QTextDocument::FindFlags() ) |
Find previous occurrence of the term and highlight it.
Definition at line 206 of file SourceCodeView.cpp.
References findPrevious().
Referenced by findPrevious().
| void acav::SourceCodeView::highlightRange | ( | const SourceRange & | range, |
| bool | moveCursor = true ) |
Highlight source range with light green background.
| range | Source range to highlight |
Definition at line 151 of file SourceCodeView.cpp.
References highlightRange(), and acav::FileManager::InvalidFileID.
Referenced by highlightRange().
|
overrideprotected |
Override to emit navigation on keyboard movement.
Definition at line 417 of file SourceCodeView.cpp.
References acav::FileManager::InvalidFileID, and keyPressEvent().
Referenced by keyPressEvent().
| void acav::SourceCodeView::lineNumberAreaPaintEvent | ( | QPaintEvent * | event | ) |
Paint line numbers for visible text blocks Called by LineNumberArea::paintEvent().
| event | Paint event with update rectangle |
Definition at line 312 of file SourceCodeView.cpp.
References lineNumberAreaPaintEvent().
Referenced by lineNumberAreaPaintEvent().
| int acav::SourceCodeView::lineNumberAreaWidth | ( | ) | const |
Calculate required width for line number area.
Definition at line 299 of file SourceCodeView.cpp.
References lineNumberAreaWidth().
Referenced by lineNumberAreaWidth(), and resizeEvent().
| bool acav::SourceCodeView::loadFile | ( | const QString & | filePath | ) |
Load and display a source file.
| filePath | Absolute path to the source file |
Definition at line 108 of file SourceCodeView.cpp.
References clearSearchHighlight(), fileLoaded(), fileLoadError(), and loadFile().
Referenced by loadFile().
|
overrideprotected |
Override to detect mouse press for selection tracking.
Definition at line 375 of file SourceCodeView.cpp.
References clearHighlight(), clearSearchHighlight(), and mousePressEvent().
Referenced by mousePressEvent().
|
overrideprotected |
Override to detect mouse selection end.
Definition at line 392 of file SourceCodeView.cpp.
References mouseReleaseEvent().
Referenced by mouseReleaseEvent().
|
overrideprotected |
Override to resize line number area with editor.
Definition at line 341 of file SourceCodeView.cpp.
References lineNumberAreaWidth(), and resizeEvent().
Referenced by resizeEvent().
|
inline |
Set the current file ID Should be called after loading a file.
Definition at line 71 of file SourceCodeView.h.
|
signal |
Emitted when user clicks in editor.
| fileId | File ID of current file |
| line | Line number (1-based) |
| column | Column number (1-based) |
|
signal |
Emitted when user selects a range in the editor.
| fileId | File ID of current file |
| startLine | Start line number (1-based) |
| startColumn | Start column number (1-based) |
| endLine | End line number (1-based) |
| endColumn | End column number (1-based) |
References acav::FileManager::InvalidFileID.