KConfigWidgets

kcommandbar.h
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 kcommandbar.h KCommandBar
16 *
17 * @short A hud style menu which allows listing and executing actions
18 *
19 * KCommandBar takes as input a list of QActions and then shows them
20 * in a "list-like-view" with a filter line edit. This allows quickly
21 * executing an action.
22 *
23 * Usage is simple. Just create a KCommandBar instance when you need it
24 * and throw it away once the user is done with it. You can store it as
25 * a class member as well but there is little benefit in that. Example:
26 *
27 * @code
28 * void slotOpenCommandBar()
29 * {
30 * // `this` is important, you must pass a parent widget
31 * // here. Ideally it will be your mainWindow
32 * KCommandBar *bar = new KCommandBar(this);
33 *
34 * // Load actions into the command bar
35 * // These actions can be from your menus / toolbars etc
36 * QList<ActionGroup> actionGroups = ...;
37 * bar->setActions(actionGroups);
38 *
39 * // Show
40 * bar->show();
41 * }
42 * @endcode
43 *
44 * @since 5.83
45 * @author Waqar Ahmed <waqar.17a@gmail.com>
46 */
47class KCONFIGWIDGETS_EXPORT KCommandBar : public QFrame
48{
49 Q_OBJECT
50
51public:
52 /**
53 * Represents a list of action that belong to the same group.
54 * For example:
55 * - All actions under the menu "File" or "Tool"
56 */
57 struct ActionGroup {
58 QString name;
59 QList<QAction *> actions;
60 };
61
62 /**
63 * constructor
64 *
65 * @p parent is used to determine position and size of the
66 * command bar. It *must* not be @c nullptr.
67 */
68 explicit KCommandBar(QWidget *parent);
69 ~KCommandBar() override;
70
71 /**
72 * @p actions is a list of {GroupName, QAction}. Group name can be the name
73 * of the component/menu where a QAction lives, for example in a menu "File -> Open File",
74 * "File" should be the GroupName.
75 */
76 void setActions(const QList<ActionGroup> &actions);
77
78public Q_SLOTS:
79 void show();
80
81protected:
82 bool eventFilter(QObject *obj, QEvent *event) override;
83
84private:
85 std::unique_ptr<class KCommandBarPrivate> const d;
86};
87
88Q_DECLARE_TYPEINFO(KCommandBar::ActionGroup, Q_RELOCATABLE_TYPE);
89
90#endif
A hud style menu which allows listing and executing actions.
Definition kcommandbar.h:48
Q_SLOTSQ_SLOTS
virtual bool eventFilter(QObject *watched, QEvent *event)
void show()
Represents a list of action that belong to the same group.
Definition kcommandbar.h:57
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:18 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.