1#ifndef YODAU_FRONTEND_WIDGETS_BOARD_HPP
2#define YODAU_FRONTEND_WIDGETS_BOARD_HPP
13
14
15
16
17
18
19
20
21
22
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
44
45
46
47
48
49
50
51
52
56
57
58
59
63
64
65
66
70
71
72
73
74
75
76
77
78
79
83
84
85
86
90
91
92
93
94
95
96
97
98
99
100
114
void clear_active()
Clear active mode and return the active cell to the grid.
QWidget * active_container
Container widget for the active stream view.
board(QWidget *parent=nullptr)
Construct the board widget.
void set_active_stream(const QString &name)
Make a stream active by name.
stream_cell * active_cell() const
Get the currently active (focused) stream cell, if any.
QVBoxLayout * active_layout
Layout inside active_container.
grid_view * grid_mode() const
Access the grid view (thumbnail mode).
stream_cell * take_active_cell()
Detach and return the active cell without putting it back to grid.
stream_cell * active_tile
Currently active stream cell (reparented into active container).
grid_view * grid
Grid view holding all non-active stream cells.
bool drawing_new_mode
True if active edit mode is "draw new line".
void on_active_template_selected(const QString &template_name)
Handler for selecting a template while in template mode.
static QString points_str_from_pct(const std::vector< QPointF > &pts)
Convert draft points to backend format string.
void on_active_line_undo_requested()
Handler for undoing last draft point.
void update_analysis_caps()
Update backend analysis interval based on visible tile count.
void update_repaint_caps()
Update repaint interval caps for all visible tiles.
void on_backend_event(const yodau::backend::event &e)
Handle a single backend event (GUI-thread safe).
QColor draft_line_color
Draft line preview color.
void on_active_template_color_changed(const QColor &color)
Handler for changing template preview color.
QMap< QString, std::vector< stream_cell::line_instance > > per_stream_lines
Per-stream persistent line instances keyed by stream name.
QMap< QString, bool > stream_loops
Remembered stream loop flags keyed by stream name.
stream_cell * active_cell_checked(const QString &fail_prefix)
Get active cell or log a failure.
void on_active_template_add_requested(const QString &template_name, const QColor &color)
Handler for adding the selected template to the active stream.
QMap< QString, QUrl > stream_sources
Remembered stream sources (as QUrl) keyed by stream name.
void on_active_edit_mode_changed(bool drawing_new)
Handler for toggling active edit mode.
static QString now_ts()
Current wall-clock timestamp as human-readable string.
void on_backend_events(const std::vector< yodau::backend::event > &evs)
Handle a batch of backend events.
yodau::backend::stream_manager * stream_mgr
Backend stream manager (non-owning).
void handle_add_url(const QString &url, const QString &name)
Handler for adding a network URL stream from UI.
void on_active_line_params_changed(const QString &name, const QColor &color, bool closed)
Handler for changes to "new line" draft parameters.
QSet< QString > used_template_names_for_stream(const QString &stream) const
Collect template names already used by a stream.
void register_stream_in_ui(const QString &final_name, const QString &source_desc)
Add newly created backend stream into UI structures.
void handle_backend_event(const QString &text)
Append a textual message to the "active log" in settings.
void setup_grid_connections()
Connect grid_view signals to controller handlers.
void handle_show_stream_changed(const QString &name, bool show)
Handler for stream visibility toggles in UI.
void apply_added_line(stream_cell *cell, const QString &final_name, const std::vector< QPointF > &pts, bool closed)
Apply effects of a newly added line to UI and state.
void log_active(const QString &msg) const
Append a message to the active log (if settings exists).
void handle_detect_local_sources()
Handler for detecting available local sources.
stream_cell * tile_for_stream_name(const QString &name) const
Resolve a tile widget for a given stream name.
QStringList template_candidates_excluding(const QSet< QString > &used) const
List templates not present in a given used set.
void handle_back_to_grid()
Return to grid mode (clear active stream).
QMap< QString, tpl_line > templates
Template registry keyed by template name.
void on_active_line_save_requested(const QString &name, bool closed)
Handler for saving a newly drawn draft line.
void handle_thumb_activate(const QString &name)
Convenience alias for activating a thumbnail stream.
void on_active_labels_enabled_changed(bool on)
Handler for toggling persistent label visibility in active view.
void sync_active_cell_lines() const
Push per-stream persistent lines into the active UI cell.
void handle_add_local(const QString &source, const QString &name)
Handler for adding a local capture device from UI.
void sync_active_persistent()
Sync persistent line overlays and template candidates for active stream.
int active_interval_ms
Repaint interval for active (focused) stream in ms.
grid_view * grid
Grid view extracted from board (non-owning).
yodau::backend::frame frame_from_image(const QImage &image) const
Convert a QImage into backend frame.
void setup_settings_connections()
Connect settings_panel signals to controller slots.
void handle_enlarge_requested(const QString &name)
Handle focus/enlarge requests from grid tiles.
void apply_template_preview(const QString &template_name)
Apply a template preview into the active cell draft.
settings_panel * settings
Settings panel (non-owning).
void handle_add_stream_common(const QString &source, const QString &name, const QString &type, bool loop)
shared implementation for add-stream commands.
bool active_labels_enabled
Whether labels are enabled in active cell.
static int repaint_interval_for_count(int n)
Choose repaint interval given number of visible streams.
board * main_zone
Main board/zone widget (non-owning).
QString active_name
Name of currently active stream (empty if none).
void init_from_backend()
Populate settings UI from backend at startup.
QString draft_line_name
Draft line name being edited.
int idle_interval_ms
Repaint interval for idle grid streams in ms.
bool draft_line_closed
Draft line closed flag.
void on_gui_frame(const QString &stream_name, const QImage &image)
Slot receiving GUI frames from stream tiles.
grid_view(QWidget *parent=nullptr)
Construct an empty grid view.
void remove_stream(const QString &name)
Remove a stream cell from the grid.
void add_stream(const QString &name)
Add a new stream cell to the grid.
stream_cell * peek_stream_cell(const QString &name) const
Get a pointer to a cell without removing it.
void stream_enlarge(const QString &name)
Emitted when a stream cell requests focus/enlargement.
void add_stream_entry(const QString &name, const QString &source, bool checked=false) const
Add a stream row to the streams list.
void active_line_undo_requested()
Emitted when user requests undo of the last draft point.
QWidget * build_streams_tab()
Build the "streams" tab.
QPushButton * active_line_undo_btn
QSet< QString > existing_names
Reserved names used for uniqueness checks.
void on_active_template_add_clicked()
"Add template" click handler.
QPushButton * choose_file_btn
void show_stream_changed(const QString &name, bool show)
Emitted when a stream's "show in grid" state changes.
settings_panel(QWidget *parent=nullptr)
Construct the settings panel.
void append_event(const QString &text) const
Append a line to the streams-tab event log.
QLineEdit * active_line_name_edit
void set_btn_color(QPushButton *btn, const QColor &c) const
Paint a QPushButton background to match a chosen color.
void append_active_log(const QString &msg) const
Append a line to the active-tab log.
void clear_add_inputs() const
Clear all add-tab input fields and reset validation.
bool current_input_valid() const
Validate that required input fields for current mode are filled.
QWidget * build_templates_box(QWidget *parent)
Build templates form box.
QGroupBox * active_mode_box
void reset_active_template_form()
Reset the templates form to "none" selection.
QPushButton * refresh_local_btn
void reset_active_line_form()
Reset the "new line" form in the active tab.
QWidget * build_active_tab()
Build the "active" tab.
void update_add_enabled() const
Update enabled state of the "add" button based on validation.
void build_ui()
Build all tabs and root layout.
QPlainTextEdit * event_log_view
void on_active_template_color_clicked()
"Choose template color" click handler.
void set_stream_checked(const QString &name, bool checked) const
Set the "show" checkbox state for a stream entry.
void active_template_selected(const QString &template_name)
Emitted when template selection changes.
QPlainTextEdit * add_log_view
void add_local_stream(const QString &source, const QString &name)
User requested adding a local capture stream.
void set_name_error(bool error) const
Apply/remove UI error styling for name edit.
void on_active_line_color_clicked()
"Choose line color" click handler.
void on_active_line_closed_toggled(bool checked)
Closed-checkbox toggle handler.
void remove_stream_entry(const QString &name) const
Remove a stream entry from the streams list.
QPushButton * active_template_add_btn
void on_add_clicked()
"Add" button handler.
QTreeWidget * streams_list
QTabWidget * tabs
Tab widget hosting add/streams/active tabs.
void append_add_log(const QString &text) const
Append a line to the add-tab log.
void on_active_template_combo_changed(const QString &text)
Template combo change handler.
void clear_stream_entries()
Remove all stream entries and clear name reservations.
QWidget * build_active_stream_box(QWidget *parent)
Build active-stream selection box.
void add_existing_name(const QString &name)
Add one name to the existing-name set.
QPushButton * active_template_color_btn
void set_active_line_closed(bool closed) const
Programmatically set active draft "closed" checkbox.
QPushButton * active_line_save_btn
void active_stream_selected(const QString &name)
Emitted when the active stream selection changes.
void active_line_save_requested(const QString &name, bool closed)
Emitted when user clicks "add line" in active tab.
bool name_is_unique(const QString &name) const
Check if name is not already reserved.
void active_edit_mode_changed(bool drawing_new)
Emitted when edit mode changes.
void active_labels_enabled_changed(bool on)
Emitted when label visibility toggle changes.
void active_line_params_changed(const QString &name, const QColor &color, bool closed)
Emitted when any draft-line parameter changes.
QString resolved_name_for_current_input() const
Resolve the name for the current input (trimmed).
void on_active_mode_clicked(int id)
Edit-mode radio click handler.
QCheckBox * active_line_closed_cb
QGroupBox * add_local_box
void set_local_sources(const QStringList &sources) const
Set detected local sources (e.g., /dev/video*).
input_mode
Input mode for the add-tab.
QRadioButton * active_mode_draw_radio
void update_add_tools() const
Update visibility/enabled state of add-tab tool boxes.
QCheckBox * loop_checkbox
void active_template_add_requested(const QString &template_name, const QColor &color)
Emitted when user adds a template instance to active stream.
void active_template_color_changed(const QColor &color)
Emitted when template preview color changes.
QCheckBox * active_labels_cb
void on_active_line_save_clicked()
"Add line" click handler.
void remove_existing_name(const QString &name)
Remove one name from the existing-name set.
void detect_local_sources_requested()
User requested re-detection of local sources.
QString active_template_current() const
Get currently selected template name.
void set_template_candidates(const QStringList &names) const
Replace the list of template candidates.
QColor active_template_preview_color() const
Get current preview color for templates.
QComboBox * local_sources_combo
void add_template_candidate(const QString &name) const
Add one template name as a candidate in the templates combo.
QGroupBox * active_line_box
QColor active_template_color
QButtonGroup * active_mode_group
QWidget * build_edit_mode_box(QWidget *parent)
Build edit-mode radio group.
QWidget * build_add_tab()
Build the "add stream" tab.
QRadioButton * local_radio
void set_active_candidates(const QStringList &names) const
Set the list of streams that can be selected as active.
void on_active_line_name_finished()
Line name edit finished handler.
void set_mode(input_mode mode)
Switch add-tab mode and refresh enabled/visible controls.
QRadioButton * file_radio
void on_name_changed(QString text) const
Handler for name edit changes (validation).
void on_refresh_local()
"Refresh local sources" handler.
void on_active_line_undo_clicked()
"Undo point" click handler.
void clear_active_log() const
Clear the active-tab log view.
void set_existing_names(QSet< QString > names)
Replace the set of existing (reserved) names.
QPushButton * active_line_color_btn
QPlainTextEdit * active_log_view
QLineEdit * file_path_edit
QButtonGroup * mode_group
void on_stream_item_changed(QTreeWidgetItem *item, int column)
Streams list item change handler (checkbox column).
void update_active_tools() const
Show/hide active-tab tool boxes based on selection/mode.
void set_active_current(const QString &name) const
Programmatically select the active stream.
QRadioButton * active_mode_template_radio
QWidget * build_new_line_box(QWidget *parent)
Build "new line" form box.
void on_choose_file()
File chooser handler.
void add_url_stream(const QString &url, const QString &name)
User requested adding a URL stream.
QGroupBox * active_templates_box
QComboBox * active_template_combo
void add_event(const QPointF &pos_pct, const QColor &color)
Add a transient event marker.
QImage last_frame
Most recent received frame as an image.
void mousePressEvent(QMouseEvent *event) override
Mouse press handler for drawing draft points.
int repaint_interval_ms
Minimum repaint interval in ms.
QHash< QString, QDateTime > line_highlights
Line highlight timestamps by line name.
std::vector< QPointF > draft_line_points_pct
Draft polyline points in percentage coordinates.
void set_loop(bool on)
Enable or disable looping for file-based playback.
void mouseMoveEvent(QMouseEvent *event) override
Mouse move handler for hover updates while drawing.
QMediaPlayer * player
Media player for file/URL sources.
void update_icon()
Update focus button icon/tooltip based on active state.
QPushButton * close_btn
UI close button (top-right).
void draw_hover_point(QPainter &p) const
Draw hover point indicator (if any).
bool is_active() const
Check whether this cell is currently active (focused).
bool active
Whether the cell is focused/active.
bool drawing_enabled
Whether interactive drawing is enabled.
QString draft_line_name
Draft line name.
std::vector< line_instance > persistent_lines
Persisted lines to render.
bool labels_enabled
Whether persistent line labels are shown when active.
void set_active(bool val)
Set active (focused) state.
void set_repaint_interval_ms(int ms)
Set minimum repaint interval for video frame updates.
QHash< QString, hit_info > line_hits
Optional hit positions per line name.
void draw_stream_name(QPainter &p) const
Draw stream name overlay at top-left.
void set_source(const QUrl &source)
Set media player source.
void set_persistent_lines(const std::vector< line_instance > &lines)
Replace all persistent lines.
bool draft_closed() const
Get whether current draft line is closed.
void set_camera_id(const QByteArray &id)
Switch to camera input by device id.
void paintEvent(QPaintEvent *event) override
Paint handler.
void draw_preview_segment(QPainter &p) const
Draw preview segment from last draft point to hover point.
QCamera * camera
Active camera (if using live input).
QColor draft_line_color
Draft line color.
void set_labels_enabled(bool on)
Enable or disable rendering of persistent line labels.
void draw_draft(QPainter &p) const
Draw the draft line (if any).
QVideoSink * sink
Video sink feeding decoded frames into the widget.
QByteArray camera_id
Selected camera id.
int line_highlight_ttl_ms
Highlight time-to-live in ms.
void clear_draft()
Clear all draft data (points, hover point, preview flag).
void clear_persistent_lines()
Remove all persistent lines.
QMediaCaptureSession * session
Capture session binding camera to sink.
QLabel * name_label
Optional name label (unused in current implementation).
void leaveEvent(QEvent *event) override
Leave handler to clear hover state.
void draw_persistent(QPainter &p) const
Draw all persistent lines and their labels/highlights.
void on_camera_error(QCamera::Error error)
Slot called on camera errors.
QElapsedTimer repaint_timer
Timer throttling repaint frequency.
void draw_events(QPainter &p)
Draw transient events and prune expired ones.
void set_draft_preview(bool on)
Enable or disable draft preview mode.
QPointF to_px(const QPointF &pos_pct) const
Convert percentage coordinates to pixel position.
void set_draft_points_pct(const std::vector< QPointF > &pts)
Replace current draft points (percentage coordinates).
const QString & get_name() const
Get logical name of this stream cell.
bool loop_enabled
Whether playback looping is enabled.
QPushButton * focus_btn
UI focus/enlarge button (top-right).
QString name
Logical stream name.
void draw_poly_with_points(QPainter &p, const std::vector< QPointF > &pts_pct, const QColor &color, bool closed, Qt::PenStyle style, qreal width) const
Draw a polyline/polygon with point markers.
void add_persistent_line(const line_instance &line)
Append a persistent line to the list.
void draw_hover_coords(QPainter &p) const
Draw hover coordinate text (if enabled).
QColor draft_color() const
Get current draft line color.
QPointF label_pos_px(const line_instance &l) const
Compute label anchor position for a line in pixel coordinates.
void set_drawing_enabled(bool on)
Enable or disable interactive drawing on this cell.
bool draft_line_closed
Draft line closed flag.
QString draft_name() const
Get current draft line name.
QString last_error
Last error string to display when no frame is available.
QVector< event_instance > events
Transient events currently displayed.
void keyPressEvent(QKeyEvent *event) override
Key press handler for draft undo.
void build_ui()
Build child UI widgets (buttons, sink/player connections).
std::vector< QPointF > draft_points_pct() const
Get current draft polyline points (percentage coordinates).
void on_media_status_changed(QMediaPlayer::MediaStatus status)
Slot called on media status changes.
bool draft_preview
Whether draft line is shown in preview mode.
QPointF to_pct(const QPointF &pos_px) const
Convert pixel position to percentage coordinates.
bool is_draft_preview() const
Check whether the draft is in preview-only mode.
std::optional< QPointF > hover_point_pct
Current hover position in percentage coordinates.
Central coordinator for streams, geometry, frame processing and events.
Represents a single video stream and its analytic connections.
event_kind
High-level classification of backend events.
pixel_format
Pixel format of a frame buffer.
stream_type
Source/transport type of a video stream.
#define str_label(text)
Create a user-visible localized label.
Stored template geometry (percentage coordinates).
std::vector< QPointF > pts_pct
Template vertices in percentage coordinates.
bool closed
Whether template is closed.
Instance of a transient visual event marker.
QPointF pos_pct
Event position in percentage coordinates.
QDateTime ts
Timestamp when event was added.
Hit info attached to a line highlight.
QDateTime ts
Hit timestamp.
QPointF pos_pct
Hit position in percentage coordinates.
Instance of a persistent (saved) line to be rendered on the stream.
Generic event produced by the backend.
event_kind kind
Type of the event.
std::string line_name
Name of the line / ROI / rule responsible for this event.
int width
Frame width in pixels.
int stride
Number of bytes per row.
int height
Frame height in pixels.
pixel_format format
Pixel format of the buffer.