KDDockWidgets API Documentation 2.1
Loading...
Searching...
No Matches
qtquick/views/DockWidget.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
12#include "DockWidget.h"
13
14#include "kddockwidgets/core/TitleBar.h"
15#include "kddockwidgets/core/DockWidget.h"
16#include "core/DockWidget_p.h"
17#include "kddockwidgets/core/Group.h"
18#include "qtquick/Platform.h"
20#include "qtquick/views/Group.h"
21#include "qtquick/ViewFactory.h"
22#include "qtquick/views/ViewWrapper_p.h"
23
24#include <Config.h>
25#include <QQuickItem>
26
34using namespace KDDockWidgets;
35using namespace KDDockWidgets::QtQuick;
36
37class QtQuick::DockWidget::Private
38{
39public:
40 Private(DockWidget *view, QQmlEngine *qmlengine)
41 : q(view)
42 , m_visualItem(
43 DockWidget::createItem(qmlengine, plat()->viewFactory()->dockwidgetFilename().toString()))
44 , m_qmlEngine(qmlengine)
45 {
46 Q_ASSERT(m_visualItem);
47 m_visualItem->setParent(view);
48 m_visualItem->setParentItem(view);
49 }
50
51 DockWidget *const q;
52 QQuickItem *const m_visualItem;
53 QQmlEngine *const m_qmlEngine;
54};
55
56DockWidget::DockWidget(const QString &uniqueName, DockWidgetOptions options,
57 LayoutSaverOptions layoutSaverOptions,
58 Qt::WindowFlags windowFlags, QQmlEngine *engine)
59 : View(new Core::DockWidget(this, uniqueName, options, layoutSaverOptions), Core::ViewType::DockWidget,
60 nullptr, windowFlags)
61 , Core::DockWidgetViewInterface(asDockWidgetController())
62 , d(new Private(this, engine ? engine : plat()->qmlEngine()))
63{
64 QQuickItem::setFlag(ItemIsFocusScope);
66
67 // To mimic what QtWidgets does when creating a new QWidget.
68 setVisible(false);
69
70 auto dw = this->dockWidget();
71 dw->d->actualTitleBarChanged.connect(&DockWidget::actualTitleBarChanged, this);
72 dw->d->guestViewChanged.connect([this, dw] {
73 if (auto guest = dw->guestView()) {
74 guest->setVisible(true);
75 Q_EMIT guestItemChanged();
76 }
77 });
78
80
81 m_dockWidget->d->isFloatingChanged.connect(&DockWidget::isFloatingChanged, this);
82 m_dockWidget->d->isFocusedChanged.connect(&DockWidget::isFocusedChanged, this);
83 m_dockWidget->d->titleChanged.connect(&DockWidget::titleChanged, this);
84 m_dockWidget->d->optionsChanged.connect(&DockWidget::optionsChanged, this);
85}
86
88{
89 delete d;
90}
91
92void DockWidget::setGuestItem(const QString &qmlFilename, QQmlContext *context)
93{
94 if (QQuickItem *guest = createItem(d->m_qmlEngine, qmlFilename, context))
95 setGuestItem(guest);
96}
97
98void DockWidget::setGuestItem(QQuickItem *item)
99{
100 auto wrapper = asQQuickWrapper(item);
101 wrapper->setParent(this);
102 makeItemFillParent(item);
103 dockWidget()->setGuestView(wrapper);
104}
105
106QQuickItem *DockWidget::guestItem() const
107{
108 if (auto guest = m_dockWidget->guestView())
109 return QtQuick::asQQuickItem(guest.get());
110
111 return nullptr;
112}
113
115{
116 if (dockWidget()->d->m_isSettingCurrent)
117 return View::event(e);
118
119 if (e->type() == QEvent::Show) {
120 dockWidget()->open();
121 }
122
123 return View::event(e);
124}
125
127{
128 if (auto guestWidget = dockWidget()->guestView()) {
129 // The guests min-size is the same as the widget's, there's no spacing or margins.
130
131 // Return the biggest size if both are set
132 return guestWidget->minSize().expandedTo(View::minSize());
133 }
134
135 return View::minSize();
136}
137
139{
140 if (auto guestWidget = dockWidget()->guestView()) {
141 // The guests max-size is the same as the widget's, there's no spacing or margins.
142
143 // Return the smallest size if both are set
144 return guestWidget->maxSizeHint().boundedTo(View::maxSizeHint());
145 }
146
147 return View::maxSizeHint();
148}
149
151{
152 if (auto tb = actualTitleBar()) {
153 return static_cast<QtQuick::TitleBar *>(tb->view());
154 }
155
156 return nullptr;
157}
158
160{
161 if (Core::Group *group = this->group()) {
162 if (auto view = QtQuick::asView_qtquick(group->view()))
163 return view->visualItem();
164 }
165
166 return nullptr;
167}
168
170{
171 if (auto group = this->group()) {
172 if (auto view = group->view()) {
173 auto groupView = static_cast<Group *>(QtQuick::asView_qtquick(view));
174 groupView->updateConstraints();
175 groupView->updateGeometry();
176 }
177 }
178}
179
181{
182 return static_cast<QtQuick::Action *>(m_dockWidget->toggleAction());
183}
184
186{
187 return static_cast<QtQuick::Action *>(m_dockWidget->toggleAction());
188}
189
190std::shared_ptr<Core::View> DockWidget::focusCandidate() const
191{
192 // For QtWidgets, if we focus the dock widget, we actually focus the user/guest widget
193 // But for QtQuick, the dock widget itself is a QtQuick FocusScope, so focus that instead. QtQuick will then focus the right inner
194 // widget.
195 return ViewWrapper::create(const_cast<QtQuick::DockWidget *>(this));
196}
Application-wide config to tune certain behaviours of the framework.
View * view() const
Returns the view associated with this controller, if any.
Action * toggleAction() const
Returns the Action that allows to hide/show the dock widget Useful to put in menus.
void open()
Opens this dock widget. Does nothing if already open. The dock widget will appear floating unless it ...
std::shared_ptr< View > guestView() const
Like widget() but returns a view.
void setGuestView(std::shared_ptr< View > guest)
sets the widget which this dock widget hosts.
QSize minSize() const override
Reimplemented for internal purposes. .
std::shared_ptr< Core::View > focusCandidate() const override
Q_INVOKABLE KDDockWidgets::QtQuick::Action * floatAction() const
QSize maxSizeHint() const override
Reimplemented for internal purposes. .
DockWidget(const QString &uniqueName, DockWidgetOptions={}, LayoutSaverOptions={}, Qt::WindowFlags=Qt::Tool, QQmlEngine *engine=nullptr)
constructs a new DockWidget
void setGuestItem(const QString &qmlFilename, QQmlContext *context=nullptr)
QQuickItem * groupVisualItem() const
Returns the visual item which represents Group in the screen Equivalent to Group::visualItem().
QObject * actualTitleBarView() const
Returns the title bar view Qt6 requires us to include TitleBar_p.h, so instead the Q_PROPERTY uses QO...
Q_INVOKABLE void onGeometryUpdated()
Called by QtQuick when min-size changes.
Q_INVOKABLE KDDockWidgets::QtQuick::Action * toggleAction() const
static QQuickItem * createItem(QQmlEngine *engine, const QString &filename, QQmlContext *context=nullptr)
Convenience to create a QQuickItem.
virtual QQuickItem * visualItem() const
void setFocusPolicy(Qt::FocusPolicy) override
static std::shared_ptr< Core::View > asQQuickWrapper(QQuickItem *item)
QSize maxSizeHint() const override
static void makeItemFillParent(QQuickItem *item)
This is equivalent to "anchors.fill: parent but in C++.
void setVisible(bool is) override
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()
QEvent::Type type() const const
QSize boundedTo(const QSize &otherSize) const const
QSize expandedTo(const QSize &otherSize) const const
StrongFocus
typedef WindowFlags
A factory class for allowing the user to customize some internal widgets.
Represents a dock widget.

© 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