KDDockWidgets API Documentation  1.6
MDIArea.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 "MDIArea.h"
13 #include "DockWidgetBase.h"
14 #include "private/MDILayoutWidget_p.h"
15 #include "private/DropAreaWithCentralFrame_p.h"
16 
17 #ifdef KDDOCKWIDGETS_QTWIDGETS
18 #include "DockWidget.h"
19 #include <QVBoxLayout>
20 #else
21 #include "DockWidgetQuick.h"
22 #endif
23 
24 #include <QGuiApplication>
25 #include <QCloseEvent>
26 
27 using namespace KDDockWidgets;
28 
29 class MDIArea::Private
30 {
31 public:
32  Private(QWidgetOrQuick *parent)
33  : layoutWidget(new MDILayoutWidget(parent))
34  {
35  }
36 
37  ~Private()
38  {
39  delete layoutWidget;
40  }
41 
42  MDILayoutWidget *const layoutWidget;
43 };
44 
46  : QWidgetAdapter(parent)
47  , d(new Private(this))
48 {
49 #ifdef KDDOCKWIDGETS_QTWIDGETS
50  auto vlay = new QVBoxLayout(this);
51  vlay->setContentsMargins({});
52  vlay->addWidget(d->layoutWidget);
53 #else
54  QWidgetAdapter::makeItemFillParent(d->layoutWidget);
55 #endif
56 }
57 
59 {
60  delete d;
61 }
62 
64 {
66  // We' wrap it with a drop area, so we can drag other dock widgets over this one and dock
67  auto wrapperDW = new DockWidgetType(QStringLiteral("%1-mdiWrapper").arg(dw->uniqueName()));
68  auto dropAreaWrapper = new DropArea(wrapperDW, /*isMDIWrapper= */ true);
69  dropAreaWrapper->addDockWidget(dw, Location_OnBottom, nullptr);
70  wrapperDW->setWidget(dropAreaWrapper);
71 
72  dw = wrapperDW;
73  }
74 
75  d->layoutWidget->addDockWidget(dw, localPt, addingOption);
76 }
77 
79 {
80  d->layoutWidget->moveDockWidget(dw, pos);
81 }
82 
84 {
85  d->layoutWidget->resizeDockWidget(dw, size);
86 }
87 
89 {
90  return d->layoutWidget->frames();
91 }
92 
94 {
95  e->accept(); // Accepted by default (will close unless ignored)
96 
97  const Frame::List frames = this->frames();
98  for (Frame *frame : frames) {
99  qApp->sendEvent(frame, e);
100  if (!e->isAccepted())
101  break; // Stop when the first frame prevents closing
102  }
103 }
DockWidgetBase.h
The DockWidget base-class that's shared between QtWidgets and QtQuick stack.
QVBoxLayout
DockWidgetQuick.h
Represents a dock widget.
KDDockWidgets::InitialOption
Struct describing the preferred dock widget size and visibility when adding it to a layout.
Definition: KDDockWidgets.h:101
QWidget
KDDockWidgets::DockWidgetBase::uniqueName
QString uniqueName
Definition: DockWidgetBase.h:65
QSize
DockWidget.h
Represents a dock widget.
KDDockWidgets::MDIArea::frames
QList< Frame * > frames() const
Returns the list of frames in this MDI Area Each Frame object represents a 'window' emebedded in the ...
Definition: MDIArea.cpp:88
QList
MDIArea.h
KDDockWidgets::Location_OnBottom
@ Location_OnBottom
Right docking location
Definition: KDDockWidgets.h:49
KDDockWidgets::MDIArea::~MDIArea
~MDIArea()
Definition: MDIArea.cpp:58
KDDockWidgets::MDIArea::addDockWidget
void addDockWidget(DockWidgetBase *dw, QPoint localPt, InitialOption addingOption={})
docks the dock widgets into this MDI area, at the specified position
Definition: MDIArea.cpp:63
QCloseEvent
KDDockWidgets::DockWidgetBase::Option_MDINestable
@ Option_MDINestable
Definition: DockWidgetBase.h:79
QEvent::isAccepted
bool isAccepted() const const
KDDockWidgets::MDIArea::moveDockWidget
void moveDockWidget(DockWidgetBase *dw, QPoint pos)
Moves a dock widget dw to point pos.
Definition: MDIArea.cpp:78
KDDockWidgets::MDIArea::resizeDockWidget
void resizeDockWidget(DockWidgetBase *dw, QSize size)
Sets the size of dock widget dw to size.
Definition: MDIArea.cpp:83
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:37
KDDockWidgets::DockWidgetType
KDDockWidgets::DockWidget DockWidgetType
Definition: QWidgetAdapter.h:51
KDDockWidgets::MDIArea::onCloseEvent
void onCloseEvent(QCloseEvent *) override
Forwards the close event to the MDI dock widgets, aborts closing if at least one dock widget doesn't ...
Definition: MDIArea.cpp:93
KDDockWidgets::DockWidgetBase::options
KDDockWidgets::DockWidgetBase::Options options
Definition: DockWidgetBase.h:69
QPoint
KDDockWidgets::MDIArea::MDIArea
MDIArea(QWidgetOrQuick *parent=nullptr)
Definition: MDIArea.cpp:45
QEvent::accept
void accept()

© 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 Thu Sep 15 2022 00:16:29 for KDDockWidgets API Documentation by doxygen 1.8.20