| 1 | #include "DockManager.h" |
| 2 | #include "DockableWidget.h" |
| 3 | #include "DockableWidgetArea.h" |
| 4 | |
| 5 | |
| 6 | void DockManager::addDockArea(DockableWidgetArea* area) |
| 7 | { |
| 8 | if (areas.indexOf(area) == -1) { |
| 9 | areas.append(area); |
| 10 | } |
| 11 | } |
| 12 | |
| 13 | int DockManager::dockAreaIndex(DockableWidgetArea* area) const |
| 14 | { |
| 15 | return areas.indexOf(area); |
| 16 | } |
| 17 | |
| 18 | void DockManager::dockWidget(DockableWidget* widget, const QPoint& /*p*/, const QRect& r) |
| 19 | { |
| 20 | auto it = areaMap.begin(); // TODO |
| 21 | if (it != areaMap.end()) { |
| 22 | areaMap[widget] = it.value(); |
| 23 | return it.value()->addWidget(widget, r); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | void DockManager::undockWidget(DockableWidget* widget) |
| 28 | { |
| 29 | auto it = areaMap.find(widget); |
| 30 | if (it != areaMap.end()) { |
| 31 | it.value()->removeWidget(widget); |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | void DockManager::insertWidget( |
| 36 | DockableWidget* widget, int index, |
| 37 | DockableWidgetLayout::DockSide side, int distance, int w, int h) |
| 38 | { |
| 39 | if (index < 0 || index >= areas.size()) return; |
| 40 | |
| 41 | //Q_ASSERT(areaMap.find(widget) == areaMap.end()); |
| 42 | |
| 43 | areas[index]->addWidget(widget, side, distance, w, h); |
| 44 | areaMap[widget] = areas[index]; |
| 45 | } |
| 46 | |
| 47 | bool DockManager::insertLocation(QRect& r, const QSizePolicy& sizePol) |
| 48 | { |
| 49 | auto it = areaMap.begin(); // TODO |
| 50 | if (it == areaMap.end()) return false; |
| 51 | |
| 52 | return it.value()->insertLocation(r, sizePol); |
| 53 | } |
| 54 | |
| 55 | void DockManager::visibilityChanged(DockableWidget* widget) |
| 56 | { |
| 57 | auto it = areaMap.find(widget); |
| 58 | if (it != areaMap.end()) { |
| 59 | it.value()->layout->changed(); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | void DockManager::getConfig(int index, QStringList& list) const |
| 64 | { |
| 65 | areas[index]->getConfig(list); |
| 66 | } |
| 67 | |
| 68 | void DockManager::attachWidget(DockableWidget* widget) |
| 69 | { |
| 70 | dockWidgets.append(widget); |
| 71 | } |
| 72 | |
| 73 | void DockManager::detachWidget(DockableWidget* widget) |
| 74 | { |
| 75 | dockWidgets.removeAll(widget); |
| 76 | } |
| 77 | |
| 78 | const QList<DockableWidget*>& DockManager::managedWidgets() const |
| 79 | { |
| 80 | return dockWidgets; |
| 81 | } |
| 82 | |
| 83 | DockableWidget* DockManager::findDockableWidget(const QString& id) const |
| 84 | { |
| 85 | for (auto* w : dockWidgets) { |
| 86 | if (w->id() == id) return w; |
| 87 | } |
| 88 | return nullptr; |
| 89 | } |