KDDockWidgets API Documentation 2.0
Loading...
Searching...
No Matches
qtwidgets/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#include "core/DockWidget_p.h"
14#include "ViewWrapper_p.h"
15
16#include <QCloseEvent>
17#include <QVBoxLayout>
18#include <QAction>
19
27using namespace KDDockWidgets;
28using namespace KDDockWidgets::QtWidgets;
29
30class DockWidget::Private
31{
32public:
33 explicit Private(DockWidget *q)
34 : layout(new QVBoxLayout(q))
35 {
36 layout->setSpacing(0);
37 layout->setContentsMargins(0, 0, 0, 0);
38
39 // propagate the max-size constraints from the guest widget to the DockWidget
40 layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
41 }
42
43 QVBoxLayout *const layout;
44 KDBindings::ScopedConnection optionsChangedConnection;
45 KDBindings::ScopedConnection guestViewChangedConnection;
46 KDBindings::ScopedConnection isFocusedChangedConnection;
47 KDBindings::ScopedConnection isFloatingChangedConnection;
48 KDBindings::ScopedConnection isOpenChangedConnection;
49 KDBindings::ScopedConnection windowActiveAboutToChangeConnection;
50 KDBindings::ScopedConnection guestChangeConnection;
51 KDBindings::ScopedConnection isCurrentTabConnection;
52};
53
54DockWidget::DockWidget(const QString &uniqueName, DockWidgetOptions options,
55 LayoutSaverOptions layoutSaverOptions,
56 Qt::WindowFlags windowFlags)
57 : View<QWidget>(new Core::DockWidget(this, uniqueName, options, layoutSaverOptions),
58 Core::ViewType::DockWidget, nullptr, windowFlags)
59 , Core::DockWidgetViewInterface(asDockWidgetController())
60 , d(new Private(this))
61{
62 d->guestChangeConnection = m_dockWidget->d->guestViewChanged.connect([this] {
63 if (auto guest = widget()) {
64 QWidget::setSizePolicy(guest->sizePolicy());
65 d->layout->addWidget(guest);
66 }
67 });
68
69 d->optionsChangedConnection = m_dockWidget->d->optionsChanged.connect([this](KDDockWidgets::DockWidgetOptions opts) {
71 });
72
73 d->guestViewChangedConnection = m_dockWidget->d->guestViewChanged.connect([this] {
75 });
76
77 d->isFocusedChangedConnection = m_dockWidget->d->isFocusedChanged.connect([this](bool focused) {
78 Q_EMIT isFocusedChanged(focused);
79 });
80
81 d->isFloatingChangedConnection = m_dockWidget->d->isFloatingChanged.connect([this](bool floating) {
82 Q_EMIT isFloatingChanged(floating);
83 });
84
85 d->isOpenChangedConnection = m_dockWidget->d->isOpenChanged.connect([this](bool open) {
87 });
88
89 d->windowActiveAboutToChangeConnection = m_dockWidget->d->windowActiveAboutToChange.connect([this](bool active) {
91 });
92
93 d->isCurrentTabConnection = m_dockWidget->d->isCurrentTabChanged.connect([this](bool isCurrent) {
94 Q_EMIT isCurrentTabChanged(isCurrent);
95 });
96
98}
99
101{
102 delete d;
103}
104
106{
107 m_dockWidget->setGuestView(ViewWrapper::create(widget));
108}
109
111{
112 if (e->type() == QEvent::Show)
114
115 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
117}
118
120{
122
123 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
125}
126
128{
129 if (auto guest = m_dockWidget->guestView())
130 return View_qt::asQWidget(guest.get());
131
132 return nullptr;
133}
134
136{
137 return dynamic_cast<QAction *>(m_dockWidget->toggleAction());
138}
139
141{
142 return dynamic_cast<QAction *>(m_dockWidget->floatAction());
143}
144
145std::shared_ptr<Core::View> DockWidget::focusCandidate() const
146{
147 // For QtWidgets, if we focus the dock widget, we actually focus the user/guest widget
148 // For QtQuick, the dock widget itself is a QtQuick FocusScope, so focus that instead. QtQuick will then focus the right inner
149 // widget.
150 return m_dockWidget->guestView();
151}
152
154{
155 // The guest widget didn't want it, so block it now.
156 // Otherwise it goes to the QTabWidget and it will make the window float.
157 ev->accept();
158}
A ScopedConnection is a RAII-style way to make sure a Connection is disconnected.
Definition signal.h:533
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 ...
Action * floatAction() const
Returns the Action that allows to dock/undock the dock widget Useful to put in menus.
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.
void setWidget(QWidget *widget)
sets the widget which this dock widget hosts.
DockWidget(const QString &uniqueName, DockWidgetOptions options={}, LayoutSaverOptions layoutSaverOptions={}, Qt::WindowFlags windowFlags=Qt::Tool)
constructs a new DockWidget
std::shared_ptr< Core::View > focusCandidate() const override
void mouseDoubleClickEvent(QMouseEvent *ev) override
void isCurrentTabChanged(bool)
Emitted when a dock widget becomes current or not in its tab group.
void optionsChanged(KDDockWidgets::DockWidgetOptions)
QWidget * widget() const
Returns the guest widget.
Class to abstract QAction, so code still works with QtQuick and Flutter.
void accept()
QEvent::Type type() const const
Q_EMITQ_EMIT
const QSize & size() const const
typedef WindowFlags
Represents a dock widget.
virtual void resizeEvent(QResizeEvent *event)
void setSizePolicy(QSizePolicy)

© 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