KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
MDILayoutWidget.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2020-2023 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
5 Author: SĂ©rgio Martins <sergio.martins@kdab.com>
6
7 SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
8
9 Contact KDAB at <info@kdab.com> for commercial licensing options.
10*/
11
12#include "MDILayoutWidget_p.h"
13#include "multisplitter/ItemFreeContainer_p.h"
14#include "DockWidgetBase_p.h"
15#include "Config.h"
17
18using namespace KDDockWidgets;
19
20MDILayoutWidget::MDILayoutWidget(QWidgetOrQuick *parent)
21 : LayoutWidget(parent)
22 , m_rootItem(new Layouting::ItemFreeContainer(this))
23{
24 setRootItem(m_rootItem);
25}
26
27MDILayoutWidget::~MDILayoutWidget()
28{
29}
30
31void MDILayoutWidget::addDockWidget(DockWidgetBase *dw, QPoint localPt, InitialOption addingOption)
32{
33 if (!dw) {
34 qWarning() << Q_FUNC_INFO << "Refusing to add null dock widget";
35 return;
36 }
37
38 auto frame = qobject_cast<Frame *>(dw->d->frame());
39 if (itemForFrame(frame) != nullptr) {
40 // Item already exists, remove it. See also comment in MultiSplitter::addWidget().
41 frame->QWidgetAdapter::setParent(nullptr);
42 frame->setLayoutItem(nullptr);
43 }
44
45 Layouting::Item *newItem = new Layouting::Item(this);
46 if (frame) {
47 newItem->setGuestWidget(frame);
48 } else {
50 frame->addWidget(dw, addingOption);
51
52 newItem->setGuestWidget(frame);
53 }
54
55 Q_ASSERT(!newItem->geometry().isEmpty());
56 m_rootItem->addDockWidget(newItem, localPt);
57
58 if (addingOption.startsHidden()) {
59 delete frame;
60 }
61}
62
63void MDILayoutWidget::setDockWidgetGeometry(Frame *frame, QRect geometry)
64{
65 if (!frame)
66 return;
67
68 Layouting::Item *item = itemForFrame(frame);
69 if (!item) {
70 qWarning() << Q_FUNC_INFO << "Frame not found in the layout" << frame;
71 return;
72 }
73
74 item->setGeometry(geometry);
75}
76
77void MDILayoutWidget::moveDockWidget(DockWidgetBase *dw, QPoint pos)
78{
79 moveDockWidget(dw->d->frame(), pos);
80}
81
82void MDILayoutWidget::moveDockWidget(Frame *frame, QPoint pos)
83{
84 if (!frame)
85 return;
86
87 Layouting::Item *item = itemForFrame(frame);
88 if (!item) {
89 qWarning() << Q_FUNC_INFO << "Frame not found in the layout" << frame;
90 return;
91 }
92
93 QRect geo = item->geometry();
94 geo.moveTopLeft(pos);
95 item->setGeometry(geo);
96}
97
98void MDILayoutWidget::resizeDockWidget(DockWidgetBase *dw, QSize size)
99{
100 resizeDockWidget(dw->d->frame(), size);
101}
102
103void MDILayoutWidget::resizeDockWidget(Frame *frame, QSize size)
104{
105 if (!frame)
106 return;
107
108 Layouting::Item *item = itemForFrame(frame);
109 if (!item) {
110 qWarning() << Q_FUNC_INFO << "Frame not found in the layout" << frame << frame->isMDI()
111 << frame->isMDIWrapper();
112 return;
113 }
114
115 item->setSize(size.expandedTo(frame->minimumSize()));
116}
Application-wide config to tune certain behaviours of the framework.
A factory class for allowing the user to customize some internal widgets.
FrameworkWidgetFactory * frameworkWidgetFactory() const
getter for the framework widget factory
Definition Config.cpp:145
static Config & self()
returns the singleton Config instance
Definition Config.cpp:84
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
virtual Frame * createFrame(QWidgetOrQuick *parent=nullptr, FrameOptions options=FrameOption_None) const =0
Called internally by the framework to create a Frame class Override to provide your own Frame sub-cla...
void moveTopLeft(const QPoint &position)
QSize expandedTo(const QSize &otherSize) const const
Struct describing the preferred dock widget size and visibility when adding it to a layout.

© 2019-2023 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
KDDockWidgets
Advanced Dock Widget Framework for Qt
https://www.kdab.com/development-resources/qt-tools/kddockwidgets/
Generated on Wed Nov 1 2023 00:02:31 for KDDockWidgets API Documentation by doxygen 1.9.8