KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
qtquick/views/Group.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
19#include "Group.h"
20
22#include "qtquick/ViewFactory.h"
23#include "qtquick/Platform.h"
25#include "qtquick/views/ViewWrapper_p.h"
26
27#include "kddockwidgets/core/Group.h"
28#include "kddockwidgets/core/Stack.h"
29#include "kddockwidgets/core/TitleBar.h"
30#include "kddockwidgets/core/DockWidget.h"
31#include "core/DockWidget_p.h"
32#include "core/Group_p.h"
33
34#include "Stack.h"
35#include "Config.h"
36#include "core/WidgetResizeHandler_p.h"
37#include "core/TabBar_p.h"
38
39#include <QDebug>
40
41using namespace KDDockWidgets;
42using namespace KDDockWidgets::QtQuick;
43
44namespace KDDockWidgets::QtQuick {
45
46class Group::Private
47{
48public:
49 KDBindings::ScopedConnection isMDIConnection;
50 KDBindings::ScopedConnection currentDockWidgetChangedConnection;
51 KDBindings::ScopedConnection updateConstraintsConnection;
52};
53
54}
55
56Group::Group(Core::Group *controller, QQuickItem *parent)
57 : QtQuick::View(controller, Core::ViewType::Frame, parent)
58 , Core::GroupViewInterface(controller)
59 , d(new Private())
60{
61}
62
64{
65 delete d;
66
67 // The QML item must be deleted with deleteLater(), as we might be currently with its mouse
68 // handler in the stack. QML doesn't support it being deleted in that case.
69 // So unparent it and deleteLater().
70 m_visualItem->setParent(nullptr);
71 m_visualItem->deleteLater();
72}
73
74void Group::init()
75{
76 d->updateConstraintsConnection = m_group->tabBar()->dptr()->countChanged.connect([this] {
78 });
79
80 d->currentDockWidgetChangedConnection = m_group->tabBar()->dptr()->currentDockWidgetChanged.connect([this] {
82 });
83
84 connect(this, &View::geometryUpdated, this,
85 [this] { Core::View::d->layoutInvalidated.emit(); });
86
87 d->isMDIConnection = m_group->dptr()->isMDIChanged.connect([this] { Q_EMIT isMDIChanged(); });
88
89 // Minor hack: While the controllers keep track of "current widget",
90 // the QML StackLayout deals in "current index", these can differ when removing a non-current
91 // tab. The currentDockWidgetChanged() won't be emitted but the index did decrement.
92 // As a workaround, always emit the signal, which is harmless if not needed.
93
94 m_group->dptr()->numDockWidgetsChanged.connect([this] { Q_EMIT currentDockWidgetChanged(); });
95 m_group->dptr()->actualTitleBarChanged.connect([this] { Q_EMIT actualTitleBarChanged(); });
96
97 connect(this, &View::itemGeometryChanged, this, [this] {
98 const auto docks = m_group->dockWidgets();
99 for (auto dw : docks) {
100 auto dwView = static_cast<DockWidget *>(QtQuick::asView_qtquick(dw->view()));
101 Q_EMIT dwView->groupGeometryChanged(geometry());
102 }
103 });
104
105 QQmlComponent component(plat()->qmlEngine(), plat()->viewFactory()->groupFilename());
106
107 m_visualItem = static_cast<QQuickItem *>(component.create());
108
109 if (!m_visualItem) {
110 qWarning() << Q_FUNC_INFO << "Failed to create item" << component.errorString();
111 return;
112 }
113
114 m_visualItem->setProperty("groupCpp", QVariant::fromValue(this));
115 m_visualItem->setParentItem(this);
116 m_visualItem->setParent(this);
117}
118
120{
122
123 // QtQuick doesn't have layouts, so we need to do constraint propagation manually
124
125 setProperty("kddockwidgets_min_size", minSize());
126 setProperty("kddockwidgets_max_size", maxSizeHint());
127
128 Core::View::d->layoutInvalidated.emit();
129}
130
135
137{
138 return m_group->currentIndex();
139}
140
142{
143 QPointer<Core::Group> oldFrame = dw->d->group();
144 m_group->tabBar()->insertDockWidget(index, dw, {}, {});
145
146 dw->setParentView(ViewWrapper::create(m_stackLayout).get());
147 makeItemFillParent(View::asQQuickItem(dw->view()));
149
150 if (oldFrame && oldFrame->beingDeletedLater()) {
151 // give it a push and delete it immediately.
152 // Having too many deleteLater() puts us in an inconsistent state. For example if
153 // LayoutSaver::saveState() would to be called while the Frame hadn't been deleted yet
154 // it would count with that group unless hacks. Also the unit-tests are full of
155 // waitForDeleted() due to deleteLater.
156
157 // Ideally we would just remove the deleteLater from Group.cpp, but
158 // QTabWidget::insertTab() would crash, as it accesses the old tab-widget we're stealing
159 // from
160
161 delete oldFrame;
162 }
163}
164
165void Group::setStackLayout(QQuickItem *stackLayout)
166{
167 if (m_stackLayout || !stackLayout) {
168 qWarning() << Q_FUNC_INFO << "Shouldn't happen";
169 return;
170 }
171
172 m_stackLayout = stackLayout;
173}
174
176{
177 const QSize contentsSize = m_group->dockWidgetsMinSize();
178 return contentsSize + QSize(0, nonContentsHeight());
179}
180
182{
183 return tabBarView();
184}
185
186QQuickItem *Group::visualItem() const
187{
188 return m_visualItem;
189}
190
192{
193 return m_visualItem->property("nonContentsHeight").toInt();
194}
195
196Stack *Group::stackView() const
197{
198 if (auto stack = m_group->stack())
199 return qobject_cast<Stack *>(asQQuickItem(stack->view()));
200
201 return nullptr;
202}
203
204TabBar *Group::tabBarView() const
205{
206 if (auto tabBar = m_group->tabBar())
207 return qobject_cast<TabBar *>(asQQuickItem(tabBar->view()));
208
209 return nullptr;
210}
211
213{
214 if (auto tb = m_group->titleBar()) {
215 return dynamic_cast<KDDockWidgets::QtQuick::TitleBar *>(tb->view());
216 }
217
218 return nullptr;
219}
220
222{
223 if (auto tb = m_group->actualTitleBar()) {
224 return dynamic_cast<KDDockWidgets::QtQuick::TitleBar *>(tb->view());
225 }
226
227 return nullptr;
228}
229
231{
232 return 0;
233}
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
void setParentView(View *parent)
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...
Core::TitleBar * titleBar() const
Vector< DockWidget * > dockWidgets() const
void setCurrentDockWidget(DockWidget *)
Sets the specified dock widget to be the current tab.
int currentIndex() const
returns the index of the current tab
Size dockWidgetsMinSize() const
Returns the minimum size of the dock widgets. This might be slightly smaller than Frame::minSize() du...
Core::Stack * stack() const
returns the tab widget
Core::TitleBar * actualTitleBar() const
Core::TabBar * tabBar() const
void removeDockWidget(Core::DockWidget *dw)
void insertDockWidget(int index, Core::DockWidget *dw, const Icon &icon, const QString &title)
void groupGeometryChanged(QRect)
The geometry of the group container this dock widget is in changed For example, when dragging a dockw...
QSize minSize() const override
Reimplemented for internal purposes. .
Group(Core::Group *controller, QQuickItem *parent=nullptr)
Q_INVOKABLE void setStackLayout(QQuickItem *)
int nonContentsHeight() const override
Returns the height of the "non-dockwidget" part. i.e.: the height of the titlebar (if any),...
void removeDockWidget(Core::DockWidget *dw) override
QQuickItem * visualItem() const override
Returns the QQuickItem which represents this group on the screen.
void insertDockWidget(Core::DockWidget *dw, int index) override
KDDockWidgets::QtQuick::TitleBar * actualTitleBar
KDDockWidgets::QtQuick::TitleBar * titleBar
QSize maxSizeHint() const override
static void makeItemFillParent(QQuickItem *item)
This is equivalent to "anchors.fill: parent but in C++.
View * asView_qtquick(Core::View *view)
QQuickItem * asQQuickItem(Core::View *view)
Class to abstract QAction, so code still works with QtQuick and Flutter.
QtQuick::Platform * plat()
void connect(T &&future, QObjectSubclass *context, Callback func)
Definition qcorotask.h:721
A factory class for allowing the user to customize some internal widgets.
Represents a dock widget.
Implements a QTabWidget derived class with support for docking and undocking KDockWidget::DockWidget ...
QVariant fromValue(const T &value)

© 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