12 #include "LayoutSaver_p.h"
14 #include "DockWidgetBase_p.h"
15 #include "FloatingWindow_p.h"
19 #include "Position_p.h"
29 LayoutWidget::~LayoutWidget()
31 if (m_rootItem->hostWidget()->asQObject() ==
this)
33 DockRegistry::self()->unregisterLayout(
this);
36 bool LayoutWidget::isInMainWindow()
const
38 return mainWindow() !=
nullptr;
43 if (
auto pw = QWidgetAdapter::parentWidget()) {
47 return qobject_cast<MainWindowBase *>(pw->parentWidget());
49 if (
auto mw = qobject_cast<MainWindowBase *>(pw))
56 FloatingWindow *LayoutWidget::floatingWindow()
const
58 return qobject_cast<FloatingWindow *>(QWidgetAdapter::parentWidget());
61 void LayoutWidget::setRootItem(Layouting::ItemContainer *root)
65 connect(m_rootItem, &Layouting::ItemContainer::numVisibleItemsChanged,
this,
66 &MultiSplitter::visibleWidgetCountChanged);
67 connect(m_rootItem, &Layouting::ItemContainer::minSizeChanged,
this,
68 [
this] { setMinimumSize(layoutMinimumSize()); });
71 QSize LayoutWidget::layoutMinimumSize()
const
73 return m_rootItem->minSize();
76 QSize LayoutWidget::layoutMaximumSizeHint()
const
78 return m_rootItem->maxSizeHint();
81 void LayoutWidget::setLayoutMinimumSize(
QSize sz)
83 if (sz != m_rootItem->minSize()) {
84 setLayoutSize(size().expandedTo(m_rootItem->minSize()));
85 m_rootItem->setMinSize(sz);
89 QSize LayoutWidget::size()
const
91 return m_rootItem->size();
94 void LayoutWidget::clearLayout()
99 bool LayoutWidget::checkSanity()
const
101 return m_rootItem->checkSanity();
104 void LayoutWidget::dumpLayout()
const
106 m_rootItem->dumpLayout();
109 void LayoutWidget::restorePlaceholder(
DockWidgetBase *dw, Layouting::Item *item,
int tabIndex)
111 if (item->isPlaceholder()) {
113 item->restore(newFrame);
116 auto frame = qobject_cast<Frame *>(item->guestAsQObject());
119 if (tabIndex != -1 && frame->dockWidgetCount() >= tabIndex) {
120 frame->insertWidget(dw, tabIndex);
122 frame->addWidget(dw);
125 frame->QWidgetAdapter::setVisible(
true);
128 void LayoutWidget::unrefOldPlaceholders(
const Frame::List &framesBeingAdded)
const
130 for (Frame *frame : framesBeingAdded) {
132 dw->d->lastPositions().removePlaceholders(
this);
137 void LayoutWidget::setLayoutSize(
QSize size)
139 if (size != this->size()) {
140 m_rootItem->setSize_recursive(size);
146 const Layouting::Item::List LayoutWidget::items()
const
148 return m_rootItem->items_recursive();
151 bool LayoutWidget::containsItem(
const Layouting::Item *item)
const
153 return m_rootItem->contains_recursive(item);
156 bool LayoutWidget::containsFrame(
const Frame *frame)
const
158 return itemForFrame(frame) !=
nullptr;
161 int LayoutWidget::count()
const
163 return m_rootItem->count_recursive();
166 int LayoutWidget::visibleCount()
const
168 return m_rootItem->visibleCount_recursive();
171 int LayoutWidget::placeholderCount()
const
173 return count() - visibleCount();
176 Layouting::Item *LayoutWidget::itemForFrame(
const Frame *frame)
const
181 return m_rootItem->itemForWidget(frame);
187 const Frame::List frames = this->frames();
188 for (Frame *frame : frames)
189 dockWidgets << frame->dockWidgets();
194 Frame::List LayoutWidget::framesFrom(
QWidgetOrQuick *frameOrMultiSplitter)
const
196 if (
auto frame = qobject_cast<Frame *>(frameOrMultiSplitter))
199 if (
auto msw = qobject_cast<MultiSplitter *>(frameOrMultiSplitter))
200 return msw->frames();
205 Frame::List LayoutWidget::frames()
const
207 const Layouting::Item::List items = m_rootItem->items_recursive();
212 for (Layouting::Item *item : items) {
213 if (
auto f =
static_cast<Frame *
>(item->guestAsQObject()))
220 void LayoutWidget::removeItem(Layouting::Item *item)
223 qWarning() << Q_FUNC_INFO <<
"nullptr item";
227 item->parentContainer()->removeItem(item);
230 void LayoutWidget::updateSizeConstraints()
232 const QSize newMinSize = m_rootItem->minSize();
233 qCDebug(sizing) << Q_FUNC_INFO <<
"Updating size constraints from" << minimumSize() <<
"to"
236 setLayoutMinimumSize(newMinSize);
239 bool LayoutWidget::deserialize(
const LayoutSaver::MultiSplitter &l)
242 for (
const LayoutSaver::Frame &frame : qAsConst(l.frames)) {
243 Frame *f = Frame::deserialize(frame);
244 Q_ASSERT(!frame.id.isEmpty());
245 frames.
insert(frame.id, f);
248 m_rootItem->fillFromVariantMap(l.layout, frames);
250 updateSizeConstraints();
254 const QSize newLayoutSize = QWidgetAdapter::size().
expandedTo(m_rootItem->minSize());
256 m_rootItem->setSize_recursive(newLayoutSize);
261 void LayoutWidget::onLayoutRequest()
263 updateSizeConstraints();
266 bool LayoutWidget::onResize(
QSize newSize)
272 setLayoutSize(newSize);
278 LayoutSaver::MultiSplitter LayoutWidget::serialize()
const
280 LayoutSaver::MultiSplitter l;
281 l.layout = m_rootItem->toVariantMap();
282 const Layouting::Item::List items = m_rootItem->items_recursive();
283 l.frames.reserve(items.size());
284 for (Layouting::Item *item : items) {
285 if (!item->isContainer()) {
286 if (
auto frame = qobject_cast<Frame *>(item->guestAsQObject()))
287 l.frames.insert(frame->id(), frame->serialize());