1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
4 SPDX-FileCopyrightText: 1999-2005 David Faure <faure@kde.org>
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 "partmanager.h"
14
15// The events have randomly generated numbers using `shuf -i1000-65535 -n 1`
16#include "guiactivateevent.h"
17#include "partactivateevent.h"
18
19#include <KXMLGUIFactory>
20
21using namespace KParts;
22
23Part::Part(QObject *parent, const KPluginMetaData &data)
24 : Part(*new PartPrivate(this, data), parent)
25{
26}
27
28Part::Part(PartPrivate &dd, QObject *parent)
29 : QObject(parent)
30 , PartBase(dd)
31{
32 Q_D(Part);
33
34 PartBase::setPartObject(this);
35 if (d->m_metaData.isValid()) {
36 KXMLGUIClient::setComponentName(componentName: d->m_metaData.pluginId(), componentDisplayName: d->m_metaData.name());
37 }
38}
39
40Part::~Part()
41{
42 Q_D(Part);
43
44 // qCDebug(KPARTSLOG) << this;
45
46 if (d->m_widget) {
47 // We need to disconnect first, to avoid calling it !
48 disconnect(sender: d->m_widget.data(), signal: &QWidget::destroyed, receiver: this, slot: &Part::slotWidgetDestroyed);
49 }
50
51 if (d->m_manager) {
52 d->m_manager->removePart(part: this);
53 }
54
55 if (d->m_widget && d->m_autoDeleteWidget) {
56 // qCDebug(KPARTSLOG) << "deleting widget" << d->m_widget << d->m_widget->objectName();
57 delete static_cast<QWidget *>(d->m_widget);
58 }
59}
60
61QWidget *Part::widget()
62{
63 Q_D(Part);
64
65 return d->m_widget;
66}
67
68void Part::setAutoDeleteWidget(bool autoDeleteWidget)
69{
70 Q_D(Part);
71 d->m_autoDeleteWidget = autoDeleteWidget;
72}
73
74void Part::setAutoDeletePart(bool autoDeletePart)
75{
76 Q_D(Part);
77 d->m_autoDeletePart = autoDeletePart;
78}
79
80KPluginMetaData Part::metaData() const
81{
82 Q_D(const Part);
83
84 return d->m_metaData;
85}
86
87void Part::setManager(PartManager *manager)
88{
89 Q_D(Part);
90
91 d->m_manager = manager;
92}
93
94PartManager *Part::manager() const
95{
96 Q_D(const Part);
97
98 return d->m_manager;
99}
100
101Part *Part::hitTest(QWidget *widget, const QPoint &)
102{
103 Q_D(Part);
104
105 if ((QWidget *)d->m_widget != widget) {
106 return nullptr;
107 }
108
109 return this;
110}
111
112void Part::setWidget(QWidget *widget)
113{
114 Q_D(Part);
115 d->m_widget = widget;
116 connect(sender: d->m_widget.data(), signal: &QWidget::destroyed, context: this, slot: &Part::slotWidgetDestroyed, type: Qt::UniqueConnection);
117}
118
119void Part::customEvent(QEvent *ev)
120{
121 if (PartActivateEvent::test(event: ev)) {
122 partActivateEvent(event: static_cast<PartActivateEvent *>(ev));
123 return;
124 }
125
126 if (GUIActivateEvent::test(event: ev)) {
127 guiActivateEvent(event: static_cast<GUIActivateEvent *>(ev));
128 return;
129 }
130
131 QObject::customEvent(event: ev);
132}
133
134void Part::partActivateEvent(PartActivateEvent *)
135{
136}
137
138void Part::guiActivateEvent(GUIActivateEvent *)
139{
140}
141
142QWidget *Part::hostContainer(const QString &containerName)
143{
144 if (!factory()) {
145 return nullptr;
146 }
147
148 return factory()->container(containerName, client: this);
149}
150
151void Part::slotWidgetDestroyed()
152{
153 Q_D(Part);
154
155 d->m_widget = nullptr;
156 if (d->m_autoDeletePart) {
157 // qCDebug(KPARTSLOG) << "deleting part" << objectName();
158 this->deleteLater();
159 }
160}
161
162#include "moc_part.cpp"
163

source code of kparts/src/part.cpp