1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2003 Daniel Molkentin <molkentin@kde.org>
4 SPDX-FileCopyrightText: 2003 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#ifndef KPARTS_STATUSBAREXTENSION_H
10#define KPARTS_STATUSBAREXTENSION_H
11
12#include <kparts/kparts_export.h>
13
14#include <QWidget>
15#include <memory>
16
17class QStatusBar;
18class KMainWindow;
19class QEvent;
20
21namespace KParts
22{
23class Part;
24class ReadOnlyPart;
25
26// Defined in impl
27class StatusBarItem;
28class StatusBarExtensionPrivate;
29
30/**
31 * @class StatusBarExtension statusbarextension.h <KParts/StatusBarExtension>
32 *
33 * @short An extension for KParts that allows more sophisticated statusbar handling
34 *
35 * Every part can use this class to customize the statusbar as long as it is active.
36 * Add items via addStatusBarItem and remove an item with removeStatusBarItem.
37 *
38 * IMPORTANT: do NOT add any items immediately after constructing the extension.
39 * Give the application time to set the statusbar in the extension if necessary.
40 */
41class KPARTS_EXPORT StatusBarExtension : public QObject
42{
43 Q_OBJECT
44
45public:
46 explicit StatusBarExtension(KParts::Part *parent);
47 explicit StatusBarExtension(KParts::ReadOnlyPart *parent); // KF6: REMOVE
48 ~StatusBarExtension() override;
49
50 /**
51 * This adds a widget to the statusbar for this part.
52 * If you use this method instead of using statusBar() directly,
53 * this extension will take care of removing the items when the parts GUI
54 * is deactivated and will re-add them when it is reactivated.
55 * The parameters are the same as QStatusBar::addWidget().
56 *
57 * Note that you can't use KStatusBar methods (inserting text items by id)
58 * but you can create a KStatusBarLabel with a dummy id instead, and use
59 * it directly in order to get the same look and feel.
60 *
61 * @param widget the widget to add
62 * @param stretch the stretch factor. 0 for a minimum size.
63 * @param permanent passed to QStatusBar::addWidget as the "permanent" bool.
64 * Note that the item isn't really permanent though, it goes away when
65 * the part is unactivated. This simply controls whether temporary messages
66 * hide the @p widget, and whether it's added to the left or to the right side.
67 *
68 * @Note that the widget does not technically become a child of the
69 * StatusBarExtension in a QObject sense. However, it @em will be deleted
70 * when the StatusBarExtension is deleted.
71 *
72 * IMPORTANT: do NOT add any items immediately after constructing the extension.
73 * Give the application time to set the statusbar in the extension if necessary.
74 */
75 void addStatusBarItem(QWidget *widget, int stretch, bool permanent);
76
77 /**
78 * Remove a widget from the statusbar for this part.
79 */
80 void removeStatusBarItem(QWidget *widget);
81
82 /**
83 * @return the statusbar of the KMainWindow in which this part is currently embedded.
84 * WARNING: this could return 0L
85 */
86 QStatusBar *statusBar() const;
87
88 /**
89 * This allows the hosting application to set a particular QStatusBar
90 * for this part. If it doesn't do this, the statusbar used will be
91 * the one of the KMainWindow in which the part is embedded.
92 * Konqueror uses this to assign a view-statusbar to the part.
93 * The part should never call this method!
94 */
95 void setStatusBar(QStatusBar *status);
96
97 /**
98 * Queries @p obj for a child object which inherits from this
99 * StatusBarExtension class. Convenience method.
100 */
101 static StatusBarExtension *childObject(QObject *obj);
102
103 /** @internal */
104 bool eventFilter(QObject *watched, QEvent *ev) override;
105
106private:
107 // for future extensions
108 friend class StatusBarExtensionPrivate;
109 std::unique_ptr<StatusBarExtensionPrivate> const d;
110};
111
112}
113#endif // KPARTS_STATUSBAREXTENSION_H
114

source code of kparts/src/statusbarextension.h