1 /* This file is part of the KDE libraries
2 Copyright (C) 1999,2000 Kurt Granroth <granroth@kde.org>
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.
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.
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 Steet, Fifth Floor,
16 Boston, MA 02110-1301, USA.
19 #include "kstdaction.h"
21 #include <qtoolbutton.h>
22 #include <qwhatsthis.h>
24 #include <kaboutdata.h>
26 #include <kapplication.h>
29 #include <kiconloader.h>
31 #include <kstdaccel.h>
32 #include <kmainwindow.h>
33 #include "kstdaction_p.h"
38 QStringList
stdNames()
40 return internal_stdNames();
43 KAction
* create( StdAction id
, const char *name
, const QObject
*recvr
, const char *slot
, KActionCollection
* parent
)
46 const KStdActionInfo
* pInfo
= infoPtr( id
);
47 kdDebug(125) << "KStdAction::create( " << id
<< "=" << (pInfo
? pInfo
->psName
: (const char*)0) << ", " << parent
<< ", " << name
<< " )" << endl
; // ellis
49 QString sLabel
, iconName
= pInfo
->psIconName
;
51 case Back
: sLabel
= i18n("go back", "&Back");
52 if (QApplication::reverseLayout() )
56 case Forward
: sLabel
= i18n("go forward", "&Forward");
57 if (QApplication::reverseLayout() )
61 case Home
: sLabel
= i18n("beginning (of line)", "&Home"); break;
62 case Help
: sLabel
= i18n("show help", "&Help"); break;
63 case AboutApp
: iconName
= kapp
->miniIconName();
67 const KAboutData
*aboutData
= KGlobal::instance()->aboutData();
69 const KAboutData *aboutData;
71 aboutData = parent->instance()->aboutData();
73 aboutData = KGlobal::instance()->aboutData();
75 QString appName
= (aboutData
) ? aboutData
->programName() : QString::fromLatin1(qApp
->name());
76 sLabel
= i18n(pInfo
->psLabel
).arg(appName
);
79 default: sLabel
= i18n(pInfo
->psLabel
);
82 if (QApplication::reverseLayout()){
83 if (id
== Prior
) iconName
= "next";
84 if (id
== Next
) iconName
= "previous";
87 KShortcut cut
= KStdAccel::shortcut(pInfo
->idAccel
);
90 pAction
= new KRecentFilesAction( sLabel
, pInfo
->psIconName
, cut
,
92 parent
, (name
) ? name
: pInfo
->psName
);
99 ret
= new KToggleAction( sLabel
, pInfo
->psIconName
, cut
,
101 parent
, (name
) ? name
: pInfo
->psName
);
102 ret
->setChecked( true );
108 KToggleFullScreenAction
*ret
;
109 ret
= new KToggleFullScreenAction( cut
, recvr
, slot
,
110 parent
, NULL
, (name
) ? name
: pInfo
->psName
);
111 ret
->setChecked( false );
117 KPasteTextAction
*ret
;
118 ret
= new KPasteTextAction(sLabel
, iconName
, cut
,
120 parent
, (name
) ? name
: pInfo
->psName
);
125 pAction
= new KAction( sLabel
, iconName
, cut
,
127 parent
, (name
) ? name
: pInfo
->psName
);
134 const char* name( StdAction id
)
136 const KStdActionInfo
* pInfo
= infoPtr( id
);
137 return (pInfo
) ? pInfo
->psName
: 0;
140 KAction
*openNew( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
141 { return KStdAction::create( New
, name
, recvr
, slot
, parent
); }
142 KAction
*open( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
143 { return KStdAction::create( Open
, name
, recvr
, slot
, parent
); }
144 KRecentFilesAction
*openRecent( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
145 { return (KRecentFilesAction
*) KStdAction::create( OpenRecent
, name
, recvr
, slot
, parent
); }
146 KAction
*save( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
147 { return KStdAction::create( Save
, name
, recvr
, slot
, parent
); }
148 KAction
*saveAs( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
149 { return KStdAction::create( SaveAs
, name
, recvr
, slot
, parent
); }
150 KAction
*revert( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
151 { return KStdAction::create( Revert
, name
, recvr
, slot
, parent
); }
152 KAction
*print( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
153 { return KStdAction::create( Print
, name
, recvr
, slot
, parent
); }
154 KAction
*printPreview( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
155 { return KStdAction::create( PrintPreview
, name
, recvr
, slot
, parent
); }
156 KAction
*close( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
157 { return KStdAction::create( Close
, name
, recvr
, slot
, parent
); }
158 KAction
*mail( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
159 { return KStdAction::create( Mail
, name
, recvr
, slot
, parent
); }
160 KAction
*quit( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
161 { return KStdAction::create( Quit
, name
, recvr
, slot
, parent
); }
162 KAction
*undo( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
163 { return KStdAction::create( Undo
, name
, recvr
, slot
, parent
); }
164 KAction
*redo( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
165 { return KStdAction::create( Redo
, name
, recvr
, slot
, parent
); }
166 KAction
*cut( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
167 { return KStdAction::create( Cut
, name
, recvr
, slot
, parent
); }
168 KAction
*copy( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
169 { return KStdAction::create( Copy
, name
, recvr
, slot
, parent
); }
170 KAction
*paste( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
171 { return KStdAction::create( Paste
, name
, recvr
, slot
, parent
); }
172 KAction
*pasteText( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
173 { return KStdAction::create( PasteText
, name
, recvr
, slot
, parent
); }
174 KAction
*clear( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
175 { return KStdAction::create( Clear
, name
, recvr
, slot
, parent
); }
176 KAction
*selectAll( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
177 { return KStdAction::create( SelectAll
, name
, recvr
, slot
, parent
); }
178 KAction
*deselect( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
179 { return KStdAction::create( Deselect
, name
, recvr
, slot
, parent
); }
180 KAction
*find( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
181 { return KStdAction::create( Find
, name
, recvr
, slot
, parent
); }
182 KAction
*findNext( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
183 { return KStdAction::create( FindNext
, name
, recvr
, slot
, parent
); }
184 KAction
*findPrev( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
185 { return KStdAction::create( FindPrev
, name
, recvr
, slot
, parent
); }
186 KAction
*replace( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
187 { return KStdAction::create( Replace
, name
, recvr
, slot
, parent
); }
188 KAction
*actualSize( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
189 { return KStdAction::create( ActualSize
, name
, recvr
, slot
, parent
); }
190 KAction
*fitToPage( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
191 { return KStdAction::create( FitToPage
, name
, recvr
, slot
, parent
); }
192 KAction
*fitToWidth( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
193 { return KStdAction::create( FitToWidth
, name
, recvr
, slot
, parent
); }
194 KAction
*fitToHeight( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
195 { return KStdAction::create( FitToHeight
, name
, recvr
, slot
, parent
); }
196 KAction
*zoomIn( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
197 { return KStdAction::create( ZoomIn
, name
, recvr
, slot
, parent
); }
198 KAction
*zoomOut( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
199 { return KStdAction::create( ZoomOut
, name
, recvr
, slot
, parent
); }
200 KAction
*zoom( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
201 { return KStdAction::create( Zoom
, name
, recvr
, slot
, parent
); }
202 KAction
*redisplay( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
203 { return KStdAction::create( Redisplay
, name
, recvr
, slot
, parent
); }
204 KAction
*up( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
205 { return KStdAction::create( Up
, name
, recvr
, slot
, parent
); }
206 KAction
*back( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
207 { return KStdAction::create( Back
, name
, recvr
, slot
, parent
); }
208 KAction
*forward( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
209 { return KStdAction::create( Forward
, name
, recvr
, slot
, parent
); }
210 KAction
*home( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
211 { return KStdAction::create( Home
, name
, recvr
, slot
, parent
); }
212 KAction
*prior( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
213 { return KStdAction::create( Prior
, name
, recvr
, slot
, parent
); }
214 KAction
*next( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
215 { return KStdAction::create( Next
, name
, recvr
, slot
, parent
); }
216 KAction
*goTo( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
217 { return KStdAction::create( Goto
, name
, recvr
, slot
, parent
); }
218 KAction
*gotoPage( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
219 { return KStdAction::create( GotoPage
, name
, recvr
, slot
, parent
); }
220 KAction
*gotoLine( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
221 { return KStdAction::create( GotoLine
, name
, recvr
, slot
, parent
); }
222 KAction
*firstPage( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
223 { return KStdAction::create( FirstPage
, name
, recvr
, slot
, parent
); }
224 KAction
*lastPage( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
225 { return KStdAction::create( LastPage
, name
, recvr
, slot
, parent
); }
226 KAction
*addBookmark( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
227 { return KStdAction::create( AddBookmark
, name
, recvr
, slot
, parent
); }
228 KAction
*editBookmarks( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
229 { return KStdAction::create( EditBookmarks
, name
, recvr
, slot
, parent
); }
230 KAction
*spelling( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
231 { return KStdAction::create( Spelling
, name
, recvr
, slot
, parent
); }
233 KToggleAction
*showMenubar( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *_name
)
236 ret
= new KToggleAction(i18n("Show &Menubar"), "showmenu", KStdAccel::shortcut(KStdAccel::ShowMenubar
), recvr
, slot
,
237 parent
, _name
? _name
: name(ShowMenubar
));
238 ret
->setWhatsThis( i18n( "Show Menubar<p>"
239 "Shows the menubar again after it has been hidden" ) );
240 KGuiItem
guiItem( i18n("Hide &Menubar"), 0 /*same icon*/, QString::null
,
241 i18n( "Hide Menubar<p>"
242 "Hide the menubar. You can usually get it back using the right mouse button inside the window itself." ) );
243 ret
->setCheckedState( guiItem
);
244 ret
->setChecked(true);
249 KToggleAction
*showToolbar( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *_name
)
252 ret
= new KToggleAction(i18n("Show &Toolbar"), 0, recvr
, slot
, parent
,
253 _name
? _name
: name(ShowToolbar
));
254 ret
->setChecked(true);
260 KToggleToolBarAction
*showToolbar( const char* toolBarName
, KActionCollection
* parent
, const char *_name
)
262 KToggleToolBarAction
*ret
;
263 ret
= new KToggleToolBarAction(toolBarName
, i18n("Show &Toolbar"), parent
,
264 _name
? _name
: name(ShowToolbar
));
268 KToggleAction
*showStatusbar( const QObject
*recvr
, const char *slot
,
269 KActionCollection
* parent
, const char *_name
)
272 ret
= new KToggleAction(i18n("Show St&atusbar"), 0, recvr
, slot
, parent
,
273 _name
? _name
: name(ShowStatusbar
));
274 ret
->setWhatsThis( i18n( "Show Statusbar<p>"
275 "Shows the statusbar, which is the bar at the bottom of the window used for status information." ) );
276 KGuiItem
guiItem( i18n("Hide St&atusbar"), QString::null
, QString::null
,
277 i18n( "Hide Statusbar<p>"
278 "Hides the statusbar, which is the bar at the bottom of the window used for status information." ) );
279 ret
->setCheckedState( guiItem
);
281 ret
->setChecked(true);
285 KToggleFullScreenAction
*fullScreen( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
,
286 QWidget
* window
, const char *name
)
288 KToggleFullScreenAction
*ret
;
289 ret
= static_cast< KToggleFullScreenAction
* >( KStdAction::create( FullScreen
, name
, recvr
, slot
, parent
));
290 ret
->setWindow( window
);
294 KAction
*saveOptions( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
295 { return KStdAction::create( SaveOptions
, name
, recvr
, slot
, parent
); }
296 KAction
*keyBindings( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
297 { return KStdAction::create( KeyBindings
, name
, recvr
, slot
, parent
); }
298 KAction
*preferences( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
299 { return KStdAction::create( Preferences
, name
, recvr
, slot
, parent
); }
300 KAction
*configureToolbars( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
301 { return KStdAction::create( ConfigureToolbars
, name
, recvr
, slot
, parent
); }
302 KAction
*configureNotifications( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
303 { return KStdAction::create( ConfigureNotifications
, name
, recvr
, slot
, parent
); }
304 KAction
*help( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
305 { return KStdAction::create( Help
, name
, recvr
, slot
, parent
); }
306 KAction
*helpContents( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
307 { return KStdAction::create( HelpContents
, name
, recvr
, slot
, parent
); }
308 KAction
*whatsThis( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
309 { return KStdAction::create( WhatsThis
, name
, recvr
, slot
, parent
); }
310 KAction
*tipOfDay( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
311 { return KStdAction::create( TipofDay
, name
, recvr
, slot
, parent
); }
312 KAction
*reportBug( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
313 { return KStdAction::create( ReportBug
, name
, recvr
, slot
, parent
); }
314 KAction
*aboutApp( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
315 { return KStdAction::create( AboutApp
, name
, recvr
, slot
, parent
); }
316 KAction
*aboutKDE( const QObject
*recvr
, const char *slot
, KActionCollection
* parent
, const char *name
)
317 { return KStdAction::create( AboutKDE
, name
, recvr
, slot
, parent
); }