KDDockWidgets API Documentation  1.5
DockWidgetInstantiator.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 "DockWidgetInstantiator_p.h"
13 #include "DockWidgetQuick.h"
14 #include "../DockRegistry_p.h"
15 
16 using namespace KDDockWidgets;
17 
18 QString DockWidgetInstantiator::uniqueName() const
19 {
20  return m_uniqueName;
21 }
22 
23 void DockWidgetInstantiator::setUniqueName(const QString &name)
24 {
25  m_uniqueName = name;
26  Q_EMIT uniqueNameChanged();
27 }
28 
29 QString DockWidgetInstantiator::source() const
30 {
31  return m_sourceFilename;
32 }
33 
34 void DockWidgetInstantiator::setSource(const QString &source)
35 {
36  m_sourceFilename = source;
37  Q_EMIT sourceChanged();
38 }
39 
40 DockWidgetQuick *DockWidgetInstantiator::dockWidget() const
41 {
42  return m_dockWidget;
43 }
44 
45 TitleBar *DockWidgetInstantiator::actualTitleBar() const
46 {
47  return m_dockWidget ? m_dockWidget->actualTitleBar() : nullptr;
48 }
49 
50 QString DockWidgetInstantiator::title() const
51 {
52  return m_dockWidget ? m_dockWidget->title() : QString();
53 }
54 
55 void DockWidgetInstantiator::setTitle(const QString &title)
56 {
57  if (m_dockWidget)
58  m_dockWidget->setTitle(title);
59  m_title = title;
60 }
61 
62 bool DockWidgetInstantiator::isFocused() const
63 {
64  return m_dockWidget && m_dockWidget->isFocused();
65 }
66 
67 bool DockWidgetInstantiator::isFloating() const
68 {
69  return m_dockWidget && m_dockWidget->isFloating();
70 }
71 
72 void DockWidgetInstantiator::setFloating(bool is)
73 {
74  if (m_dockWidget)
75  m_dockWidget->setFloating(is);
76  m_isFloating = is;
77 }
78 
79 void DockWidgetInstantiator::addDockWidgetAsTab(DockWidgetInstantiator *other,
81 {
82  if (m_dockWidget)
83  m_dockWidget->addDockWidgetAsTab(other ? other->dockWidget() : nullptr, option);
84 }
85 
86 void DockWidgetInstantiator::addDockWidgetAsTab(DockWidgetBase *other,
88 {
89  if (m_dockWidget)
90  m_dockWidget->addDockWidgetAsTab(other, option);
91 }
92 
93 void DockWidgetInstantiator::addDockWidgetToContainingWindow(DockWidgetBase *other,
94  Location location,
95  DockWidgetBase *relativeTo,
96  QSize initialSize,
98 {
99  if (m_dockWidget)
100  m_dockWidget->addDockWidgetToContainingWindow(other, location, relativeTo,
101  InitialOption(option, initialSize));
102 }
103 
104 void DockWidgetInstantiator::addDockWidgetToContainingWindow(DockWidgetInstantiator *other,
105  Location location,
106  DockWidgetInstantiator *relativeTo,
107  QSize initialSize,
109 {
110  if (m_dockWidget)
111  m_dockWidget->addDockWidgetToContainingWindow(
112  other ? other->dockWidget() : nullptr, location,
113  relativeTo ? relativeTo->dockWidget() : nullptr, InitialOption(option, initialSize));
114 }
115 
116 void DockWidgetInstantiator::setAsCurrentTab()
117 {
118  if (m_dockWidget)
119  m_dockWidget->setAsCurrentTab();
120 }
121 
122 void DockWidgetInstantiator::forceClose()
123 {
124  if (m_dockWidget)
125  m_dockWidget->forceClose();
126 }
127 
128 Q_INVOKABLE bool DockWidgetInstantiator::close()
129 {
130  if (m_dockWidget)
131  return m_dockWidget->close();
132 
133  return false;
134 }
135 
136 void DockWidgetInstantiator::show()
137 {
138  if (m_dockWidget)
139  m_dockWidget->show();
140 }
141 
142 void DockWidgetInstantiator::raise()
143 {
144  if (m_dockWidget)
145  m_dockWidget->raise();
146 }
147 
148 void DockWidgetInstantiator::moveToSideBar()
149 {
150  if (m_dockWidget)
151  m_dockWidget->moveToSideBar();
152 }
153 
154 void DockWidgetInstantiator::classBegin()
155 {
156  // Nothing interesting to do here.
157 }
158 
159 void DockWidgetInstantiator::componentComplete()
160 {
161  if (m_uniqueName.isEmpty()) {
162  qWarning() << Q_FUNC_INFO << "Each DockWidget need an unique name. Set the uniqueName property.";
163  return;
164  }
165 
166  if (DockRegistry::self()->containsDockWidget(m_uniqueName)) {
167  // Dock widget already exists. all good.
168  return;
169  }
170 
171  if (m_dockWidget) {
172  qWarning() << Q_FUNC_INFO << "Unexpected bug.";
173  return;
174  }
175  const auto childItems = this->childItems();
176  if (m_sourceFilename.isEmpty() && childItems.size() != 1) {
177  qWarning() << Q_FUNC_INFO << "Either 'source' property must be set or add exactly one child"
178  << "; source=" << m_sourceFilename << "; num children=" << childItems.size();
179  return;
180  }
181 
182  m_dockWidget = new DockWidgetQuick(m_uniqueName, {}, {}, qmlEngine(this));
183 
184  connect(m_dockWidget, &DockWidgetQuick::titleChanged, this,
185  &DockWidgetInstantiator::titleChanged);
186  connect(m_dockWidget, &DockWidgetQuick::actualTitleBarChanged, this,
187  &DockWidgetInstantiator::actualTitleBarChanged);
188  connect(m_dockWidget, &DockWidgetQuick::optionsChanged, this,
189  &DockWidgetInstantiator::optionsChanged);
190  connect(m_dockWidget, &DockWidgetQuick::shown, this, &DockWidgetInstantiator::shown);
191  connect(m_dockWidget, &DockWidgetQuick::hidden, this, &DockWidgetInstantiator::hidden);
192  connect(m_dockWidget, &DockWidgetQuick::iconChanged, this,
193  &DockWidgetInstantiator::iconChanged);
194  connect(m_dockWidget, &DockWidgetQuick::widgetChanged, this,
195  &DockWidgetInstantiator::widgetChanged);
196  connect(m_dockWidget, &DockWidgetQuick::isFocusedChanged, this,
197  &DockWidgetInstantiator::isFocusedChanged);
198  connect(m_dockWidget, &DockWidgetQuick::isFocusedChanged, this,
199  &DockWidgetInstantiator::isFocusedChanged);
200  connect(m_dockWidget, &DockWidgetQuick::isOverlayedChanged, this,
201  &DockWidgetInstantiator::isOverlayedChanged);
202  connect(m_dockWidget, &DockWidgetQuick::isFloatingChanged, this,
203  &DockWidgetInstantiator::isFloatingChanged);
204  connect(m_dockWidget, &DockWidgetQuick::removedFromSideBar, this,
205  &DockWidgetInstantiator::removedFromSideBar);
206  connect(m_dockWidget, &DockWidgetQuick::windowActiveAboutToChange, this,
207  &DockWidgetInstantiator::windowActiveAboutToChange);
208 
209 
210  if (m_sourceFilename.isEmpty()) {
211  m_dockWidget->setWidget(childItems.constFirst());
212  } else {
213  m_dockWidget->setWidget(m_sourceFilename);
214  }
215 
216  if (!m_title.isEmpty())
217  m_dockWidget->setTitle(m_title);
218 
219  if (m_isFloating.has_value())
220  m_dockWidget->setFloating(m_isFloating.value());
221 
222  Q_EMIT dockWidgetChanged();
223 }
KDDockWidgets::DockWidgetBase::optionsChanged
void optionsChanged(KDDockWidgets::DockWidgetBase::Options)
emitted when the options change
KDDockWidgets::DockWidgetQuick::actualTitleBar
QObject * actualTitleBar
Definition: DockWidgetQuick.h:42
DockWidgetQuick.h
Represents a dock widget.
KDDockWidgets::InitialVisibilityOption
InitialVisibilityOption
Definition: KDDockWidgets.h:88
KDDockWidgets::InitialOption
Struct describing the preferred dock widget size and visibility when adding it to a layout.
Definition: KDDockWidgets.h:105
KDDockWidgets::Location
Location
Definition: KDDockWidgets.h:45
KDDockWidgets::DockWidgetBase::iconChanged
void iconChanged()
signal emitted when the icon changed
KDDockWidgets::DockWidgetBase::widgetChanged
void widgetChanged(KDDockWidgets::QWidgetOrQuick *)
emitted when the hosted widget changed
QSize
KDDockWidgets::DockWidgetQuick
Represents a dock widget.
Definition: DockWidgetQuick.h:40
KDDockWidgets::DockWidgetBase::isFloatingChanged
void isFloatingChanged(bool)
emitted when isFloating changes
KDDockWidgets::DockWidgetBase::titleChanged
void titleChanged(const QString &title)
signal emitted when the title changed
QString
KDDockWidgets::DockWidgetBase::isFocusedChanged
void isFocusedChanged(bool)
emitted when isFocused changes
KDDockWidgets::DockWidgetBase::actualTitleBarChanged
void actualTitleBarChanged()
Emitted when the title bar that serves this dock widget changes.
KDDockWidgets::DockWidgetBase::removedFromSideBar
void removedFromSideBar()
emitted when this dock widget is removed from a side-bar. Only relevant for the auto-hide/sidebar fea...
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::DockWidgetBase::hidden
void hidden()
signal emitted when the DockWidget is hidden. As in QEvent::Hide.
KDDockWidgets
Definition: Config.cpp:36
KDDockWidgets::DockWidgetBase::shown
void shown()
signal emitted when the DockWidget is shown. As in QEvent::Show.
KDDockWidgets::DockWidgetBase::windowActiveAboutToChange
void windowActiveAboutToChange(bool activated)
Emitted when the top-level window this dock widget is in is activated or deactivated This is convenie...
KDDockWidgets::DockWidgetBase::isOverlayedChanged
void isOverlayedChanged(bool)
emitted when isOverlayed changes

© 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