KDDockWidgets API Documentation 2.1
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 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
13#include "kddockwidgets/core/DockRegistry.h"
14#include "core/DockWidget_p.h"
15#include "ViewFactory.h"
16#include "Config.h"
17#include "Platform.h"
18
19#include <kdbindings/signal.h>
20
21using namespace KDDockWidgets;
22using namespace KDDockWidgets::QtQuick;
23
24class DockWidgetInstantiator::Private
25{
26public:
27 std::optional<bool> m_isFloating;
28 QString m_uniqueName;
29 QString m_sourceFilename;
30 QString m_title;
31 Core::DockWidget *m_dockWidget = nullptr;
32 QVector<QString> m_affinities;
33
34 KDBindings::ScopedConnection titleConnection;
35 KDBindings::ScopedConnection closedConnection;
36 KDBindings::ScopedConnection iconConnection;
37 KDBindings::ScopedConnection actualTitleBarConnection;
38 KDBindings::ScopedConnection optionsConnection;
39 KDBindings::ScopedConnection windowActiveAboutToChangeConnection;
40 KDBindings::ScopedConnection isOverlayedConnection;
41 KDBindings::ScopedConnection isFocusedConnection;
42 KDBindings::ScopedConnection isFloatingConnection;
43 KDBindings::ScopedConnection isOpenConnection;
44 KDBindings::ScopedConnection guestViewChangedConnection;
45 KDBindings::ScopedConnection removedFromSideBarConnection;
46};
47
49 : d(new Private())
50{
51}
52
57
59{
60 return d->m_uniqueName;
61}
62
64{
65 d->m_uniqueName = name;
66 Q_EMIT uniqueNameChanged();
67}
68
70{
71 return d->m_sourceFilename;
72}
73
75{
76 d->m_sourceFilename = source;
77 Q_EMIT sourceChanged();
78}
79
81{
82 if (d->m_dockWidget) {
83 return static_cast<QtQuick::DockWidget *>(d->m_dockWidget->view());
84 }
85
86 return nullptr;
87}
88
90{
91 return d->m_dockWidget;
92}
93
95{
96 if (auto dockView = dockWidget()) {
97 return dockView->actualTitleBarView();
98 }
99
100 return nullptr;
101}
102
104{
105 return d->m_dockWidget ? d->m_dockWidget->title() : QString();
106}
107
109{
110 if (d->m_dockWidget)
111 d->m_dockWidget->setTitle(title);
112 d->m_title = title;
113}
114
116{
117 return d->m_dockWidget && d->m_dockWidget->isFocused();
118}
119
121{
122 return d->m_dockWidget && d->m_dockWidget->isFloating();
123}
124
126{
127 return d->m_dockWidget && d->m_dockWidget->isOpen();
128}
129
131{
132 if (d->m_dockWidget)
133 d->m_dockWidget->setFloating(is);
134 d->m_isFloating = is;
135}
136
138{
139 if (!other || !d->m_dockWidget)
140 return;
141
142 Core::DockWidget *otherDockWidget = Platform::dockWidgetForItem(other);
143 d->m_dockWidget->addDockWidgetAsTab(otherDockWidget, option);
144}
145
147 QQuickItem *relativeTo,
148 QSize initialSize,
150{
151 if (!other || !d->m_dockWidget)
152 return;
153
154 Core::DockWidget *otherDockWidget = Platform::dockWidgetForItem(other);
155 Core::DockWidget *relativeToDockWidget = Platform::dockWidgetForItem(relativeTo);
156
157 d->m_dockWidget->addDockWidgetToContainingWindow(otherDockWidget, location, relativeToDockWidget,
158 InitialOption(option, initialSize));
159}
160
162{
163 if (d->m_dockWidget)
164 d->m_dockWidget->setAsCurrentTab();
165}
166
168{
169 if (d->m_dockWidget)
170 d->m_dockWidget->forceClose();
171}
172
174{
175 if (d->m_dockWidget)
176 return d->m_dockWidget->close();
177
178 return false;
179}
180
182{
183 if (d->m_dockWidget)
184 d->m_dockWidget->open();
185}
186
188{
189 // "show" is deprecated vocabulary
190 open();
191}
192
194{
195 if (d->m_dockWidget)
196 d->m_dockWidget->raise();
197}
198
200{
201 if (d->m_dockWidget)
202 d->m_dockWidget->moveToSideBar();
203}
204
206{
207 delete d->m_dockWidget;
208 delete this;
209}
210
212{
213 // Nothing interesting to do here.
214}
215
217{
218 return d->m_dockWidget ? d->m_dockWidget->affinities() : QVector<QString>();
219}
220
222{
223 if (d->m_affinities != affinities) {
224 d->m_affinities = affinities;
225 Q_EMIT affinitiesChanged();
226 }
227}
228
230{
231 if (d->m_uniqueName.isEmpty()) {
232 qWarning() << Q_FUNC_INFO
233 << "Each DockWidget need an unique name. Set the uniqueName property.";
234 return;
235 }
236
237 if (DockRegistry::self()->containsDockWidget(d->m_uniqueName)) {
238 // Dock widget already exists. all good.
239 return;
240 }
241
242 if (d->m_dockWidget) {
243 qWarning() << Q_FUNC_INFO << "Unexpected bug.";
244 return;
245 }
246 const auto childItems = this->childItems();
247 if (d->m_sourceFilename.isEmpty() && childItems.size() != 1) {
248 qWarning() << Q_FUNC_INFO << "Either 'source' property must be set or add exactly one child"
249 << "; source=" << d->m_sourceFilename << "; num children=" << childItems.size();
250 return;
251 }
252
253 d->m_dockWidget = ViewFactory::self()
254 ->createDockWidget(d->m_uniqueName, qmlEngine(this))
256
257 d->titleConnection = d->m_dockWidget->d->titleChanged.connect([this](const QString &title) { Q_EMIT titleChanged(title); });
258 d->closedConnection = d->m_dockWidget->d->closed.connect([this] { Q_EMIT closed(); });
259 d->iconConnection = d->m_dockWidget->d->iconChanged.connect([this] { Q_EMIT iconChanged(); });
260 d->actualTitleBarConnection = d->m_dockWidget->d->actualTitleBarChanged.connect([this] { Q_EMIT actualTitleBarChanged(); });
261 d->optionsConnection = d->m_dockWidget->d->optionsChanged.connect([this](KDDockWidgets::DockWidgetOptions opts) { Q_EMIT optionsChanged(opts); });
262
263 d->windowActiveAboutToChangeConnection = d->m_dockWidget->d->windowActiveAboutToChange.connect([this](bool is) { Q_EMIT windowActiveAboutToChange(is); });
264 d->isFocusedConnection = d->m_dockWidget->d->isFocusedChanged.connect([this](bool is) { Q_EMIT isFocusedChanged(is); });
265
266 d->isOverlayedConnection = d->m_dockWidget->d->isOverlayedChanged.connect([this](bool is) { Q_EMIT isOverlayedChanged(is); });
267 d->isFloatingConnection = d->m_dockWidget->d->isFloatingChanged.connect([this](bool is) { Q_EMIT isFloatingChanged(is); });
268 d->isOpenConnection = d->m_dockWidget->d->isOpenChanged.connect([this](bool is) { Q_EMIT isOpenChanged(is); });
269
270 d->guestViewChangedConnection = d->m_dockWidget->d->guestViewChanged.connect([this] { Q_EMIT guestViewChanged(QtQuick::asQQuickItem(d->m_dockWidget->guestView().get())); });
271 d->removedFromSideBarConnection = d->m_dockWidget->d->removedFromSideBar.connect([this] { Q_EMIT removedFromSideBar(); });
272
273 auto view = this->dockWidget();
274 if (d->m_sourceFilename.isEmpty()) {
275 view->setGuestItem(childItems.constFirst());
276 } else {
277 view->setGuestItem(d->m_sourceFilename);
278 }
279
280 if (!d->m_title.isEmpty())
281 d->m_dockWidget->setTitle(d->m_title);
282
283 if (d->m_isFloating.has_value())
284 d->m_dockWidget->setFloating(d->m_isFloating.value());
285
286 d->m_dockWidget->setAffinities(d->m_affinities);
287
288 Q_EMIT dockWidgetChanged();
289}
Application-wide config to tune certain behaviours of the framework.
A ScopedConnection is a RAII-style way to make sure a Connection is disconnected.
Definition signal.h:533
The DockWidget base-class. DockWidget and Core::DockWidget are only split in two so we can share some...
Core::DockWidget * asDockWidgetController() const
static DockRegistry * self()
Q_INVOKABLE void addDockWidgetToContainingWindow(QQuickItem *other, KDDockWidgets::Location location, QQuickItem *relativeTo=nullptr, QSize initialSize={}, KDDockWidgets::InitialVisibilityOption={})
void windowActiveAboutToChange(bool activated)
void setAffinities(const QVector< QString > &)
KDDockWidgets::QtQuick::DockWidget * dockWidget
void titleChanged(const QString &title)
KDDockWidgets::Core::DockWidget * controller() const
void optionsChanged(KDDockWidgets::DockWidgetOptions)
Q_INVOKABLE void addDockWidgetAsTab(QQuickItem *other, KDDockWidgets::InitialVisibilityOption={})
static Core::DockWidget * dockWidgetForItem(QQuickItem *)
Core::View * createDockWidget(const QString &uniqueName, DockWidgetOptions options={}, LayoutSaverOptions layoutSaverOptions={}, Qt::WindowFlags windowFlags={}) const override
Creates a dock widget. This is only used by MainWindow's persistent widget feature....
QQuickItem * asQQuickItem(Core::View *view)
Class to abstract QAction, so code still works with QtQuick and Flutter.
A factory class for allowing the user to customize some internal widgets.
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