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: 2002 Joseph Wenninger <jowenn@kde.org> |
11 | SPDX-FileCopyrightText: 2003 Andras Mantia <amantia@kde.org> |
12 | SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <rodda@kde.org> |
13 | |
14 | SPDX-License-Identifier: LGPL-2.0-only |
15 | */ |
16 | |
17 | #include "ktoggleaction.h" |
18 | #include "ktoggleaction_p.h" |
19 | |
20 | KToggleAction::KToggleAction(QObject *parent) |
21 | : KToggleAction(*new KToggleActionPrivate(this), parent) |
22 | { |
23 | } |
24 | |
25 | KToggleAction::KToggleAction(KToggleActionPrivate &dd, QObject *parent) |
26 | : QAction(parent) |
27 | , d_ptr(&dd) |
28 | { |
29 | Q_D(KToggleAction); |
30 | |
31 | d->init(); |
32 | } |
33 | |
34 | KToggleAction::KToggleAction(const QString &text, QObject *parent) |
35 | : QAction(parent) |
36 | , d_ptr(new KToggleActionPrivate(this)) |
37 | { |
38 | Q_D(KToggleAction); |
39 | |
40 | setText(text); |
41 | d->init(); |
42 | } |
43 | |
44 | KToggleAction::KToggleAction(const QIcon &icon, const QString &text, QObject *parent) |
45 | : QAction(parent) |
46 | , d_ptr(new KToggleActionPrivate(this)) |
47 | { |
48 | Q_D(KToggleAction); |
49 | |
50 | setIcon(icon); |
51 | setText(text); |
52 | d->init(); |
53 | } |
54 | |
55 | KToggleAction::~KToggleAction() = default; |
56 | |
57 | void KToggleAction::setCheckedState(const KGuiItem &checkedItem) |
58 | { |
59 | Q_D(KToggleAction); |
60 | |
61 | delete d->checkedGuiItem; |
62 | d->checkedGuiItem = new KGuiItem(checkedItem); |
63 | } |
64 | |
65 | void KToggleAction::slotToggled(bool) |
66 | { |
67 | Q_D(KToggleAction); |
68 | |
69 | if (d->checkedGuiItem) { |
70 | QString string = d->checkedGuiItem->text(); |
71 | d->checkedGuiItem->setText(text()); |
72 | setText(string); |
73 | |
74 | string = d->checkedGuiItem->toolTip(); |
75 | d->checkedGuiItem->setToolTip(toolTip()); |
76 | setToolTip(string); |
77 | |
78 | if (d->checkedGuiItem->hasIcon()) { |
79 | QIcon icon = d->checkedGuiItem->icon(); |
80 | d->checkedGuiItem->setIcon(this->icon()); |
81 | QAction::setIcon(icon); |
82 | } |
83 | } |
84 | } |
85 | |
86 | #include "moc_ktoggleaction.cpp" |
87 |