KWidgetsAddons

ktoggleaction.cpp
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 1999 Reginald Stadlbauer <[email protected]>
4  SPDX-FileCopyrightText: 1999 Simon Hausmann <[email protected]>
5  SPDX-FileCopyrightText: 2000 Nicolas Hadacek <[email protected]>
6  SPDX-FileCopyrightText: 2000 Kurt Granroth <[email protected]>
7  SPDX-FileCopyrightText: 2000 Michael Koch <[email protected]>
8  SPDX-FileCopyrightText: 2001 Holger Freyther <[email protected]>
9  SPDX-FileCopyrightText: 2002 Ellis Whitehead <[email protected]>
10  SPDX-FileCopyrightText: 2002 Joseph Wenninger <[email protected]>
11  SPDX-FileCopyrightText: 2003 Andras Mantia <[email protected]>
12  SPDX-FileCopyrightText: 2005-2006 Hamish Rodda <[email protected]>
13 
14  SPDX-License-Identifier: LGPL-2.0-only
15 */
16 
17 #include "ktoggleaction.h"
18 #include "ktoggleaction_p.h"
19 
21  : KToggleAction(*new KToggleActionPrivate(this), parent)
22 {
23 }
24 
25 KToggleAction::KToggleAction(KToggleActionPrivate &dd, QObject *parent)
26  : QAction(parent)
27  , d(&dd)
28 {
30 
31  d->init();
32 }
33 
35  : QAction(parent)
36  , d(new KToggleActionPrivate(this))
37 {
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(new KToggleActionPrivate(this))
47 {
49 
50  setIcon(icon);
51  setText(text);
52  d->init();
53 }
54 
56 
57 void KToggleAction::setCheckedState(const KGuiItem &checkedItem)
58 {
60 
61  delete d->checkedGuiItem;
62  d->checkedGuiItem = new KGuiItem(checkedItem);
63 }
64 
65 void KToggleAction::slotToggled(bool)
66 {
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"
KToggleAction(QObject *parent)
Constructs an action with the specified parent.
void setIcon(const QIcon &icon)
~KToggleAction() override
Destructor.
void setText(const QString &text)
Checkbox like action.
Definition: ktoggleaction.h:35
Q_D(Todo)
void setCheckedState(const KGuiItem &checkedItem)
Defines the text (and icon, tooltip, whatsthis) that should be displayed instead of the normal text,...
An abstract class for setting the text, icon, tooltip and WhatsThis data on a GUI item (e....
Definition: kguiitem.h:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Dec 1 2023 04:04:14 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.