Skip to content

Feature: Add custom text browser QDiffTextBrowser with its line number area QLineNumberArea for visual diff rendering#5

Merged
djad04 merged 16 commits intodevfrom
feature/custom-diff-textbrowser
Jul 29, 2025
Merged

Feature: Add custom text browser QDiffTextBrowser with its line number area QLineNumberArea for visual diff rendering#5
djad04 merged 16 commits intodevfrom
feature/custom-diff-textbrowser

Conversation

@djad04
Copy link
Owner

@djad04 djad04 commented Jul 29, 2025

This pull request adds a new QDiffTextBrowser widget — an enhanced QTextBrowser that renders diff results complete with line-number gutter, per-line background coloring, and rich text highlighting. Alongside it comes the QLineNumberArea helper widget to display and align line numbers dynamically.


🚀 Key Changes

QDiffTextBrowser

  • Inheritance: Extends QTextBrowser.
  • Diff Rendering:
    • Accepts a QDiffResult and highlights inserted, deleted, and replaced lines using configurable colors.
    • Applies per-line QTextCharFormat based on DiffOperation.
  • Layout & Styling:
    • Automatic font‑scaling between MIN_FONT_SIZE (14) and MAX_FONT_SIZE (36).
    • Custom left/right margins and line‑spacing for readability.
    • Constants exposed for padding, text‑width ratio, and color values.
  • Event Handling:
    • Overrides paintEvent(), resizeEvent(), and scrollContentsBy() to keep the text area and gutter in sync.
    • Implements paintLineNumberArea() and applyDiffHighlighting() helpers.

QLineNumberArea

  • Standalone Widget: Lightweight QWidget that lives alongside QDiffTextBrowser.
  • Painting:
    • Draws line numbers with background, border, and text color constants.
    • Reacts to scroll and resize events of the parent editor.
  • Sizing:
    • Implements sizeHint() based on dynamic content width and padding ratios.
      e parent QDiffTextBrowser.

djad04 added 16 commits July 7, 2025 23:05
…rArea implementation to separate files

- Removed the old LineNumberArea.cpp file and added a new QLineNumberArea.cpp and QLineNumberArea.h.
- Updated CMakeLists.txt to reflect the new file structure and include necessary headers.
- Implemented line numbering in QDiffTextBrowser by adding a QLineNumberArea.
- Updated the constructor and added methods for calculating line number area width and handling paint events.
- Refactored the header file to include necessary declarations and updated the namespace to QDiffX.
- Increase padding and improve styling for line numbers
- Add dynamic font size adjustment based on widget height
- Replace QTextBrowser with QDiffTextBrowser for both sides
- Set initial content and geometry in main.cpp
Add functionality to display and highlight diff results with different colors for insertions, deletions and replacements. Store line operations in a map and apply appropriate formatting when rendering the text. Also includes basic setup for line number area connections and document properties.
…vent

Add background color highlighting for lines based on their operation
- Add destructor to properly clean up line number area
- Refactor line number painting to use visual position calculations
- Add top/bottom margin constant and apply consistent spacing
- Remove redundant comments and improve code clarity
Clean up source files by removing completed or no longer relevant TODO comments that were cluttering the code
@djad04 djad04 marked this pull request as ready for review July 29, 2025 10:47
@djad04 djad04 merged commit 0bc1b6b into dev Jul 29, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant