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

KDEUI

  • kdeui
  • actions
ktoggletoolbaraction.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 "ktoggletoolbaraction.h"
29
30#include <QtCore/QByteArray>
31#include <QtCore/QEvent>
32#include <QtCore/QPointer>
33
34#include <kdebug.h>
35#include <klocale.h>
36#include <kmainwindow.h>
37#include <ktoolbar.h>
38
39class KToggleToolBarAction::Private
40{
41 public:
42 Private()
43 : toolBarName( 0 ), toolBar( 0 ), beingToggled( false )
44 {
45 }
46
47 QByteArray toolBarName;
48 QPointer<KToolBar> toolBar;
49 bool beingToggled;
50};
51
52
53KToggleToolBarAction::KToggleToolBarAction(const char* toolBarName, const QString& text, QObject *parent)
54 : KToggleAction(text, parent),
55 d( new Private )
56{
57 d->toolBarName = toolBarName;
58}
59
60KToggleToolBarAction::KToggleToolBarAction(KToolBar *toolBar, const QString &text, QObject *parent)
61 : KToggleAction(text, parent),
62 d( new Private )
63{
64 d->toolBar = toolBar;
65 d->toolBar->installEventFilter( this );
66
67 d->beingToggled = true;
68
69 if ( d->toolBar->isVisible() )
70 setChecked( true );
71
72 d->beingToggled = false;
73}
74
75KToggleToolBarAction::~KToggleToolBarAction()
76{
77 delete d;
78}
79
80bool KToggleToolBarAction::eventFilter( QObject * watched, QEvent * event )
81{
82 if ( d->beingToggled )
83 return false;
84
85 d->beingToggled = true;
86
87 if ( watched == d->toolBar ) {
88 switch ( event->type() ) {
89 case QEvent::Hide:
90 if ( isChecked() )
91 setChecked( false );
92 break;
93
94 case QEvent::Show:
95 if ( !isChecked() )
96 setChecked( true );
97 break;
98
99 default:
100 break;
101 }
102 }
103
104 d->beingToggled = false;
105
106 return false;
107}
108
109KToolBar * KToggleToolBarAction::toolBar( )
110{
111 return d->toolBar;
112}
113
114void KToggleToolBarAction::slotToggled( bool checked )
115{
116 if ( !d->beingToggled && d->toolBar && checked != d->toolBar->isVisible() ) {
117 d->beingToggled = true;
118
119 if ( checked )
120 d->toolBar->show();
121 else
122 d->toolBar->hide();
123
124 d->beingToggled = false;
125
126 QMainWindow* mw = d->toolBar->mainWindow();
127 if ( mw && qobject_cast<KMainWindow*>( mw ) )
128 static_cast<KMainWindow *>( mw )->setSettingsDirty();
129 }
130
131 KToggleAction::slotToggled( checked );
132}
133
134#include "ktoggletoolbaraction.moc"
KMainWindow
KDE top level main window
Definition: kmainwindow.h:107
KToggleAction
Checkbox like action.
Definition: ktoggleaction.h:41
KToggleAction::slotToggled
virtual void slotToggled(bool checked)
Definition: ktoggleaction.cpp:93
KToggleToolBarAction::eventFilter
virtual bool eventFilter(QObject *watched, QEvent *event)
Reimplemented from.
Definition: ktoggletoolbaraction.cpp:80
KToggleToolBarAction::~KToggleToolBarAction
virtual ~KToggleToolBarAction()
Destroys toggle toolbar action.
Definition: ktoggletoolbaraction.cpp:75
KToggleToolBarAction::KToggleToolBarAction
KToggleToolBarAction(const char *toolBarName, const QString &text, QObject *parent)
Create a KToggleToolbarAction that manages the toolbar named toolBarName.
Definition: ktoggletoolbaraction.cpp:53
KToggleToolBarAction::toolBar
KToolBar * toolBar()
Returns a pointer to the tool bar it manages.
Definition: ktoggletoolbaraction.cpp:109
KToolBar
Floatable toolbar with auto resize.
Definition: ktoolbar.h:54
QMainWindow
QObject
kdebug.h
klocale.h
kmainwindow.h
ktoggletoolbaraction.h
ktoolbar.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