KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
FrameQuick.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
19#include "FrameQuick_p.h"
20#include "Config.h"
22#include "TabWidgetQuick_p.h"
23#include "DockWidgetQuick.h"
24#include "../DockWidgetBase_p.h"
25#include "../WidgetResizeHandler_p.h"
26
27#include <QDebug>
28
29using namespace KDDockWidgets;
30
31FrameQuick::FrameQuick(QWidgetAdapter *parent, FrameOptions options, int userType)
32 : Frame(parent, options, userType)
33{
34 connect(m_tabWidget->asWidget(), SIGNAL(countChanged()),
35 this, SLOT(updateConstriants()));
36
37 connect(m_tabWidget->asWidget(), SIGNAL(currentDockWidgetChanged(KDDockWidgets::DockWidgetBase *)),
38 this, SIGNAL(currentDockWidgetChanged(KDDockWidgets::DockWidgetBase *)));
39
40 connect(this, &QWidgetAdapter::geometryUpdated, this, &Frame::layoutInvalidated);
41
42 connect(this, &QWidgetAdapter::widgetGeometryChanged, this, [this] {
43 for (auto dw : dockWidgets()) {
44 Q_EMIT static_cast<DockWidgetQuick *>(dw)->frameGeometryChanged(QWidgetAdapter::geometry());
45 }
46 });
47
48 QQmlComponent component(Config::self().qmlEngine(),
49 Config::self().frameworkWidgetFactory()->frameFilename());
50
51 m_visualItem = static_cast<QQuickItem *>(component.create());
52
53 if (!m_visualItem) {
54 qWarning() << Q_FUNC_INFO << "Failed to create item" << component.errorString();
55 return;
56 }
57
58 m_visualItem->setProperty("frameCpp", QVariant::fromValue(this));
59 m_visualItem->setParentItem(this);
60 m_visualItem->setParent(this);
61}
62
63FrameQuick::~FrameQuick()
64{
65 {
66 const DockWidgetBase::List docks = dockWidgets();
67
68 // The QML item must be deleted with deleteLater(), has we might be currently with its mouse
69 // handler in the stack. QML doesn't support it being deleted in that case.
70 // So unparent it and deleteLater().
71 m_visualItem->setParent(nullptr);
72 m_visualItem->deleteLater();
73
74 qDeleteAll(docks);
75 }
76}
77
78void FrameQuick::updateConstriants()
79{
80 onDockWidgetCountChanged();
81
82 // QtQuick doesn't have layouts, so we need to do constraint propagation manually
83
84 setProperty("kddockwidgets_min_size", minimumSize());
85 setProperty("kddockwidgets_max_size", maximumSize());
86
87 Q_EMIT layoutInvalidated();
88}
89
90void FrameQuick::removeWidget_impl(DockWidgetBase *dw)
91{
92 m_tabWidget->removeDockWidget(dw);
93 disconnect(m_connections.take(dw));
94}
95
96int FrameQuick::indexOfDockWidget_impl(const DockWidgetBase *dw)
97{
98 return m_tabWidget->indexOfDockWidget(dw);
99}
100
101int FrameQuick::currentIndex_impl() const
102{
103 return m_tabWidget->currentIndex();
104}
105
106void FrameQuick::setCurrentTabIndex_impl(int index)
107{
108 setCurrentDockWidget_impl(dockWidgetAt(index));
109}
110
111void FrameQuick::setCurrentDockWidget_impl(DockWidgetBase *dw)
112{
113 m_tabWidget->TabWidget::setCurrentDockWidget(dw);
114}
115
116void FrameQuick::insertDockWidget_impl(DockWidgetBase *dw, int index)
117{
118 QPointer<Frame> oldFrame = dw->d->frame();
119 if (m_tabWidget->insertDockWidget(index, dw, {}, {})) {
120 dw->setParent(m_stackLayout);
121
122 QMetaObject::Connection conn = connect(dw, &DockWidgetBase::parentChanged, this, [dw, this] {
123 if (dw->parent() != m_stackLayout)
124 removeWidget_impl(dw);
125 });
126
127 m_connections[dw] = conn;
128 setCurrentDockWidget_impl(dw);
129
130 if (oldFrame && oldFrame->beingDeletedLater()) {
131 // give it a push and delete it immediately.
132 // Having too many deleteLater() puts us in an inconsistent state. For example if LayoutSaver::saveState()
133 // would to be called while the Frame hadn't been deleted yet it would count with that frame unless hacks.
134 // Also the unit-tests are full of waitForDeleted() due to deleteLater.
135
136 // Ideally we would just remove the deleteLater from frame.cpp, but QTabWidget::insertTab()
137 // would crash, as it accesses the old tab-widget we're stealing from
138
139 delete oldFrame;
140 }
141 }
142}
143
144DockWidgetBase *FrameQuick::dockWidgetAt_impl(int index) const
145{
146 return m_tabWidget->dockwidgetAt(index);
147}
148
149DockWidgetBase *FrameQuick::currentDockWidget_impl() const
150{
151 return m_tabWidget->currentDockWidget();
152}
153
154void FrameQuick::renameTab(int, const QString &)
155{
156 // Not needed for QtQuick. Our model reacts to titleChanged()
157}
158
159
160void FrameQuick::changeTabIcon(int index, const QIcon &)
161{
162 Q_UNUSED(index);
163 qDebug() << Q_FUNC_INFO << "Not implemented";
164}
165
166void FrameQuick::setStackLayout(QQuickItem *stackLayout)
167{
168 if (m_stackLayout || !stackLayout) {
169 qWarning() << Q_FUNC_INFO << "Shouldn't happen";
170 return;
171 }
172
173 m_stackLayout = stackLayout;
174}
175
176QSize FrameQuick::minimumSize() const
177{
178 const QSize contentsSize = dockWidgetsMinSize();
179 return contentsSize + QSize(0, nonContentsHeight());
180}
181
182QSize FrameQuick::maximumSize() const
183{
184 return Frame::maximumSize();
185}
186
187QObject *FrameQuick::tabWidgetObj() const
188{
189 return m_tabWidget->asWidget();
190}
191
192TabWidget *FrameQuick::tabWidget() const
193{
194 return m_tabWidget;
195}
196
197QQuickItem *FrameQuick::visualItem() const
198{
199 return m_visualItem;
200}
201
202int FrameQuick::nonContentsHeight() const
203{
204 return m_visualItem->property("nonContentsHeight").toInt();
205}
Application-wide config to tune certain behaviours of the framework.
Represents a dock widget.
A factory class for allowing the user to customize some internal widgets.
static Config & self()
returns the singleton Config instance
Definition Config.cpp:84
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
void parentChanged()
signal emitted when the parent changed QtQuick already has QQuickItem::parentChanged(),...
Represents a dock widget.
QVariant property(const char *name) const const
QVariant fromValue(const T &value)
int toInt(bool *ok) const const

© 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