| 259 | } |
| 260 | |
| 261 | void ContainerManager::dockContainer(const QString& id) |
| 262 | { |
| 263 | ContainerWidget* c = m_containers.value(id).data(); |
| 264 | if (!c || !c->isFloating()) return; |
| 265 | |
| 266 | auto* win = m_floatingWindows.take(id); |
| 267 | if (!win) return; |
| 268 | |
| 269 | ContainerWidget* released = win->releaseContainer(); |
| 270 | win->close(); |
| 271 | win->deleteLater(); |
| 272 | if (!released) return; |
| 273 | |
| 274 | const auto& meta = m_meta.value(id); |
| 275 | |
| 276 | if (!meta.parentId.isEmpty()) { |
| 277 | // Nested: re-insert into logical parent container's body. |
| 278 | // If the parent is itself currently floating, re-docking the |
| 279 | // child just re-inserts it into the parent's body which |
| 280 | // happens to live in a floating window — Qt reparenting is |
| 281 | // transparent to that. |
| 282 | ContainerWidget* parent = m_containers.value(meta.parentId).data(); |
| 283 | if (parent) { |
| 284 | const int clamped = std::min(std::max(meta.originalIndex, 0), |
| 285 | parent->childWidgetCount()); |
| 286 | parent->insertChildWidget(clamped, released); |
| 287 | } |
| 288 | } else if (meta.originalParent) { |
| 289 | // Top-level: re-insert into the external layout we came from. |
| 290 | released->setParent(meta.originalParent); |
| 291 | if (auto* box = qobject_cast<QBoxLayout*>(meta.originalParent->layout())) { |
| 292 | const int clamped = std::min(std::max(meta.originalIndex, 0), |
| 293 | box->count()); |
| 294 | box->insertWidget(clamped, released); |
| 295 | } |
| 296 | released->show(); |
| 297 | } |
| 298 | saveState(); |
| 299 | } |
| 300 | |
| 301 | void ContainerManager::setFramelessMode(bool on) |
| 302 | { |