Fluent-Qt

Text fields

DiffView

Syntax-highlighted Side-by-Side and Unified text diff viewer with inline word diffs, context folding, and hunk navigation.

Example

DiffView: Side-by-side and unified diff

Usage

Side-by-side and unified diff

Set both texts with setOriginalText() and setModifiedText(). Copied patches preserve final newlines. The summary marks approximate results when a large region exceeds the exact comparison budget.

#include <FluentQt/TextFields.h>
using namespace fluent::textfields;

auto* diff = new DiffView(this);
diff->setOriginalTitle("v1/Server.cpp");
diff->setModifiedTitle("v2/Server.cpp");
diff->setLanguage("cpp");
diff->setOriginalText(
    "struct ServerConfig {\n"
    "    int timeoutSeconds = 30;\n"
    "    bool autoReconnect = false;\n"
    "};\n"
    "void startServer() { listen(8080); }");
diff->setModifiedText(
    "struct ServerConfig {\n"
    "    int timeoutSeconds = 120;\n"
    "    bool autoReconnect = true;\n"
    "    int maxConnections = 64;\n"
    "};\n"
    "void startServer() { listen(8443); }");

fluent::textfields::DiffView

Inherits QWidget · FluentElement · QMLPlus

Fluent syntax-highlighted text diff viewer supporting Side-by-Side and Unified views with inline word diffs and hunk navigation.

Constructors

Properties

QString originalText

Original (baseline) text displayed for comparison.

Read originalText()Write setOriginalText()Notify originalTextChanged()
QString modifiedText

Modified (updated) text displayed for comparison.

Read modifiedText()Write setModifiedText()Notify modifiedTextChanged()
QString originalTitle

Header title identifying the original pane.

Read originalTitle()Write setOriginalTitle()Notify originalTitleChanged()
QString modifiedTitle

Header title identifying the modified pane.

Read modifiedTitle()Write setModifiedTitle()Notify modifiedTitleChanged()
QString language

Syntax highlighting language. Changing it preserves the current hunk and scroll position.

Read language()Write setLanguage()Notify languageChanged()
ViewMode viewMode

Presentation mode selecting side-by-side split panes or a unified stream.

Read viewMode()Write setViewMode()Notify viewModeChanged()
bool lineNumbersVisible

Whether line-number gutters are shown next to diff lines.

Read isLineNumbersVisible()Write setLineNumbersVisible()Notify lineNumbersVisibleChanged()
bool wordDiffEnabled

Whether changed word/token spans inside modified lines are emphasized inline.

Read isWordDiffEnabled()Write setWordDiffEnabled()Notify wordDiffEnabledChanged()
int contextLines

Number of unchanged context lines kept around each change hunk (-1 shows all lines).

Read contextLines()Write setContextLines()Notify contextLinesChanged()
int addedLineCount

Total added line count in the current diff.

Read addedLineCount()Notify diffComputed()
int removedLineCount

Total removed line count in the current diff.

Read removedLineCount()Notify diffComputed()
int hunkCount

Total contiguous change hunk count.

Read hunkCount()Notify diffComputed()
int currentHunkIndex

Zero-based index of the currently focused hunk, or -1 when no hunks exist.

Read currentHunkIndex()Notify currentHunkChanged()

Methods

QString originalText() const

Original (baseline) text displayed for comparison.

void setOriginalText(const QString& text)

Original (baseline) text displayed for comparison.

QString modifiedText() const

Modified (updated) text displayed for comparison.

void setModifiedText(const QString& text)

Modified (updated) text displayed for comparison.

QString originalTitle() const

Header title identifying the original pane.

void setOriginalTitle(const QString& title)

Header title identifying the original pane.

QString modifiedTitle() const

Header title identifying the modified pane.

void setModifiedTitle(const QString& title)

Header title identifying the modified pane.

QString language() const

Syntax highlighting language. Changing it preserves the current hunk and scroll position.

void setLanguage(const QString& language)

Syntax highlighting language. Changing it preserves the current hunk and scroll position.

ViewMode viewMode() const

Presentation mode selecting side-by-side split panes or a unified stream.

void setViewMode(ViewMode mode)

Presentation mode selecting side-by-side split panes or a unified stream.

bool isLineNumbersVisible() const

Whether line-number gutters are shown next to diff lines.

void setLineNumbersVisible(bool visible)

Whether line-number gutters are shown next to diff lines.

bool isWordDiffEnabled() const

Whether changed word/token spans inside modified lines are emphasized inline.

void setWordDiffEnabled(bool enabled)

Whether changed word/token spans inside modified lines are emphasized inline.

int contextLines() const

Number of unchanged context lines kept around each change hunk (-1 shows all lines).

void setContextLines(int lines)

Number of unchanged context lines kept around each change hunk (-1 shows all lines).

int addedLineCount() const

Total added line count in the current diff.

int removedLineCount() const

Total removed line count in the current diff.

int hunkCount() const

Total contiguous change hunk count.

int currentHunkIndex() const

Zero-based index of the currently focused hunk, or -1 when no hunks exist.

bool isUnified() const

Returns true when viewMode is ViewMode::Unified.

bool jumpToNextHunk()

Scrolls to and activates the next change hunk (wrapping around).

bool jumpToPreviousHunk()

Scrolls to and activates the previous change hunk (wrapping around).

bool jumpToHunk(int index)

Scrolls to and activates the change hunk at @p index.

void copyUnifiedPatch()

Copies a standard unified diff patch representation to the system clipboard.

QString unifiedPatch() const

Formats the current diff as a unified diff patch string.

int visibleRowCount() const

Returns the number of rendered rows in the active presentation mode (excluding folded filler details).

Signals

void originalTextChanged(const QString& text)

Original (baseline) text displayed for comparison.

void modifiedTextChanged(const QString& text)

Modified (updated) text displayed for comparison.

void originalTitleChanged(const QString& title)

Header title identifying the original pane.

void modifiedTitleChanged(const QString& title)

Header title identifying the modified pane.

void languageChanged(const QString& language)

Syntax highlighting language. Changing it preserves the current hunk and scroll position.

void viewModeChanged(ViewMode viewMode)

Presentation mode selecting side-by-side split panes or a unified stream.

void lineNumbersVisibleChanged(bool visible)

Whether line-number gutters are shown next to diff lines.

void wordDiffEnabledChanged(bool enabled)

Whether changed word/token spans inside modified lines are emphasized inline.

void contextLinesChanged(int contextLines)

Number of unchanged context lines kept around each change hunk (-1 shows all lines).

void diffComputed(int addedLines, int removedLines, int hunks)

Total added line count in the current diff.

void currentHunkChanged(int currentHunkIndex)

Zero-based index of the currently focused hunk, or -1 when no hunks exist.

Enumerations

enum class ViewMode

Diff presentation layout mode.

  • SideBySide = 0
  • Unified = 1
enum class LineKind

Semantic role of an individual diff line slot.

  • Context = 0
  • Added = 1
  • Removed = 2
  • Modified = 3
  • Empty = 4

Destructors

Protected members

Methods

Inherited from fluent::FluentElement

Methods

static void setTheme(Theme theme)

Updates the global theme and notifies active FluentElement instances.

static void setThemeDeferred(Theme theme)

Schedules a visible-first batched theme refresh without blocking the current interaction.

static Theme currentTheme()

Returns the currently active global theme.

static bool themeUsesDarkAppearance(Theme theme)

Returns whether a theme uses dark-backed chrome and material tokens.

static void refreshTheme()

Re-broadcasts the current theme to repaint after a design-token change.

static int themeGeneration()

Monotonic counter bumped on every theme change, for staleness checks.

Theme effectiveTheme() const

Resolves the theme used by this element, honoring an inherited QWidget override.

bool effectiveThemeUsesDarkAppearance() const

Returns whether this element's effective theme uses dark-backed chrome.

bool setThemeOverrides(const QJsonObject& overrides)

Replaces this element's sparse color, radius, and font token overrides.

QJsonObject themeOverrides() const

Returns this element's authored overrides.

void clearThemeOverrides()

Restores all token fields to global theme defaults.

const Colors& themeColorsRef() const

Non-copying access to the active color set for hot paint paths.

Material::AcrylicToken themeAcrylic() const

Material, elevation, and adaptive layout tokens.

QColor themeBackdrop(bool active) const

Window-chrome backdrop color for the given activation state.

virtual void onThemeUpdated()

Called after the global theme changes.

Enumerations

enum Theme

Global visual theme used when resolving design tokens.

  • Light = 0
  • Dark = 1
  • HighContrast = 2

Types and aliases

struct Colors

Design token snapshots returned to components.

Inherited from fluent::QMLPlus

Methods

AnchorLayout::Anchors* anchors()

Returns mutable anchors for the QWidget host.

void setState(const QString& name)

Applies a registered state by name, or restores the default state when @p name is empty. Unknown names are ignored, and existing bindings resume when leaving the state.

void addState(const QMLState& state)

Registers or replaces a named state definition; replacing the active state applies it immediately.

void evaluateStates()

Reevaluates state conditions in registration order and activates the first match, or the default state if none match. Also runs automatically when dependency properties notify; derived states using extend inherit ancestor changes unless cyclic or missing.

QMLPlusRuntime* runtime()

Returns the lazily created state observer owned by this host.

void setAnchors(const AnchorLayout::Anchors& anchors)

Replaces all host anchors and invalidates the parent layout.

void resetAnchors()

Clears all host anchors and invalidates the parent layout.

void bind(const char* targetProp, QObject* source, const char* sourceProp, PropertyBinder::Direction dir = PropertyBinder::OneWay)

Binds @p sourceProp on @p source to @p targetProp on this QWidget host via PropertyBinder::bind().

void addTransition(const StateTransition& transition)

Registers a state transition in precedence order.

void setBehavior(const char* propertyName, const PropertyAnimation& animation)

Sets the default animation used when @p propertyName is written via writeProperty() or a binding. Explicit StateTransition rules take precedence; direct C++ setter calls are not animated.

void clearBehavior(const char* propertyName)

Removes the default animation for future managed writes.

bool writeProperty(const char* propertyName, const QVariant& value)

Writes a host property through Behavior without removing its binding.

Qt base class docs: QWidget