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

KDEUI

ktoggletoolbaraction.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 "ktoggletoolbaraction.h"
00029 
00030 #include <QtCore/QByteArray>
00031 #include <QtCore/QEvent>
00032 #include <QtCore/QPointer>
00033 
00034 #include <kdebug.h>
00035 #include <klocale.h>
00036 #include <kmainwindow.h>
00037 #include <ktoolbar.h>
00038 
00039 class KToggleToolBarAction::Private
00040 {
00041   public:
00042     Private()
00043       : toolBarName( 0 ), toolBar( 0 ), beingToggled( false )
00044     {
00045     }
00046 
00047     QByteArray toolBarName;
00048     QPointer<KToolBar> toolBar;
00049     bool beingToggled;
00050 };
00051 
00052 
00053 KToggleToolBarAction::KToggleToolBarAction(const char* toolBarName, const QString& text, QObject *parent)
00054   : KToggleAction(text, parent),
00055     d( new Private )
00056 {
00057   d->toolBarName = toolBarName;
00058 }
00059 
00060 KToggleToolBarAction::KToggleToolBarAction(KToolBar *toolBar, const QString &text, QObject *parent)
00061   : KToggleAction(text, parent),
00062     d( new Private )
00063 {
00064   d->toolBar = toolBar;
00065   d->toolBar->installEventFilter( this );
00066 
00067   d->beingToggled = true;
00068 
00069   if ( d->toolBar->isVisible() )
00070     setChecked( true );
00071 
00072   d->beingToggled = false;
00073 }
00074 
00075 KToggleToolBarAction::~KToggleToolBarAction()
00076 {
00077   delete d;
00078 }
00079 
00080 bool KToggleToolBarAction::eventFilter( QObject * watched, QEvent * event )
00081 {
00082   if ( d->beingToggled )
00083     return false;
00084 
00085   d->beingToggled = true;
00086 
00087   if ( watched == d->toolBar ) {
00088     switch ( event->type() ) {
00089       case QEvent::Hide:
00090         if ( isChecked() )
00091           setChecked( false );
00092         break;
00093 
00094       case QEvent::Show:
00095         if ( !isChecked() )
00096           setChecked( true );
00097         break;
00098 
00099       default:
00100         break;
00101     }
00102   }
00103 
00104   d->beingToggled = false;
00105 
00106   return false;
00107 }
00108 
00109 KToolBar * KToggleToolBarAction::toolBar( )
00110 {
00111   return d->toolBar;
00112 }
00113 
00114 void KToggleToolBarAction::slotToggled( bool checked )
00115 {
00116   if ( !d->beingToggled && d->toolBar && checked != d->toolBar->isVisible() ) {
00117     d->beingToggled = true;
00118 
00119     if ( checked )
00120       d->toolBar->show();
00121     else
00122       d->toolBar->hide();
00123 
00124     d->beingToggled = false;
00125 
00126     QMainWindow* mw = d->toolBar->mainWindow();
00127     if ( mw && qobject_cast<KMainWindow*>( mw ) )
00128       static_cast<KMainWindow *>( mw )->setSettingsDirty();
00129   }
00130 
00131   KToggleAction::slotToggled( checked );
00132 }
00133 
00134 #include "ktoggletoolbaraction.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
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
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