KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
core/MDILayout.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2020 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 "MDILayout.h"
13#include "core/layouting/ItemFreeContainer_p.h"
14#include "Config.h"
15#include "core/ViewFactory.h"
16#include "core/Group_p.h"
17#include "core/DockWidget_p.h"
18#include "core/Logging_p.h"
19
20using namespace KDDockWidgets;
21using namespace KDDockWidgets::Core;
22
24 : Layout(ViewType::MDILayout, Config::self().viewFactory()->createMDILayout(this, parent))
25 , m_rootItem(new Core::ItemFreeContainer(asLayoutingHost()))
26{
27 setRootItem(m_rootItem);
28}
29
33
35 const InitialOption &addingOption)
36{
37 if (!dw) {
38 KDDW_ERROR("Refusing to add null dock widget");
39 return;
40 }
41
42 const Size dwSize = dw->size();
43
44 auto group = object_cast<Core::Group *>(dw->d->group());
45 if (itemForGroup(group) != nullptr) {
46 // Item already exists, remove it. See also comment in MultiSplitter::addWidget().
47 group->setParentView(nullptr);
48 group->setLayoutItem(nullptr);
49 }
50
51 Core::Item *newItem = new Core::Item(asLayoutingHost());
52 if (group) {
53 newItem->setGuest(group->asLayoutingGuest());
54 } else {
55 group = new Core::Group();
56 group->addTab(dw, addingOption);
57
58 newItem->setGuest(group->asLayoutingGuest());
59 }
60
61 newItem->setSize(dwSize.expandedTo(newItem->minSize()));
62
63 assert(!newItem->geometry().isEmpty());
64 m_rootItem->addDockWidget(newItem, localPt);
65
66 if (addingOption.startsHidden()) {
67 delete group;
68 }
69}
70
72{
73 if (!group)
74 return;
75
76 Core::Item *item = itemForGroup(group);
77 if (!item) {
78 KDDW_ERROR("Group not found in the layout {}", ( void * )group);
79 return;
80 }
81
82 item->setGeometry(geometry);
83}
84
86{
87 moveDockWidget(dw->d->group(), pos);
88}
89
91{
92 if (!group)
93 return;
94
95 Core::Item *item = itemForGroup(group);
96 if (!item) {
97 KDDW_ERROR("Group not found in the layout {}.", ( void * )group);
98 return;
99 }
100
101 Rect geo = item->geometry();
102 geo.moveTopLeft(pos);
103 item->setGeometry(geo);
104}
105
107{
108 resizeDockWidget(dw->d->group(), size);
109}
110
112{
113 if (!group)
114 return;
115
116 Core::Item *item = itemForGroup(group);
117 if (!item) {
118 KDDW_ERROR("Group not found in the layout {} isMDI={}, isMDIWrapper={}", ( void * )group, group->isMDI(), group->isMDIWrapper());
119 return;
120 }
121
122 item->setSize(size.expandedTo(group->view()->minSize()));
123}
Application-wide config to tune certain behaviours of the framework.
Singleton to allow to choose certain behaviours of the framework.
Definition Config.h:64
View * view() const
Returns the view associated with this controller, if any.
The DockWidget base-class. DockWidget and Core::DockWidget are only split in two so we can share some...
bool isMDI() const
Returns whether this group is in a MDI layout Usually no, unless you're using an MDI main window.
The widget (QWidget or QQuickItem) which holds a layout of dock widgets.
Definition Layout.h:57
void setRootItem(Core::ItemContainer *root)
Definition Layout.cpp:101
LayoutingHost * asLayoutingHost() const
Definition Layout.cpp:367
Core::Item * itemForGroup(const Core::Group *group) const
returns the Item that holds group in this layout
Definition Layout.cpp:224
The MDILayout class implements a layout suitable for MDI style docking. Where dock widgets are free t...
void moveDockWidget(Core::DockWidget *dw, Point pos)
Moves a dock widget dw to point pos.
void addDockWidget(Core::DockWidget *dw, Point localPt, const InitialOption &addingOption={})
docks the dock widgets into this MDI area, at the specified position
void setDockWidgetGeometry(Core::Group *group, Rect)
sets the size and position of the dock widget group
void resizeDockWidget(Core::DockWidget *dw, Size size)
Sets the size of dock widget dw to size.
MDILayout(View *parent=nullptr)
virtual Size minSize() const =0
ViewType
Each View type also has a specific Controller associated with, except for ViewType::None.
Definition Controller.h:26
Class to abstract QAction, so code still works with QtQuick and Flutter.
Struct describing the preferred dock widget size and visibility when adding it to a layout.

© 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 by doxygen 1.9.8