* @brief Applies saved manual-mode geometries to live windows and stashes the * anchored rects for any window that hasn't registered yet. */
| 705 | * anchored rects for any window that hasn't registered yet. |
| 706 | */ |
| 707 | void UI::WindowManager::applySavedGeometries(const QJsonObject& layout, |
| 708 | const QHash<StableKey, int>& stableLookup, |
| 709 | int marginCanvasW, |
| 710 | int marginCanvasH) |
| 711 | { |
| 712 | const int canvasW = static_cast<int>(width()); |
| 713 | const int canvasH = static_cast<int>(height()); |
| 714 | const QJsonArray geometries = layout["geometries"].toArray(); |
| 715 | |
| 716 | for (const auto& val : std::as_const(geometries)) { |
| 717 | const QJsonObject winGeom = val.toObject(); |
| 718 | const int id = resolveSavedWindowId(winGeom, stableLookup, m_windows); |
| 719 | if (id < 0) |
| 720 | continue; |
| 721 | |
| 722 | const int x = static_cast<int>(SerialStudio::toDouble(winGeom["x"], 0.0)); |
| 723 | const int y = static_cast<int>(SerialStudio::toDouble(winGeom["y"], 0.0)); |
| 724 | const int w = static_cast<int>(SerialStudio::toDouble(winGeom["width"], 200.0)); |
| 725 | const int h = static_cast<int>(SerialStudio::toDouble(winGeom["height"], 150.0)); |
| 726 | const QRect geom(x, y, w, h); |
| 727 | const QMargins margins = manualMarginsForGeometry(geom, marginCanvasW, marginCanvasH); |
| 728 | const QRect anchored = anchoredGeometry(geom, margins, canvasW, canvasH); |
| 729 | |
| 730 | auto* win = m_windows.value(id); |
| 731 | if (win) { |
| 732 | win->setX(anchored.x()); |
| 733 | win->setY(anchored.y()); |
| 734 | win->setWidth(anchored.width()); |
| 735 | win->setHeight(anchored.height()); |
| 736 | } |
| 737 | |
| 738 | m_manualGeometries.insert(id, geom); |
| 739 | m_manualMargins.insert(id, margins); |
| 740 | m_pendingGeometries.insert(id, anchored); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | /** |
| 745 | * @brief Restores a previously serialized window layout. |
nothing calls this directly
no test coverage detected