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 David Faure <faure@kde.org>
0005 
0006    SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #ifndef _KPARTS_PART_H
0010 #define _KPARTS_PART_H
0011 
0012 #include <kparts/partbase.h>
0013 
0014 class KPluginMetaData;
0015 class KIconLoader;
0016 class QWidget;
0017 class QEvent;
0018 class QPoint;
0019 
0020 /**
0021  * The KParts namespace,
0022  */
0023 namespace KParts
0024 {
0025 class PartManager;
0026 class PartPrivate;
0027 class PartActivateEvent;
0028 
0029 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72)
0030 class PartSelectEvent;
0031 #endif
0032 
0033 class GUIActivateEvent;
0034 
0035 /**
0036  * @class Part part.h <KParts/Part>
0037  *
0038  * @short Base class for parts.
0039  *
0040  * A "part" is a GUI component, featuring:
0041  * @li A widget embeddedable in any application.
0042  * @li GUI elements that will be merged in the "host" user interface
0043  * (menubars, toolbars... ).
0044  *
0045  * <b>About the widget:</b>\n
0046  *
0047  * Note that KParts::Part does not inherit QWidget.
0048  * This is due to the fact that the "visual representation"
0049  * will probably not be a mere QWidget, but an elaborate one.
0050  * That's why when implementing your KParts::Part (or derived)
0051  * you should call KParts::Part::setWidget() in your constructor.
0052  *
0053  * <b>About the GUI elements:</b>\n
0054  *
0055  * Those elements trigger actions, defined by the part ( action()).
0056  * The layout of the actions in the GUI is defined by an XML file ( setXMLFile()).
0057  *
0058  * See also ReadOnlyPart and ReadWritePart, which define the
0059  * framework for a "viewer" part and for an "editor"-like part.
0060  * Use Part directly only if your part doesn't fit into those.
0061  */
0062 class KPARTS_EXPORT Part : public QObject, public PartBase
0063 {
0064     Q_OBJECT
0065 
0066     KPARTS_DECLARE_PRIVATE(Part)
0067 
0068 public:
0069     /**
0070      *  Constructor.
0071      *
0072      *  @param parent Parent object of the part.
0073      */
0074     explicit Part(QObject *parent = nullptr);
0075 
0076     /**
0077      *  Destructor.
0078      */
0079     ~Part() override;
0080 
0081 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 77)
0082     /**
0083      * Embed this part into a host widget.
0084      *
0085      * You don't need to do this if you created the widget with the
0086      * correct parent widget - this is just a QWidget::reparent().
0087      * Note that the Part is still the holder
0088      * of the QWidget, meaning that if you delete the Part,
0089      * then the widget gets destroyed as well, and vice-versa.
0090      * This method is not recommended since creating the widget with the correct
0091      * parent is simpler anyway.
0092      *
0093      * @deprecated Since 5.77, for lack of usage.
0094      */
0095     KPARTS_DEPRECATED_VERSION(5, 77, "Deprecated for lack of usage")
0096     virtual void embed(QWidget *parentWidget);
0097 #endif
0098 
0099     /**
0100      * @return The widget defined by this part, set by setWidget().
0101      */
0102     virtual QWidget *widget();
0103 
0104     /**
0105      * @internal
0106      * Used by the part manager.
0107      */
0108     virtual void setManager(PartManager *manager);
0109 
0110     /**
0111      * Returns the part manager handling this part, if any (0L otherwise).
0112      */
0113     PartManager *manager() const;
0114 
0115     /**
0116      * By default, the widget is deleted by the part when the part is deleted.
0117      * The hosting application can call setAutoDeleteWidget(false) to
0118      * disable this behavior, given that the widget is usually deleted by
0119      * its parent widget anyway.
0120      * This is a method for the hosting application only, Part subclasses
0121      * should never call this.
0122      */
0123     void setAutoDeleteWidget(bool autoDeleteWidget);
0124 
0125     /**
0126      * By default, the part deletes itself when its widget is deleted.
0127      * The hosting application can call setAutoDeletePart(false) to
0128      * disable this behavior, to be able to delete the widget and then the part,
0129      * independently.
0130      * This is a method for the hosting application only, Part subclasses
0131      * should never call this.
0132      */
0133     void setAutoDeletePart(bool autoDeletePart);
0134 
0135     /**
0136      * Returns the part (this, or a child part) at the given global position.
0137      * This is called by the part manager to ask whether a part should be activated
0138      * when clicking somewhere. In most cases the default implementation is enough.
0139      * Reimplement this if your part has child parts in some areas (like in khtml or koffice)
0140      * @param widget the part widget being clicked - usually the same as widget(), except in koffice.
0141      * @param globalPos the mouse coordinates in global coordinates
0142      */
0143     virtual Part *hitTest(QWidget *widget, const QPoint &globalPos);
0144 
0145 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72)
0146     /**
0147      *  @param selectable Indicates whether the part is selectable or not.
0148      *
0149      * @deprecated Since 5.72, for lack of usage.
0150      */
0151     KPARTS_DEPRECATED_VERSION(5, 72, "Deprecated for lack of usage")
0152     virtual void setSelectable(bool selectable);
0153 #endif
0154 
0155 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 72)
0156     /**
0157      *  Returns whether the part is selectable or not.
0158      *
0159      * @deprecated Since 5.72, for lack of usage.
0160      */
0161     KPARTS_DEPRECATED_VERSION(5, 72, "Deprecated for lack of usage")
0162     bool isSelectable() const;
0163 #endif
0164 
0165     /**
0166      * @since 5.77
0167      */
0168     KPluginMetaData metaData() const;
0169 
0170 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 82)
0171     /**
0172      * Use this icon loader to load any icons that are specific to this part,
0173      * i.e. icons installed into this part's own directories as opposed to standard
0174      * kde icons.
0175      *
0176      * Make sure to call setMetaData (or deprecated setComponentData) before calling iconLoader.
0177      * @deprecated since 5.82, use QIcon::fromTheme() and set QIcon::setThemeSearchPaths()
0178      * or QIcon::setFallbackSearchPaths appropriately.
0179      */
0180     KPARTS_DEPRECATED_VERSION(5, 82, "See API docs.")
0181     KIconLoader *iconLoader();
0182 #endif
0183 
0184 Q_SIGNALS:
0185     /**
0186      * Emitted by the part, to set the caption of the window(s)
0187      * hosting this part
0188      *
0189      * @note this signal has only an effect on the window title if window title
0190      *       handling is enabled @see KParts::MainWindow::setWindowTitleHandling
0191      */
0192     void setWindowCaption(const QString &caption);
0193     /**
0194      * Emitted by the part, to set a text in the statusbar of the window(s)
0195      * hosting this part
0196      */
0197     void setStatusBarText(const QString &text);
0198 
0199 protected:
0200     /**
0201      * Set the main widget.
0202      *
0203      * Call this in the Part-inherited class constructor.
0204      */
0205     virtual void setWidget(QWidget *widget);
0206 
0207     /**
0208      * @internal
0209      */
0210     void customEvent(QEvent *event) override;
0211 
0212     /**
0213      * Convenience method which is called when the Part received a PartActivateEvent .
0214      * Reimplement this if you don't want to reimplement event and test for the event yourself
0215      * or even install an event filter.
0216      */
0217     virtual void partActivateEvent(PartActivateEvent *event);
0218 
0219 #if KPARTS_BUILD_DEPRECATED_SINCE(5, 72)
0220     /**
0221      * Convenience method which is called when the Part received a
0222      * PartSelectEvent .
0223      * Reimplement this if you don't want to reimplement event and
0224      * test for the event yourself or even install an event filter.
0225      *
0226      * @deprecated Since 5.72, for lack of usage.
0227      */
0228     virtual void partSelectEvent(PartSelectEvent *event);
0229 #endif
0230 
0231     /**
0232      * Convenience method which is called when the Part received a
0233      * GUIActivateEvent .
0234      * Reimplement this if you don't want to reimplement event and
0235      * test for the event yourself or even install an event filter.
0236      */
0237     virtual void guiActivateEvent(GUIActivateEvent *event);
0238 
0239     /**
0240      * Convenience method for KXMLGUIFactory::container.
0241      * @return a container widget owned by the Part's GUI.
0242      */
0243     QWidget *hostContainer(const QString &containerName);
0244 
0245 #if KPARTS_ENABLE_DEPRECATED_SINCE(5, 90)
0246     /**
0247      * Load this part's plugins now.
0248      * Call this at the end of the part constructor, unless you are still using the
0249      * deprecated setComponentData(componentData, true)).
0250      * @since 4.1
0251      * @deprecated Since 5.90, the concept of KPart plugins is deprecated, see docs of @ref KParts::Plugin class
0252      */
0253     KPARTS_DEPRECATED_VERSION(5, 90, "The concept of KPart plugins is deprecated, see docs of KParts::Plugin class")
0254     void loadPlugins();
0255     using PartBase::loadPlugins;
0256 #endif
0257 
0258     /**
0259      * Set the meta data for this part.
0260      *
0261      * Call this at the begin of the part constructor.
0262      *
0263      * @since 5.77
0264      */
0265     void setMetaData(const KPluginMetaData &metaData);
0266 
0267 protected Q_SLOTS:
0268     /**
0269      * @internal
0270      */
0271     void slotWidgetDestroyed();
0272 
0273 protected:
0274     KPARTS_NO_EXPORT Part(PartPrivate &dd, QObject *parent);
0275 
0276 private:
0277     Q_DISABLE_COPY(Part)
0278 };
0279 
0280 } // namespace
0281 
0282 #endif