Skip to main content

MediaWidgetState

MediaWidgetState

State class for Media_Widget. More…

#include <MediaWidgetState.hpp>

Inherits from EditorState, QObject

Public Signals

Name
void displayedDataKeyChanged(QString const & key)
Emitted when the displayed data key changes.
void zoomChanged(double zoom)
Emitted when zoom changes.
void panChanged(double x, double y)
Emitted when pan position changes.
void canvasSizeChanged(int width, int height)
Emitted when canvas size changes.
void viewportChanged()
Emitted when any viewport property changes.
void canvasCoordinateSystemChanged(CanvasCoordinateSystem const & coord_system)
Emitted when the canvas coordinate system changes.
void featureEnabledChanged(QString const & data_key, QString const & data_type, bool enabled)
Emitted when a feature’s enabled state changes.
void displayOptionsChanged(QString const & data_key, QString const & data_type)
Emitted when display options for a feature change.
void displayOptionsRemoved(QString const & data_key, QString const & data_type)
Emitted when display options for a feature are removed.
void interactionPrefsChanged(QString const & category)
Emitted when any interaction preferences change (consolidated).
void rulerPrefsChanged()
Emitted when ruler display preferences change.
void selectPrefsChanged()
Emitted when Select tool preferences change.
void eraserPrefsChanged()
Emitted when Eraser tool preferences change.
void smoothPrefsChanged()
Emitted when Smooth tool preferences change.
void textOverlaysChanged()
Emitted when any text overlay operation occurs (consolidated).
void toolModesChanged(QString const & category)
Emitted when any active tool mode changes (consolidated).
void activeMediaToolChanged(MediaToolId tool)
Emitted when the global Media Viewer toolbar tool changes.
void developerModeChanged(bool enabled)
Emitted when developer mode is toggled.
void canvasImageChanged(QImage const & image)
Emitted when the rendered canvas image changes.

Public Functions

Name
MediaWidgetState(QObject * parent =[nullptr])
Construct a new MediaWidgetState.
~MediaWidgetState() override =default
virtual QString getTypeName() const override
Get the type name for this state.
virtual QString getDisplayName() const override
Get the display name for UI.
virtual void setDisplayName(QString const & name) override
Set the display name.
virtual std::string toJson() const override
Serialize state to JSON.
virtual bool fromJson(std::string const & json) override
Restore state from JSON.
MediaWidgetStateData const & data() const
Get const reference to underlying data for efficiency.
DisplayOptionsRegistry & displayOptions()
Get the display options registry for generic access.
DisplayOptionsRegistry const & displayOptions() const
void setDisplayedDataKey(QString const & key)
Set the displayed data key.
QString displayedDataKey() const
Get the displayed data key.
void setZoom(double zoom)
Set the zoom level.
double zoom() const
Get the zoom level.
void setPan(double x, double y)
Set the pan offset.
std::pair< double, double > pan() const
Get the pan offset.
void setCanvasSize(int width, int height)
Set the canvas size.
std::pair< int, int > canvasSize() const
Get the canvas size.
ViewportState const & viewport() const
Get the complete viewport state.
void setViewport(ViewportState const & viewport)
Set the complete viewport state.
CanvasCoordinateSystem const & canvasCoordinateSystem() const
Get the current canvas coordinate system.
void setCanvasCoordinateSystem(CanvasCoordinateSystem const & coord_system)
Set the resolved canvas coordinate system (called by Media_Window).
bool isCanvasCoordOverrideActive() const
Check if the user has manually overridden the coordinate system.
void setCanvasCoordOverride(int width, int height)
Set a manual canvas coordinate system override.
void clearCanvasCoordOverride()
Clear the manual canvas coordinate system override.
void setFeatureEnabled(QString const & data_key, QString const & data_type, bool enabled)
Enable or disable a feature.
bool isFeatureEnabled(QString const & data_key, QString const & data_type) const
Check if a feature is enabled.
QStringList enabledFeatures(QString const & data_type) const
Get list of enabled features for a data type.
LineInteractionPrefs const & linePrefs() const
Get line interaction preferences.
void setLinePrefs(LineInteractionPrefs const & prefs)
Set line interaction preferences.
MaskInteractionPrefs const & maskPrefs() const
Get mask interaction preferences.
void setMaskPrefs(MaskInteractionPrefs const & prefs)
Set mask interaction preferences.
PointInteractionPrefs const & pointPrefs() const
Get point interaction preferences.
void setPointPrefs(PointInteractionPrefs const & prefs)
Set point interaction preferences.
RulerPrefs const & rulerPrefs() const
Get ruler display preferences.
void setRulerPrefs(RulerPrefs const & prefs)
Set ruler display preferences.
SelectToolPrefs const & selectPrefs() const
Get Select tool preferences.
void setSelectPrefs(SelectToolPrefs const & prefs)
Set Select tool preferences.
EraserToolPrefs const & eraserPrefs() const
Get Eraser tool preferences.
void setEraserPrefs(EraserToolPrefs const & prefs)
Set Eraser tool preferences.
SmoothToolPrefs const & smoothPrefs() const
Get Smooth tool preferences.
void setSmoothPrefs(SmoothToolPrefs const & prefs)
Set Smooth tool preferences.
void setDeveloperMode(bool enabled)
Toggle the developer diagnostics panel.
bool developerMode() const
Get whether developer mode is enabled.
std::vector< TextOverlayData > const & textOverlays() const
Get all text overlays.
int addTextOverlay(TextOverlayData overlay)
Add a text overlay.
bool removeTextOverlay(int overlay_id)
Remove a text overlay by ID.
bool updateTextOverlay(int overlay_id, TextOverlayData const & overlay)
Update an existing text overlay.
void clearTextOverlays()
Clear all text overlays.
TextOverlayData const * getTextOverlay(int overlay_id) const
Get a text overlay by ID.
void setActiveMediaTool(MediaToolId tool)
Set the active global Media Viewer toolbar tool.
MediaToolId activeMediaTool() const
Get the active global Media Viewer toolbar tool.
void setActiveLineMode(LineToolMode mode)
Set the active line tool mode.
LineToolMode activeLineMode() const
Get the active line tool mode.
void setActiveMaskMode(MaskToolMode mode)
Set the active mask tool mode.
MaskToolMode activeMaskMode() const
Get the active mask tool mode.
void setActivePointMode(PointToolMode mode)
Set the active point tool mode.
PointToolMode activePointMode() const
Get the active point tool mode.
void setCanvasImage(QImage const & image)
Set the current canvas image.
QImage const & canvasImage() const
Get the current canvas image.

Public Attributes

Name
TimePosition current_position

Additional inherited members

Public Signals inherited from EditorState

Name
void stateChanged()
Emitted when any state property changes.
void displayNameChanged(QString const & newName)
Emitted when display name changes.
void dirtyChanged(bool isDirty)
Emitted when dirty state changes.

Public Functions inherited from EditorState

Name
EditorState(QObject * parent =[nullptr])
Construct a new EditorState.
~EditorState() override =default
Virtual destructor.
QString getInstanceId() const
Get unique instance ID.
bool isDirty() const
Check if state has unsaved changes.
void markClean()
Mark state as clean (after save).

Protected Functions inherited from EditorState

Name
void markDirty()
Mark state as modified.
void setInstanceId(QString const & id)
Set instance ID (for deserialization).
QString generateInstanceId()
Generate a new unique instance ID.

Detailed Description

class MediaWidgetState;

State class for Media_Widget.

MediaWidgetState is the Qt wrapper around MediaWidgetStateData that provides typed accessors and Qt signals for all state properties.

Signal Categories

  • Viewport: zoomChanged, panChanged, canvasSizeChanged
  • Features: featureEnabledChanged, displayOptionsChanged
  • Interaction: linePrefsChanged, maskPrefsChanged, pointPrefsChanged
  • Text Overlays: textOverlayAdded, textOverlayRemoved, textOverlayUpdated
  • Tool Modes: activeLineModeChanged, activeMaskModeChanged, activePointModeChanged

Thread Safety

This class is NOT thread-safe. All access should be from the main/GUI thread.

Public Signals Documentation

signal displayedDataKeyChanged

void displayedDataKeyChanged(
    QString const & key
)

Emitted when the displayed data key changes.

Parameters:

  • key The new displayed data key

signal zoomChanged

void zoomChanged(
    double zoom
)

Emitted when zoom changes.

Parameters:

  • zoom New zoom factor

signal panChanged

void panChanged(
    double x,
    double y
)

Emitted when pan position changes.

Parameters:

  • x New horizontal pan offset
  • y New vertical pan offset

signal canvasSizeChanged

void canvasSizeChanged(
    int width,
    int height
)

Emitted when canvas size changes.

Parameters:

  • width New canvas width
  • height New canvas height

signal viewportChanged

void viewportChanged()

Emitted when any viewport property changes.

signal canvasCoordinateSystemChanged

void canvasCoordinateSystemChanged(
    CanvasCoordinateSystem const & coord_system
)

Emitted when the canvas coordinate system changes.

Parameters:

  • coord_system The new coordinate system

signal featureEnabledChanged

void featureEnabledChanged(
    QString const & data_key,
    QString const & data_type,
    bool enabled
)

Emitted when a feature’s enabled state changes.

Parameters:

  • data_key The data key
  • data_type The type (“line”, “mask”, etc.)
  • enabled New enabled state

signal displayOptionsChanged

void displayOptionsChanged(
    QString const & data_key,
    QString const & data_type
)

Emitted when display options for a feature change.

Parameters:

  • data_key The data key
  • data_type The type (“line”, “mask”, etc.)

signal displayOptionsRemoved

void displayOptionsRemoved(
    QString const & data_key,
    QString const & data_type
)

Emitted when display options for a feature are removed.

Parameters:

  • data_key The data key
  • data_type The type

signal interactionPrefsChanged

void interactionPrefsChanged(
    QString const & category
)

Emitted when any interaction preferences change (consolidated).

Parameters:

  • category “line”, “mask”, or “point”

signal rulerPrefsChanged

void rulerPrefsChanged()

Emitted when ruler display preferences change.

signal selectPrefsChanged

void selectPrefsChanged()

Emitted when Select tool preferences change.

signal eraserPrefsChanged

void eraserPrefsChanged()

Emitted when Eraser tool preferences change.

signal smoothPrefsChanged

void smoothPrefsChanged()

Emitted when Smooth tool preferences change.

signal textOverlaysChanged

void textOverlaysChanged()

Emitted when any text overlay operation occurs (consolidated).

This signal is emitted after any add/remove/update/clear operation.

signal toolModesChanged

void toolModesChanged(
    QString const & category
)

Emitted when any active tool mode changes (consolidated).

Parameters:

  • category “line”, “mask”, or “point”

signal activeMediaToolChanged

void activeMediaToolChanged(
    MediaToolId tool
)

Emitted when the global Media Viewer toolbar tool changes.

Parameters:

  • tool Newly active toolbar tool

signal developerModeChanged

void developerModeChanged(
    bool enabled
)

Emitted when developer mode is toggled.

Parameters:

  • enabled Whether developer diagnostics are shown

signal canvasImageChanged

void canvasImageChanged(
    QImage const & image
)

Emitted when the rendered canvas image changes.

Parameters:

  • image The new canvas image

This signal is emitted by Media_Window after rendering completes. Export_Video_Widget connects to this to capture frames.

Public Functions Documentation

function MediaWidgetState

explicit MediaWidgetState(
    QObject * parent =nullptr
)

Construct a new MediaWidgetState.

Parameters:

  • parent Parent QObject (typically nullptr, managed by WorkspaceManager)

function ~MediaWidgetState

~MediaWidgetState() override =default

function getTypeName

inline virtual QString getTypeName() const override

Get the type name for this state.

Return: “MediaWidget”

Reimplements: EditorState::getTypeName

function getDisplayName

virtual QString getDisplayName() const override

Get the display name for UI.

Return: User-visible name (default: “Media Viewer”)

Reimplements: EditorState::getDisplayName

function setDisplayName

virtual void setDisplayName(
    QString const & name
) override

Set the display name.

Parameters:

  • name New display name

Reimplements: EditorState::setDisplayName

function toJson

virtual std::string toJson() const override

Serialize state to JSON.

Return: JSON string representation

Reimplements: EditorState::toJson

function fromJson

virtual bool fromJson(
    std::string const & json
) override

Restore state from JSON.

Parameters:

  • json JSON string to parse

Return: true if parsing succeeded

Reimplements: EditorState::fromJson

function data

inline MediaWidgetStateData const & data() const

Get const reference to underlying data for efficiency.

Return: Const reference to MediaWidgetStateData

Use this for reading multiple values without individual accessor overhead. For modification, use the typed setters to ensure signals are emitted.

function displayOptions

inline DisplayOptionsRegistry & displayOptions()

Get the display options registry for generic access.

Return: Reference to DisplayOptionsRegistry

The registry provides a unified API for all display option types:


// Set options (type inferred)
LineDisplayOptions opts;
opts.line_thickness = 3;
state->displayOptions().set("whisker_1", opts);

// Get options (type explicit)
auto* opts = state->displayOptions().get<LineDisplayOptions>("whisker_1");

// Get enabled keys
QStringList enabled = state->displayOptions().enabledKeys<LineDisplayOptions>();

function displayOptions

inline DisplayOptionsRegistry const & displayOptions() const

function setDisplayedDataKey

void setDisplayedDataKey(
    QString const & key
)

Set the displayed data key.

Parameters:

  • key Data key to display (empty string to clear)

This represents the primary data being displayed in the Media_Widget. For image/video data, this is typically the media source.

function displayedDataKey

QString displayedDataKey() const

Get the displayed data key.

Return: Currently displayed data key, or empty string if none

function setZoom

void setZoom(
    double zoom
)

Set the zoom level.

Parameters:

  • zoom Zoom factor (1.0 = no zoom)

function zoom

inline double zoom() const

Get the zoom level.

Return: Current zoom factor

function setPan

void setPan(
    double x,
    double y
)

Set the pan offset.

Parameters:

  • x Horizontal pan offset in pixels
  • y Vertical pan offset in pixels

function pan

std::pair< double, double > pan() const

Get the pan offset.

Return: Pair of (x, y) pan offset in pixels

function setCanvasSize

void setCanvasSize(
    int width,
    int height
)

Set the canvas size.

Parameters:

  • width Canvas width in pixels
  • height Canvas height in pixels

function canvasSize

std::pair< int, int > canvasSize() const

Get the canvas size.

Return: Pair of (width, height) in pixels

function viewport

inline ViewportState const & viewport() const

Get the complete viewport state.

Return: Const reference to ViewportState

function setViewport

void setViewport(
    ViewportState const & viewport
)

Set the complete viewport state.

Parameters:

  • viewport New viewport state

function canvasCoordinateSystem

inline CanvasCoordinateSystem const & canvasCoordinateSystem() const

Get the current canvas coordinate system.

Return: The current CanvasCoordinateSystem

This is the resolved coordinate system (after applying the priority chain). Set by Media_Window during UpdateCanvas via resolveCanvasCoordinateSystem().

function setCanvasCoordinateSystem

void setCanvasCoordinateSystem(
    CanvasCoordinateSystem const & coord_system
)

Set the resolved canvas coordinate system (called by Media_Window).

Parameters:

  • coord_system The resolved coordinate system

function isCanvasCoordOverrideActive

inline bool isCanvasCoordOverrideActive() const

Check if the user has manually overridden the coordinate system.

function setCanvasCoordOverride

void setCanvasCoordOverride(
    int width,
    int height
)

Set a manual canvas coordinate system override.

Parameters:

  • width Logical width
  • height Logical height

function clearCanvasCoordOverride

void clearCanvasCoordOverride()

Clear the manual canvas coordinate system override.

The coordinate system will be auto-determined from media/data objects.

function setFeatureEnabled

void setFeatureEnabled(
    QString const & data_key,
    QString const & data_type,
    bool enabled
)

Enable or disable a feature.

Parameters:

  • data_key The data key (e.g., “whisker_1”)
  • data_type The type (“line”, “mask”, “point”, “tensor”, “interval”, “media”)
  • enabled Whether the feature should be visible

This sets the is_visible flag in the corresponding display options. If options don’t exist for this key, they will be created with defaults.

function isFeatureEnabled

bool isFeatureEnabled(
    QString const & data_key,
    QString const & data_type
) const

Check if a feature is enabled.

Parameters:

  • data_key The data key
  • data_type The type

Return: true if the feature exists and is visible

function enabledFeatures

QStringList enabledFeatures(
    QString const & data_type
) const

Get list of enabled features for a data type.

Parameters:

  • data_type The type (“line”, “mask”, etc.)

Return: List of data keys that are enabled

function linePrefs

inline LineInteractionPrefs const & linePrefs() const

Get line interaction preferences.

Return: Const reference to LineInteractionPrefs

function setLinePrefs

void setLinePrefs(
    LineInteractionPrefs const & prefs
)

Set line interaction preferences.

Parameters:

  • prefs The new preferences

function maskPrefs

inline MaskInteractionPrefs const & maskPrefs() const

Get mask interaction preferences.

Return: Const reference to MaskInteractionPrefs

function setMaskPrefs

void setMaskPrefs(
    MaskInteractionPrefs const & prefs
)

Set mask interaction preferences.

Parameters:

  • prefs The new preferences

function pointPrefs

inline PointInteractionPrefs const & pointPrefs() const

Get point interaction preferences.

Return: Const reference to PointInteractionPrefs

function setPointPrefs

void setPointPrefs(
    PointInteractionPrefs const & prefs
)

Set point interaction preferences.

Parameters:

  • prefs The new preferences

function rulerPrefs

inline RulerPrefs const & rulerPrefs() const

Get ruler display preferences.

Return: Const reference to RulerPrefs

function setRulerPrefs

void setRulerPrefs(
    RulerPrefs const & prefs
)

Set ruler display preferences.

Parameters:

  • prefs The new preferences

function selectPrefs

inline SelectToolPrefs const & selectPrefs() const

Get Select tool preferences.

Return: Const reference to SelectToolPrefs

function setSelectPrefs

void setSelectPrefs(
    SelectToolPrefs const & prefs
)

Set Select tool preferences.

Parameters:

  • prefs The new preferences

function eraserPrefs

inline EraserToolPrefs const & eraserPrefs() const

Get Eraser tool preferences.

Return: Const reference to EraserToolPrefs

function setEraserPrefs

void setEraserPrefs(
    EraserToolPrefs const & prefs
)

Set Eraser tool preferences.

Parameters:

  • prefs The new preferences

function smoothPrefs

inline SmoothToolPrefs const & smoothPrefs() const

Get Smooth tool preferences.

Return: Const reference to SmoothToolPrefs

function setSmoothPrefs

void setSmoothPrefs(
    SmoothToolPrefs const & prefs
)

Set Smooth tool preferences.

Parameters:

  • prefs The new preferences

function setDeveloperMode

void setDeveloperMode(
    bool enabled
)

Toggle the developer diagnostics panel.

Parameters:

  • enabled Whether developer mode is active

function developerMode

inline bool developerMode() const

Get whether developer mode is enabled.

Return: true if developer diagnostics are shown

function textOverlays

inline std::vector< TextOverlayData > const & textOverlays() const

Get all text overlays.

Return: Const reference to text overlay vector

function addTextOverlay

int addTextOverlay(
    TextOverlayData overlay
)

Add a text overlay.

Parameters:

  • overlay The overlay data (id field will be overwritten)

Return: The assigned overlay ID

The overlay’s ID will be assigned automatically.

function removeTextOverlay

bool removeTextOverlay(
    int overlay_id
)

Remove a text overlay by ID.

Parameters:

  • overlay_id The overlay ID to remove

Return: true if the overlay was found and removed

function updateTextOverlay

bool updateTextOverlay(
    int overlay_id,
    TextOverlayData const & overlay
)

Update an existing text overlay.

Parameters:

  • overlay_id The overlay ID to update
  • overlay The new overlay data (id field preserved)

Return: true if the overlay was found and updated

function clearTextOverlays

void clearTextOverlays()

Clear all text overlays.

function getTextOverlay

TextOverlayData const * getTextOverlay(
    int overlay_id
) const

Get a text overlay by ID.

Parameters:

  • overlay_id The overlay ID

Return: Pointer to overlay, or nullptr if not found

function setActiveMediaTool

void setActiveMediaTool(
    MediaToolId tool
)

Set the active global Media Viewer toolbar tool.

Parameters:

  • tool The toolbar tool identifier

function activeMediaTool

inline MediaToolId activeMediaTool() const

Get the active global Media Viewer toolbar tool.

Return: Current toolbar tool

function setActiveLineMode

void setActiveLineMode(
    LineToolMode mode
)

Set the active line tool mode.

Parameters:

  • mode The tool mode

function activeLineMode

inline LineToolMode activeLineMode() const

Get the active line tool mode.

Return: Current line tool mode

function setActiveMaskMode

void setActiveMaskMode(
    MaskToolMode mode
)

Set the active mask tool mode.

Parameters:

  • mode The tool mode

function activeMaskMode

inline MaskToolMode activeMaskMode() const

Get the active mask tool mode.

Return: Current mask tool mode

function setActivePointMode

void setActivePointMode(
    PointToolMode mode
)

Set the active point tool mode.

Parameters:

  • mode The tool mode

function activePointMode

inline PointToolMode activePointMode() const

Get the active point tool mode.

Return: Current point tool mode

function setCanvasImage

void setCanvasImage(
    QImage const & image
)

Set the current canvas image.

Parameters:

  • image The rendered canvas image

Called by Media_Window after rendering to update the transient canvas image. This is NOT serialized - it’s only for inter-widget communication.

function canvasImage

inline QImage const & canvasImage() const

Get the current canvas image.

Return: The most recently rendered canvas image (may be null)

Public Attributes Documentation

variable current_position

TimePosition current_position;

Updated on 2026-11-13 at 20:25:40 +0000