KDDockWidgets API Documentation  1.5
MDILayoutWidget.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KDDockWidgets.
3 
4  SPDX-FileCopyrightText: 2020-2022 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"
16 #include "FrameworkWidgetFactory.h"
17 
18 using namespace KDDockWidgets;
19 
20 MDILayoutWidget::MDILayoutWidget(QWidgetOrQuick *parent)
21  : LayoutWidget(parent)
22  , m_rootItem(new Layouting::ItemFreeContainer(this))
23 {
24  setRootItem(m_rootItem);
25 }
26 
27 MDILayoutWidget::~MDILayoutWidget()
28 {
29 }
30 
31 void 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 
63 void 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 
77 void MDILayoutWidget::moveDockWidget(DockWidgetBase *dw, QPoint pos)
78 {
79  moveDockWidget(dw->d->frame(), pos);
80 }
81 
82 void 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 
98 void MDILayoutWidget::resizeDockWidget(DockWidgetBase *dw, QSize size)
99 {
100  resizeDockWidget(dw->d->frame(), size);
101 }
102 
103 void 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;
111  return;
112  }
113 
114  item->setSize(size.expandedTo(frame->minimumSize()));
115 }
QRect::moveTopLeft
void moveTopLeft(const QPoint &position)
KDDockWidgets::FrameOption_None
@ FrameOption_None
Definition: KDDockWidgets.h:260
QRect
KDDockWidgets::InitialOption
Struct describing the preferred dock widget size and visibility when adding it to a layout.
Definition: KDDockWidgets.h:105
QWidget
QSize
KDDockWidgets::Config::frameworkWidgetFactory
FrameworkWidgetFactory * frameworkWidgetFactory() const
getter for the framework widget factory
Definition: Config.cpp:143
KDDockWidgets::FrameworkWidgetFactory::createFrame
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...
Config.h
Application-wide config to tune certain behaviours of the framework.
QSize::expandedTo
QSize expandedTo(const QSize &otherSize) const const
KDDockWidgets::InitialOption::startsHidden
bool startsHidden() const
Definition: KDDockWidgets.h:133
KDDockWidgets::DockWidgetBase
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
Definition: DockWidgetBase.h:61
KDDockWidgets
Definition: Config.cpp:36
Layouting
Definition: FrameworkWidgetFactory.h:32
QPoint
KDDockWidgets::Config::self
static Config & self()
returns the singleton Config instance
Definition: Config.cpp:82
FrameworkWidgetFactory.h
A factory class for allowing the user to customize some internal widgets.

© 2019-2022 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 Mon Mar 7 2022 02:01:20 for KDDockWidgets API Documentation by doxygen 1.8.20