KWidgetsAddons

ktoolbarlabelaction.h
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 ktoolbarlabelaction.h KToolBarLabelAction
18 *
19 * @short Class to display a label in a toolbar.
20 *
21 * KToolBarLabelAction is a convenience class for displaying a label in a
22 * toolbar.
23 *
24 * It provides easy access to the label's #setBuddy(QAction*) and #buddy()
25 * methods and can be used as follows:
26 *
27 * \code
28 *
29 * KHistoryComboBox *findCombo = new KHistoryComboBox(true, this);
30 *
31 * KWidgetAction *action = new KWidgetAction(findCombo, i18n("Find Combo"),
32 * Qt::Key_F6, this, SLOT( slotFocus()),
33 * actionCollection(), "find_combo");
34 *
35 * QAction *action = new KToolBarLabelAction(action, i18n("Find "), "find_label");
36 * action->setShortcut(Qt::Key_F6);
37 * connect(action, &QAction::triggered, this, [this]() { slotFocus(); });
38 *
39 * \endcode
40 *
41 * @author Felix Berger <felixberger@beldesign.de>
42 */
43class KWIDGETSADDONS_EXPORT KToolBarLabelAction : public QWidgetAction
44{
45 Q_OBJECT
46
47public:
48 /**
49 * Creates a toolbar label.
50 *
51 * @param text The label's and the action's text.
52 * @param 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 * @param buddy The action whose widget which is focused when the label's accelerator is
60 * typed.
61 * @param text The label's and the action's text.
62 * @param parent This action's parent.
63 */
64 KToolBarLabelAction(QAction *buddy, const QString &text, QObject *parent);
65
66 /**
67 * Destroys the toolbar label.
68 */
70
71 /**
72 * Sets the label's buddy to buddy.
73 *
74 * See QLabel#setBuddy() for details.
75 */
76 void setBuddy(QAction *buddy);
77
78 /**
79 * Returns the label's buddy or a null pointer if no buddy is currently set.
80 *
81 * See QLabel#buddy() and QLabel#setBuddy() for more information.
82 */
83 QAction *buddy() const;
84
85 /**
86 * Reimplemented from QWidgetAction.
87 */
88 QWidget *createWidget(QWidget *parent) override;
89
91 /**
92 * This signal is emitted whenever the text of this action
93 * is changed.
94 */
95 void textChanged(const QString &newText);
96
97protected:
98 bool event(QEvent *) override;
99 bool eventFilter(QObject *watched, QEvent *event) override;
100
101private:
102 std::unique_ptr<class KToolBarLabelActionPrivate> const d;
103};
104
105#endif
Class to display a label in a toolbar.
void textChanged(const QString &newText)
This signal is emitted whenever the text of this action is changed.
~KToolBarLabelAction() override
Destroys the toolbar label.
Q_SIGNALSQ_SIGNALS
virtual QWidget * createWidget(QWidget *parent)
virtual bool event(QEvent *event) override
virtual bool eventFilter(QObject *obj, QEvent *event) override
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:59:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.