KDDockWidgets API Documentation  1.5
MainWindowInstantiator.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KDDockWidgets.
3 
4  SPDX-FileCopyrightText: 2019-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 "MainWindowInstantiator_p.h"
13 #include "MainWindowQuick_p.h"
14 #include "MainWindowMDI.h"
15 
16 #include "DockWidgetInstantiator_p.h"
17 
18 #include "../DockRegistry_p.h"
19 
20 using namespace KDDockWidgets;
21 
22 MainWindowInstantiator::MainWindowInstantiator()
23  : QQuickItem()
24 {
25 }
26 
27 QString MainWindowInstantiator::uniqueName() const
28 {
29  return m_uniqueName;
30 }
31 
32 void MainWindowInstantiator::setUniqueName(const QString &name)
33 {
34  if (name != m_uniqueName) {
35  m_uniqueName = name;
36  Q_EMIT uniqueNameChanged();
37  }
38 }
39 
40 MainWindowOptions MainWindowInstantiator::options() const
41 {
42  return m_options;
43 }
44 
45 void MainWindowInstantiator::setOptions(MainWindowOptions options)
46 {
47  if (m_options != options) {
48  m_options = options;
49  Q_EMIT optionsChanged();
50  }
51 }
52 
53 QStringList MainWindowInstantiator::affinities() const
54 {
55  return m_mainWindow ? m_mainWindow->affinities() : QStringList();
56 }
57 
58 bool MainWindowInstantiator::isMDI() const
59 {
60  return m_mainWindow && m_mainWindow->isMDI();
61 }
62 
63 void MainWindowInstantiator::addDockWidget(DockWidgetBase *dockWidget, Location location,
64  DockWidgetBase *relativeTo, QSize initialSize,
66 {
67  if (!m_mainWindow) {
68  qWarning() << Q_FUNC_INFO << "No MainWindow created yet";
69  return;
70  }
71 
72  m_mainWindow->addDockWidget(dockWidget, location, relativeTo, { option, initialSize });
73 }
74 
75 void MainWindowInstantiator::addDockWidget(DockWidgetInstantiator *dockWidget, Location location,
76  DockWidgetInstantiator *relativeTo, QSize initialSize,
78 {
79  addDockWidget(dockWidget ? dockWidget->dockWidget() : nullptr, location,
80  relativeTo ? relativeTo->dockWidget() : nullptr, initialSize, option);
81 }
82 
83 void MainWindowInstantiator::layoutEqually()
84 {
85  if (m_mainWindow)
86  m_mainWindow->layoutEqually();
87 }
88 
89 void MainWindowInstantiator::layoutParentContainerEqually(DockWidgetBase *dw)
90 {
91  if (m_mainWindow)
92  m_mainWindow->layoutParentContainerEqually(dw);
93 }
94 
95 void MainWindowInstantiator::moveToSideBar(DockWidgetBase *dw)
96 {
97  if (m_mainWindow)
98  m_mainWindow->moveToSideBar(dw);
99 }
100 
101 void MainWindowInstantiator::moveToSideBar(DockWidgetBase *dw, SideBarLocation loc)
102 {
103  if (m_mainWindow)
104  m_mainWindow->moveToSideBar(dw, loc);
105 }
106 
107 void MainWindowInstantiator::restoreFromSideBar(DockWidgetBase *dw)
108 {
109  if (m_mainWindow)
110  m_mainWindow->restoreFromSideBar(dw);
111 }
112 
113 void MainWindowInstantiator::overlayOnSideBar(DockWidgetBase *dw)
114 {
115  if (m_mainWindow)
116  m_mainWindow->overlayOnSideBar(dw);
117 }
118 
119 void MainWindowInstantiator::toggleOverlayOnSideBar(DockWidgetBase *dw)
120 {
121  if (m_mainWindow)
122  m_mainWindow->toggleOverlayOnSideBar(dw);
123 }
124 
125 void MainWindowInstantiator::clearSideBarOverlay(bool deleteFrame)
126 {
127  if (m_mainWindow)
128  m_mainWindow->clearSideBarOverlay(deleteFrame);
129 }
130 
131 SideBar *MainWindowInstantiator::sideBarForDockWidget(const DockWidgetBase *dw) const
132 {
133  return m_mainWindow ? m_mainWindow->sideBarForDockWidget(dw) : nullptr;
134 }
135 
136 bool MainWindowInstantiator::sideBarIsVisible(SideBarLocation loc) const
137 {
138  return m_mainWindow && m_mainWindow->sideBarIsVisible(loc);
139 }
140 
141 bool MainWindowInstantiator::closeDockWidgets(bool force)
142 {
143  return m_mainWindow && m_mainWindow->closeDockWidgets(force);
144 }
145 
146 void MainWindowInstantiator::classBegin()
147 {
148  // Nothing interesting to do here.
149 }
150 
151 void MainWindowInstantiator::componentComplete()
152 {
153  if (m_uniqueName.isEmpty()) {
154  qWarning() << Q_FUNC_INFO
155  << "Each DockWidget need an unique name. Set the uniqueName property.";
156  return;
157  }
158 
159  if (DockRegistry::self()->containsMainWindow(m_uniqueName)) {
160  // MainWindow already exists
161  return;
162  }
163 
164  if (m_uniqueName.isEmpty()) {
165  qWarning() << Q_FUNC_INFO << "Name can't be empty";
166  return;
167  }
168 
169  if (m_mainWindow) {
170  qWarning() << Q_FUNC_INFO << "Main window is already initialized";
171  return;
172  }
173 
174  const auto mainWindowOptions = MainWindowOptions(m_options);
175 
176  if (mainWindowOptions & MainWindowOption_MDI)
177  m_mainWindow = new MainWindowMDI(m_uniqueName, this);
178  else
179  m_mainWindow = new MainWindowQuick(m_uniqueName, mainWindowOptions, this);
180 }
KDDockWidgets::InitialVisibilityOption
InitialVisibilityOption
Definition: KDDockWidgets.h:88
KDDockWidgets::Location
Location
Definition: KDDockWidgets.h:45
QSize
KDDockWidgets::MainWindowOption_MDI
@ MainWindowOption_MDI
Makes the MainWindow always have a central frame, for tabbing documents
Definition: KDDockWidgets.h:58
QString
KDDockWidgets::SideBarLocation
SideBarLocation
Each main window supports 4 sidebars.
Definition: KDDockWidgets.h:211
KDDockWidgets::MainWindowMDI
MainWindow sub-class which uses MDI as a layout.
Definition: MainWindowMDI.h:32
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
MainWindowMDI.h
MainWindow sub-class which uses MDI as a layout.
QStringList

© 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