20 #include "MultiSplitter_p.h"
21 #include "LayoutSaver_p.h"
23 #include "DockRegistry_p.h"
25 #include "DockWidgetBase_p.h"
26 #include "FloatingWindow_p.h"
30 #include "Logging_p.h"
32 #include "Position_p.h"
33 #include "WindowBeingDragged_p.h"
36 #include <QScopedValueRollback>
41 : LayoutWidget(parent)
44 setRootItem(
new Layouting::ItemBoxContainer(
this));
45 DockRegistry::self()->registerLayout(
this);
47 setLayoutSize(
parent->size());
50 updateSizeConstraints();
55 MultiSplitter::~MultiSplitter()
63 qWarning() << Q_FUNC_INFO <<
"Widget is null";
67 const bool isDockWidget = qobject_cast<DockWidgetBase *>(widget);
70 if (!qobject_cast<Frame *>(widget) && !qobject_cast<MultiSplitter *>(widget) && !isDockWidget) {
71 qWarning() <<
"Unknown widget type" << widget;
75 if (isDockWidget != isStartHidden) {
76 qWarning() <<
"Wrong parameters" << isDockWidget << isStartHidden;
80 if (relativeToFrame && relativeToFrame == widget) {
81 qWarning() <<
"widget can't be relative to itself";
85 Layouting::Item *item = itemForFrame(qobject_cast<Frame *>(widget));
87 if (containsItem(item)) {
88 qWarning() <<
"MultiSplitter::addWidget: Already contains" << widget;
93 qWarning() <<
"MultiSplitter::addWidget: not adding to location None";
97 const bool relativeToThis = relativeToFrame ==
nullptr;
99 Layouting::Item *relativeToItem = itemForFrame(relativeToFrame);
100 if (!relativeToThis && !containsItem(relativeToItem)) {
101 qWarning() <<
"MultiSplitter::addWidget: Doesn't contain relativeTo:"
102 <<
"; relativeToFrame=" << relativeToFrame
103 <<
"; relativeToItem=" << relativeToItem
104 <<
"; options=" << option;
112 Frame *relativeToWidget,
115 auto frame = qobject_cast<Frame *>(w);
116 if (itemForFrame(frame) !=
nullptr) {
119 frame->QWidgetAdapter::setParent(
nullptr);
120 frame->setLayoutItem(
nullptr);
124 if (!validateInputs(w, location, relativeToWidget, option))
127 Layouting::Item *relativeTo = itemForFrame(relativeToWidget);
129 relativeTo = m_rootItem;
131 Layouting::Item *newItem =
nullptr;
133 Frame::List frames = framesFrom(w);
134 unrefOldPlaceholders(frames);
135 auto dw = qobject_cast<DockWidgetBase *>(w);
138 newItem =
new Layouting::Item(
this);
139 newItem->setGuestWidget(frame);
141 newItem =
new Layouting::Item(
this);
143 newItem->setGuestWidget(frame);
144 frame->addWidget(dw, option);
145 }
else if (
auto ms = qobject_cast<MultiSplitter *>(w)) {
146 newItem = ms->m_rootItem;
147 newItem->setHostWidget(
this);
149 if (FloatingWindow *fw = ms->floatingWindow()) {
150 newItem->setSize_recursive(fw->size());
157 qWarning() << Q_FUNC_INFO <<
"Unknown widget added" << w;
161 Q_ASSERT(!newItem->geometry().isEmpty());
162 Layouting::ItemBoxContainer::insertItemRelativeTo(newItem, relativeTo, location, option);
168 void MultiSplitter::addMultiSplitter(MultiSplitter *sourceMultiSplitter,
Location location,
172 qCDebug(addwidget) << Q_FUNC_INFO << sourceMultiSplitter << location << relativeTo;
173 addWidget(sourceMultiSplitter, location, relativeTo, option);
178 return m_rootItem->separators_recursive();
181 int MultiSplitter::availableLengthForOrientation(
Qt::Orientation orientation)
const
184 return availableSize().height();
186 return availableSize().width();
189 QSize MultiSplitter::availableSize()
const
191 return m_rootItem->availableSize();
194 void MultiSplitter::layoutEqually()
199 layoutEqually(m_rootItem);
202 void MultiSplitter::layoutEqually(Layouting::ItemBoxContainer *container)
205 container->layoutEqually_recursive();
207 qWarning() << Q_FUNC_INFO <<
"null container";
211 void MultiSplitter::setRootItem(Layouting::ItemBoxContainer *root)
213 LayoutWidget::setRootItem(root);
217 Layouting::ItemBoxContainer *MultiSplitter::rootItem()
const
222 QRect MultiSplitter::rectForDrop(
const WindowBeingDragged *wbd,
Location location,
223 const Layouting::Item *relativeTo)
const
225 Layouting::Item item(
nullptr);
229 item.setSize(wbd->size().boundedTo(wbd->maxSize()));
230 item.setMinSize(wbd->minSize());
231 item.setMaxSizeHint(wbd->maxSize());
233 Layouting::ItemBoxContainer *container = relativeTo ? relativeTo->parentBoxContainer()
236 return container->suggestedDropRect(&item, relativeTo, location);
239 bool MultiSplitter::deserialize(
const LayoutSaver::MultiSplitter &l)
241 setRootItem(
new Layouting::ItemBoxContainer(
this));
242 return LayoutWidget::deserialize(l);