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"
32LayoutWidget::~LayoutWidget()
34 if (m_rootItem->hostWidget()->asQObject() ==
this)
36 DockRegistry::self()->unregisterLayout(
this);
39bool 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))
68FloatingWindow *LayoutWidget::floatingWindow()
const
70 return qobject_cast<FloatingWindow *>(QWidgetAdapter::parentWidget());
73void 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()); });
83QSize LayoutWidget::layoutMinimumSize()
const
85 return m_rootItem->minSize();
88QSize LayoutWidget::layoutMaximumSizeHint()
const
90 return m_rootItem->maxSizeHint();
93void LayoutWidget::setLayoutMinimumSize(
QSize sz)
95 if (sz != m_rootItem->minSize()) {
96 setLayoutSize(size().expandedTo(m_rootItem->minSize()));
97 m_rootItem->setMinSize(sz);
101QSize LayoutWidget::size()
const
103 return m_rootItem->size();
106void LayoutWidget::clearLayout()
111bool LayoutWidget::checkSanity()
const
113 return m_rootItem->checkSanity();
116void LayoutWidget::dumpLayout()
const
118 m_rootItem->dumpLayout();
121void 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);
140void LayoutWidget::unrefOldPlaceholders(
const Frame::List &framesBeingAdded)
const
142 for (Frame *frame : framesBeingAdded) {
144 dw->d->lastPosition()->removePlaceholders(
this);
149void LayoutWidget::setLayoutSize(
QSize size)
151 if (size != this->size()) {
152 m_rootItem->setSize_recursive(size);
158const Layouting::Item::List LayoutWidget::items()
const
160 return m_rootItem->items_recursive();
163bool LayoutWidget::containsItem(
const Layouting::Item *item)
const
165 return m_rootItem->contains_recursive(item);
168bool LayoutWidget::containsFrame(
const Frame *frame)
const
170 return itemForFrame(frame) !=
nullptr;
173int LayoutWidget::count()
const
175 return m_rootItem->count_recursive();
178int LayoutWidget::visibleCount()
const
180 return m_rootItem->visibleCount_recursive();
183int LayoutWidget::placeholderCount()
const
185 return count() - visibleCount();
188Layouting::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();
206Frame::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();
217Frame::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()))
232void LayoutWidget::removeItem(Layouting::Item *item)
235 qWarning() << Q_FUNC_INFO <<
"nullptr item";
239 item->parentContainer()->removeItem(item);
242void LayoutWidget::updateSizeConstraints()
244 const QSize newMinSize = m_rootItem->minSize();
245 qCDebug(sizing) << Q_FUNC_INFO <<
"Updating size constraints from" << minimumSize() <<
"to"
248 setLayoutMinimumSize(newMinSize);
251bool 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);
273void LayoutWidget::onLayoutRequest()
275 updateSizeConstraints();
278bool LayoutWidget::onResize(
QSize newSize)
284 setLayoutSize(newSize);
290LayoutSaver::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);
Application-wide config to tune certain behaviours of the framework.
The MainWindow base-class that's shared between QtWidgets and QtQuick stack.
The MainWindow base-class. MainWindow and MainWindowBase are only split in two so we can share some c...
bool isAccepted() const const
QHash::iterator insert(const Key &key, const T &value)
QSize expandedTo(const QSize &otherSize) const const