KDDockWidgets API Documentation 2.0
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
19using namespace KDDockWidgets;
20using namespace KDDockWidgets::QtQuick;
21
23{
24 return m_uniqueName;
25}
26
28{
29 m_uniqueName = name;
30 Q_EMIT uniqueNameChanged();
31}
32
34{
35 return m_sourceFilename;
36}
37
39{
40 m_sourceFilename = source;
41 Q_EMIT sourceChanged();
42}
43
45{
46 if (m_dockWidget) {
47 return static_cast<QtQuick::DockWidget *>(m_dockWidget->view());
48 }
49
50 return nullptr;
51}
52
57
59{
60 if (auto dockView = dockWidget()) {
61 return dockView->actualTitleBarView();
62 }
63
64 return nullptr;
65}
66
68{
69 return m_dockWidget ? m_dockWidget->title() : QString();
70}
71
73{
74 if (m_dockWidget)
75 m_dockWidget->setTitle(title);
76 m_title = title;
77}
78
80{
81 return m_dockWidget && m_dockWidget->isFocused();
82}
83
85{
86 return m_dockWidget && m_dockWidget->isFloating();
87}
88
90{
91 return m_dockWidget && m_dockWidget->isOpen();
92}
93
95{
96 if (m_dockWidget)
97 m_dockWidget->setFloating(is);
98 m_isFloating = is;
99}
100
102{
103 if (!other || !m_dockWidget)
104 return;
105
106 Core::DockWidget *otherDockWidget = Platform::dockWidgetForItem(other);
107 m_dockWidget->addDockWidgetAsTab(otherDockWidget, option);
108}
109
111 QQuickItem *relativeTo,
112 QSize initialSize,
114{
115 if (!other || !m_dockWidget)
116 return;
117
118 Core::DockWidget *otherDockWidget = Platform::dockWidgetForItem(other);
119 Core::DockWidget *relativeToDockWidget = Platform::dockWidgetForItem(relativeTo);
120
121 m_dockWidget->addDockWidgetToContainingWindow(otherDockWidget, location, relativeToDockWidget,
122 InitialOption(option, initialSize));
123}
124
126{
127 if (m_dockWidget)
128 m_dockWidget->setAsCurrentTab();
129}
130
132{
133 if (m_dockWidget)
134 m_dockWidget->forceClose();
135}
136
138{
139 if (m_dockWidget)
140 return m_dockWidget->close();
141
142 return false;
143}
144
146{
147 if (m_dockWidget)
148 m_dockWidget->open();
149}
150
152{
153 // "show" is deprecated vocabulary
154 open();
155}
156
158{
159 if (m_dockWidget)
160 m_dockWidget->raise();
161}
162
164{
165 if (m_dockWidget)
166 m_dockWidget->moveToSideBar();
167}
168
170{
171 delete m_dockWidget;
172 delete this;
173}
174
176{
177 // Nothing interesting to do here.
178}
179
181{
182 if (m_uniqueName.isEmpty()) {
183 qWarning() << Q_FUNC_INFO
184 << "Each DockWidget need an unique name. Set the uniqueName property.";
185 return;
186 }
187
188 if (DockRegistry::self()->containsDockWidget(m_uniqueName)) {
189 // Dock widget already exists. all good.
190 return;
191 }
192
193 if (m_dockWidget) {
194 qWarning() << Q_FUNC_INFO << "Unexpected bug.";
195 return;
196 }
197 const auto childItems = this->childItems();
198 if (m_sourceFilename.isEmpty() && childItems.size() != 1) {
199 qWarning() << Q_FUNC_INFO << "Either 'source' property must be set or add exactly one child"
200 << "; source=" << m_sourceFilename << "; num children=" << childItems.size();
201 return;
202 }
203
204 m_dockWidget = ViewFactory::self()
205 ->createDockWidget(m_uniqueName, qmlEngine(this))
207
208 m_dockWidget->d->titleChanged.connect([this](const QString &title) { Q_EMIT titleChanged(title); });
209 m_dockWidget->d->closed.connect([this] { Q_EMIT closed(); });
210 m_dockWidget->d->iconChanged.connect([this] { Q_EMIT iconChanged(); });
211 m_dockWidget->d->actualTitleBarChanged.connect([this] { Q_EMIT actualTitleBarChanged(); });
212 m_dockWidget->d->optionsChanged.connect([this](KDDockWidgets::DockWidgetOptions opts) { Q_EMIT optionsChanged(opts); });
213
214 m_dockWidget->d->windowActiveAboutToChange.connect([this](bool is) { Q_EMIT windowActiveAboutToChange(is); });
215 m_dockWidget->d->isFocusedChanged.connect([this](bool is) { Q_EMIT isFocusedChanged(is); });
216
217 m_dockWidget->d->isOverlayedChanged.connect([this](bool is) { Q_EMIT isOverlayedChanged(is); });
218 m_dockWidget->d->isFloatingChanged.connect([this](bool is) { Q_EMIT isFloatingChanged(is); });
219 m_dockWidget->d->isOpenChanged.connect([this](bool is) { Q_EMIT isOpenChanged(is); });
220
221 m_dockWidget->d->guestViewChanged.connect([this] { Q_EMIT guestViewChanged(QtQuick::asQQuickItem(m_dockWidget->guestView().get())); });
222 m_dockWidget->d->removedFromSideBar.connect([this] { Q_EMIT removedFromSideBar(); });
223
224 auto view = this->dockWidget();
225 if (m_sourceFilename.isEmpty()) {
226 view->setGuestItem(childItems.constFirst());
227 } else {
228 view->setGuestItem(m_sourceFilename);
229 }
230
231 if (!m_title.isEmpty())
232 m_dockWidget->setTitle(m_title);
233
234 if (m_isFloating.has_value())
235 m_dockWidget->setFloating(m_isFloating.value());
236
237 Q_EMIT dockWidgetChanged();
238}
Application-wide config to tune certain behaviours of the framework.
View * view() const
Returns the view associated with this controller, if any.
The DockWidget base-class. DockWidget and Core::DockWidget are only split in two so we can share some...
bool setFloating(bool floats)
setter to make the dock widget float or dock.
void setAsCurrentTab()
Makes this dock widget current in its tab group.
void setTitle(const QString &title)
setter for the dock widget's title
void addDockWidgetToContainingWindow(KDDockWidgets::Core::DockWidget *other, KDDockWidgets::Location location, KDDockWidgets::Core::DockWidget *relativeTo=nullptr, KDDockWidgets::InitialOption initialOption={})
docks other widget into the window that contains this one. Equivalent to MainWindow::addDockWidget() ...
void addDockWidgetAsTab(KDDockWidgets::Core::DockWidget *other, KDDockWidgets::InitialOption initialOption={})
docks other widget into this one. Tabs will be shown if not already.
bool isOpen() const
Returns whether this dock widget is open. Equivalent to calling toggleAction().isChecked()
void open()
Opens this dock widget. Does nothing if already open. The dock widget will appear floating unless it ...
bool isFocused() const
Returns whether This or any child of this dock widget is focused Not to be confused with QWidget::has...
QString title() const
Returns the dock widget's title. This title is visible in title bars and tab bars.
void moveToSideBar()
Minimizes this dock widget to the MainWindow's side-bar.
bool isFloating() const
Returns whether the dock widget is floating. Floating means it's not docked and has a window of its o...
std::shared_ptr< View > guestView() const
Like widget() but returns a view.
void raise()
Brings the dock widget to the front.
void forceClose()
Like QWidget::close() but the hosted widget won't be asked if we should close.
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)
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.
bool isEmpty() const const
int size() const const
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