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

tdeui

  • tdeui
tdetoolbarhandler.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 "tdetoolbarhandler.h"
20 
21 #include <tqpopupmenu.h>
22 #include <tdeapplication.h>
23 #include <tdetoolbar.h>
24 #include <tdemainwindow.h>
25 #include <tdelocale.h>
26 #include <tdeaction.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( TDEActionCollection *actionCollection, TDEMainWindow *mainWindow, TQPtrList<TDEToolBar> &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  TDEToolBar *toolBar = tqt_dynamic_cast<TDEToolBar *>( 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<TDEAction> create()
71  {
72  if ( !m_needsRebuild )
73  return TQPtrList<TDEAction>();
74 
75  TQPtrListIterator<TDEToolBar> toolBarIt( m_toolBars );
76  for ( ; toolBarIt.current(); ++toolBarIt )
77  handleToolBar( toolBarIt.current() );
78 
79  TQPtrList<TDEAction> actions;
80 
81  if ( m_toolBarActions.count() == 0 )
82  return actions;
83 
84  if ( m_toolBarActions.count() == 1 ) {
85  TDEToggleToolBarAction* action = static_cast<TDEToggleToolBarAction *>( m_toolBarActions.getFirst() );
86  action->setText( i18n( "Show Toolbar" ) );
87  action->setCheckedState( i18n( "Hide Toolbar" ) );
88  return m_toolBarActions;
89  }
90 
91  TDEActionMenu *menuAction = new TDEActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" );
92 
93  TQPtrListIterator<TDEAction> 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<TDEToolBar> &toolBars() const { return m_toolBars; }
102 
103  private:
104  void handleToolBar( TDEToolBar *toolBar )
105  {
106  TDEToggleToolBarAction *action = new TDEToggleToolBarAction(
107  toolBar,
108  toolBar->label(),
109  m_actionCollection,
110  toolBar->name() );
111  // ## tooltips, whatsthis?
112  m_toolBarActions.append( action );
113  }
114 
115  TDEActionCollection *m_actionCollection;
116  TDEMainWindow *m_mainWindow;
117 
118  TQPtrList<TDEToolBar> m_toolBars;
119  TQPtrList<TDEAction> m_toolBarActions;
120 
121  bool m_needsRebuild : 1;
122  };
123 }
124 
125 using namespace KDEPrivate;
126 
127 ToolBarHandler::ToolBarHandler( TDEMainWindow *mainWindow, const char *name )
128  : TQObject( mainWindow, name ), KXMLGUIClient( mainWindow )
129 {
130  init( mainWindow );
131 }
132 
133 ToolBarHandler::ToolBarHandler( TDEMainWindow *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 TDEAction *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<TDEToolBar> toolBarIt( m_toolBars );
171  toolBarIt.current(); ++toolBarIt )
172  toolBarIt.current()->disconnect( this );
173  */
174 
175  m_toolBars = builder.toolBars();
176 
177  /*
178  for ( TQPtrListIterator<TDEToolBar> 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->authorizeTDEAction("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( TDEMainWindow *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<TDEAction> actionIt( m_actions );
222  for ( ; actionIt.current(); ++actionIt )
223  connectToActionContainer( actionIt.current() );
224 }
225 
226 void ToolBarHandler::connectToActionContainer( TDEAction *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 "tdetoolbarhandler.moc"
KXMLGUIClient::setXML
virtual void setXML(const TQString &document, bool merge=false)
Sets the XML for the part.
Definition: kxmlguiclient.cpp:217
KXMLGUIClient
A KXMLGUIClient can be used with KXMLGUIFactory to create a GUI from actions and an XML document...
Definition: kxmlguiclient.h:43
KXMLGUIClient::factory
KXMLGUIFactory * factory() const
Retrieves a pointer to the KXMLGUIFactory this client is associated with (will return 0L if the clien...
Definition: kxmlguiclient.cpp:555
TDEToggleToolBarAction
An action that takes care of everything associated with showing or hiding a toolbar by a menu action...
Definition: tdeactionclasses.h:1217
TDEActionMenu
A TDEActionMenu is an action that holds a sub-menu of other actions.
Definition: tdeactionclasses.h:1020
TDEActionCollection
A managed set of TDEAction objects.
Definition: tdeactioncollection.h:78
TDEAction
Class to encapsulate user-driven action or event.
Definition: tdeaction.h:202
KXMLGUIClient::unplugActionList
void unplugActionList(const TQString &name)
The complement of plugActionList() ...
Definition: kxmlguiclient.cpp:613
TDEMainWindow
KDE top level main window
Definition: tdemainwindow.h:98
tdelocale.h
TDEToolBar
Floatable toolbar with auto resize.
Definition: tdetoolbar.h:104
KXMLGUIClient::actionCollection
virtual TDEActionCollection * actionCollection() const
Retrieves the entire action collection for the GUI client.
Definition: kxmlguiclient.cpp:107
TDEAction::setText
virtual void setText(const TQString &text)
Sets the text associated with this action.
Definition: tdeaction.cpp:879
KXMLGUIClient::domDocument
virtual TQDomDocument domDocument() const
Definition: kxmlguiclient.cpp:128
KDEPrivate
Definition: tdetoolbarhandler.h:29
TDEToggleAction::setCheckedState
void setCheckedState(const KGuiItem &checkedItem)
Defines the text (and icon, tooltip, whatsthis) that should be displayed instead of the normal text...
Definition: tdeactionclasses.cpp:259
KXMLGUIClient::plugActionList
void plugActionList(const TQString &name, const TQPtrList< TDEAction > &actionList)
ActionLists are a way for XMLGUI to support dynamic lists of actions.
Definition: kxmlguiclient.cpp:605
KStdAction::create
TDEAction * create(StdAction id, const char *name, const TQObject *recvr, const char *slot, TDEActionCollection *parent)
Creates an action corresponding to the KStdAction::StdAction enum.
Definition: kstdaction.cpp:43
TDEStdAccel::action
TQString action(StdAccel id) KDE_DEPRECATED

tdeui

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

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  •     tdecore
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  • tdeioslave
  •   http
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.8.8
This website is maintained by Timothy Pearson.