• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KDEUI

  • kdeui
  • actions
ktoggleaction.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
3 (C) 1999 Simon Hausmann <hausmann@kde.org>
4 (C) 2000 Nicolas Hadacek <haadcek@kde.org>
5 (C) 2000 Kurt Granroth <granroth@kde.org>
6 (C) 2000 Michael Koch <koch@kde.org>
7 (C) 2001 Holger Freyther <freyther@kde.org>
8 (C) 2002 Ellis Whitehead <ellis@kde.org>
9 (C) 2002 Joseph Wenninger <jowenn@kde.org>
10 (C) 2003 Andras Mantia <amantia@kde.org>
11 (C) 2005-2006 Hamish Rodda <rodda@kde.org>
12
13 This library is free software; you can redistribute it and/or
14 modify it under the terms of the GNU Library General Public
15 License version 2 as published by the Free Software Foundation.
16
17 This library is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 Library General Public License for more details.
21
22 You should have received a copy of the GNU Library General Public License
23 along with this library; see the file COPYING.LIB. If not, write to
24 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 Boston, MA 02110-1301, USA.
26*/
27
28#include "ktoggleaction.h"
29
30#include <kdebug.h>
31#include <kguiitem.h>
32#include <kicon.h>
33#include <klocale.h>
34
35class KToggleAction::Private
36{
37 public:
38 Private( KToggleAction *_parent )
39 : parent( _parent ), checkedGuiItem( 0L )
40 {
41 }
42
43 ~Private()
44 {
45 delete checkedGuiItem;
46 }
47
48 void init()
49 {
50 parent->setCheckable( true );
51 connect( parent, SIGNAL(toggled(bool)),
52 parent, SLOT(slotToggled(bool)) );
53 }
54
55 KToggleAction* parent;
56 KGuiItem* checkedGuiItem;
57};
58
59
60KToggleAction::KToggleAction( QObject *parent )
61 : KAction( parent ),
62 d( new Private( this ) )
63{
64 d->init();
65}
66
67KToggleAction::KToggleAction( const QString & text, QObject *parent )
68 : KAction( text, parent ),
69 d( new Private( this ) )
70{
71 d->init();
72}
73
74KToggleAction::KToggleAction( const KIcon & icon, const QString & text, QObject *parent )
75 : KAction( icon, text, parent ),
76 d( new Private( this ) )
77{
78 d->init();
79}
80
81KToggleAction::~KToggleAction()
82{
83 delete d;
84}
85
86
87void KToggleAction::setCheckedState( const KGuiItem& checkedItem )
88{
89 delete d->checkedGuiItem;
90 d->checkedGuiItem = new KGuiItem( checkedItem );
91}
92
93void KToggleAction::slotToggled( bool )
94{
95 if ( d->checkedGuiItem ) {
96 QString string = d->checkedGuiItem->text();
97 d->checkedGuiItem->setText( text() );
98 setText( string );
99
100 string = d->checkedGuiItem->toolTip();
101 d->checkedGuiItem->setToolTip( toolTip() );
102 setToolTip( string );
103
104 if ( d->checkedGuiItem->hasIcon() ) {
105 KIcon icon = d->checkedGuiItem->icon();
106 d->checkedGuiItem->setIcon( KIcon(this->icon()) );
107 QAction::setIcon( icon );
108 }
109 }
110}
111
112#include "ktoggleaction.moc"
KAction
Class to encapsulate user-driven action or event.
Definition: kaction.h:217
KGuiItem
An abstract class for GUI data such as ToolTip and Icon.
Definition: kguiitem.h:37
KIcon
A wrapper around QIcon that provides KDE icon features.
Definition: kicon.h:41
KToggleAction
Checkbox like action.
Definition: ktoggleaction.h:41
KToggleAction::slotToggled
virtual void slotToggled(bool checked)
Definition: ktoggleaction.cpp:93
KToggleAction::setCheckedState
void setCheckedState(const KGuiItem &checkedItem)
Defines the text (and icon, tooltip, whatsthis) that should be displayed instead of the normal text,...
Definition: ktoggleaction.cpp:87
KToggleAction::KToggleAction
KToggleAction(QObject *parent)
Constructs an action with the specified parent.
Definition: ktoggleaction.cpp:60
KToggleAction::~KToggleAction
virtual ~KToggleAction()
Destructor.
Definition: ktoggleaction.cpp:81
QObject
kdebug.h
kguiitem.h
kicon.h
klocale.h
ktoggleaction.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDEUI

Skip menu "KDEUI"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal