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

Method applyManualAnchors

app/src/UI/WindowManager.cpp:1224–1276  ·  view source on GitHub ↗

* @brief Repositions manual-layout windows to preserve edge anchoring on resize. */

Source from the content-addressed store, hash-verified

1222 * @brief Repositions manual-layout windows to preserve edge anchoring on resize.
1223 */
1224void UI::WindowManager::applyManualAnchors(const int newWidth, const int newHeight)
1225{
1226 if (newWidth <= 0 || newHeight <= 0)
1227 return;
1228
1229 int refWidth = m_manualCanvasWidth > 0 ? m_manualCanvasWidth : newWidth;
1230 int refHeight = m_manualCanvasHeight > 0 ? m_manualCanvasHeight : newHeight;
1231
1232 if (m_manualCanvasWidth <= 0 && m_lastCanvasWidth > 0)
1233 refWidth = m_lastCanvasWidth;
1234
1235 if (m_manualCanvasHeight <= 0 && m_lastCanvasHeight > 0)
1236 refHeight = m_lastCanvasHeight;
1237
1238 if (m_manualCanvasWidth <= 0 && refWidth > 0)
1239 m_manualCanvasWidth = refWidth;
1240
1241 if (m_manualCanvasHeight <= 0 && refHeight > 0)
1242 m_manualCanvasHeight = refHeight;
1243
1244 const double scaleX = refWidth > 0 ? double(newWidth) / double(refWidth) : 1.0;
1245 const double scaleY = refHeight > 0 ? double(newHeight) / double(refHeight) : 1.0;
1246
1247 for (auto it = m_windows.constBegin(); it != m_windows.constEnd(); ++it) {
1248 const int id = it.key();
1249 auto* win = it.value();
1250 if (!win || win->state() != "normal")
1251 continue;
1252
1253 if (!m_manualGeometries.contains(id) || !m_manualMargins.contains(id))
1254 storeManualGeometry(id, win);
1255
1256 const QRect prefGeom = m_manualGeometries.value(id, extractGeometry(win));
1257 const QMargins margins = m_manualMargins.value(id, QMargins());
1258 int scaledW = qRound(prefGeom.width() * scaleX);
1259 int scaledH = qRound(prefGeom.height() * scaleY);
1260 const QMargins scaledMargins(qRound(margins.left() * scaleX),
1261 qRound(margins.top() * scaleY),
1262 qRound(margins.right() * scaleX),
1263 qRound(margins.bottom() * scaleY));
1264 const int maxW = qMax(0, newWidth - scaledMargins.left() - scaledMargins.right());
1265 const int maxH = qMax(0, newHeight - scaledMargins.top() - scaledMargins.bottom());
1266 scaledW = qMin(scaledW, maxW);
1267 scaledH = qMin(scaledH, maxH);
1268 const QRect scaledPref(0, 0, scaledW, scaledH);
1269 const QRect anchored = anchoredGeometry(scaledPref, scaledMargins, newWidth, newHeight);
1270
1271 win->setX(anchored.x());
1272 win->setY(anchored.y());
1273 win->setWidth(anchored.width());
1274 win->setHeight(anchored.height());
1275 }
1276}
1277
1278/**
1279 * @brief Applies the manual snap indicator to the dragged window.

Callers

nothing calls this directly

Calls 7

anchoredGeometryFunction · 0.85
keyMethod · 0.80
widthMethod · 0.80
heightMethod · 0.80
xMethod · 0.80
valueMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected