1#include "widgets/grid_view.hpp"
2#include "widgets/stream_cell.hpp"
15 , scroll(
new QScrollArea(
this))
16 , grid_container(
new QWidget(scroll))
17 , grid_layout(
new QGridLayout(grid_container)) {
21 grid_container->setLayout(grid_layout);
23 scroll->setWidgetResizable(
true);
24 scroll->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
25 scroll->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
26 scroll->setWidget(grid_container);
28 auto* outer =
new QVBoxLayout(
this);
29 outer->setContentsMargins(0, 0, 0, 0);
34bool grid_view::has_stream(
const QString& name)
const {
35 return tiles.contains(name);
41 if (name.isEmpty() || tiles.contains(name)) {
45 auto* tile =
new stream_cell(name, grid_container);
47 tile->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
50 tile, &stream_cell::request_close,
this, &grid_view::close_requested
53 tile, &stream_cell::request_focus,
this, &grid_view::enlarge_requested
56 tiles.insert(name, tile);
61 const auto it = tiles.find(name);
62 if (it == tiles.end()) {
66 auto* tile = it.value();
76 auto it = tiles.find(name);
77 if (it == tiles.end()) {
96 const QString name = cell->get_name();
97 if (tiles.contains(name)) {
101 cell->setParent(grid_container);
102 tiles.insert(name, cell);
109 const auto it = tiles.find(name);
110 if (it == tiles.end()) {
118 emit stream_closed(name);
122 emit stream_enlarge(name);
125static int ceil_div(
const int a,
const int b) {
return (a + b - 1) / b; }
131 if (item->widget()) {
132 item->widget()->hide();
137 const int n =
static_cast<
int>(tiles.size());
145 const int cols = qCeil(qSqrt(
static_cast<
double>(n)));
148 for (
int c = 0; c < cols; ++c) {
151 for (
int r = 0; r < rows; ++r) {
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();
164 grid_container->updateGeometry();
grid_view(QWidget *parent=nullptr)
Construct an empty grid view.
QStringList stream_names() const
Get names of all streams currently in the grid.
QGridLayout * grid_layout
Grid layout arranging tiles.
QScrollArea * scroll
Scroll area wrapping the grid container.
void rebuild_layout()
Recompute and rebuild the grid layout.
void put_stream_cell(stream_cell *cell)
Return a previously taken cell back into the grid.
static int ceil_div(const int a, const int b)
static constexpr int kMinTileW
static constexpr int kMinTileH
Instance of a persistent (saved) line to be rendered on the stream.