12 #include "LayoutSaver_p.h"
14 #include "DockWidgetBase_p.h"
15 #include "FloatingWindow_p.h"
19 #include "Position_p.h"
22 #include "multisplitter/Item_p.h"
32 LayoutWidget::~LayoutWidget()
34 if (m_rootItem->hostWidget()->asQObject() ==
this)
36 DockRegistry::self()->unregisterLayout(
this);
39 bool LayoutWidget::isInMainWindow(
bool honourNesting)
const
41 return mainWindow(honourNesting) !=
nullptr;
47 honourNesting = honourNesting && kddwUsesQtWidgets();
51 return firstParentOfType<MainWindowBase>(
this);
54 if (
auto pw = QWidgetAdapter::parentWidget()) {
58 return qobject_cast<MainWindowBase *>(pw->parentWidget());
60 if (
auto mw = qobject_cast<MainWindowBase *>(pw))
68 FloatingWindow *LayoutWidget::floatingWindow()
const
70 return qobject_cast<FloatingWindow *>(QWidgetAdapter::parentWidget());
73 void LayoutWidget::setRootItem(Layouting::ItemContainer *root)
77 connect(m_rootItem, &Layouting::ItemContainer::numVisibleItemsChanged,
this,
78 &MultiSplitter::visibleWidgetCountChanged);
79 connect(m_rootItem, &Layouting::ItemContainer::minSizeChanged,
this,
80 [
this] { setMinimumSize(layoutMinimumSize()); });
83 QSize LayoutWidget::layoutMinimumSize()
const
85 return m_rootItem->minSize();
88 QSize LayoutWidget::layoutMaximumSizeHint()
const
90 return m_rootItem->maxSizeHint();
93 void LayoutWidget::setLayoutMinimumSize(
QSize sz)
95 if (sz != m_rootItem->minSize()) {
96 setLayoutSize(size().expandedTo(m_rootItem->minSize()));
97 m_rootItem->setMinSize(sz);
101 QSize LayoutWidget::size()
const
103 return m_rootItem->size();
106 void LayoutWidget::clearLayout()
111 bool LayoutWidget::checkSanity()
const
113 return m_rootItem->checkSanity();
116 void LayoutWidget::dumpLayout()
const
118 m_rootItem->dumpLayout();
121 void LayoutWidget::restorePlaceholder(
DockWidgetBase *dw, Layouting::Item *item,
int tabIndex)
123 if (item->isPlaceholder()) {
125 item->restore(newFrame);
128 auto frame = qobject_cast<Frame *>(item->guestAsQObject());
131 if (tabIndex != -1 && frame->dockWidgetCount() >= tabIndex) {
132 frame->insertWidget(dw, tabIndex);
134 frame->addWidget(dw);
137 frame->QWidgetAdapter::setVisible(
true);
140 void LayoutWidget::unrefOldPlaceholders(
const Frame::List &framesBeingAdded)
const
142 for (Frame *frame : framesBeingAdded) {
144 dw->d->lastPosition()->removePlaceholders(
this);
149 void LayoutWidget::setLayoutSize(
QSize size)
151 if (size != this->size()) {
152 m_rootItem->setSize_recursive(size);
158 const Layouting::Item::List LayoutWidget::items()
const
160 return m_rootItem->items_recursive();
163 bool LayoutWidget::containsItem(
const Layouting::Item *item)
const
165 return m_rootItem->contains_recursive(item);
168 bool LayoutWidget::containsFrame(
const Frame *frame)
const
170 return itemForFrame(frame) !=
nullptr;
173 int LayoutWidget::count()
const
175 return m_rootItem->count_recursive();
178 int LayoutWidget::visibleCount()
const
180 return m_rootItem->visibleCount_recursive();
183 int LayoutWidget::placeholderCount()
const
185 return count() - visibleCount();
188 Layouting::Item *LayoutWidget::itemForFrame(
const Frame *frame)
const
193 return m_rootItem->itemForWidget(frame);
199 const Frame::List frames = this->frames();
200 for (Frame *frame : frames)
201 dockWidgets << frame->dockWidgets();
206 Frame::List LayoutWidget::framesFrom(
QWidgetOrQuick *frameOrMultiSplitter)
const
208 if (
auto frame = qobject_cast<Frame *>(frameOrMultiSplitter))
211 if (
auto msw = qobject_cast<MultiSplitter *>(frameOrMultiSplitter))
212 return msw->frames();
217 Frame::List LayoutWidget::frames()
const
219 const Layouting::Item::List items = m_rootItem->items_recursive();
224 for (Layouting::Item *item : items) {
225 if (
auto f =
static_cast<Frame *
>(item->guestAsQObject()))
232 void LayoutWidget::removeItem(Layouting::Item *item)
235 qWarning() << Q_FUNC_INFO <<
"nullptr item";
239 item->parentContainer()->removeItem(item);
242 void LayoutWidget::updateSizeConstraints()
244 const QSize newMinSize = m_rootItem->minSize();
245 qCDebug(sizing) << Q_FUNC_INFO <<
"Updating size constraints from" << minimumSize() <<
"to"
248 setLayoutMinimumSize(newMinSize);
251 bool LayoutWidget::deserialize(
const LayoutSaver::MultiSplitter &l)
254 for (
const LayoutSaver::Frame &frame : qAsConst(l.frames)) {
255 Frame *f = Frame::deserialize(frame);
256 Q_ASSERT(!frame.id.isEmpty());
257 frames.
insert(frame.id, f);
260 m_rootItem->fillFromVariantMap(l.layout, frames);
262 updateSizeConstraints();
266 const QSize newLayoutSize = QWidgetAdapter::size().
expandedTo(m_rootItem->minSize());
268 m_rootItem->setSize_recursive(newLayoutSize);
273 void LayoutWidget::onLayoutRequest()
275 updateSizeConstraints();
278 bool LayoutWidget::onResize(
QSize newSize)
284 setLayoutSize(newSize);
290 LayoutSaver::MultiSplitter LayoutWidget::serialize()
const
292 LayoutSaver::MultiSplitter l;
293 l.layout = m_rootItem->toVariantMap();
294 const Layouting::Item::List items = m_rootItem->items_recursive();
295 l.frames.reserve(items.size());
296 for (Layouting::Item *item : items) {
297 if (!item->isContainer()) {
298 if (
auto frame = qobject_cast<Frame *>(item->guestAsQObject()))
299 l.frames.insert(frame->id(), frame->serialize());
310 const Frame::List frames = this->frames();
311 for (Frame *frame : frames) {
312 qApp->sendEvent(frame, e);