1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2004 Felix Berger <felixberger@beldesign.de>
4
5 SPDX-License-Identifier: LGPL-2.0-only
6*/
7
8#ifndef KTOOLBARLABELACTION_H
9#define KTOOLBARLABELACTION_H
10
11#include <QWidgetAction>
12#include <memory>
13
14#include <kwidgetsaddons_export.h>
15
16/*!
17 * \class KToolBarLabelAction
18 * \inmodule KWidgetsAddons
19 *
20 * \brief Class to display a label in a toolbar.
21 *
22 * KToolBarLabelAction is a convenience class for displaying a label in a
23 * toolbar.
24 *
25 * It provides easy access to the label's #setBuddy(QAction*) and #buddy()
26 * methods and can be used as follows:
27 *
28 * \code
29 *
30 * KHistoryComboBox *findCombo = new KHistoryComboBox(true, this);
31 *
32 * KWidgetAction *action = new KWidgetAction(findCombo, i18n("Find Combo"),
33 * Qt::Key_F6, this, SLOT( slotFocus()),
34 * actionCollection(), "find_combo");
35 *
36 * QAction *action = new KToolBarLabelAction(action, i18n("Find "), "find_label");
37 * action->setShortcut(Qt::Key_F6);
38 * connect(action, &QAction::triggered, this, [this]() { slotFocus(); });
39 *
40 * \endcode
41 */
42class KWIDGETSADDONS_EXPORT KToolBarLabelAction : public QWidgetAction
43{
44 Q_OBJECT
45
46public:
47 /*!
48 * Creates a toolbar label.
49 *
50 * \a text The label's and the action's text.
51 *
52 * \a parent This action's parent.
53 */
54 KToolBarLabelAction(const QString &text, QObject *parent);
55
56 /*!
57 * Creates a toolbar label setting a buddy for the label.
58 *
59 * \a buddy The action whose widget which is focused when the label's accelerator is
60 * typed.
61 *
62 * \a text The label's and the action's text.
63 *
64 * \a parent This action's parent.
65 */
66 KToolBarLabelAction(QAction *buddy, const QString &text, QObject *parent);
67
68 ~KToolBarLabelAction() override;
69
70 /*!
71 * Sets the label's buddy to buddy.
72 *
73 * See QLabel::setBuddy() for details.
74 */
75 void setBuddy(QAction *buddy);
76
77 /*!
78 * Returns the label's buddy or a null pointer if no buddy is currently set.
79 *
80 * See QLabel::buddy() and QLabel::setBuddy() for more information.
81 */
82 QAction *buddy() const;
83
84 QWidget *createWidget(QWidget *parent) override;
85
86Q_SIGNALS:
87 /*!
88 * This signal is emitted whenever the text of this action
89 * is changed.
90 */
91 void textChanged(const QString &newText);
92
93protected:
94 bool event(QEvent *) override;
95 bool eventFilter(QObject *watched, QEvent *event) override;
96
97private:
98 std::unique_ptr<class KToolBarLabelActionPrivate> const d;
99};
100
101#endif
102

source code of kwidgetsaddons/src/ktoolbarlabelaction.h