KParts

part.cpp
1 /*
2  This file is part of the KDE project
3  SPDX-FileCopyrightText: 1999 Simon Hausmann <[email protected]>
4  SPDX-FileCopyrightText: 1999-2005 David Faure <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "part.h"
10 #include "part_p.h"
11 
12 #include "kparts_logging.h"
13 #include "partactivateevent.h"
14 
15 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72)
16 #include "partselectevent.h"
17 #endif
18 
19 #include "guiactivateevent.h"
20 #include "partmanager.h"
21 
22 #include <KIconLoader>
23 #include <KXMLGUIFactory>
24 
25 using namespace KParts;
26 
28  : QObject(parent)
29  , PartBase(*new PartPrivate(this))
30 {
32 }
33 
34 Part::Part(PartPrivate &dd, QObject *parent)
35  : QObject(parent)
36  , PartBase(dd)
37 {
39 }
40 
42 {
43  Q_D(Part);
44 
45  // qCDebug(KPARTSLOG) << this;
46 
47  if (d->m_widget) {
48  // We need to disconnect first, to avoid calling it !
49  disconnect(d->m_widget.data(), &QWidget::destroyed, this, &Part::slotWidgetDestroyed);
50  }
51 
52  if (d->m_manager) {
53  d->m_manager->removePart(this);
54  }
55 
56  if (d->m_widget && d->m_autoDeleteWidget) {
57  // qCDebug(KPARTSLOG) << "deleting widget" << d->m_widget << d->m_widget->objectName();
58  delete static_cast<QWidget *>(d->m_widget);
59  }
60 
61  delete d->m_iconLoader;
62 }
63 
64 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
65 void Part::embed(QWidget *parentWidget)
66 {
67  if (widget()) {
68  widget()->setParent(parentWidget, Qt::WindowFlags());
69  widget()->setGeometry(0, 0, widget()->width(), widget()->height());
70  widget()->show();
71  }
72 }
73 #endif
74 
76 {
77  Q_D(Part);
78 
79  return d->m_widget;
80 }
81 
82 void Part::setAutoDeleteWidget(bool autoDeleteWidget)
83 {
84  Q_D(Part);
85  d->m_autoDeleteWidget = autoDeleteWidget;
86 }
87 
88 void Part::setAutoDeletePart(bool autoDeletePart)
89 {
90  Q_D(Part);
91  d->m_autoDeletePart = autoDeletePart;
92 }
93 
94 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 82)
96 {
97  Q_D(Part);
98 
99  if (!d->m_iconLoader) {
100  d->m_iconLoader = new KIconLoader(componentName());
101  }
102  return d->m_iconLoader;
103 }
104 #endif
105 
107 {
108  Q_D(const Part);
109 
110  return d->m_metaData;
111 }
112 
114 {
115  Q_D(Part);
116 
117  d->m_manager = manager;
118 }
119 
121 {
122  Q_D(const Part);
123 
124  return d->m_manager;
125 }
126 
127 Part *Part::hitTest(QWidget *widget, const QPoint &)
128 {
129  Q_D(Part);
130 
131  if ((QWidget *)d->m_widget != widget) {
132  return nullptr;
133  }
134 
135  return this;
136 }
137 
139 {
140  Q_D(Part);
141  d->m_widget = widget;
143 }
144 
145 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72)
146 void Part::setSelectable(bool selectable)
147 {
148  Q_D(Part);
149 
150  d->m_bSelectable = selectable;
151 }
152 
153 bool Part::isSelectable() const
154 {
155  Q_D(const Part);
156 
157  return d->m_bSelectable;
158 }
159 #endif
160 
162 {
163  if (PartActivateEvent::test(ev)) {
164  partActivateEvent(static_cast<PartActivateEvent *>(ev));
165  return;
166  }
167 
168 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72)
169  if (PartSelectEvent::test(ev)) {
170  partSelectEvent(static_cast<PartSelectEvent *>(ev));
171  return;
172  }
173 #endif
174 
175  if (GUIActivateEvent::test(ev)) {
176  guiActivateEvent(static_cast<GUIActivateEvent *>(ev));
177  return;
178  }
179 
181 }
182 
184 {
185 }
186 
187 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72)
189 {
190 }
191 #endif
192 
194 {
195 }
196 
197 QWidget *Part::hostContainer(const QString &containerName)
198 {
199  if (!factory()) {
200  return nullptr;
201  }
202 
203  return factory()->container(containerName, this);
204 }
205 
207 {
208  Q_D(Part);
209 
210  d->m_widget = nullptr;
211  if (d->m_autoDeletePart) {
212  // qCDebug(KPARTSLOG) << "deleting part" << objectName();
213  this->deleteLater();
214  }
215 }
216 
217 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 90)
219 {
220  Q_D(Part);
221 
222  PartBase::loadPlugins(this, this, d->m_metaData.pluginId());
223 }
224 #endif
225 
226 void Part::setMetaData(const KPluginMetaData &metaData)
227 {
228  Q_D(Part);
229 
230  d->m_metaData = metaData;
231 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
232  QT_WARNING_PUSH
233  QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
234  QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
235  d->PartBasePrivate::setComponentData(KAboutData::fromPluginMetaData(metaData));
236 
237  // backward-compatible registration, usage deprecated
238 #if KCOREADDONS_BUILD_DEPRECATED_SINCE(5, 76)
239  KAboutData::registerPluginData(d->componentData());
240 #endif
241  QT_WARNING_POP
242 #endif
243 
245 }
246 
247 #include "moc_part.cpp"
virtual void embed(QWidget *parentWidget)
Embed this part into a host widget.
Definition: part.cpp:65
void setParent(QWidget *parent)
This event is sent when a part is selected or deselected.
The part manager is an object which knows about a collection of parts (even nested ones) and handles ...
Definition: partmanager.h:36
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
void setAutoDeletePart(bool autoDeletePart)
By default, the part deletes itself when its widget is deleted.
Definition: part.cpp:88
void setAutoDeleteWidget(bool autoDeleteWidget)
By default, the widget is deleted by the part when the part is deleted.
Definition: part.cpp:82
PartManager * manager() const
Returns the part manager handling this part, if any (0L otherwise).
Definition: part.cpp:120
This event is sent to a Part when its GUI has been activated or deactivated. This is related to PartA...
void slotWidgetDestroyed()
Definition: part.cpp:206
bool isSelectable() const
Returns whether the part is selectable or not.
Definition: part.cpp:153
QWidget * hostContainer(const QString &containerName)
Convenience method for KXMLGUIFactory::container.
Definition: part.cpp:197
Part(QObject *parent=nullptr)
Constructor.
Definition: part.cpp:27
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void setPartObject(QObject *object)
Internal method.
Definition: partbase.cpp:28
void destroyed(QObject *obj)
typedef WindowFlags
void deleteLater()
virtual void setComponentName(const QString &componentName, const QString &componentDisplayName)
QString name() const
virtual void setManager(PartManager *manager)
Definition: part.cpp:113
KXMLGUIFactory * factory() const
UniqueConnection
virtual Part * hitTest(QWidget *widget, const QPoint &globalPos)
Returns the part (this, or a child part) at the given global position.
Definition: part.cpp:127
void setMetaData(const KPluginMetaData &metaData)
Set the meta data for this part.
Definition: part.cpp:226
void show()
Base class for all parts.
Definition: partbase.h:38
void setGeometry(int x, int y, int w, int h)
Base class for parts.
Definition: part.h:62
static void registerPluginData(const KAboutData &aboutData)
KPluginMetaData metaData() const
Definition: part.cpp:106
virtual void partActivateEvent(PartActivateEvent *event)
Convenience method which is called when the Part received a PartActivateEvent .
Definition: part.cpp:183
QWidget * container(const QString &containerName, KXMLGUIClient *client, bool useTagName=false)
virtual void guiActivateEvent(GUIActivateEvent *event)
Convenience method which is called when the Part received a GUIActivateEvent .
Definition: part.cpp:193
~Part() override
Destructor.
Definition: part.cpp:41
virtual void partSelectEvent(PartSelectEvent *event)
Convenience method which is called when the Part received a PartSelectEvent .
Definition: part.cpp:188
virtual void customEvent(QEvent *event)
virtual void setWidget(QWidget *widget)
Set the main widget.
Definition: part.cpp:138
KIconLoader * iconLoader()
Use this icon loader to load any icons that are specific to this part, i.e.
Definition: part.cpp:95
virtual QWidget * widget()
Definition: part.cpp:75
QString pluginId() const
void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const KAboutData &aboutData)
Load the Plugins honoring the PluginLoadingMode.
Definition: partbase.cpp:82
This event is sent by the part manager when the active part changes. Each time the active part change...
void loadPlugins()
Load this part's plugins now.
Definition: part.cpp:218
void customEvent(QEvent *event) override
Definition: part.cpp:161
The KParts namespace,.
Q_D(Todo)
virtual void setSelectable(bool selectable)
Definition: part.cpp:146
virtual QString componentName() const
static KAboutData fromPluginMetaData(const KPluginMetaData &plugin)
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Dec 6 2022 03:55:09 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.