src/WhiskerToolbox/Media_Widget/Core/MediaWidgetStateData.hpp
src/WhiskerToolbox/Media_Widget/Core/MediaWidgetStateData.hpp
Comprehensive serializable state data structure for MediaWidget. More…
Classes
| Name | |
|---|---|
| struct | TextOverlayData Serializable text overlay data. |
| struct | LineInteractionPrefs User preferences for line interaction tools. |
| struct | MaskInteractionPrefs User preferences for mask interaction tools. |
| struct | PointInteractionPrefs User preferences for point interaction. |
| struct | RulerPrefs User preferences for media viewer pixel rulers. |
| struct | ViewportState Viewport/camera state for the media display. |
| struct | SelectToolPrefs Preferences for the Media Viewer Select tool. |
| struct | EraserToolPrefs Preferences for the Media Viewer Eraser tool. |
| struct | SmoothToolPrefs Preferences for the Media Viewer Smooth tool. |
| struct | MediaWidgetStateData Complete serializable state for MediaWidget. |
Types
| Name | |
|---|---|
| enum class | TextOverlayOrientation { Horizontal, Vertical} Orientation for text overlays. |
| enum class | LineAppendEndpoint { Tip, Base, Nearest} Endpoint policy for Pen tool line appending. |
| enum class | PenLineTargetMode { SelectedLine, NewLine} Pen tool target for line create/edit operations. |
| enum class | RulerTickMode { Auto, Fixed} Tick spacing mode for media viewer rulers. |
| enum class | LineToolMode { None, Add, Erase, Select, DrawAllFrames} Active mode for line tools. |
| enum class | MaskToolMode { None, Brush} Active mode for mask tools. |
| enum class | PointToolMode { None, Select} Active mode for point tools. |
Detailed Description
Comprehensive serializable state data structure for MediaWidget.
This file defines the full state structure that MediaWidgetState serializes to JSON using reflect-cpp. It captures all persistent state needed for workspace save/restore:
- Display options for all data types (lines, masks, points, tensors, intervals, media)
- Viewport state (zoom, pan, canvas size)
- Interaction preferences (line tools, mask brush, point selection)
- Text overlays
- Active tool modes
Design Principles
- Nested objects for clarity - Unlike DisplayOptions which use rfl::Flatten, this top-level structure uses nested objects for clear JSON organization
- Native enum serialization - Enums serialize as strings automatically
- No Qt types - All Qt types converted to std equivalents (QString → std::string)
- Transient state excluded - Hover positions, drag state, preview flags are NOT included
Example JSON Output
{
"instance_id": "abc123",
"display_name": "Media Viewer",
"displayed_media_key": "video.mp4",
"viewport": {
"zoom": 2.0,
"pan_x": 100.0,
"pan_y": 50.0
},
"line_options": {
"whisker_1": { "hex_color": "#ff0000", "line_thickness": 3 }
},
"active_line_mode": "Add"
}MediaWidgetState for the Qt wrapper class
DisplayOptions.hpp for per-feature display option types
Types Documentation
enum TextOverlayOrientation
| Enumerator | Value | Description |
|---|---|---|
| Horizontal | Normal horizontal text. | |
| Vertical | Rotated 90 degrees for vertical display. |
Orientation for text overlays.
Serializes as “Horizontal” or “Vertical” automatically. Matches the TextOrientation enum in MediaText_Widget.hpp
enum LineAppendEndpoint
| Enumerator | Value | Description |
|---|---|---|
| Tip | Append at line.back(). | |
| Base | Prepend at line.front(). | |
| Nearest | Choose the closer of front/back to the click. |
Endpoint policy for Pen tool line appending.
Serializes as “Tip”, “Base”, or “Nearest”
enum PenLineTargetMode
| Enumerator | Value | Description |
|---|---|---|
| SelectedLine | Append to or delete from the currently selected line entity. | |
| NewLine | Create a new Line2D entity in pen_new_line_key on click. |
Pen tool target for line create/edit operations.
Serializes as “SelectedLine” or “NewLine”
enum RulerTickMode
| Enumerator | Value | Description |
|---|---|---|
| Auto | Nice-number intervals based on visible range. | |
| Fixed | Fixed interval in media pixels. |
Tick spacing mode for media viewer rulers.
enum LineToolMode
| Enumerator | Value | Description |
|---|---|---|
| None | No line tool active. | |
| Add | Adding points to line. | |
| Erase | Erasing points from line. | |
| Select | Selecting lines. | |
| DrawAllFrames | Drawing across all frames. |
Active mode for line tools.
Serializes as “None”, “Add”, “Erase”, “Select”, or “DrawAllFrames”
enum MaskToolMode
| Enumerator | Value | Description |
|---|---|---|
| None | No mask tool active. | |
| Brush | Brush painting mode. |
Active mode for mask tools.
Serializes as “None” or “Brush”
enum PointToolMode
| Enumerator | Value | Description |
|---|---|---|
| None | No point tool active. | |
| Select | Point selection mode. |
Active mode for point tools.
Serializes as “None” or “Select”
Source code
#ifndef MEDIA_WIDGET_STATE_DATA_HPP
#define MEDIA_WIDGET_STATE_DATA_HPP
#include "Core/LineEditOperations.hpp"
#include "UI/Tools/MediaToolId.hpp"
#include "DisplayOptions/DisplayOptions.hpp"
#include "CorePlotting/Layout/CanvasCoordinateSystem.hpp"
#include <rfl.hpp>
#include <rfl/json.hpp>
#include <map>
#include <string>
#include <vector>
// ==================== Text Overlay Data ====================
enum class TextOverlayOrientation {
Horizontal,
Vertical
};
struct TextOverlayData {
int id = -1;
std::string text;
TextOverlayOrientation orientation = TextOverlayOrientation::Horizontal;
float x_position = 0.5f;
float y_position = 0.5f;
std::string color = "#ffffff";
int font_size = 12;
bool enabled = true;
};
// ==================== Interaction Preferences ====================
enum class LineAppendEndpoint {
Tip,
Base,
Nearest
};
enum class PenLineTargetMode {
SelectedLine,
NewLine
};
struct LineInteractionPrefs {
std::string smoothing_mode = "SimpleSmooth";
int polynomial_order = 3;
bool edge_snapping_enabled = false;
int edge_threshold = 100;
int edge_search_radius = 20;
int eraser_radius = 10;
float selection_threshold = 15.0f;
LineAppendEndpoint append_endpoint = LineAppendEndpoint::Tip;
PenLineTargetMode pen_target_mode = PenLineTargetMode::SelectedLine;
std::string pen_new_line_key;
};
struct MaskInteractionPrefs {
int brush_size = 15;
bool hover_circle_visible = true;
bool allow_empty_mask = false;
float selection_threshold = 5.0f;
};
struct PointInteractionPrefs {
float selection_threshold = 10.0f;
};
// ==================== Ruler Preferences ====================
enum class RulerTickMode {
Auto,
Fixed
};
struct RulerPrefs {
bool enabled = true;
RulerTickMode tick_mode = RulerTickMode::Auto;
int fixed_interval_px = 100;
int target_tick_count = 7;
bool show_minor_ticks = true;
std::string negative_color = "#FF9966";
};
// ==================== Viewport State ====================
struct ViewportState {
double zoom = 1.0;
double pan_x = 0.0;
double pan_y = 0.0;
int canvas_width = 640;
int canvas_height = 480;
};
// ==================== Tool Mode Enums ====================
enum class LineToolMode {
None,
Add,
Erase,
Select,
DrawAllFrames
};
enum class MaskToolMode {
None,
Brush
};
enum class PointToolMode {
None,
Select
};
struct SelectToolPrefs {
bool filter_to_key = false;
std::string filter_key;
std::string filter_data_type;
float pick_radius_px = 15.0f;
};
struct EraserToolPrefs {
int radius_px = 10;
};
struct SmoothToolPrefs {
int radius_px = 10;
LineSmoothAlgorithm algorithm = LineSmoothAlgorithm::MovingAverage;
int polynomial_order = 3;
int strength = 1;
};
// ==================== Main State Structure ====================
struct MediaWidgetStateData {
// === Identity ===
std::string instance_id;
std::string display_name = "Media Viewer";
// === Primary Display ===
std::string displayed_media_key;
// === Viewport (nested object in JSON) ===
ViewportState viewport;
// === Canvas Coordinate System Override ===
bool canvas_coord_override_active{false};
int canvas_coord_override_width{640};
int canvas_coord_override_height{480};
// === Per-Feature Display Options ===
// Each key is a data key (e.g., "whisker_1"), value is the display options.
// The 'is_visible' field in each options struct indicates if that feature is enabled.
std::map<std::string, MediaDisplayOptions> media_options;
std::map<std::string, LineDisplayOptions> line_options;
std::map<std::string, MaskDisplayOptions> mask_options;
std::map<std::string, PointDisplayOptions> point_options;
std::map<std::string, DigitalIntervalDisplayOptions> interval_options;
std::map<std::string, TensorDisplayOptions> tensor_options;
// === Interaction Preferences (nested objects in JSON) ===
LineInteractionPrefs line_prefs;
MaskInteractionPrefs mask_prefs;
PointInteractionPrefs point_prefs;
RulerPrefs ruler_prefs;
SelectToolPrefs select_prefs;
EraserToolPrefs eraser_prefs;
SmoothToolPrefs smooth_prefs;
// === Text Overlays ===
std::vector<TextOverlayData> text_overlays;
int next_overlay_id = 0;
// === Active Tool State ===
MediaToolId active_media_tool = MediaToolId::Select;
LineToolMode active_line_mode = LineToolMode::None;
MaskToolMode active_mask_mode = MaskToolMode::None;
PointToolMode active_point_mode = PointToolMode::None;
// === UI Preferences ===
bool developer_mode = false;
};
#endif// MEDIA_WIDGET_STATE_DATA_HPPUpdated on 2026-11-13 at 20:25:45 +0000