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 KParts::StatusBarExtension
32 * \inheaderfile KParts/StatusBarExtension
33 * \inmodule KParts
34 *
35 * \brief An extension for KParts that allows more sophisticated statusbar handling.
36 *
37 * Every part can use this class to customize the statusbar as long as it is active.
38 * Add items via addStatusBarItem and remove an item with removeStatusBarItem.
39 *
40 * IMPORTANT: do NOT add any items immediately after constructing the extension.
41 * Give the application time to set the statusbar in the extension if necessary.
42 */
43class KPARTS_EXPORT StatusBarExtension : public QObject
44{
45 Q_OBJECT
46
47public:
48 /*!
49 *
50 */
51 explicit StatusBarExtension(KParts::Part *parent);
52
53 /*!
54 *
55 */
56 explicit StatusBarExtension(KParts::ReadOnlyPart *parent); // KF6: REMOVE
57 ~StatusBarExtension() override;
58
59 /*!
60 * This adds a widget to the statusbar for this part.
61 * If you use this method instead of using statusBar() directly,
62 * this extension will take care of removing the items when the parts GUI
63 * is deactivated and will re-add them when it is reactivated.
64 * The parameters are the same as QStatusBar::addWidget().
65 *
66 * Note that you can't use KStatusBar methods (inserting text items by id)
67 * but you can create a KStatusBarLabel with a dummy id instead, and use
68 * it directly in order to get the same look and feel.
69 *
70 * \a widget the widget to add
71 *
72 * \a stretch the stretch factor. 0 for a minimum size.
73 *
74 * \a permanent passed to QStatusBar::addWidget as the "permanent" bool.
75 *
76 * Note that the item isn't really permanent though, it goes away when
77 * the part is unactivated. This simply controls whether temporary messages
78 * hide the \a widget, and whether it's added to the left or to the right side.
79 *
80 * \note that the widget does not technically become a child of the
81 * StatusBarExtension in a QObject sense. However, it will be deleted
82 * when the StatusBarExtension is deleted.
83 *
84 * IMPORTANT: do NOT add any items immediately after constructing the extension.
85 * Give the application time to set the statusbar in the extension if necessary.
86 */
87 void addStatusBarItem(QWidget *widget, int stretch, bool permanent);
88
89 /*!
90 * Remove a widget from the statusbar for this part.
91 */
92 void removeStatusBarItem(QWidget *widget);
93
94 /*!
95 * Returns the statusbar of the KMainWindow in which this part is currently embedded.
96 * This can return \c nullptr
97 */
98 QStatusBar *statusBar() const;
99
100 /*!
101 * This allows the hosting application to set a particular QStatusBar
102 * for this part. If it doesn't do this, the statusbar used will be
103 * the one of the KMainWindow in which the part is embedded.
104 * Konqueror uses this to assign a view-statusbar to the part.
105 * The part should never call this method!
106 */
107 void setStatusBar(QStatusBar *status);
108
109 /*!
110 * Queries \a obj for a child object which inherits from this
111 * StatusBarExtension class. Convenience method.
112 */
113 static StatusBarExtension *childObject(QObject *obj);
114
115 bool eventFilter(QObject *watched, QEvent *ev) override;
116
117private:
118 // for future extensions
119 friend class StatusBarExtensionPrivate;
120 std::unique_ptr<StatusBarExtensionPrivate> const d;
121};
122
123}
124#endif // KPARTS_STATUSBAREXTENSION_H
125

source code of kparts/src/statusbarextension.h