KDDockWidgets API Documentation  1.5
DockWidgetQuick.cpp
Go to the documentation of this file.
1 /*
2  This file is part of KDDockWidgets.
3 
4  SPDX-FileCopyrightText: 2019-2022 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"
13 #include "FrameworkWidgetFactory.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 
30 using namespace KDDockWidgets;
31 
32 class DockWidgetQuick::Private
33 {
34 public:
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 
51 DockWidgetQuick::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 
65 void 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 
74 void DockWidgetQuick::setWidget(QWidgetAdapter *widget)
75 {
76  widget->QWidgetAdapter::setParent(this);
77  QWidgetAdapter::makeItemFillParent(widget);
79 }
80 
81 void 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) {
100  onParentChanged();
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 
141 {
142  return actualTitleBar();
143 }
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 }
KDDockWidgets::DockWidgetQuick::actualTitleBar
QObject * actualTitleBar
Definition: DockWidgetQuick.h:42
DockWidgetQuick.h
Represents a dock widget.
QEvent::ParentChange
ParentChange
QVariant::fromValue
QVariant fromValue(const T &value)
KDDockWidgets::DockWidgetQuick::frameVisualItem
QQuickItem * frameVisualItem() const
Returns the visual item which represents Frame in the screen Equivalent to Frame::visualItem().
Definition: DockWidgetQuick.cpp:145
KDDockWidgets::DockWidgetQuick::actualTitleBarObj
QObject * actualTitleBarObj() const
Returns the title bar Qt6 requires us to include TitleBar_p.h, so instead the Q_PROPERTY uses QObject...
Definition: DockWidgetQuick.cpp:140
QSize
KDDockWidgets::DockWidgetQuick::minimumSize
QSize minimumSize() const override
Reimplemented for internal purposes. .
Definition: DockWidgetQuick.cpp:113
KDDockWidgets::DockWidgetQuick
Represents a dock widget.
Definition: DockWidgetQuick.h:40
KDDockWidgets::DockWidgetBase::widget
QObject * widget
Definition: DockWidgetBase.h:67
KDDockWidgets::DockWidgetBase::onCloseEvent
void onCloseEvent(QCloseEvent *e) override
Definition: DockWidgetBase.cpp:788
KDDockWidgets::DockWidgetBase::setWidget
virtual void setWidget(QWidgetOrQuick *widget)
sets the widget which this dock widget hosts.
Definition: DockWidgetBase.cpp:148
KDDockWidgets::DockWidgetQuick::frame
Q_INVOKABLE KDDockWidgets::Frame * frame() const
Definition: DockWidgetQuick.cpp:161
QCloseEvent
QObject
QString
KDDockWidgets::DockWidgetQuick::onGeometryUpdated
Q_INVOKABLE void onGeometryUpdated()
Called by QtQuick when min-size changes.
Definition: DockWidgetQuick.cpp:153
KDDockWidgets::Config
Singleton to allow to choose certain behaviours of the framework.
Definition: Config.h:55
KDDockWidgets::DockWidgetBase::onHidden
void onHidden(bool spontaneous)
Definition: DockWidgetBase.cpp:763
KDDockWidgets::DockWidgetQuick::DockWidgetQuick
DockWidgetQuick(const QString &uniqueName, Options options={}, LayoutSaverOptions layoutSaverOptions=LayoutSaverOptions(), QQmlEngine *engine=nullptr)
constructs a new DockWidget
Definition: DockWidgetQuick.cpp:51
KDDockWidgets::DockWidgetQuick::maximumSize
QSize maximumSize() const override
Reimplemented for internal purposes. .
Definition: DockWidgetQuick.cpp:123
KDDockWidgets::DockWidgetBase::actualTitleBarChanged
void actualTitleBarChanged()
Emitted when the title bar that serves this dock widget changes.
QEvent::spontaneous
bool spontaneous() const const
Config.h
Application-wide config to tune certain behaviours of the framework.
QEvent::type
QEvent::Type type() const const
QEvent
KDDockWidgets::DockWidgetBase::Frame
friend class Frame
Definition: DockWidgetBase.h:532
KDDockWidgets::DockWidgetBase
The DockWidget base-class. DockWidget and DockWidgetBase are only split in two so we can share some c...
Definition: DockWidgetBase.h:61
KDDockWidgets
Definition: Config.cpp:36
KDDockWidgets::DockWidgetQuick::~DockWidgetQuick
~DockWidgetQuick() override
destructor
Definition: DockWidgetQuick.cpp:60
KDDockWidgets::DockWidgetQuick::setWidget
void setWidget(const QString &qmlFilename)
Definition: DockWidgetQuick.cpp:65
KDDockWidgets::DockWidgetBase::onShown
void onShown(bool spontaneous)
Definition: DockWidgetBase.cpp:746
FrameworkWidgetFactory.h
A factory class for allowing the user to customize some internal widgets.
KDDockWidgets::DockWidgetBase::onParentChanged
void onParentChanged()
Definition: DockWidgetBase.cpp:733
KDDockWidgets::DockWidgetQuick::event
bool event(QEvent *e) override
Definition: DockWidgetQuick.cpp:97

© 2019-2022 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 Mon Mar 7 2022 02:01:20 for KDDockWidgets API Documentation by doxygen 1.8.20