1/*
2 * SPDX-FileCopyrightText: 2021 Waqar Ahmed <waqar.17a@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6#ifndef KCOMMANDBAR_H
7#define KCOMMANDBAR_H
8
9#include "kconfigwidgets_export.h"
10
11#include <QFrame>
12#include <memory>
13
14/*!
15 * \class KCommandBar
16 * \inmodule KConfigWidgets
17 *
18 * \brief A hud style menu which allows listing and executing actions.
19 *
20 * KCommandBar takes as input a list of QActions and then shows them
21 * in a "list-like-view" with a filter line edit. This allows quickly
22 * executing an action.
23 *
24 * Usage is simple. Just create a KCommandBar instance when you need it
25 * and throw it away once the user is done with it. You can store it as
26 * a class member as well but there is little benefit in that. Example:
27 *
28 * \code
29 * void slotOpenCommandBar()
30 * {
31 * // `this` is important, you must pass a parent widget
32 * // here. Ideally it will be your mainWindow
33 * KCommandBar *bar = new KCommandBar(this);
34 *
35 * // Load actions into the command bar
36 * // These actions can be from your menus / toolbars etc
37 * QList<ActionGroup> actionGroups = ...;
38 * bar->setActions(actionGroups);
39 *
40 * // Show
41 * bar->show();
42 * }
43 * \endcode
44 *
45 * \since 5.83
46 */
47class KCONFIGWIDGETS_EXPORT KCommandBar : public QFrame
48{
49 Q_OBJECT
50
51public:
52 /*!
53 * \inmodule KConfigWidgets
54 * Represents a list of action that belong to the same group.
55 * For example:
56 * \list
57 * \li All actions under the menu "File" or "Tool"
58 * \endlist
59 */
60 struct ActionGroup {
61 /*!
62 *
63 */
64 QString name;
65
66 /*!
67 *
68 */
69 QList<QAction *> actions;
70 };
71
72 /*!
73 * Constructor
74 *
75 * \a parent is used to determine position and size of the
76 * command bar. It *must* not be \c nullptr.
77 */
78 explicit KCommandBar(QWidget *parent);
79 ~KCommandBar() override;
80
81 /*!
82 * \a actions is a list of {GroupName, QAction}. Group name can be the name
83 * of the component/menu where a QAction lives, for example in a menu "File -> Open File",
84 * "File" should be the GroupName.
85 */
86 void setActions(const QList<ActionGroup> &actions);
87
88public Q_SLOTS:
89 /*!
90 *
91 */
92 void show();
93
94protected:
95 bool eventFilter(QObject *obj, QEvent *event) override;
96
97private:
98 std::unique_ptr<class KCommandBarPrivate> const d;
99};
100
101Q_DECLARE_TYPEINFO(KCommandBar::ActionGroup, Q_RELOCATABLE_TYPE);
102
103#endif
104

source code of kconfigwidgets/src/kcommandbar.h