2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 2022 Felix Ernst <felixernst@zohomail.eu>
5 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8 #ifndef ACTIONTEXTHELPER_H
9 #define ACTIONTEXTHELPER_H
15 namespace SelectionMode
19 * @brief Helps changing the texts of actions depending on the current selection.
21 class ActionTextHelper
: QObject
24 explicit ActionTextHelper(QObject
*parent
);
27 * Changes the text of \a action to \a text whenever textsWhenNothingIsSelectedEnabled(true) is called.
28 * The texts can be changed back by calling textsWhenNothingIsSelectedEnabled(false) is called.
29 * @see textsWhenNothingIsSelectedEnabled()
31 void registerTextWhenNothingIsSelected(QAction
*action
, QString registeredText
);
34 * Changes all texts that were registered previously using registerTextWhenNothingIsSelected() to those
35 * registered texts if called with \a enabled == true. Otherwise resets the texts to the original one.
37 void textsWhenNothingIsSelectedEnabled(bool enabled
);
41 TextWhenNothingIsSelected
,
42 TextWhenSomethingIsSelected
46 * Utility struct to allow switching back and forth between registered actions showing their
47 * distinct texts for when no items are selected or when items are selected.
48 * An example is "Copy" or "Copy…". The latter one is used when nothing is selected and signifies
49 * that it will trigger SelectionMode so items can be selected and then copied.
51 struct RegisteredActionTextChange
{
52 QPointer
<QAction
> action
;
53 QString registeredText
;
54 TextState textStateOfRegisteredText
;
56 RegisteredActionTextChange(QAction
*action
, QString registeredText
, TextState state
) :
58 registeredText
{registeredText
},
59 textStateOfRegisteredText
{state
}
64 * @see RegisteredActionTextChange
66 std::vector
<RegisteredActionTextChange
> m_registeredActionTextChanges
;
71 #endif // ACTIONTEXTHELPER_H