Diffstat (limited to 'microkde/kdeui/ktoolbarhandler.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | microkde/kdeui/ktoolbarhandler.cpp | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/microkde/kdeui/ktoolbarhandler.cpp b/microkde/kdeui/ktoolbarhandler.cpp index 7b97233..4d3ace7 100644 --- a/microkde/kdeui/ktoolbarhandler.cpp +++ b/microkde/kdeui/ktoolbarhandler.cpp | |||
@@ -1,151 +1,153 @@ | |||
1 | /* This file is part of the KDE libraries | 1 | /* This file is part of the KDE libraries |
2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> | 2 | Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> |
3 | 3 | ||
4 | This library is free software; you can redistribute it and/or | 4 | This library is free software; you can redistribute it and/or |
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License version 2 as published by the Free Software Foundation. | 6 | License version 2 as published by the Free Software Foundation. |
7 | 7 | ||
8 | This library is distributed in the hope that it will be useful, | 8 | This library is distributed in the hope that it will be useful, |
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
11 | Library General Public License for more details. | 11 | Library General Public License for more details. |
12 | 12 | ||
13 | You should have received a copy of the GNU Library General Public License | 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 | 14 | along with this library; see the file COPYING.LIB. If not, write to |
15 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 15 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
16 | Boston, MA 02111-1307, USA. | 16 | Boston, MA 02111-1307, USA. |
17 | */ | 17 | */ |
18 | 18 | ||
19 | #include "ktoolbarhandler.h" | 19 | #include "ktoolbarhandler.h" |
20 | 20 | ||
21 | #include <qpopupmenu.h> | 21 | #include <q3popupmenu.h> |
22 | //Added by qt3to4: | ||
23 | #include <Q3PtrList> | ||
22 | #include <kapplication.h> | 24 | #include <kapplication.h> |
23 | #include <ktoolbar.h> | 25 | #include <ktoolbar.h> |
24 | #include <kmainwindow.h> | 26 | #include <kmainwindow.h> |
25 | #include <klocale.h> | 27 | #include <klocale.h> |
26 | #include <kaction.h> | 28 | #include <kaction.h> |
27 | #include <assert.h> | 29 | #include <assert.h> |
28 | 30 | ||
29 | namespace | 31 | namespace |
30 | { | 32 | { |
31 | const char *actionListName = "show_menu_and_toolbar_actionlist"; | 33 | const char *actionListName = "show_menu_and_toolbar_actionlist"; |
32 | 34 | ||
33 | const char *guiDescription = "" | 35 | const char *guiDescription = "" |
34 | "<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">" | 36 | "<!DOCTYPE kpartgui><kpartgui name=\"StandardToolBarMenuHandler\">" |
35 | "<MenuBar>" | 37 | "<MenuBar>" |
36 | " <Menu name=\"settings\">" | 38 | " <Menu name=\"settings\">" |
37 | " <ActionList name=\"%1\" />" | 39 | " <ActionList name=\"%1\" />" |
38 | " </Menu>" | 40 | " </Menu>" |
39 | "</MenuBar>" | 41 | "</MenuBar>" |
40 | "</kpartgui>"; | 42 | "</kpartgui>"; |
41 | 43 | ||
42 | const char *resourceFileName = "barhandler.rc"; | 44 | const char *resourceFileName = "barhandler.rc"; |
43 | 45 | ||
44 | class BarActionBuilder | 46 | class BarActionBuilder |
45 | { | 47 | { |
46 | public: | 48 | public: |
47 | BarActionBuilder( KActionCollection *actionCollection, KMainWindow *mainWindow, QPtrList<KToolBar> &oldToolBarList ) | 49 | BarActionBuilder( KActionCollection *actionCollection, KMainWindow *mainWindow, Q3PtrList<KToolBar> &oldToolBarList ) |
48 | : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false ) | 50 | : m_actionCollection( actionCollection ), m_mainWindow( mainWindow ), m_needsRebuild( false ) |
49 | { | 51 | { |
50 | /*US | 52 | /*US |
51 | QPtrList<QDockWindow> dockWindows = m_mainWindow->dockWindows(); | 53 | QPtrList<QDockWindow> dockWindows = m_mainWindow->dockWindows(); |
52 | QPtrListIterator<QDockWindow> dockWindowIt( dockWindows ); | 54 | QPtrListIterator<QDockWindow> dockWindowIt( dockWindows ); |
53 | for ( ; dockWindowIt.current(); ++dockWindowIt ) { | 55 | for ( ; dockWindowIt.current(); ++dockWindowIt ) { |
54 | 56 | ||
55 | //US KToolBar *toolBar = dynamic_cast<KToolBar *>( dockWindowIt.current() ); | 57 | //US KToolBar *toolBar = dynamic_cast<KToolBar *>( dockWindowIt.current() ); |
56 | KToolBar *toolBar = (KToolBar *)( dockWindowIt.current() ); | 58 | KToolBar *toolBar = (KToolBar *)( dockWindowIt.current() ); |
57 | if ( !toolBar ) | 59 | if ( !toolBar ) |
58 | continue; | 60 | continue; |
59 | 61 | ||
60 | if ( oldToolBarList.findRef( toolBar ) == -1 ) | 62 | if ( oldToolBarList.findRef( toolBar ) == -1 ) |
61 | m_needsRebuild = true; | 63 | m_needsRebuild = true; |
62 | 64 | ||
63 | m_toolBars.append( toolBar ); | 65 | m_toolBars.append( toolBar ); |
64 | } | 66 | } |
65 | */ | 67 | */ |
66 | if ( !m_needsRebuild ) | 68 | if ( !m_needsRebuild ) |
67 | m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() ); | 69 | m_needsRebuild = ( oldToolBarList.count() != m_toolBars.count() ); |
68 | 70 | ||
69 | } | 71 | } |
70 | 72 | ||
71 | bool needsRebuild() const { return m_needsRebuild; } | 73 | bool needsRebuild() const { return m_needsRebuild; } |
72 | 74 | ||
73 | QPtrList<KAction> create() | 75 | Q3PtrList<KAction> create() |
74 | { | 76 | { |
75 | if ( !m_needsRebuild ) | 77 | if ( !m_needsRebuild ) |
76 | return QPtrList<KAction>(); | 78 | return Q3PtrList<KAction>(); |
77 | 79 | ||
78 | QPtrListIterator<KToolBar> toolBarIt( m_toolBars ); | 80 | Q3PtrListIterator<KToolBar> toolBarIt( m_toolBars ); |
79 | for ( ; toolBarIt.current(); ++toolBarIt ) | 81 | for ( ; toolBarIt.current(); ++toolBarIt ) |
80 | handleToolBar( toolBarIt.current() ); | 82 | handleToolBar( toolBarIt.current() ); |
81 | 83 | ||
82 | QPtrList<KAction> actions; | 84 | Q3PtrList<KAction> actions; |
83 | 85 | ||
84 | if ( m_toolBarActions.count() == 0 ) | 86 | if ( m_toolBarActions.count() == 0 ) |
85 | return actions; | 87 | return actions; |
86 | 88 | ||
87 | if ( m_toolBarActions.count() == 1 ) { | 89 | if ( m_toolBarActions.count() == 1 ) { |
88 | m_toolBarActions.getFirst()->setText( i18n( "Show Toolbar" ) ); | 90 | m_toolBarActions.getFirst()->setText( i18n( "Show Toolbar" ) ); |
89 | return m_toolBarActions; | 91 | return m_toolBarActions; |
90 | } | 92 | } |
91 | 93 | ||
92 | KActionMenu *menuAction = new KActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" ); | 94 | KActionMenu *menuAction = new KActionMenu( i18n( "Toolbars" ), m_actionCollection, "toolbars_submenu_action" ); |
93 | 95 | ||
94 | QPtrListIterator<KAction> actionIt( m_toolBarActions ); | 96 | Q3PtrListIterator<KAction> actionIt( m_toolBarActions ); |
95 | for ( ; actionIt.current(); ++actionIt ) | 97 | for ( ; actionIt.current(); ++actionIt ) |
96 | menuAction->insert( actionIt.current() ); | 98 | menuAction->insert( actionIt.current() ); |
97 | 99 | ||
98 | actions.append( menuAction ); | 100 | actions.append( menuAction ); |
99 | return actions; | 101 | return actions; |
100 | } | 102 | } |
101 | 103 | ||
102 | const QPtrList<KToolBar> &toolBars() const { return m_toolBars; } | 104 | const Q3PtrList<KToolBar> &toolBars() const { return m_toolBars; } |
103 | 105 | ||
104 | private: | 106 | private: |
105 | void handleToolBar( KToolBar *toolBar ) | 107 | void handleToolBar( KToolBar *toolBar ) |
106 | { | 108 | { |
107 | KAction *action = new KToggleToolBarAction( toolBar, | 109 | KAction *action = new KToggleToolBarAction( toolBar, |
108 | i18n( "Show %1" ).arg( toolBar->label() ), | 110 | i18n( "Show %1" ).arg( toolBar->label() ), |
109 | m_actionCollection, | 111 | m_actionCollection, |
110 | toolBar->name() ); | 112 | toolBar->name() ); |
111 | 113 | ||
112 | m_toolBarActions.append( action ); | 114 | m_toolBarActions.append( action ); |
113 | } | 115 | } |
114 | 116 | ||
115 | KActionCollection *m_actionCollection; | 117 | KActionCollection *m_actionCollection; |
116 | KMainWindow *m_mainWindow; | 118 | KMainWindow *m_mainWindow; |
117 | 119 | ||
118 | QPtrList<KToolBar> m_toolBars; | 120 | Q3PtrList<KToolBar> m_toolBars; |
119 | QPtrList<KAction> m_toolBarActions; | 121 | Q3PtrList<KAction> m_toolBarActions; |
120 | 122 | ||
121 | bool m_needsRebuild : 1; | 123 | bool m_needsRebuild : 1; |
122 | }; | 124 | }; |
123 | } | 125 | } |
124 | 126 | ||
125 | using namespace KDEPrivate; | 127 | using namespace KDEPrivate; |
126 | 128 | ||
127 | ToolBarHandler::ToolBarHandler( KMainWindow *mainWindow, const char *name ) | 129 | ToolBarHandler::ToolBarHandler( KMainWindow *mainWindow, const char *name ) |
128 | : QObject( mainWindow, name ), KXMLGUIClient( mainWindow ) | 130 | : QObject( mainWindow, name ), KXMLGUIClient( mainWindow ) |
129 | { | 131 | { |
130 | init( mainWindow ); | 132 | init( mainWindow ); |
131 | } | 133 | } |
132 | 134 | ||
133 | ToolBarHandler::ToolBarHandler( KMainWindow *mainWindow, QObject *parent, const char *name ) | 135 | ToolBarHandler::ToolBarHandler( KMainWindow *mainWindow, QObject *parent, const char *name ) |
134 | : QObject( parent, name ), KXMLGUIClient( mainWindow ) | 136 | : QObject( parent, name ), KXMLGUIClient( mainWindow ) |
135 | { | 137 | { |
136 | init( mainWindow ); | 138 | init( mainWindow ); |
137 | } | 139 | } |
138 | 140 | ||
139 | ToolBarHandler::~ToolBarHandler() | 141 | ToolBarHandler::~ToolBarHandler() |
140 | { | 142 | { |
141 | m_actions.setAutoDelete( true ); | 143 | m_actions.setAutoDelete( true ); |
142 | m_actions.clear(); | 144 | m_actions.clear(); |
143 | } | 145 | } |
144 | 146 | ||
145 | KAction *ToolBarHandler::toolBarMenuAction() | 147 | KAction *ToolBarHandler::toolBarMenuAction() |
146 | { | 148 | { |
147 | assert( m_actions.count() == 1 ); | 149 | assert( m_actions.count() == 1 ); |
148 | return m_actions.getFirst(); | 150 | return m_actions.getFirst(); |
149 | } | 151 | } |
150 | 152 | ||
151 | void ToolBarHandler::setupActions() | 153 | void ToolBarHandler::setupActions() |
@@ -195,59 +197,59 @@ void ToolBarHandler::clientAdded( KXMLGUIClient *client ) | |||
195 | if ( client == this ) | 197 | if ( client == this ) |
196 | setupActions(); | 198 | setupActions(); |
197 | } | 199 | } |
198 | */ | 200 | */ |
199 | 201 | ||
200 | void ToolBarHandler::init( KMainWindow *mainWindow ) | 202 | void ToolBarHandler::init( KMainWindow *mainWindow ) |
201 | { | 203 | { |
202 | d = 0; | 204 | d = 0; |
203 | m_mainWindow = mainWindow; | 205 | m_mainWindow = mainWindow; |
204 | 206 | ||
205 | /*US | 207 | /*US |
206 | connect( m_mainWindow->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ), | 208 | connect( m_mainWindow->guiFactory(), SIGNAL( clientAdded( KXMLGUIClient * ) ), |
207 | this, SLOT( clientAdded( KXMLGUIClient * ) ) ); | 209 | this, SLOT( clientAdded( KXMLGUIClient * ) ) ); |
208 | */ | 210 | */ |
209 | /* re-use an existing resource file if it exists. can happen if the user launches the | 211 | /* re-use an existing resource file if it exists. can happen if the user launches the |
210 | * toolbar editor */ | 212 | * toolbar editor */ |
211 | /* | 213 | /* |
212 | setXMLFile( resourceFileName ); | 214 | setXMLFile( resourceFileName ); |
213 | */ | 215 | */ |
214 | /*US | 216 | /*US |
215 | if ( domDocument().documentElement().isNull() ) { | 217 | if ( domDocument().documentElement().isNull() ) { |
216 | 218 | ||
217 | QString completeDescription = QString::fromLatin1( guiDescription ) | 219 | QString completeDescription = QString::fromLatin1( guiDescription ) |
218 | .arg( actionListName ); | 220 | .arg( actionListName ); |
219 | 221 | ||
220 | setXML( completeDescription, false*/ /*merge*/ /*); | 222 | setXML( completeDescription, false*/ /*merge*/ /*); |
221 | } | 223 | } |
222 | */ | 224 | */ |
223 | } | 225 | } |
224 | 226 | ||
225 | void ToolBarHandler::connectToActionContainers() | 227 | void ToolBarHandler::connectToActionContainers() |
226 | { | 228 | { |
227 | QPtrListIterator<KAction> actionIt( m_actions ); | 229 | Q3PtrListIterator<KAction> actionIt( m_actions ); |
228 | for ( ; actionIt.current(); ++actionIt ) | 230 | for ( ; actionIt.current(); ++actionIt ) |
229 | connectToActionContainer( actionIt.current() ); | 231 | connectToActionContainer( actionIt.current() ); |
230 | } | 232 | } |
231 | 233 | ||
232 | void ToolBarHandler::connectToActionContainer( KAction *action ) | 234 | void ToolBarHandler::connectToActionContainer( KAction *action ) |
233 | { | 235 | { |
234 | uint containerCount = action->containerCount(); | 236 | uint containerCount = action->containerCount(); |
235 | for ( uint i = 0; i < containerCount; ++i ) | 237 | for ( uint i = 0; i < containerCount; ++i ) |
236 | connectToActionContainer( action->container( i ) ); | 238 | connectToActionContainer( action->container( i ) ); |
237 | } | 239 | } |
238 | 240 | ||
239 | void ToolBarHandler::connectToActionContainer( QWidget *container ) | 241 | void ToolBarHandler::connectToActionContainer( QWidget *container ) |
240 | { | 242 | { |
241 | //US QPopupMenu *popupMenu = dynamic_cast<QPopupMenu *>( container ); | 243 | //US QPopupMenu *popupMenu = dynamic_cast<QPopupMenu *>( container ); |
242 | QPopupMenu *popupMenu = (QPopupMenu *)( container ); | 244 | Q3PopupMenu *popupMenu = (Q3PopupMenu *)( container ); |
243 | if ( !popupMenu ) | 245 | if ( !popupMenu ) |
244 | return; | 246 | return; |
245 | 247 | ||
246 | connect( popupMenu, SIGNAL( aboutToShow() ), | 248 | connect( popupMenu, SIGNAL( aboutToShow() ), |
247 | this, SLOT( setupActions() ) ); | 249 | this, SLOT( setupActions() ) ); |
248 | } | 250 | } |
249 | 251 | ||
250 | //US #include "ktoolbarhandler.moc" | 252 | //US #include "ktoolbarhandler.moc" |
251 | 253 | ||
252 | /* vim: et sw=4 ts=4 | 254 | /* vim: et sw=4 ts=4 |
253 | */ | 255 | */ |