File indexing completed on 2024-04-28 15:29:24
0001 /* 0002 This file is part of the KDE project 0003 SPDX-FileCopyrightText: 2003 Daniel Molkentin <molkentin@kde.org> 0004 SPDX-FileCopyrightText: 2003 David Faure <faure@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #ifndef KPARTS_STATUSBAREXTENSION_H 0010 #define KPARTS_STATUSBAREXTENSION_H 0011 0012 #include <kparts/kparts_export.h> 0013 0014 #include <QWidget> 0015 #include <memory> 0016 0017 class QStatusBar; 0018 class KMainWindow; 0019 class QEvent; 0020 0021 namespace KParts 0022 { 0023 class Part; 0024 class ReadOnlyPart; 0025 0026 // Defined in impl 0027 class StatusBarItem; 0028 class StatusBarExtensionPrivate; 0029 0030 /** 0031 * @class StatusBarExtension statusbarextension.h <KParts/StatusBarExtension> 0032 * 0033 * @short An extension for KParts that allows more sophisticated statusbar handling 0034 * 0035 * Every part can use this class to customize the statusbar as long as it is active. 0036 * Add items via addStatusBarItem and remove an item with removeStatusBarItem. 0037 * 0038 * IMPORTANT: do NOT add any items immediately after constructing the extension. 0039 * Give the application time to set the statusbar in the extension if necessary. 0040 */ 0041 class KPARTS_EXPORT StatusBarExtension : public QObject 0042 { 0043 Q_OBJECT 0044 0045 public: 0046 explicit StatusBarExtension(KParts::Part *parent); 0047 explicit StatusBarExtension(KParts::ReadOnlyPart *parent); // KF6: REMOVE 0048 ~StatusBarExtension() override; 0049 0050 /** 0051 * This adds a widget to the statusbar for this part. 0052 * If you use this method instead of using statusBar() directly, 0053 * this extension will take care of removing the items when the parts GUI 0054 * is deactivated and will re-add them when it is reactivated. 0055 * The parameters are the same as QStatusBar::addWidget(). 0056 * 0057 * Note that you can't use KStatusBar methods (inserting text items by id) 0058 * but you can create a KStatusBarLabel with a dummy id instead, and use 0059 * it directly in order to get the same look and feel. 0060 * 0061 * @param widget the widget to add 0062 * @param stretch the stretch factor. 0 for a minimum size. 0063 * @param permanent passed to QStatusBar::addWidget as the "permanent" bool. 0064 * Note that the item isn't really permanent though, it goes away when 0065 * the part is unactivated. This simply controls whether temporary messages 0066 * hide the @p widget, and whether it's added to the left or to the right side. 0067 * 0068 * @Note that the widget does not technically become a child of the 0069 * StatusBarExtension in a QObject sense. However, it @em will be deleted 0070 * when the StatusBarExtension is deleted. 0071 * 0072 * IMPORTANT: do NOT add any items immediately after constructing the extension. 0073 * Give the application time to set the statusbar in the extension if necessary. 0074 */ 0075 void addStatusBarItem(QWidget *widget, int stretch, bool permanent); 0076 0077 /** 0078 * Remove a widget from the statusbar for this part. 0079 */ 0080 void removeStatusBarItem(QWidget *widget); 0081 0082 /** 0083 * @return the statusbar of the KMainWindow in which this part is currently embedded. 0084 * WARNING: this could return 0L 0085 */ 0086 QStatusBar *statusBar() const; 0087 0088 /** 0089 * This allows the hosting application to set a particular QStatusBar 0090 * for this part. If it doesn't do this, the statusbar used will be 0091 * the one of the KMainWindow in which the part is embedded. 0092 * Konqueror uses this to assign a view-statusbar to the part. 0093 * The part should never call this method! 0094 */ 0095 void setStatusBar(QStatusBar *status); 0096 0097 /** 0098 * Queries @p obj for a child object which inherits from this 0099 * StatusBarExtension class. Convenience method. 0100 */ 0101 static StatusBarExtension *childObject(QObject *obj); 0102 0103 /** @internal */ 0104 bool eventFilter(QObject *watched, QEvent *ev) override; 0105 0106 private: 0107 // for future extensions 0108 friend class StatusBarExtensionPrivate; 0109 std::unique_ptr<StatusBarExtensionPrivate> const d; 0110 }; 0111 0112 } 0113 #endif // KPARTS_STATUSBAREXTENSION_H