File indexing completed on 2024-04-28 15:29:21
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> 0004 SPDX-FileCopyrightText: 1999-2005 David Faure <faure@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "part.h" 0010 #include "part_p.h" 0011 0012 #include "kparts_logging.h" 0013 #include "partactivateevent.h" 0014 0015 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72) 0016 #include "partselectevent.h" 0017 #endif 0018 0019 #include "guiactivateevent.h" 0020 #include "partmanager.h" 0021 0022 #include <KIconLoader> 0023 #include <KXMLGUIFactory> 0024 0025 using namespace KParts; 0026 0027 Part::Part(QObject *parent) 0028 : QObject(parent) 0029 , PartBase(*new PartPrivate(this)) 0030 { 0031 PartBase::setPartObject(this); 0032 } 0033 0034 Part::Part(PartPrivate &dd, QObject *parent) 0035 : QObject(parent) 0036 , PartBase(dd) 0037 { 0038 PartBase::setPartObject(this); 0039 } 0040 0041 Part::~Part() 0042 { 0043 Q_D(Part); 0044 0045 // qCDebug(KPARTSLOG) << this; 0046 0047 if (d->m_widget) { 0048 // We need to disconnect first, to avoid calling it ! 0049 disconnect(d->m_widget.data(), &QWidget::destroyed, this, &Part::slotWidgetDestroyed); 0050 } 0051 0052 if (d->m_manager) { 0053 d->m_manager->removePart(this); 0054 } 0055 0056 if (d->m_widget && d->m_autoDeleteWidget) { 0057 // qCDebug(KPARTSLOG) << "deleting widget" << d->m_widget << d->m_widget->objectName(); 0058 delete static_cast<QWidget *>(d->m_widget); 0059 } 0060 0061 delete d->m_iconLoader; 0062 } 0063 0064 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77) 0065 void Part::embed(QWidget *parentWidget) 0066 { 0067 if (widget()) { 0068 widget()->setParent(parentWidget, Qt::WindowFlags()); 0069 widget()->setGeometry(0, 0, widget()->width(), widget()->height()); 0070 widget()->show(); 0071 } 0072 } 0073 #endif 0074 0075 QWidget *Part::widget() 0076 { 0077 Q_D(Part); 0078 0079 return d->m_widget; 0080 } 0081 0082 void Part::setAutoDeleteWidget(bool autoDeleteWidget) 0083 { 0084 Q_D(Part); 0085 d->m_autoDeleteWidget = autoDeleteWidget; 0086 } 0087 0088 void Part::setAutoDeletePart(bool autoDeletePart) 0089 { 0090 Q_D(Part); 0091 d->m_autoDeletePart = autoDeletePart; 0092 } 0093 0094 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 82) 0095 KIconLoader *Part::iconLoader() 0096 { 0097 Q_D(Part); 0098 0099 if (!d->m_iconLoader) { 0100 d->m_iconLoader = new KIconLoader(componentName()); 0101 } 0102 return d->m_iconLoader; 0103 } 0104 #endif 0105 0106 KPluginMetaData Part::metaData() const 0107 { 0108 Q_D(const Part); 0109 0110 return d->m_metaData; 0111 } 0112 0113 void Part::setManager(PartManager *manager) 0114 { 0115 Q_D(Part); 0116 0117 d->m_manager = manager; 0118 } 0119 0120 PartManager *Part::manager() const 0121 { 0122 Q_D(const Part); 0123 0124 return d->m_manager; 0125 } 0126 0127 Part *Part::hitTest(QWidget *widget, const QPoint &) 0128 { 0129 Q_D(Part); 0130 0131 if ((QWidget *)d->m_widget != widget) { 0132 return nullptr; 0133 } 0134 0135 return this; 0136 } 0137 0138 void Part::setWidget(QWidget *widget) 0139 { 0140 Q_D(Part); 0141 d->m_widget = widget; 0142 connect(d->m_widget.data(), &QWidget::destroyed, this, &Part::slotWidgetDestroyed, Qt::UniqueConnection); 0143 } 0144 0145 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72) 0146 void Part::setSelectable(bool selectable) 0147 { 0148 Q_D(Part); 0149 0150 d->m_bSelectable = selectable; 0151 } 0152 0153 bool Part::isSelectable() const 0154 { 0155 Q_D(const Part); 0156 0157 return d->m_bSelectable; 0158 } 0159 #endif 0160 0161 void Part::customEvent(QEvent *ev) 0162 { 0163 if (PartActivateEvent::test(ev)) { 0164 partActivateEvent(static_cast<PartActivateEvent *>(ev)); 0165 return; 0166 } 0167 0168 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72) 0169 if (PartSelectEvent::test(ev)) { 0170 partSelectEvent(static_cast<PartSelectEvent *>(ev)); 0171 return; 0172 } 0173 #endif 0174 0175 if (GUIActivateEvent::test(ev)) { 0176 guiActivateEvent(static_cast<GUIActivateEvent *>(ev)); 0177 return; 0178 } 0179 0180 QObject::customEvent(ev); 0181 } 0182 0183 void Part::partActivateEvent(PartActivateEvent *) 0184 { 0185 } 0186 0187 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72) 0188 void Part::partSelectEvent(PartSelectEvent *) 0189 { 0190 } 0191 #endif 0192 0193 void Part::guiActivateEvent(GUIActivateEvent *) 0194 { 0195 } 0196 0197 QWidget *Part::hostContainer(const QString &containerName) 0198 { 0199 if (!factory()) { 0200 return nullptr; 0201 } 0202 0203 return factory()->container(containerName, this); 0204 } 0205 0206 void Part::slotWidgetDestroyed() 0207 { 0208 Q_D(Part); 0209 0210 d->m_widget = nullptr; 0211 if (d->m_autoDeletePart) { 0212 // qCDebug(KPARTSLOG) << "deleting part" << objectName(); 0213 this->deleteLater(); 0214 } 0215 } 0216 0217 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 90) 0218 void Part::loadPlugins() 0219 { 0220 Q_D(Part); 0221 0222 PartBase::loadPlugins(this, this, d->m_metaData.pluginId()); 0223 } 0224 #endif 0225 0226 void Part::setMetaData(const KPluginMetaData &metaData) 0227 { 0228 Q_D(Part); 0229 0230 d->m_metaData = metaData; 0231 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77) 0232 QT_WARNING_PUSH 0233 QT_WARNING_DISABLE_CLANG("-Wdeprecated-declarations") 0234 QT_WARNING_DISABLE_GCC("-Wdeprecated-declarations") 0235 d->PartBasePrivate::setComponentData(KAboutData::fromPluginMetaData(metaData)); 0236 0237 // backward-compatible registration, usage deprecated 0238 #if KCOREADDONS_BUILD_DEPRECATED_SINCE(5, 76) 0239 KAboutData::registerPluginData(d->componentData()); 0240 #endif 0241 QT_WARNING_POP 0242 #endif 0243 0244 KXMLGUIClient::setComponentName(metaData.pluginId(), metaData.name()); 0245 } 0246 0247 #include "moc_part.cpp"