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 isOpenChangedConnection;
48 KDBindings::ScopedConnection windowActiveAboutToChangeConnection;
49 KDBindings::ScopedConnection guestChangeConnection;
50 KDBindings::ScopedConnection isCurrentTabConnection;
51};
52
53DockWidget::DockWidget(const QString &uniqueName, DockWidgetOptions options,
54 LayoutSaverOptions layoutSaverOptions,
55 Qt::WindowFlags windowFlags)
56 : View<QWidget>(new Core::DockWidget(this, uniqueName, options, layoutSaverOptions),
57 Core::ViewType::DockWidget, nullptr, windowFlags)
58 , Core::DockWidgetViewInterface(asDockWidgetController())
59 , d(new Private(this))
60{
61 d->guestChangeConnection = m_dockWidget->d->guestViewChanged.connect([this] {
62 if (auto guest = widget()) {
63 QWidget::setSizePolicy(guest->sizePolicy());
64 d->layout->addWidget(guest);
65 }
66 });
67
68 d->optionsChangedConnection = m_dockWidget->d->optionsChanged.connect([this](KDDockWidgets::DockWidgetOptions opts) {
70 });
71
72 d->guestViewChangedConnection = m_dockWidget->d->guestViewChanged.connect([this] {
74 });
75
76 d->isFocusedChangedConnection = m_dockWidget->d->isFocusedChanged.connect([this](bool focused) {
77 Q_EMIT isFocusedChanged(focused);
78 });
79
80 d->isOpenChangedConnection = m_dockWidget->d->isOpenChanged.connect([this](bool open) {
82 });
83
84 d->windowActiveAboutToChangeConnection = m_dockWidget->d->windowActiveAboutToChange.connect([this](bool active) {
86 });
87
88 d->isCurrentTabConnection = m_dockWidget->d->isCurrentTabChanged.connect([this](bool isCurrent) {
89 Q_EMIT isCurrentTabChanged(isCurrent);
90 });
91
93}
94
96{
97 delete d;
98}
99
101{
102 m_dockWidget->setGuestView(ViewWrapper::create(widget));
103}
104
106{
107 if (e->type() == QEvent::Show)
109
110 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
112}
113
115{
117
118 // NOLINTNEXTLINE(bugprone-parent-virtual-call)
120}
121
123{
124 if (auto guest = m_dockWidget->guestView())
125 return View_qt::asQWidget(guest.get());
126
127 return nullptr;
128}
129
131{
132 return dynamic_cast<QAction *>(m_dockWidget->toggleAction());
133}
134
136{
137 return dynamic_cast<QAction *>(m_dockWidget->floatAction());
138}
139
140std::shared_ptr<Core::View> DockWidget::focusCandidate() const
141{
142 // For QtWidgets, if we focus the dock widget, we actually focus the user/guest widget
143 // For QtQuick, the dock widget itself is a QtQuick FocusScope, so focus that instead. QtQuick will then focus the right inner
144 // widget.
145 return m_dockWidget->guestView();
146}
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 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.
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