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 {
29  Q_D(KToggleAction);
30 
31  d->init();
32 }
33 
35  : QAction(parent)
36  , d(new KToggleActionPrivate(this))
37 {
38  Q_D(KToggleAction);
39 
40  setText(text);
41  d->init();
42 }
43 
45  : QAction(parent)
46  , d(new KToggleActionPrivate(this))
47 {
48  Q_D(KToggleAction);
49 
50  setIcon(icon);
51  setText(text);
52  d->init();
53 }
54 
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 }
QString text() const const
QIcon icon() const const
virtual ~KToggleAction()
Destructor.
QString toolTip() const const
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
Checkbox like action.
Definition: ktoggleaction.h:35
QAction(QObject *parent)
QObject * parent() const const
KToggleAction(QObject *parent)
Constructs an action with the specified parent.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Apr 20 2021 22:44:07 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.