]>
cloud.milkyroute.net Git - dolphin.git/blob - src/disabledactionnotifier.h
2 * SPDX-FileCopyrightText: 2024 Jin Liu <m.liu.jin@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
14 * @brief A helper class to display a notification when the user presses the shortcut of a disabled action.
16 class DisabledActionNotifier
: public QObject
21 DisabledActionNotifier(QObject
*parent
= nullptr);
24 * Set the reason why the action is disabled.
26 * If the action is enabled, this function does nothing.
28 * Otherwise, it registers a shortcut, so when the user presses the shortcut for the
29 * disabled action, it emits the disabledActionTriggered() signal with the disabled
30 * action and the reason.
32 * If a reason has already been set, it will be replaced.
34 void setDisabledReason(QAction
*action
, QStringView reason
);
37 * Clear the reason if it's set before by setDisabledReason().
39 * If the action is enabled, this function does nothing.
41 * Otherwise, it unregisters any shortcut set by setDisabledReason() on the same action.
43 * When an action is disabled in two cases, but only case A needs to show the reason,
44 * then case B should call this function. Otherwise, the reason set by case A might be
47 void clearDisabledReason(QAction
*action
);
51 * Emitted when the user presses the shortcut of a disabled action.
53 * @param action The disabled action.
54 * @param reason The reason set in setDisabledReason().
56 void disabledActionTriggered(const QAction
*action
, QString reason
);
59 QHash
<QAction
*, QShortcut
*> m_shortcuts
;