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 InitialOption addingOption)
36{
37 if (!dw) {
38 KDDW_ERROR("Refusing to add null dock widget");
39 return;
40 }
41
42 auto group = object_cast<Core::Group *>(dw->d->group());
43 if (itemForFrame(group) != nullptr) {
44 // Item already exists, remove it. See also comment in MultiSplitter::addWidget().
45 group->setParentView(nullptr);
46 group->setLayoutItem(nullptr);
47 }
48
49 Core::Item *newItem = new Core::Item(asLayoutingHost());
50 if (group) {
51 newItem->setGuest(group->asLayoutingGuest());
52 } else {
53 group = new Core::Group();
54 group->addTab(dw, addingOption);
55
56 newItem->setGuest(group->asLayoutingGuest());
57 }
58
59 assert(!newItem->geometry().isEmpty());
60 m_rootItem->addDockWidget(newItem, localPt);
61
62 if (addingOption.startsHidden()) {
63 delete group;
64 }
65}
66
68{
69 if (!group)
70 return;
71
72 Core::Item *item = itemForFrame(group);
73 if (!item) {
74 KDDW_ERROR("Group not found in the layout {}", ( void * )group);
75 return;
76 }
77
78 item->setGeometry(geometry);
79}
80
82{
83 moveDockWidget(dw->d->group(), pos);
84}
85
87{
88 if (!group)
89 return;
90
91 Core::Item *item = itemForFrame(group);
92 if (!item) {
93 KDDW_ERROR("Group not found in the layout {}.", ( void * )group);
94 return;
95 }
96
97 Rect geo = item->geometry();
98 geo.moveTopLeft(pos);
99 item->setGeometry(geo);
100}
101
103{
104 resizeDockWidget(dw->d->group(), size);
105}
106
108{
109 if (!group)
110 return;
111
112 Core::Item *item = itemForFrame(group);
113 if (!item) {
114 KDDW_ERROR("Group not found in the layout {} isMDI={}, isMDIWrapper={}", ( void * )group, group->isMDI(), group->isMDIWrapper());
115 return;
116 }
117
118 item->setSize(size.expandedTo(group->view()->minSize()));
119}
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:104
LayoutingHost * asLayoutingHost() const
Definition Layout.cpp:370
Core::Item * itemForFrame(const Core::Group *group) const
returns the Item that holds group in this layout
Definition Layout.cpp:227
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, 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