KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
DockWidgetInstantiator.cpp
Go to the documentation of this file.
1/*
2 This file is part of KDDockWidgets.
3
4 SPDX-FileCopyrightText: 2019-2023 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 "DockWidgetInstantiator_p.h"
13#include "DockWidgetQuick.h"
14#include "../DockRegistry_p.h"
15
16using namespace KDDockWidgets;
17
18QString DockWidgetInstantiator::uniqueName() const
19{
20 return m_uniqueName;
21}
22
23void DockWidgetInstantiator::setUniqueName(const QString &name)
24{
25 m_uniqueName = name;
26 Q_EMIT uniqueNameChanged();
27}
28
29QString DockWidgetInstantiator::source() const
30{
31 return m_sourceFilename;
32}
33
34void DockWidgetInstantiator::setSource(const QString &source)
35{
36 m_sourceFilename = source;
37 Q_EMIT sourceChanged();
38}
39
40DockWidgetQuick *DockWidgetInstantiator::dockWidget() const
41{
42 return m_dockWidget;
43}
44
45TitleBar *DockWidgetInstantiator::actualTitleBar() const
46{
47 return m_dockWidget ? m_dockWidget->actualTitleBar() : nullptr;
48}
49
50QString DockWidgetInstantiator::title() const
51{
52 return m_dockWidget ? m_dockWidget->title() : QString();
53}
54
55void DockWidgetInstantiator::setTitle(const QString &title)
56{
57 if (m_dockWidget)
58 m_dockWidget->setTitle(title);
59 m_title = title;
60}
61
62bool DockWidgetInstantiator::isFocused() const
63{
64 return m_dockWidget && m_dockWidget->isFocused();
65}
66
67bool DockWidgetInstantiator::isFloating() const
68{
69 return m_dockWidget && m_dockWidget->isFloating();
70}
71
72void DockWidgetInstantiator::setFloating(bool is)
73{
74 if (m_dockWidget)
75 m_dockWidget->setFloating(is);
76 m_isFloating = is;
77}
78
79void DockWidgetInstantiator::addDockWidgetAsTab(DockWidgetInstantiator *other,
81{
82 if (m_dockWidget)
83 m_dockWidget->addDockWidgetAsTab(other ? other->dockWidget() : nullptr, option);
84}
85
86void DockWidgetInstantiator::addDockWidgetAsTab(DockWidgetBase *other,
88{
89 if (m_dockWidget)
90 m_dockWidget->addDockWidgetAsTab(other, option);
91}
92
93void DockWidgetInstantiator::addDockWidgetToContainingWindow(DockWidgetBase *other,
94 Location location,
95 DockWidgetBase *relativeTo,
96 QSize initialSize,
98{
99 if (m_dockWidget)
100 m_dockWidget->addDockWidgetToContainingWindow(other, location, relativeTo,
101 InitialOption(option, initialSize));
102}
103
104void DockWidgetInstantiator::addDockWidgetToContainingWindow(DockWidgetInstantiator *other,
105 Location location,
106 DockWidgetInstantiator *relativeTo,
107 QSize initialSize,
109{
110 if (m_dockWidget)
111 m_dockWidget->addDockWidgetToContainingWindow(
112 other ? other->dockWidget() : nullptr, location,
113 relativeTo ? relativeTo->dockWidget() : nullptr, InitialOption(option, initialSize));
114}
115
116void DockWidgetInstantiator::setAsCurrentTab()
117{
118 if (m_dockWidget)
119 m_dockWidget->setAsCurrentTab();
120}
121
122void DockWidgetInstantiator::forceClose()
123{
124 if (m_dockWidget)
125 m_dockWidget->forceClose();
126}
127
128Q_INVOKABLE bool DockWidgetInstantiator::close()
129{
130 if (m_dockWidget)
131 return m_dockWidget->close();
132
133 return false;
134}
135
136void DockWidgetInstantiator::show()
137{
138 if (m_dockWidget)
139 m_dockWidget->show();
140}
141
142void DockWidgetInstantiator::raise()
143{
144 if (m_dockWidget)
145 m_dockWidget->raise();
146}
147
148void DockWidgetInstantiator::moveToSideBar()
149{
150 if (m_dockWidget)
151 m_dockWidget->moveToSideBar();
152}
153
154void DockWidgetInstantiator::classBegin()
155{
156 // Nothing interesting to do here.
157}
158
159void DockWidgetInstantiator::componentComplete()
160{
161 if (m_uniqueName.isEmpty()) {
162 qWarning() << Q_FUNC_INFO << "Each DockWidget need an unique name. Set the uniqueName property.";
163 return;
164 }
165
166 if (DockRegistry::self()->containsDockWidget(m_uniqueName)) {
167 // Dock widget already exists. all good.
168 return;
169 }
170
171 if (m_dockWidget) {
172 qWarning() << Q_FUNC_INFO << "Unexpected bug.";
173 return;
174 }
175 const auto childItems = this->childItems();
176 if (m_sourceFilename.isEmpty() && childItems.size() != 1) {
177 qWarning() << Q_FUNC_INFO << "Either 'source' property must be set or add exactly one child"
178 << "; source=" << m_sourceFilename << "; num children=" << childItems.size();
179 return;
180 }
181
182 m_dockWidget = new DockWidgetQuick(m_uniqueName, {}, {}, qmlEngine(this));
183
184 connect(m_dockWidget, &DockWidgetQuick::titleChanged, this,
185 &DockWidgetInstantiator::titleChanged);
186 connect(m_dockWidget, &DockWidgetQuick::actualTitleBarChanged, this,
187 &DockWidgetInstantiator::actualTitleBarChanged);
188 connect(m_dockWidget, &DockWidgetQuick::optionsChanged, this,
189 &DockWidgetInstantiator::optionsChanged);
190 connect(m_dockWidget, &DockWidgetQuick::shown, this, &DockWidgetInstantiator::shown);
191 connect(m_dockWidget, &DockWidgetQuick::hidden, this, &DockWidgetInstantiator::hidden);
192 connect(m_dockWidget, &DockWidgetQuick::iconChanged, this,
193 &DockWidgetInstantiator::iconChanged);
194 connect(m_dockWidget, &DockWidgetQuick::widgetChanged, this,
195 &DockWidgetInstantiator::widgetChanged);
196 connect(m_dockWidget, &DockWidgetQuick::isFocusedChanged, this,
197 &DockWidgetInstantiator::isFocusedChanged);
198 connect(m_dockWidget, &DockWidgetQuick::isFocusedChanged, this,
199 &DockWidgetInstantiator::isFocusedChanged);
200 connect(m_dockWidget, &DockWidgetQuick::isOverlayedChanged, this,
201 &DockWidgetInstantiator::isOverlayedChanged);
202 connect(m_dockWidget, &DockWidgetQuick::isFloatingChanged, this,
203 &DockWidgetInstantiator::isFloatingChanged);
204 connect(m_dockWidget, &DockWidgetQuick::removedFromSideBar, this,
205 &DockWidgetInstantiator::removedFromSideBar);
206 connect(m_dockWidget, &DockWidgetQuick::windowActiveAboutToChange, this,
207 &DockWidgetInstantiator::windowActiveAboutToChange);
208
209
210 if (m_sourceFilename.isEmpty()) {
211 m_dockWidget->setWidget(childItems.constFirst());
212 } else {
213 m_dockWidget->setWidget(m_sourceFilename);
214 }
215
216 if (!m_title.isEmpty())
217 m_dockWidget->setTitle(m_title);
218
219 if (m_isFloating.has_value())
220 m_dockWidget->setFloating(m_isFloating.value());
221
222 Q_EMIT dockWidgetChanged();
223}
Represents a dock widget.
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
Represents a dock widget.
Struct describing the preferred dock widget size and visibility when adding it to a layout.

© 2019-2023 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 Wed Nov 1 2023 00:02:31 for KDDockWidgets API Documentation by doxygen 1.9.8