1 | /* |
2 | This file is part of the KDE libraries |
3 | SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <reggie@kde.org> |
4 | SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org> |
5 | SPDX-FileCopyrightText: 2000 Nicolas Hadacek <haadcek@kde.org> |
6 | SPDX-FileCopyrightText: 2000 Kurt Granroth <granroth@kde.org> |
7 | SPDX-FileCopyrightText: 2000 Michael Koch <koch@kde.org> |
8 | SPDX-FileCopyrightText: 2001 Holger Freyther <freyther@kde.org> |
9 | SPDX-FileCopyrightText: 2002 Ellis Whitehead <ellis@kde.org> |
10 | SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org> |
11 | SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> |
12 | |
13 | SPDX-License-Identifier: LGPL-2.0-only |
14 | */ |
15 | |
16 | #ifndef KTOGGLEACTION_H |
17 | #define KTOGGLEACTION_H |
18 | |
19 | #include <QAction> |
20 | #include <memory> |
21 | |
22 | #include <kwidgetsaddons_export.h> |
23 | |
24 | class KGuiItem; |
25 | class KToggleActionPrivate; |
26 | |
27 | /*! |
28 | * \class KToggleAction |
29 | * \inmodule KWidgetsAddons |
30 | * |
31 | * \brief Checkbox like action. |
32 | * |
33 | * This action provides two states: checked or not. |
34 | */ |
35 | class KWIDGETSADDONS_EXPORT KToggleAction : public QAction |
36 | { |
37 | Q_OBJECT |
38 | |
39 | public: |
40 | /*! |
41 | * Constructs an action with the specified parent. |
42 | * |
43 | * \a parent The action's parent object. |
44 | */ |
45 | explicit KToggleAction(QObject *parent); |
46 | |
47 | /*! |
48 | * Constructs an action with text; a shortcut may be specified by |
49 | * the ampersand character (e.g.\ "&Option" creates a shortcut with key \e O ) |
50 | * |
51 | * This is the most common QAction used when you do not have a |
52 | * corresponding icon (note that it won't appear in the current version |
53 | * of the "Edit ToolBar" dialog, because an action needs an icon to be |
54 | * plugged in a toolbar...). |
55 | * |
56 | * \a text The text that will be displayed. |
57 | * |
58 | * \a parent The action's parent object. |
59 | */ |
60 | KToggleAction(const QString &text, QObject *parent); |
61 | |
62 | /*! |
63 | * Constructs an action with text and an icon; a shortcut may be specified by |
64 | * the ampersand character (e.g.\ "&Option" creates a shortcut with key \e O ) |
65 | * |
66 | * This is the other common QAction used. Use it when you |
67 | * do have a corresponding icon. |
68 | * |
69 | * \a icon The icon to display. |
70 | * |
71 | * \a text The text that will be displayed. |
72 | * |
73 | * \a parent The action's parent object. |
74 | */ |
75 | KToggleAction(const QIcon &icon, const QString &text, QObject *parent); |
76 | |
77 | ~KToggleAction() override; |
78 | |
79 | /*! |
80 | * Defines the text (and icon, tooltip, whatsthis) that should be displayed |
81 | * instead of the normal text, when the action is checked. |
82 | * Note that this does not replace the check box in front of the |
83 | * menu. So you should not use it to replace the text "Show <foo>" with |
84 | * "Hide <foo>", for example. |
85 | * |
86 | * If hasIcon(), the icon is kept for the 'checked state', unless |
87 | * \a checkedItem defines an icon explicitly. Same thing for tooltip and whatsthis. |
88 | */ |
89 | void setCheckedState(const KGuiItem &checkedItem); |
90 | |
91 | protected Q_SLOTS: |
92 | /*! |
93 | * |
94 | */ |
95 | virtual void slotToggled(bool checked); |
96 | |
97 | protected: |
98 | KWIDGETSADDONS_NO_EXPORT KToggleAction(KToggleActionPrivate &dd, QObject *parent); |
99 | |
100 | protected: |
101 | std::unique_ptr<class KToggleActionPrivate> const d_ptr; |
102 | |
103 | private: |
104 | Q_DECLARE_PRIVATE(KToggleAction) |
105 | }; |
106 | |
107 | #endif |
108 | |