KMoreTools

kmoretoolsmenufactory.h
1/*
2 SPDX-FileCopyrightText: 2015 Gregor Mi <codestruct@posteo.org>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#ifndef KMORETOOLSMENUFACTORY_H
8#define KMORETOOLSMENUFACTORY_H
9
10#include <QMenu>
11#include <QString>
12#include <QUrl>
13
14#include <memory>
15
16#include <kmoretools_export.h>
17
18class KMoreTools;
19class KMoreToolsMenuFactoryPrivate;
20
21/**
22 * This is the class with the highest abstraction in KMoreTools.
23 *
24 * Creates a QMenu from a list of grouping names. For details on available
25 * grouping names see KMoreToolsPresets::registerServicesByGroupingNames.
26 */
27class KMORETOOLS_EXPORT KMoreToolsMenuFactory
28{
29public:
30 /**
31 * @param uniqueId defines the config section name where the user
32 * settings done by the Configure dialog will be stored.
33 *
34 * For more information about the parameter see KMoreTools::KMoreTools.
35 */
36 KMoreToolsMenuFactory(const QString &uniqueId);
37
39
41 KMoreToolsMenuFactory &operator=(const KMoreToolsMenuFactory &) = delete;
42
43 /**
44 * For each grouping name menu items will be created an appended to a
45 * lazy menu which is returned. The menu is lazy in a sense that the
46 * items are not added until the menu is about to be shown.
47 * NOTE: This means if the menu is not shown (as would be by e.g.
48 * calling exec()) then the menu stays empty.
49 *
50 * For details on available grouping names see
51 * KMoreToolsPresets::registerServicesByGroupingNames.
52 *
53 * For each grouping name there might be special handlings that take the
54 * optional given @p url into account if needed. By default the url is
55 * empty.
56 *
57 * Furthermore, some selected menu items will be put into the "More"
58 * menu section by default.
59 *
60 * The "more:" grouping name
61 * -------------------------
62 * There is a special grouping name "more:" (note the colon). If this name
63 * is given in the list, all further groupings are put into the More
64 * section by default.
65 *
66 * NOTE that this method overrides a previously created QMenu* instance
67 * of the same KMoreToolsMenuFactory instance. The reason is that the
68 * internal KMoreTools pointer is reused.
69 * (todo: solve this or rename the class?)
70 *
71 * @returns the created QMenu which includes a Main and (maybe) a More
72 * section and an item that starts configure dialog where the user can
73 * configure the menu (see KMoreTools).
74 */
75 QMenu *createMenuFromGroupingNames(const QStringList &groupingNames, const QUrl &url = QUrl());
76
77 /**
78 * See createMenuFromGroupingNames except that the menu is not created
79 * but you have to provide one yourself. This is useful to create
80 * lazy menus by connecting QMenu::aboutToShow.
81 *
82 * WARN 1: KMoreToolsMenuFactory must live as long as you would like to use
83 * the menu.
84 *
85 * WARN 2: You must NOT reuse an existing KMoreToolsMenuFactory instance
86 * to create a different menu.
87 */
88 void fillMenuFromGroupingNames(QMenu *menu, const QStringList &groupingNames, const QUrl &url = QUrl());
89
90 /**
91 * Set @p widget as the parent widget of the QMenu that will be created
92 * by createMenuFromGroupingNames().
93 * @see createMenuFromGroupingNames()
94 */
95 void setParentWidget(QWidget *widget);
96
97private:
98 const std::unique_ptr<KMoreToolsMenuFactoryPrivate> d;
99};
100
101#endif
This is the class with the highest abstraction in KMoreTools.
Helps to create user-configurable menus with tools which are potentially not yet installed.
Definition kmoretools.h:163
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:46:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.