• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdeui
 

kdeui

  • kdeui
ktoolbarhandler.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7 
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12 
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 */
18 
19 #include "ktoolbarhandler.h"
20 
21 #include <tqpopupmenu.h>
22 #include <kapplication.h>
23 #include <ktoolbar.h>
24 #include <kmainwindow.h>
25 #include <klocale.h>
26 #include <kaction.h>
27 #include <assert.h>
28 
29 namespace
30 {
31  const char *actionListName = "show_menu_and_toolbar_actionlist";
32 
33  const char *guiDescription = ""
34  "<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">"
35  "<MenuBar>"
36  " <Menu name=\"settings\">"
37  " <ActionList name=\"%1\" />"
38  " </Menu>"
39  "</MenuBar>"
40  "</kpartgui>";
41 
42  const char *resourceFileName = "barhandler.rc";
43 
44  class BarActionBuilder
45  {
46  public:
47  BarActionBuilder( KActionCollection *actionCollection, KMainWindow *mainWindow, TQPtrList<KToolBar> &oldToolBarList )
48  : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false )
49  {
50  TQPtrList<TQDockWindow> dockWindows = m_mainWindow->dockWindows();
51  TQPtrListIterator<TQDockWindow> dockWindowIt( dockWindows );
52  for ( ; dockWindowIt.current(); ++dockWindowIt ) {
53 
54  KToolBar *toolBar = tqt_dynamic_cast<KToolBar *>( dockWindowIt.current() );
55  if ( !toolBar )
56  continue;
57 
58  if ( oldToolBarList.findRef( toolBar ) == -1 )
59  m_needsRebuild = true;
60 
61  m_toolBars.append( toolBar );
62  }
63 
64  if ( !m_needsRebuild )
65  m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() );
66  }
67 
68  bool needsRebuild() const { return m_needsRebuild; }
69 
70  TQPtrList<KAction> create()
71  {
72  if ( !m_needsRebuild )
73  return TQPtrList<KAction>();
74 
75  TQPtrListIterator<KToolBar> toolBarIt( m_toolBars );
76  for ( ; toolBarIt.current(); ++toolBarIt )
77  handleToolBar( toolBarIt.current() );
78 
79  TQPtrList<KAction> actions;
80 
81  if ( m_toolBarActions.count() == 0 )
82  return actions;
83 
84  if ( m_toolBarActions.count() == 1 ) {
85  KToggleToolBarAction* action = static_cast<KToggleToolBarAction *>( m_toolBarActions.getFirst() );
86  action->setText( i18n( "Show Toolbar" ) );
87  action->setCheckedState( i18n( "Hide Toolbar" ) );
88  return m_toolBarActions;
89  }
90 
91  KActionMenu *menuAction = new KActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" );
92 
93  TQPtrListIterator<KAction> actionIt( m_toolBarActions );
94  for ( ; actionIt.current(); ++actionIt )
95  menuAction->insert( actionIt.current() );
96 
97  actions.append( menuAction );
98  return actions;
99  }
100 
101  const TQPtrList<KToolBar> &toolBars() const { return m_toolBars; }
102 
103  private:
104  void handleToolBar( KToolBar *toolBar )
105  {
106  KToggleToolBarAction *action = new KToggleToolBarAction(
107  toolBar,
108  toolBar->label(),
109  m_actionCollection,
110  toolBar->name() );
111  // ## tooltips, whatsthis?
112  m_toolBarActions.append( action );
113  }
114 
115  KActionCollection *m_actionCollection;
116  KMainWindow *m_mainWindow;
117 
118  TQPtrList<KToolBar> m_toolBars;
119  TQPtrList<KAction> m_toolBarActions;
120 
121  bool m_needsRebuild : 1;
122  };
123 }
124 
125 using namespace KDEPrivate;
126 
127 ToolBarHandler::ToolBarHandler( KMainWindow *mainWindow, const char *name )
128  : TQObject( mainWindow, name ), KXMLGUIClient( mainWindow )
129 {
130  init( mainWindow );
131 }
132 
133 ToolBarHandler::ToolBarHandler( KMainWindow *mainWindow, TQObject *parent, const char *name )
134  : TQObject( parent, name ), KXMLGUIClient( mainWindow )
135 {
136  init( mainWindow );
137 }
138 
139 ToolBarHandler::~ToolBarHandler()
140 {
141  m_actions.setAutoDelete( true );
142  m_actions.clear();
143 }
144 
145 KAction *ToolBarHandler::toolBarMenuAction()
146 {
147  assert( m_actions.count() == 1 );
148  return m_actions.getFirst();
149 }
150 
151 void ToolBarHandler::setupActions()
152 {
153  if ( !factory() || !m_mainWindow )
154  return;
155 
156  BarActionBuilder builder( actionCollection(), m_mainWindow, m_toolBars );
157 
158  if ( !builder.needsRebuild() )
159  return;
160 
161  unplugActionList( actionListName );
162 
163  m_actions.setAutoDelete( true );
164  m_actions.clear();
165  m_actions.setAutoDelete( false );
166 
167  m_actions = builder.create();
168 
169  /*
170  for ( TQPtrListIterator<KToolBar> toolBarIt( m_toolBars );
171  toolBarIt.current(); ++toolBarIt )
172  toolBarIt.current()->disconnect( this );
173  */
174 
175  m_toolBars = builder.toolBars();
176 
177  /*
178  for ( TQPtrListIterator<KToolBar> toolBarIt( m_toolBars );
179  toolBarIt.current(); ++toolBarIt )
180  connect( toolBarIt.current(), TQT_SIGNAL( destroyed() ),
181  this, TQT_SLOT( setupActions() ) );
182  */
183 
184  if (kapp && kapp->authorizeKAction("options_show_toolbar"))
185  plugActionList( actionListName, m_actions );
186 
187  connectToActionContainers();
188 }
189 
190 void ToolBarHandler::clientAdded( KXMLGUIClient *client )
191 {
192  if ( client == this )
193  setupActions();
194 }
195 
196 void ToolBarHandler::init( KMainWindow *mainWindow )
197 {
198  d = 0;
199  m_mainWindow = mainWindow;
200 
201  connect( m_mainWindow->guiFactory(), TQT_SIGNAL( clientAdded( KXMLGUIClient * ) ),
202  this, TQT_SLOT( clientAdded( KXMLGUIClient * ) ) );
203 
204  /* re-use an existing resource file if it exists. can happen if the user launches the
205  * toolbar editor */
206  /*
207  setXMLFile( resourceFileName );
208  */
209 
210  if ( domDocument().documentElement().isNull() ) {
211 
212  TQString completeDescription = TQString::fromLatin1( guiDescription )
213  .arg( actionListName );
214 
215  setXML( completeDescription, false /*merge*/ );
216  }
217 }
218 
219 void ToolBarHandler::connectToActionContainers()
220 {
221  TQPtrListIterator<KAction> actionIt( m_actions );
222  for ( ; actionIt.current(); ++actionIt )
223  connectToActionContainer( actionIt.current() );
224 }
225 
226 void ToolBarHandler::connectToActionContainer( KAction *action )
227 {
228  uint containerCount = action->containerCount();
229  for ( uint i = 0; i < containerCount; ++i )
230  connectToActionContainer( action->container( i ) );
231 }
232 
233 void ToolBarHandler::connectToActionContainer( TQWidget *container )
234 {
235  TQPopupMenu *popupMenu = tqt_dynamic_cast<TQPopupMenu *>( container );
236  if ( !popupMenu )
237  return;
238 
239  connect( popupMenu, TQT_SIGNAL( aboutToShow() ),
240  this, TQT_SLOT( setupActions() ) );
241 }
242 
243 #include "ktoolbarhandler.moc"
244 
245 /* vim: et sw=4 ts=4
246  */

kdeui

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

kdeui

Skip menu "kdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdeui by doxygen 1.8.3.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |