MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / tileGrid

Function tileGrid

app/src/UI/WindowManager.cpp:367–454  ·  view source on GitHub ↗

* @brief Seven or more windows distributed in an aspect-aware optimal grid. */

Source from the content-addressed store, hash-verified

365 * @brief Seven or more windows distributed in an aspect-aware optimal grid.
366 */
367static void tileGrid(const QList<QQuickItem*>& wins, const TileEnv& env)
368{
369 const int n = wins.size();
370 if (n <= 0)
371 return;
372
373 const double safeW = qMax(1, env.availW);
374 const double safeH = qMax(1, env.availH);
375
376 int cols, rows;
377 if (env.isLandscape) {
378 cols = qCeil(qSqrt(static_cast<double>(n) * safeW / safeH));
379 cols = qBound(1, cols, n);
380 rows = qCeil(static_cast<double>(n) / cols);
381 } else {
382 rows = qCeil(qSqrt(static_cast<double>(n) * safeH / safeW));
383 rows = qBound(1, rows, n);
384 cols = qCeil(static_cast<double>(n) / rows);
385 }
386
387 cols = qBound(1, cols, n);
388 rows = qBound(1, rows, n);
389
390 for (int guard = 0; guard < 2 * n && cols * rows < n; ++guard)
391 if (env.isLandscape)
392 cols++;
393 else
394 rows++;
395
396 const int spacingForSizing = qMax(env.spacing, 0);
397 const int totalSpacingW = (cols - 1) * spacingForSizing;
398 const int totalSpacingH = (rows - 1) * spacingForSizing;
399 const int totalCellsW = qMax(1, env.availW - totalSpacingW);
400 const int totalCellsH = qMax(1, env.availH - totalSpacingH);
401
402 const int baseCellW = totalCellsW / cols;
403 const int baseCellH = totalCellsH / rows;
404 const int extraW = totalCellsW % cols;
405 const int extraH = totalCellsH % rows;
406
407 QVector<int> colWidths(cols), colXs(cols);
408 QVector<int> rowHeights(rows), rowYs(rows);
409
410 int runningX = env.margin;
411 for (int c = 0; c < cols; ++c) {
412 colWidths[c] = baseCellW + (c < extraW ? 1 : 0);
413 colXs[c] = runningX;
414 runningX += colWidths[c] + env.spacing;
415 }
416
417 int runningY = env.margin;
418 for (int r = 0; r < rows; ++r) {
419 rowHeights[r] = baseCellH + (r < extraH ? 1 : 0);
420 rowYs[r] = runningY;
421 runningY += rowHeights[r] + env.spacing;
422 }
423
424 const int windowsInLastRow = n - (rows - 1) * cols;

Callers 1

dispatchTileFunction · 0.85

Calls 3

placeWindowFunction · 0.85
sizeMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected