1#ifndef YODAU_FRONTEND_WIDGETS_STREAM_CELL_HPP
2#define YODAU_FRONTEND_WIDGETS_STREAM_CELL_HPP
5#include <QCameraDevice>
8#include <QElapsedTimer>
11#include <QMediaCaptureSession>
12#include <QMediaDevices>
13#include <QMediaPlayer>
26
27
28
29
30
31
32
33
34
35
36
37
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
80
81
82
83
84
97
98
99
100
101
102 explicit stream_cell(
const QString& name, QWidget* parent =
nullptr);
105
106
107
111
112
113
117
118
119
123
124
125
129
130
131
135
136
137
141
142
143
144
148
149
150
151
152
153
157
158
159
160
161
162
166
167
168
169
170
171
172
173
175 set_draft_params(
const QString& name,
const QColor& color,
bool closed);
178
179
180
181
185
186
190
191
192
193
197
198
199
200
204
205
209
210
211
212
216
217
218
219
220
221
225
226
227
228
229
230
231
235
236
237
238
242
243
244
245
246
247
248
252
253
254
255
256
267
268
269
270
271
272 void add_event(
const QPointF& pos_pct,
const QColor& color);
275
276
277
278
279
280
284
285
286
287
288
289
290 void highlight_line(
const QString& line_name);
293
294
295
296
297
298
299
300
301 void highlight_line_at(
const QString& line_name,
const QPointF& pos_pct);
305
306
307
308
309
310
314
315
316
317
318
319
320 void request_focus(
const QString& name);
323
324
325
326
327
328
329
330 void frame_ready(
const QString& stream_name,
const QImage& image);
334
335
336
337
338
339
340
341
345
346
350
351
355
356
360
361
371
372
373
374
375
376
377
378
379
380
381
383 QPainter& p,
const std::vector<QPointF>& pts_pct,
const QColor& color,
384 bool closed, Qt::PenStyle style, qreal width
401
402
403
404
408
409
413
414
418
419
424
425
426
427
428
432
433
434
435
439
440
441
442
444 on_player_error(QMediaPlayer::Error error,
const QString& error_string);
447
448
449
450
515
516
517
518
525
526
527
528
void clear_active()
Clear active mode and return the active cell to the grid.
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.
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.
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 active_line_undo_requested()
Emitted when user requests undo of the last draft point.
settings_panel(QWidget *parent=nullptr)
Construct the settings panel.
void clear_add_inputs() const
Clear all add-tab input fields and reset validation.
void reset_active_template_form()
Reset the templates form to "none" selection.
void reset_active_line_form()
Reset the "new line" form in the active tab.
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 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.