KDDockWidgets API Documentation 1.7
Loading...
Searching...
No Matches
DockWidgetQuick.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 "DockWidgetQuick.h"
14
15#include "private/TitleBar_p.h"
16#include "private/DockWidgetBase_p.h"
17#include "private/quick/FrameQuick_p.h"
18
19#include <Config.h>
20#include <QQuickItem>
21#include <QCloseEvent>
22
30using namespace KDDockWidgets;
31
32class DockWidgetQuick::Private
33{
34public:
35 Private(DockWidgetQuick *dw, QQmlEngine *qmlengine)
36 : q(dw)
37 , m_visualItem(q->createItem(qmlengine,
38 Config::self().frameworkWidgetFactory()->dockwidgetFilename().toString()))
39 , m_qmlEngine(qmlengine)
40 {
41 Q_ASSERT(m_visualItem);
42 m_visualItem->setParent(q);
43 m_visualItem->setParentItem(q);
44 }
45
46 DockWidgetBase *const q;
47 QQuickItem *const m_visualItem;
48 QQmlEngine *const m_qmlEngine;
49};
50
51DockWidgetQuick::DockWidgetQuick(const QString &name, Options options,
52 LayoutSaverOptions layoutSaverOptions, QQmlEngine *engine)
53 : DockWidgetBase(name, options, layoutSaverOptions)
54 , d(new Private(this, engine ? engine : Config::self().qmlEngine()))
55{
56 // To mimic what QtWidgets does when creating a new QWidget.
57 setVisible(false);
58}
59
61{
62 delete d;
63}
64
65void DockWidgetQuick::setWidget(const QString &qmlFilename)
66{
67 QQuickItem *guest = createItem(d->m_qmlEngine, qmlFilename);
68 if (!guest)
69 return;
70
71 setWidget(guest);
72}
73
74void DockWidgetQuick::setWidget(QWidgetAdapter *widget)
75{
76 widget->QWidgetAdapter::setParent(this);
77 QWidgetAdapter::makeItemFillParent(widget);
79}
80
81void DockWidgetQuick::setWidget(QQuickItem *guest)
82{
83 auto adapter = new QWidgetAdapter(this);
84 adapter->setIsWrapper();
85
86 // In case the user app needs to use them:
87 adapter->setProperty("originalParent", QVariant::fromValue(guest->parent()));
88 adapter->setProperty("originalParentItem", QVariant::fromValue(guest->parentItem()));
89
90 guest->setParentItem(adapter);
91 guest->setParent(adapter);
92 QWidgetAdapter::makeItemFillParent(guest);
93
94 setWidget(adapter);
95}
96
98{
99 if (e->type() == QEvent::ParentChange) {
101 Q_EMIT actualTitleBarChanged();
102 } else if (e->type() == QEvent::Show) {
103 onShown(e->spontaneous());
104 } else if (e->type() == QEvent::Hide) {
105 onHidden(e->spontaneous());
106 } else if (e->type() == QEvent::Close) {
107 onCloseEvent(static_cast<QCloseEvent *>(e));
108 }
109
110 return DockWidgetBase::event(e);
111}
112
114{
115 if (QWidgetAdapter *guestWidget = widget()) {
116 // The guests min-size is the same as the widget's, there's no spacing or margins.
117 return guestWidget->minimumSize();
118 }
119
120 return DockWidgetBase::minimumSize();
121}
122
124{
125 if (QWidgetAdapter *guestWidget = widget()) {
126 // The guests max-size is the same as the widget's, there's no spacing or margins.
127 return guestWidget->maximumSize();
128 }
129
130 return DockWidgetBase::maximumSize();
131}
132
134{
135 if (Frame *frame = DockWidgetBase::d->frame())
136 return frame->actualTitleBar();
137 return nullptr;
138}
139
144
146{
147 if (auto frame = qobject_cast<FrameQuick *>(DockWidgetBase::d->frame()))
148 return frame->visualItem();
149
150 return nullptr;
151}
152
154{
155 if (auto frame = qobject_cast<FrameQuick *>(DockWidgetBase::d->frame())) {
156 frame->updateConstriants();
157 frame->updateGeometry();
158 }
159}
160
162{
163 return qobject_cast<FrameQuick *>(DockWidgetBase::d->frame());
164}
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.
Singleton to allow to choose certain behaviours of the framework.
Definition Config.h:75
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
virtual void setWidget(QWidgetOrQuick *widget)
sets the widget which this dock widget hosts.
void onHidden(bool spontaneous)
void onCloseEvent(QCloseEvent *e) override
void onShown(bool spontaneous)
void actualTitleBarChanged()
Emitted when the title bar that serves this dock widget changes.
Represents a dock widget.
bool event(QEvent *e) override
Q_INVOKABLE void onGeometryUpdated()
Called by QtQuick when min-size changes.
Q_INVOKABLE KDDockWidgets::Frame * frame() const
~DockWidgetQuick() override
destructor
QSize maximumSize() const override
Reimplemented for internal purposes. .
QSize minimumSize() const override
Reimplemented for internal purposes. .
DockWidgetQuick(const QString &uniqueName, Options options={}, LayoutSaverOptions layoutSaverOptions=LayoutSaverOptions(), QQmlEngine *engine=nullptr)
constructs a new DockWidget
QObject * actualTitleBarObj() const
Returns the title bar Qt6 requires us to include TitleBar_p.h, so instead the Q_PROPERTY uses QObject...
void setWidget(const QString &qmlFilename)
QQuickItem * frameVisualItem() const
Returns the visual item which represents Frame in the screen Equivalent to Frame::visualItem().
bool spontaneous() const const
QEvent::Type type() const const
QVariant fromValue(const T &value)

© 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