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 
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 
218 {
219  Q_D(Part);
220 
221  PartBase::loadPlugins(this, this, d->m_metaData.pluginId());
222 }
223 
225 {
226  Q_D(Part);
227 
228  d->m_metaData = metaData;
229 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
230  QT_WARNING_PUSH
231  QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations")
232  QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations")
233  d->PartBasePrivate::setComponentData(KAboutData::fromPluginMetaData(metaData));
234 
235  // backward-compatible registration, usage deprecated
236 #if KCOREADDONS_BUILD_DEPRECATED_SINCE(5, 76)
237  KAboutData::registerPluginData(d->componentData());
238 #endif
239  QT_WARNING_POP
240 #endif
241 
242  KXMLGUIClient::setComponentName(metaData.pluginId(), metaData.name());
243 }
244 
245 #include "moc_part.cpp"
QString name() const
This event is sent by the part manager when the active part changes.
void loadPlugins()
Load this part&#39;s plugins now.
Definition: part.cpp:217
void setPartObject(QObject *object)
Internal method.
Definition: partbase.cpp:28
virtual void embed(QWidget *parentWidget)
Embed this part into a host widget.
Definition: part.cpp:65
virtual QWidget * widget()
Definition: part.cpp:75
void customEvent(QEvent *event) override
Definition: part.cpp:161
KXMLGUIFactory * factory() const
virtual QString componentName() const
Base class for parts.
Definition: part.h:62
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
void setParent(QWidget *parent)
static void registerPluginData(const KAboutData &aboutData)
void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const KAboutData &aboutData)
Load the Plugins honoring the PluginLoadingMode.
Definition: partbase.cpp:82
Base class for all parts.
Definition: partbase.h:38
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
QWidget * hostContainer(const QString &containerName)
Convenience method for KXMLGUIFactory::container.
Definition: part.cpp:197
void deleteLater()
virtual void partActivateEvent(PartActivateEvent *event)
Convenience method which is called when the Part received a PartActivateEvent .
Definition: part.cpp:183
void slotWidgetDestroyed()
Definition: part.cpp:206
This event is sent to a Part when its GUI has been activated or deactivated.
virtual void setSelectable(bool selectable)
Definition: part.cpp:146
~Part() override
Destructor.
Definition: part.cpp:41
Part(QObject *parent=nullptr)
Constructor.
Definition: part.cpp:27
static KAboutData fromPluginMetaData(const KPluginMetaData &plugin)
virtual void setWidget(QWidget *widget)
Set the main widget.
Definition: part.cpp:138
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 setComponentName(const QString &componentName, const QString &componentDisplayName)
QObject(QObject *parent)
bool isSelectable() const
Returns whether the part is selectable or not.
Definition: part.cpp:153
KIconLoader * iconLoader()
Use this icon loader to load any icons that are specific to this part, i.e.
Definition: part.cpp:95
PartBase()
Constructor.
Definition: partbase.cpp:16
PartManager * manager() const
Returns the part manager handling this part, if any (0L otherwise).
Definition: part.cpp:120
virtual void setManager(PartManager *manager)
Definition: part.cpp:113
void setAutoDeletePart(bool autoDeletePart)
By default, the part deletes itself when its widget is deleted.
Definition: part.cpp:88
The part manager is an object which knows about a collection of parts (even nested ones) and handles ...
Definition: partmanager.h:36
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
void show()
UniqueConnection
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QObject * parent() const const
The KParts namespace,.
void setMetaData(const KPluginMetaData &metaData)
Set the meta data for this part.
Definition: part.cpp:224
typedef WindowFlags
void destroyed(QObject *obj)
QString pluginId() const
void setAutoDeleteWidget(bool autoDeleteWidget)
By default, the widget is deleted by the part when the part is deleted.
Definition: part.cpp:82
This event is sent when a part is selected or deselected.
void setGeometry(int x, int y, int w, int h)
KPluginMetaData metaData() const
Definition: part.cpp:106
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Sep 27 2021 22:56:33 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.