• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KDEUI

ktoggleaction.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1999 Reginald Stadlbauer <reggie@kde.org>
00003               (C) 1999 Simon Hausmann <hausmann@kde.org>
00004               (C) 2000 Nicolas Hadacek <haadcek@kde.org>
00005               (C) 2000 Kurt Granroth <granroth@kde.org>
00006               (C) 2000 Michael Koch <koch@kde.org>
00007               (C) 2001 Holger Freyther <freyther@kde.org>
00008               (C) 2002 Ellis Whitehead <ellis@kde.org>
00009               (C) 2002 Joseph Wenninger <jowenn@kde.org>
00010               (C) 2003 Andras Mantia <amantia@kde.org>
00011               (C) 2005-2006 Hamish Rodda <rodda@kde.org>
00012 
00013     This library is free software; you can redistribute it and/or
00014     modify it under the terms of the GNU Library General Public
00015     License version 2 as published by the Free Software Foundation.
00016 
00017     This library is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020     Library General Public License for more details.
00021 
00022     You should have received a copy of the GNU Library General Public License
00023     along with this library; see the file COPYING.LIB.  If not, write to
00024     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00025     Boston, MA 02110-1301, USA.
00026 */
00027 
00028 #include "ktoggleaction.h"
00029 
00030 #include <kdebug.h>
00031 #include <kguiitem.h>
00032 #include <kicon.h>
00033 #include <klocale.h>
00034 
00035 class KToggleAction::Private
00036 {
00037   public:
00038     Private( KToggleAction *_parent )
00039       : parent( _parent ), checkedGuiItem( 0L )
00040     {
00041     }
00042 
00043     ~Private()
00044     {
00045       delete checkedGuiItem;
00046     }
00047 
00048     void init()
00049     {
00050       parent->setCheckable( true );
00051       connect( parent, SIGNAL( toggled( bool ) ),
00052                parent, SLOT( slotToggled( bool ) ) );
00053     }
00054 
00055     KToggleAction* parent;
00056     KGuiItem* checkedGuiItem;
00057 };
00058 
00059 
00060 KToggleAction::KToggleAction( QObject *parent )
00061   : KAction( parent ),
00062     d( new Private( this ) )
00063 {
00064   d->init();
00065 }
00066 
00067 KToggleAction::KToggleAction( const QString & text, QObject *parent )
00068   : KAction( text, parent ),
00069     d( new Private( this ) )
00070 {
00071   d->init();
00072 }
00073 
00074 KToggleAction::KToggleAction( const KIcon & icon, const QString & text, QObject *parent )
00075   : KAction( icon, text, parent ),
00076     d( new Private( this ) )
00077 {
00078   d->init();
00079 }
00080 
00081 KToggleAction::~KToggleAction()
00082 {
00083   delete d;
00084 }
00085 
00086 
00087 void KToggleAction::setCheckedState( const KGuiItem& checkedItem )
00088 {
00089   delete d->checkedGuiItem;
00090   d->checkedGuiItem = new KGuiItem( checkedItem );
00091 }
00092 
00093 void KToggleAction::slotToggled( bool )
00094 {
00095   if ( d->checkedGuiItem ) {
00096     QString string = d->checkedGuiItem->text();
00097     d->checkedGuiItem->setText( text() );
00098     setText( string );
00099 
00100     string = d->checkedGuiItem->toolTip();
00101     d->checkedGuiItem->setToolTip( toolTip() );
00102     setToolTip( string );
00103 
00104     if ( d->checkedGuiItem->hasIcon() ) {
00105       KIcon icon = d->checkedGuiItem->icon();
00106       d->checkedGuiItem->setIcon( KIcon(this->icon()) );
00107       QAction::setIcon( icon );
00108     }
00109   }
00110 }
00111 
00112 #include "ktoggleaction.moc"

KDEUI

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal