ACAV f0ba4b7c9529
Abstract Syntax Tree (AST) visualization tool for C, C++, and Objective-C
Loading...
Searching...
No Matches
acav::SourceCodeView Class Reference

Source code viewer with line numbers and lightweight syntax highlighting. More...

#include <SourceCodeView.h>

Inheritance diagram for acav::SourceCodeView:
[legend]

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.

Detailed Description

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.

Constructor & Destructor Documentation

◆ SourceCodeView()

acav::SourceCodeView::SourceCodeView ( QWidget * parent = nullptr)
explicit

Definition at line 55 of file SourceCodeView.cpp.

Member Function Documentation

◆ applyFontSize()

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().

◆ clearHighlight()

void acav::SourceCodeView::clearHighlight ( )

Clear current highlight.

Definition at line 217 of file SourceCodeView.cpp.

References clearHighlight().

Referenced by clearHighlight(), clearView(), and mousePressEvent().

◆ clearSearchHighlight()

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().

◆ clearView()

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().

◆ currentFileId()

FileID acav::SourceCodeView::currentFileId ( ) const
inline

Get the current file ID.

Definition at line 67 of file SourceCodeView.h.

◆ currentFilePath()

QString acav::SourceCodeView::currentFilePath ( ) const
inline

Get the currently loaded file path.

Definition at line 64 of file SourceCodeView.h.

◆ findNext()

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().

◆ findPrevious()

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().

◆ highlightRange()

void acav::SourceCodeView::highlightRange ( const SourceRange & range,
bool moveCursor = true )

Highlight source range with light green background.

Parameters
rangeSource range to highlight

Definition at line 151 of file SourceCodeView.cpp.

References highlightRange(), and acav::FileManager::InvalidFileID.

Referenced by highlightRange().

◆ keyPressEvent()

void acav::SourceCodeView::keyPressEvent ( QKeyEvent * event)
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().

◆ lineNumberAreaPaintEvent()

void acav::SourceCodeView::lineNumberAreaPaintEvent ( QPaintEvent * event)

Paint line numbers for visible text blocks Called by LineNumberArea::paintEvent().

Parameters
eventPaint event with update rectangle

Definition at line 312 of file SourceCodeView.cpp.

References lineNumberAreaPaintEvent().

Referenced by lineNumberAreaPaintEvent().

◆ lineNumberAreaWidth()

int acav::SourceCodeView::lineNumberAreaWidth ( ) const

Calculate required width for line number area.

Returns
Width in pixels for current line count

Definition at line 299 of file SourceCodeView.cpp.

References lineNumberAreaWidth().

Referenced by lineNumberAreaWidth(), and resizeEvent().

◆ loadFile()

bool acav::SourceCodeView::loadFile ( const QString & filePath)

Load and display a source file.

Parameters
filePathAbsolute path to the source file
Returns
true if file was loaded successfully, false otherwise

Definition at line 108 of file SourceCodeView.cpp.

References clearSearchHighlight(), fileLoaded(), fileLoadError(), and loadFile().

Referenced by loadFile().

◆ mousePressEvent()

void acav::SourceCodeView::mousePressEvent ( QMouseEvent * event)
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().

◆ mouseReleaseEvent()

void acav::SourceCodeView::mouseReleaseEvent ( QMouseEvent * event)
overrideprotected

Override to detect mouse selection end.

Definition at line 392 of file SourceCodeView.cpp.

References mouseReleaseEvent().

Referenced by mouseReleaseEvent().

◆ resizeEvent()

void acav::SourceCodeView::resizeEvent ( QResizeEvent * event)
overrideprotected

Override to resize line number area with editor.

Definition at line 341 of file SourceCodeView.cpp.

References lineNumberAreaWidth(), and resizeEvent().

Referenced by resizeEvent().

◆ setCurrentFileId()

void acav::SourceCodeView::setCurrentFileId ( FileID fileId)
inline

Set the current file ID Should be called after loading a file.

Definition at line 71 of file SourceCodeView.h.

◆ sourcePositionClicked

void acav::SourceCodeView::sourcePositionClicked ( FileID fileId,
unsigned line,
unsigned column )
signal

Emitted when user clicks in editor.

Parameters
fileIdFile ID of current file
lineLine number (1-based)
columnColumn number (1-based)

◆ sourceRangeSelected

void acav::SourceCodeView::sourceRangeSelected ( FileID fileId,
unsigned startLine,
unsigned startColumn,
unsigned endLine,
unsigned endColumn )
signal

Emitted when user selects a range in the editor.

Parameters
fileIdFile ID of current file
startLineStart line number (1-based)
startColumnStart column number (1-based)
endLineEnd line number (1-based)
endColumnEnd column number (1-based)

References acav::FileManager::InvalidFileID.


The documentation for this class was generated from the following files: