YODAU 1.0
YEAR OF THE DEPEND ADULT UNDERGARMENT
Loading...
Searching...
No Matches
grid_view Class Referencefinal

Scrollable grid of stream thumbnails. More...

#include <frontend/include/widgets/grid_view.hpp>

Inheritance diagram for grid_view:
Collaboration diagram for grid_view:

Signals

void stream_closed (const QString &name)
 Emitted after a stream cell was closed and removed.
void stream_enlarge (const QString &name)
 Emitted when a stream cell requests focus/enlargement.

Public Member Functions

 grid_view (QWidget *parent=nullptr)
 Construct an empty grid view.
bool has_stream (const QString &name) const
 Check whether a stream with given name exists in the grid.
QStringList stream_names () const
 Get names of all streams currently in the grid.
void add_stream (const QString &name)
 Add a new stream cell to the grid.
void remove_stream (const QString &name)
 Remove a stream cell from the grid.
stream_celltake_stream_cell (const QString &name)
 Detach a stream cell from the grid without deleting it.
void put_stream_cell (stream_cell *cell)
 Return a previously taken cell back into the grid.
stream_cellpeek_stream_cell (const QString &name) const
 Get a pointer to a cell without removing it.

Private Member Functions

void rebuild_layout ()
 Recompute and rebuild the grid layout.
void close_requested (const QString &name)
 Internal handler for stream_cell::request_close.
void enlarge_requested (const QString &name)
 Internal handler for stream_cell::request_focus.

Private Attributes

QScrollArea * scroll
 Scroll area wrapping the grid container.
QWidget * grid_container
 Widget that owns the grid layout and all tiles.
QGridLayout * grid_layout
 Grid layout arranging tiles.
QMap< QString, stream_cell * > tiles
 Map of stream name to corresponding tile widget.

Detailed Description

Scrollable grid of stream thumbnails.

Responsibilities:

  • Own and display a collection of stream_cell widgets in a grid.
  • Rebuild the layout when the set changes, choosing a roughly square grid.
  • Forward user intents from individual cells via signals:

Ownership model:

  • grid_view owns all cells currently present in the grid.
  • take_stream_cell transfers a cell out of the grid without deleting it (caller is expected to reparent/place it elsewhere).
  • put_stream_cell returns a cell back into the grid.

Threading:

  • UI class; all methods are expected to be called from the Qt GUI thread.

Definition at line 44 of file grid_view.hpp.

Constructor & Destructor Documentation

◆ grid_view()

grid_view::grid_view ( QWidget * parent = nullptr)
explicit

Construct an empty grid view.

Creates an internal QScrollArea with a container widget holding a QGridLayout. The scroll area is configured for horizontal scrolling when needed and no vertical scrollbar (layout expands horizontally).

Parameters
parentOptional parent widget.

Definition at line 13 of file grid_view.cpp.

14 : QWidget(parent)
15 , scroll(new QScrollArea(this))
16 , grid_container(new QWidget(scroll))
17 , grid_layout(new QGridLayout(grid_container)) {
18 grid_layout->setContentsMargins(6, 6, 6, 6);
19 grid_layout->setSpacing(6);
20
21 grid_container->setLayout(grid_layout);
22
23 scroll->setWidgetResizable(true);
24 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
25 scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
26 scroll->setWidget(grid_container);
27
28 auto* outer = new QVBoxLayout(this);
29 outer->setContentsMargins(0, 0, 0, 0);
30 outer->addWidget(scroll);
31 setLayout(outer);
32}
QWidget * grid_container
Widget that owns the grid layout and all tiles.
QGridLayout * grid_layout
Grid layout arranging tiles.
QScrollArea * scroll
Scroll area wrapping the grid container.

References grid_layout, and scroll.

Referenced by controller::setup_grid_connections().

Here is the caller graph for this function:

Member Function Documentation

◆ add_stream()

void grid_view::add_stream ( const QString & name)

Add a new stream cell to the grid.

If name is empty or already present, the call is ignored. The created cell is connected to internal handlers and the layout is rebuilt.

Parameters
nameLogical stream name.

Definition at line 40 of file grid_view.cpp.

40 {
41 if (name.isEmpty() || tiles.contains(name)) {
42 return;
43 }
44
45 auto* tile = new stream_cell(name, grid_container);
46 tile->setMinimumSize(kMinTileW, kMinTileH);
47 tile->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
48
49 connect(
51 );
52 connect(
54 );
55
56 tiles.insert(name, tile);
58}
void enlarge_requested(const QString &name)
Internal handler for stream_cell::request_focus.
QMap< QString, stream_cell * > tiles
Map of stream name to corresponding tile widget.
void close_requested(const QString &name)
Internal handler for stream_cell::request_close.
void rebuild_layout()
Recompute and rebuild the grid layout.
void request_focus(const QString &name)
Emitted when the user requests focusing/enlarging this cell.
void request_close(const QString &name)
Emitted when the user requests closing this stream cell.
static constexpr int kMinTileW
Definition grid_view.cpp:10
static constexpr int kMinTileH
Definition grid_view.cpp:11

References kMinTileH, kMinTileW, and rebuild_layout().

Referenced by controller::handle_show_stream_changed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ close_requested()

void grid_view::close_requested ( const QString & name)
private

Internal handler for stream_cell::request_close.

Removes the stream and emits stream_closed.

Parameters
nameStream name.

Definition at line 116 of file grid_view.cpp.

116 {
117 remove_stream(name);
118 emit stream_closed(name);
119}
void stream_closed(const QString &name)
Emitted after a stream cell was closed and removed.
void remove_stream(const QString &name)
Remove a stream cell from the grid.
Definition grid_view.cpp:60

◆ enlarge_requested()

void grid_view::enlarge_requested ( const QString & name)
private

Internal handler for stream_cell::request_focus.

Emits stream_enlarge.

Parameters
nameStream name.

Definition at line 121 of file grid_view.cpp.

121 {
122 emit stream_enlarge(name);
123}
void stream_enlarge(const QString &name)
Emitted when a stream cell requests focus/enlargement.

◆ has_stream()

bool grid_view::has_stream ( const QString & name) const

Check whether a stream with given name exists in the grid.

Parameters
nameStream name.
Returns
true if a cell with that name is present.

Definition at line 34 of file grid_view.cpp.

34 {
35 return tiles.contains(name);
36}

◆ peek_stream_cell()

stream_cell * grid_view::peek_stream_cell ( const QString & name) const

Get a pointer to a cell without removing it.

Parameters
nameStream name.
Returns
Pointer to the cell, or nullptr if not found.

Definition at line 108 of file grid_view.cpp.

108 {
109 const auto it = tiles.find(name);
110 if (it == tiles.end()) {
111 return nullptr;
112 }
113 return it.value();
114}

Referenced by controller::handle_show_stream_changed(), and controller::tile_for_stream_name().

Here is the caller graph for this function:

◆ put_stream_cell()

void grid_view::put_stream_cell ( stream_cell * cell)

Return a previously taken cell back into the grid.

The cell is reparented to the grid container, inserted by its name, shown, and the layout is rebuilt. If a cell with the same name already exists, the call is ignored.

Parameters
cellCell to put back.

Definition at line 91 of file grid_view.cpp.

91 {
92 if (!cell) {
93 return;
94 }
95
96 const QString name = cell->get_name();
97 if (tiles.contains(name)) {
98 return;
99 }
100
101 cell->setParent(grid_container);
102 tiles.insert(name, cell);
103 cell->show();
104
106}
const QString & get_name() const
Get logical name of this stream cell.

References rebuild_layout().

Referenced by board::clear_active(), and board::set_active_stream().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rebuild_layout()

void grid_view::rebuild_layout ( )
private

Recompute and rebuild the grid layout.

Clears existing layout items, hides widgets during rebuild, and places all current tiles into a grid with approximately sqrt(n) columns, stretched equally.

If there are no tiles, the widget hides itself.

Definition at line 127 of file grid_view.cpp.

127 {
128 // todo fix layout
129 while (grid_layout->count() > 0) {
130 auto* item = grid_layout->takeAt(0);
131 if (item->widget()) {
132 item->widget()->hide();
133 }
134 delete item;
135 }
136
137 const int n = static_cast<int>(tiles.size());
138 if (n == 0) {
139 this->hide();
140 updateGeometry();
141 return;
142 }
143 this->show();
144
145 const int cols = qCeil(qSqrt(static_cast<double>(n)));
146 const int rows = ceil_div(n, cols);
147
148 for (int c = 0; c < cols; ++c) {
149 grid_layout->setColumnStretch(c, 1);
150 }
151 for (int r = 0; r < rows; ++r) {
152 grid_layout->setRowStretch(r, 1);
153 }
154
155 int idx = 0;
156 for (auto it = tiles.cbegin(); it != tiles.cend(); ++it, ++idx) {
157 const int r = idx / cols;
158 const int c = idx % cols;
159 auto* tile = it.value();
160 tile->show();
161 grid_layout->addWidget(tile, r, c);
162 }
163
164 grid_container->updateGeometry();
165}
static int ceil_div(const int a, const int b)

References ceil_div(), and grid_layout.

Referenced by add_stream(), put_stream_cell(), remove_stream(), and take_stream_cell().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ remove_stream()

void grid_view::remove_stream ( const QString & name)

Remove a stream cell from the grid.

If no such stream exists, this is a no-op. Otherwise the cell is removed from the layout and scheduled for deletion with deleteLater().

Parameters
nameLogical stream name.

Definition at line 60 of file grid_view.cpp.

60 {
61 const auto it = tiles.find(name);
62 if (it == tiles.end()) {
63 return;
64 }
65
66 auto* tile = it.value();
67 tiles.erase(it);
68
69 grid_layout->removeWidget(tile);
70 tile->deleteLater();
71
73}

References grid_layout, and rebuild_layout().

Referenced by controller::handle_show_stream_changed().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stream_closed

void grid_view::stream_closed ( const QString & name)
signal

Emitted after a stream cell was closed and removed.

Triggered by the close button in a cell.

Parameters
nameName of the closed stream.

◆ stream_enlarge

void grid_view::stream_enlarge ( const QString & name)
signal

Emitted when a stream cell requests focus/enlargement.

Triggered by the focus/enlarge button in a cell.

Parameters
nameName of the stream to enlarge.

Referenced by controller::setup_grid_connections().

Here is the caller graph for this function:

◆ stream_names()

QStringList grid_view::stream_names ( ) const

Get names of all streams currently in the grid.

Returns
List of stream names in insertion/order of the internal map.

Definition at line 38 of file grid_view.cpp.

38{ return tiles.keys(); }

◆ take_stream_cell()

stream_cell * grid_view::take_stream_cell ( const QString & name)

Detach a stream cell from the grid without deleting it.

This is used when a stream becomes "active" elsewhere. The cell is:

  • removed from internal map,
  • removed from the layout,
  • hidden,
  • returned to the caller.

Layout is rebuilt afterwards.

Parameters
nameStream name to take.
Returns
Pointer to the detached cell, or nullptr if not found.

Definition at line 75 of file grid_view.cpp.

75 {
76 auto it = tiles.find(name);
77 if (it == tiles.end()) {
78 return nullptr;
79 }
80
81 stream_cell* cell = it.value();
82
83 tiles.erase(it);
84 grid_layout->removeWidget(cell);
85 cell->hide();
86
88 return cell;
89}

References grid_layout, and rebuild_layout().

Referenced by board::set_active_stream().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ grid_container

QWidget* grid_view::grid_container
private

Widget that owns the grid layout and all tiles.

Definition at line 183 of file grid_view.hpp.

◆ grid_layout

QGridLayout* grid_view::grid_layout
private

Grid layout arranging tiles.

Definition at line 186 of file grid_view.hpp.

Referenced by grid_view(), rebuild_layout(), remove_stream(), and take_stream_cell().

◆ scroll

QScrollArea* grid_view::scroll
private

Scroll area wrapping the grid container.

Definition at line 180 of file grid_view.hpp.

Referenced by grid_view().

◆ tiles

QMap<QString, stream_cell*> grid_view::tiles
private

Map of stream name to corresponding tile widget.

Definition at line 189 of file grid_view.hpp.


The documentation for this class was generated from the following files: