subtraction of already painted area: be fool and
[kdelibs.git] / kdeui / kmainwindow.h
blobeab5bf8c70522abadd291c5e80b72da59650b41e
1 /*
2 This file is part of the KDE libraries
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.
21 #ifndef KMAINWINDOW_H
22 #define KMAINWINDOW_H
24 #include "kxmlguifactory.h"
25 #include "kxmlguiclient.h"
26 #include "kxmlguibuilder.h"
27 #include <qmainwindow.h>
28 #include <qmetaobject.h>
29 #include <ktoolbar.h>
31 class KPopupMenu;
32 class KXMLGUIFactory;
33 class KConfig;
34 class KHelpMenu;
35 class KStatusBar;
36 class QStatusBar;
37 class KMenuBar;
38 class KMWSessionManaged;
39 class KMainWindowPrivate;
40 class KAccel;
41 class KToolBarMenuAction;
42 class DCOPObject;
44 #define KDE_DEFAULT_WINDOWFLAGS WType_TopLevel | WDestructiveClose
47 /**
48 * @short %KDE top level main window
50 * Top level widget that provides toolbars, a status line and a frame.
52 * It should be used as a top level (parent-less) widget.
53 * It manages the geometry for all its children, including your
54 * main widget.
56 * Normally, you will inherit from KMainWindow,
57 * then construct (or use some existing) widget as
58 * your main view. You can set only one main view.
60 * You can add as many toolbars as you like. There can be only one menubar
61 * and only one statusbar.
63 * The toolbars, menubar, and statusbar can be created by the
64 * KMainWindow and - unlike the old KMainWindow - may, but do not
65 * have to, be deleted by you. KMainWindow will handle that internally.
67 * Height and width can be operated independently from each other. Simply
68 * define the minimum/maximum height/width of your main widget and
69 * KMainWindow will take this into account. For fixed size windows set
70 * your main widget to a fixed size.
72 * Fixed aspect ratios (heightForWidth()) and fixed width widgets are
73 * not supported.
75 * KMainWindow will set icon, mini icon and caption, which it gets
76 * from KApplication. It provides full session management, and
77 * will save its position, geometry and positions of toolbars and
78 * menubar on logout. If you want to save additional data, reimplement
79 * saveProperties() and (to read them again on next login)
80 * readProperties(). To save special data about your data, reimplement
81 * saveGlobalProperties(). To warn user that application or
82 * windows have unsaved data on close or logout, reimplement
83 * queryClose() and/or queryExit().
85 * There are also kRestoreMainWindows convenience functions which
86 * can restore all your windows on next login.
88 * Note that a KMainWindow per-default is created with the
89 * WDestructiveClose flag, i.e. it is automatically destroyed when the
90 * window is closed. If you do not want this behavior, specify 0 as
91 * widget flag in the constructor.
93 * @see KApplication
94 * @author Reginald Stadlbauer (reggie@kde.org) Stephan Kulow (coolo@kde.org), Matthias Ettrich (ettrich@kde.org), Chris Schlaeger (cs@kde.org), Sven Radej (radej@kde.org). Maintained by Sven Radej (radej@kde.org)
98 class KDEUI_EXPORT KMainWindow : public QMainWindow, public KXMLGUIBuilder, virtual public KXMLGUIClient
100 friend class KMWSessionManaged;
101 Q_OBJECT
103 public:
105 * Construct a main window.
107 * @param parent The widget parent. This is usually 0 but it may also be the window
108 * group leader. In that case, the KMainWindow becomes sort of a
109 * secondary window.
111 * @param name The object name. For session management and window management to work
112 * properly, all main windows in the application should have a
113 * different name. When passing 0 (the default), KMainWindow will create
114 * a unique name, but it's recommended to explicitly pass a window name that will
115 * also describe the type of the window. If there can be several windows of the same
116 * type, append '#' (hash) to the name, and KMainWindow will append numbers to make
117 * the names unique. For example, for a mail client which has one main window showing
118 * the mails and folders, and which can also have one or more windows for composing
119 * mails, the name for the folders window should be e.g. "mainwindow" and
120 * for the composer windows "composer#".
122 * @param f Specify the widget flags. The default is
123 * WType_TopLevel and WDestructiveClose. TopLevel indicates that a
124 * main window is a toplevel window, regardless of whether it has a
125 * parent or not. DestructiveClose indicates that a main window is
126 * automatically destroyed when its window is closed. Pass 0 if
127 * you do not want this behavior.
129 * @see http://doc.trolltech.com/3.2/qt.html#WidgetFlags-enum
131 * KMainWindows must be created on the heap with 'new', like:
132 * \code
133 * KMainWindow *kmw = new KMainWindow (...);
134 * \endcode
136 KMainWindow( QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
139 * Flags that can be passed in an argument to the constructor to
140 * change the behavior.
142 * NoDCOPObject tells KMainWindow not to create a KMainWindowInterface.
143 * This can be useful in particular for inherited classes, which
144 * might want to create more specific dcop interfaces. It's a good
145 * idea to use KMainWindowInterface as the base class for such interfaces
146 * though (to provide the standard mainwindow functionality via DCOP).
148 enum CreationFlags
150 NoDCOPObject = 1
154 * Overloaded constructor which allows passing some KMainWindow::CreationFlags.
156 * @since 3.2
158 KMainWindow( int cflags, QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
161 * \brief Destructor.
163 * Will also destroy the toolbars, and menubar if
164 * needed.
166 virtual ~KMainWindow();
169 * Retrieve the standard help menu.
171 * It contains entires for the
172 * help system (activated by F1), an optional "What's This?" entry
173 * (activated by Shift F1), an application specific dialog box,
174 * and an "About KDE" dialog box.
176 * Example (adding a standard help menu to your application):
177 * \code
178 * KPopupMenu *help = helpMenu( <myTextString> );
179 * menuBar()->insertItem( i18n("&Help"), help );
180 * \endcode
182 * @param aboutAppText The string that is used in the application
183 * specific dialog box. If you leave this string empty the
184 * information in the global KAboutData of the
185 * application will be used to make a standard dialog box.
187 * @param showWhatsThis Set this to false if you do not want to include
188 * the "What's This" menu entry.
190 * @return A standard help menu.
192 KPopupMenu* helpMenu( const QString &aboutAppText = QString::null,
193 bool showWhatsThis = true );
196 * Returns the help menu. Creates a standard help menu if none exists yet.
198 * It contains entries for the
199 * help system (activated by F1), an optional "What's This?" entry
200 * (activated by Shift F1), an application specific dialog box,
201 * and an "About KDE" dialog box. You must create the application
202 * specific dialog box yourself. When the "About application"
203 * menu entry is activated, a signal will trigger the
204 * showAboutApplication slot. See showAboutApplication for more
205 * information.
207 * Example (adding a help menu to your application):
208 * \code
209 * menuBar()->insertItem( i18n("&Help"), customHelpMenu() );
210 * \endcode
212 * @param showWhatsThis Set this to @p false if you do not want to include
213 * the "What's This" menu entry.
215 * @return A standard help menu.
217 KPopupMenu* customHelpMenu( bool showWhatsThis = true );
220 * <b>Session Management</b>
222 * Try to restore the toplevel widget as defined by the number (1..X).
224 * If the session did not contain so high a number, the configuration
225 * is not changed and @p false returned.
227 * That means clients could simply do the following:
228 * \code
229 * if (kapp->isRestored()){
230 * int n = 1;
231 * while (KMainWindow::canBeRestored(n)){
232 * (new childMW)->restore(n);
233 * n++;
235 * } else {
236 * // create default application as usual
238 * \endcode
239 * Note that QWidget::show() is called implicitly in restore.
241 * With this you can easily restore all toplevel windows of your
242 * application.
244 * If your application uses different kinds of toplevel
245 * windows, then you can use KMainWindow::classNameOfToplevel(n)
246 * to determine the exact type before calling the childMW
247 * constructor in the example from above.
249 * If your client has only one kind of toplevel widgets (which
250 * should be pretty usual) then you should use the RESTORE-macro
251 * for backwards compatibility with 3.1 and 3.0 branches:
253 * \code
254 * if (kapp->isRestored())
255 * RESTORE(childMW)
256 * else {
257 * // create default application as usual
259 * \endcode
261 * The macro expands to the term above but is easier to use and
262 * less code to write.
264 * For new code or if you have more than one kind of toplevel
265 * widget (each derived from KMainWindow, of course), you can
266 * use the templated kRestoreMainWindows global functions:
268 * \code
269 * if (kapp->isRestored())
270 * kRestoreMainWindows< childMW1, childMW2, childMW3 >();
271 * else {
272 * // create default application as usual
274 * \endcode
276 * Currently, these functions are provided for up to three
277 * template arguments. If you need more, tell us. To help you in
278 * deciding whether or not you can use kRestoreMainWindows, a
279 * define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS is provided.
281 * @see restore()
282 * @see classNameOfToplevel()
285 static bool canBeRestored( int number );
288 * Returns the className() of the @p number of the toplevel window which
289 * should be restored.
291 * This is only useful if your application uses
292 * different kinds of toplevel windows.
294 // KDE 4 return QCString - QObject::className() returns const char*
295 static const QString classNameOfToplevel( int number );
298 * Reimplementation of QMainWindow::show()
300 // KDE4 remove this method if this has been fixed in Qt
301 virtual void show();
304 * Reimplementation of QMainWindow::hide()
306 // KDE4 remove this method if this has been fixed in Qt
307 virtual void hide();
310 * Restore the session specified by @p number.
312 * Returns @p false if this
313 * fails, otherwise returns @p true and shows the window.
314 * You should call canBeRestored() first.
315 * If @p show is true (default), this widget will be shown automatically.
317 bool restore( int number, bool show = true );
319 virtual KXMLGUIFactory *guiFactory();
322 * Create a GUI given a local XML file.
324 * If @p xmlfile is NULL,
325 * then it will try to construct a local XML filename like
326 * appnameui.rc where 'appname' is your app's name. If that file
327 * does not exist, then the XML UI code will only use the global
328 * (standard) XML file for the layout purposes.
330 * Note that when passing true for the conserveMemory argument subsequent
331 * calls to guiFactory()->addClient/removeClient may not work as expected.
332 * Also retrieving references to containers like popup menus or toolbars using
333 * the container method will not work.
335 * @param xmlfile The local xmlfile (relative or absolute)
336 * @param _conserveMemory Specify whether createGUI() should call
337 * KXMLGuiClient::conserveMemory() to free all memory
338 * allocated by the QDomDocument and by the KXMLGUIFactory.
340 void createGUI( const QString &xmlfile = QString::null, bool _conserveMemory = true );
343 * Enables the build of a standard help menu when calling createGUI().
345 * The default behavior is to build one, you must call this function
346 * to disable it
348 void setHelpMenuEnabled(bool showHelpMenu = true);
351 * Return @p true when the help menu is enabled
353 bool isHelpMenuEnabled();
357 * Returns true, if there is a menubar
358 * @since 3.1
360 bool hasMenuBar();
363 * Returns a pointer to the menu bar.
365 * If there is no menu bar yet one will be created.
367 KMenuBar *menuBar();
370 * Returns a pointer to the status bar.
372 * If there is no status bar yet, one will be created.
374 * Note that tooltips for kactions in actionCollection() are not
375 * automatically connected to this statusBar.
376 * See the KActionCollection documentation for more details.
378 * @see KActionCollection
380 KStatusBar *statusBar();
383 * List of members of KMainWindow class.
385 static QPtrList<KMainWindow>* memberList;
387 //KDE4: replace with memberList() and make memberList member private
389 * List of members of KMainWindow class.
390 * @since 3.4
392 static QPtrList<KMainWindow>* getMemberList();
395 * Returns a pointer to the toolbar with the specified name.
396 * This refers to toolbars created dynamically from the XML UI
397 * framework. If the toolbar does not exist one will be created.
399 * @param name The internal name of the toolbar. If no name is
400 * specified "mainToolBar" is assumed.
402 * @return A pointer to the toolbar
404 KToolBar *toolBar( const char *name=0 );
407 * @return An iterator over the list of all toolbars for this window.
409 QPtrListIterator<KToolBar> toolBarIterator();
412 * @return A KAccel instance bound to this mainwindow. Used automatically
413 * by KAction to make keybindings work in all cases.
415 KAccel *accel();
417 void setFrameBorderWidth( int ) {}
420 * Call this to enable "auto-save" of toolbar/menubar/statusbar settings
421 * (and optionally window size).
422 * If the *bars were moved around/shown/hidden when the window is closed,
423 * saveMainWindowSettings( KGlobal::config(), groupName ) will be called.
425 * @param groupName a name that identifies this "type of window".
426 * You can have several types of window in the same application.
428 * @param saveWindowSize set it to true to include the window size
429 * when saving.
431 * Typically, you will call setAutoSaveSettings() in your
432 * KMainWindow-inherited class constructor, and it will take care
433 * of restoring and saving automatically. Make sure you call this
434 * _after all_ your *bars have been created.
436 * To make sure that KMainWindow propertly obtains the default
437 * size of the window you should do the following:
438 * - Remove hard coded resize() calls in the constructor or main, they
439 * should be removed in favor of letting the automatic resizing
440 * determine the default window size. Hard coded window sizes will
441 * be wrong for users that have big fonts, use different styles,
442 * long/small translations, large toolbars, and other factors.
443 * - Put the setAutoSaveSettings ( or setupGUI() ) call after all widgets
444 * have been created and placed inside the main window (i.e. for 99% of
445 * apps setCentralWidget())
446 * - Widgets that inherit from QWidget (like game boards) should overload
447 * "virtual QSize sizeHint() const;" to specify a default size rather
448 * than letting QWidget::adjust use the default size of 0x0.
450 void setAutoSaveSettings( const QString & groupName = QString::fromLatin1("MainWindow"),
451 bool saveWindowSize = true );
454 * Disable the auto-save-settings feature.
455 * You don't normally need to call this, ever.
457 void resetAutoSaveSettings();
460 * @return the current autosave setting, i.e. true if setAutoSaveSettings() was called,
461 * false by default or if resetAutoSaveSettings() was called.
462 * @since 3.1
464 bool autoSaveSettings() const;
467 * @return the group used for setting-autosaving.
468 * Only meaningful if setAutoSaveSettings() was called.
469 * This can be useful for forcing a save or an apply, e.g. before and after
470 * using KEditToolbar.
471 * @since 3.1
473 QString autoSaveGroup() const;
476 * Read settings for statusbar, menubar and toolbar from their respective
477 * groups in the config file and apply them.
479 * @param config Config file to read the settings from.
480 * @param groupName Group name to use. If not specified, the last used
481 * group name is used.
482 * @param force if set, even default settings are re-applied
484 void applyMainWindowSettings(KConfig *config, const QString &groupName, bool force);
485 // KDE4 merge with force=false
486 void applyMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
489 * Save settings for statusbar, menubar and toolbar to their respective
490 * groups in the config file @p config.
492 * @param config Config file to save the settings to.
493 * @param groupName Group name to use. If not specified, the last used
494 * group name is used
496 void saveMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
499 * Sets whether KMainWindow should provide a menu that allows showing/hiding
500 * the available toolbars ( using KToggleToolBarAction ) . In case there
501 * is only one toolbar configured a simple 'Show \<toolbar name here\>' menu item
502 * is shown.
504 * The menu / menu item is implemented using xmlgui. It will be inserted in your
505 * menu structure in the 'Settings' menu.
507 * If your application uses a non-standard xmlgui resource file then you can
508 * specify the exact position of the menu / menu item by adding a
509 * &lt;Merge name="StandardToolBarMenuHandler" /&gt;
510 * line to the settings menu section of your resource file ( usually appname.rc ).
512 * Note that you should enable this feature before calling createGUI() ( or similar ) .
513 * You enable/disable it anytime if you pass false to the conserveMemory argument of createGUI.
514 * @since 3.1
516 void setStandardToolBarMenuEnabled( bool enable );
517 /// @since 3.1
518 bool isStandardToolBarMenuEnabled() const;
522 * Sets whether KMainWindow should provide a menu that allows showing/hiding
523 * of the statusbar ( using KToggleStatusBarAction ).
525 * The menu / menu item is implemented using xmlgui. It will be inserted
526 * in your menu structure in the 'Settings' menu.
528 * Note that you should enable this feature before calling createGUI()
529 * ( or similar ).
531 * If an application maintains the action on its own (i.e. never calls
532 * this function) a connection needs to be made to let KMainWindow
533 * know when that status (hidden/shown) of the statusbar has changed.
534 * For example:
535 * connect(action, SIGNAL(activated()),
536 * kmainwindow, SLOT(setSettingsDirty()));
537 * Otherwise the status (hidden/show) of the statusbar might not be saved
538 * by KMainWindow.
539 * @since 3.2
541 void createStandardStatusBarAction();
544 * @see setupGUI()
546 enum StandardWindowOptions
549 * adds action to show/hide the toolbar(s) and adds
550 * action to configure the toolbar(s).
551 * @see setStandardToolBarMenuEnabled
553 ToolBar = 1,
556 * adds action to show the key configure action.
558 Keys = 2,
561 * adds action to show/hide the statusbar if the
562 * statusbar exists. See createStandardStatusBarAction
564 StatusBar = 4,
567 * auto-saves (and loads) the toolbar/menubar/statusbar settings and
568 * window size using the default name. See setAutoSaveSettings
570 * Typically you want to let the default window size be determined by
571 * the widgets size hints. Make sure that setupGUI() is called after
572 * all the widgets are created ( including setCentralWidget ) so the
573 * default size's will be correct. See setAutoSaveSettings for
574 * more information on this topic.
576 Save = 8,
579 * calls createGUI() once ToolBar, Keys and Statusbar have been
580 * taken care of. See createGUI
582 Create = 16
586 * Configures the current windows and its actions in the typical KDE
587 * fashion. The options are all enabled by default but can be turned
588 * off if desired through the params or if the prereqs don't exists.
590 * Typically this function replaces createGUI().
592 * @see StandardWindowOptions
594 * @since 3.3
596 void setupGUI( int options = ToolBar | Keys | StatusBar | Save | Create, const QString& xmlfile = QString::null );
599 * Configures the current windows and its actions in the typical KDE
600 * fashion. The options are all enabled by default but can be turned
601 * off if desired through the params or if the prereqs don't exists.
603 * @p defaultSize The default size of the window
605 * Typically this function replaces createGUI().
607 * @see StandardWindowOptions
609 * @since 3.5
611 void setupGUI( QSize defaultSize, int options = ToolBar | Keys | StatusBar | Save | Create, const QString& xmlfile = QString::null );
614 * Returns a pointer to the mainwindows action responsible for the toolbars menu
615 * @since 3.1
617 KAction *toolBarMenuAction();
620 * @internal for KToolBar
621 * @since 3.3.1
623 void setupToolbarMenuActions();
625 // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI;
626 /// @since 3.1
627 virtual void finalizeGUI( KXMLGUIClient *client );
630 * @internal
632 void finalizeGUI( bool force );
635 * @return true if a -geometry argument was given on the command line,
636 * and this is the first window created (the one on which this option applies)
638 bool initialGeometrySet() const;
641 * @internal
642 * Used from Konqueror when reusing the main window.
644 void ignoreInitialGeometry();
647 * @return the size the mainwindow should have so that the central
648 * widget will be of @p size.
650 * @deprecated You normally don't need this, the recommended way to achieve a
651 * certain central widget size is as follows:
652 * @li Override sizeHint() in the central widget so that it
653 * returns the desired size.
654 * @li Call updateGeometry() in the central widget whenever the
655 * desired size changes. This ensures that the new sizeHint() is properly
656 * propagated to any parent layout.
657 * @li Now call adjustSize() in the mainwindow to resize the
658 * mainwindow such that the central widget will become the desired size.
661 // KDE4 to be removed
662 QSize sizeForCentralWidgetSize(QSize size) KDE_DEPRECATED;
665 * @internal
667 // KDE4 remove
668 virtual void setIcon( const QPixmap & );
670 public slots:
672 * Show a standard configure toolbar dialog.
674 * This slot can be connected dirrectly to the action to configure shortcuts.
675 * This is very simple to do that by adding a single line
676 * \code
677 * KStdAction::configureToolbars( guiFactory(), SLOT( configureToolbars() ),
678 * actionCollection() );
679 * \endcode
681 * @since 3.3
683 int configureToolbars(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow
686 * Makes a KDE compliant caption.
688 * @param caption Your caption. @em Do @em not include the application name
689 * in this string. It will be added automatically according to the KDE
690 * standard.
692 virtual void setCaption( const QString &caption );
694 * Makes a KDE compliant caption.
696 * @param caption Your caption. @em Do @em not include the application name
697 * in this string. It will be added automatically according to the KDE
698 * standard.
699 * @param modified Specify whether the document is modified. This displays
700 * an additional sign in the title bar, usually "**".
702 virtual void setCaption( const QString &caption, bool modified );
705 * Make a plain caption without any modifications.
707 * @param caption Your caption. This is the string that will be
708 * displayed in the window title.
710 virtual void setPlainCaption( const QString &caption );
713 * Open the help page for the application.
715 * The application name is
716 * used as a key to determine what to display and the system will attempt
717 * to open \<appName\>/index.html.
719 * This method is intended for use by a help button in the toolbar or
720 * components outside the regular help menu. Use helpMenu() when you
721 * want to provide access to the help system from the help menu.
723 * Example (adding a help button to the first toolbar):
725 * \code
726 * KIconLoader &loader = *KGlobal::iconLoader();
727 * QPixmap pixmap = loader.loadIcon( "help" );
728 * toolBar(0)->insertButton( pixmap, 0, SIGNAL(clicked()),
729 * this, SLOT(appHelpActivated()), true, i18n("Help") );
730 * \endcode
733 void appHelpActivated( void );
736 * Apply a state change
738 * Enable and disable actions as defined in the XML rc file
739 * @since 3.1
741 virtual void slotStateChanged(const QString &newstate);
744 * Apply a state change
746 * Enable and disable actions as defined in the XML rc file,
747 * can "reverse" the state (disable the actions which should be
748 * enabled, and vice-versa) if specified.
749 * @since 3.1
751 void slotStateChanged(const QString &newstate,
752 KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this
756 * Apply a state change
758 * Enable and disable actions as defined in the XML rc file,
759 * can "reverse" the state (disable the actions which should be
760 * enabled, and vice-versa) if specified.
762 // void slotStateChanged(const QString &newstate,
763 // bool reverse); // KDE 4.0: enable this
766 * Tell the main window that it should save its settings when being closed.
767 * This is part of the auto-save-settings feature.
768 * For everything related to toolbars this happens automatically,
769 * but you have to call setSettingsDirty() in the slot that toggles
770 * the visibility of the statusbar.
772 void setSettingsDirty();
774 protected:
775 void paintEvent( QPaintEvent* e );
776 void childEvent( QChildEvent* e);
777 void resizeEvent( QResizeEvent* e);
779 * Reimplemented to call the queryClose() and queryExit() handlers.
781 * We recommend that you reimplement the handlers rather than closeEvent().
782 * If you do it anyway, ensure to call the base implementation to keep
783 * queryExit() running.
785 virtual void closeEvent ( QCloseEvent *);
787 // KDE4 This seems to be flawed to me. Either the app has only one
788 // mainwindow, so queryClose() is enough, or if it can have more of them,
789 // then the windows should take care of themselves, and queryExit()
790 // would be useful only for the annoying 'really quit' dialog, which
791 // also doesn't make sense in apps with multiple mainwindows.
792 // And saving configuration in something called queryExit()? IMHO
793 // one can e.g. use KApplication::shutDown(), which if nothing else
794 // has at least better fitting name.
795 // See also KApplication::sessionSaving().
796 // This stuff should get changed somehow, so that it at least doesn't
797 // mess with session management.
799 Called before the very last window is closed, either by the
800 user or indirectly by the session manager.
802 It is not recommended to do any user interaction in this
803 function other than indicating severe errors. Better ask the
804 user on queryClose() (see below).
806 A typical usage of queryExit() is to write configuration data back.
807 Note that the application may continue to run after queryExit()
808 (the user may have canceled a shutdown), so you should not do any cleanups
809 here. The purpose of queryExit() is purely to prepare the application
810 (with possible user interaction) so it can safely be closed later (without
811 user interaction).
813 If you need to do serious things on exit (like shutting a
814 dial-up connection down), connect to the signal
815 KApplication::shutDown().
817 Default implementation returns @p true. Returning @p false will
818 cancel the exiting. In the latter case, the last window will
819 remain visible. If KApplication::sessionSaving() is true, refusing
820 the exit will also cancel KDE logout.
822 @see queryClose()
823 @see KApplication::sessionSaving()
825 virtual bool queryExit();
828 Called before the window is closed, either by the user or indirectly by
829 the session manager.
831 The purpose of this function is to prepare the window in a way that it is
832 safe to close it, i.e. without the user losing some data.
834 Default implementation returns true. Returning @p false will cancel
835 the closing, and, if KApplication::sessionSaving() is true, it will also
836 cancel KDE logout.
838 Reimplement this function to prevent the user from losing data.
839 Example:
840 \code
841 switch ( KMessageBox::warningYesNoCancel( this,
842 i18n("Save changes to document foo?")) ) {
843 case KMessageBox::Yes :
844 // save document here. If saving fails, return false;
845 return true;
846 case KMessageBox::No :
847 return true;
848 default: // cancel
849 return false;
850 \endcode
852 Note that you should probably @em not actually close the document from
853 within this method, as it may be called by the session manager before the
854 session is saved. If the document is closed before the session save occurs,
855 its location might not be properly saved. In addition, the session shutdown
856 may be canceled, in which case the document should remain open.
858 @see queryExit()
859 @see KApplication::sessionSaving()
861 virtual bool queryClose();
864 * Save your instance-specific properties. The function is
865 * invoked when the session manager requests your application
866 * to save its state.
868 * You @em must @em not change the group of the @p kconfig object, since
869 * KMainWindow uses one group for each window. Please
870 * reimplement these function in childclasses.
872 * Note: No user interaction is allowed
873 * in this function!
876 virtual void saveProperties( KConfig* ) {}
879 * Read your instance-specific properties.
881 virtual void readProperties( KConfig* ) {}
884 * Save your application-wide properties. The function is
885 * invoked when the session manager requests your application
886 * to save its state.
888 * This function is similar to saveProperties() but is only called for
889 * the very first main window, regardless how many main window are open.
891 * Override it if you need to save other data about your documents on
892 * session end. sessionConfig is a config to which that data should be
893 * saved. Normally, you don't need this function. But if you want to save
894 * data about your documents that are not in opened windows you might need
895 * it.
897 * Default implementation does nothing.
899 virtual void saveGlobalProperties( KConfig* sessionConfig );
902 * The counterpart of saveGlobalProperties().
904 * Read the application-specific properties in again.
906 virtual void readGlobalProperties( KConfig* sessionConfig );
907 void savePropertiesInternal( KConfig*, int );
908 bool readPropertiesInternal( KConfig*, int );
911 * For inherited classes
913 bool settingsDirty() const;
915 * For inherited classes
917 QString settingsGroup() const;
919 * For inherited classes
920 * Note that the group must be set before calling
922 void saveWindowSize( KConfig * config ) const;
924 * For inherited classes
925 * Note that the group must be set before calling, and that
926 * a -geometry on the command line has priority.
928 void restoreWindowSize( KConfig * config );
930 /// parse the geometry from the geometry command line argument
931 void parseGeometry(bool parsewidth);
933 protected slots:
935 * Rebuilds the GUI after KEditToolbar changed the toolbar layout.
936 * @see configureToolbars()
938 void saveNewToolbarConfig(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow
941 * This slot does nothing.
943 * It must be reimplemented if you want
944 * to use a custom About Application dialog box. This slot is
945 * connected to the About Application entry in the menu returned
946 * by customHelpMenu.
948 * Example:
949 * \code
951 * void MyMainLevel::setupInterface()
953 * ..
954 * menuBar()->insertItem( i18n("&Help"), customHelpMenu() );
955 * ..
958 * void MyMainLevel::showAboutApplication()
960 * <activate your custom dialog>
962 * \endcode
964 virtual void showAboutApplication();
967 * This slot should only be called in case you reimplement closeEvent() and
968 * if you are using the "auto-save" feature. In all other cases,
969 * setSettingsDirty() should be called instead to benefit from the delayed
970 * saving.
972 * @see setAutoSaveSettings
973 * @see setSettingsDirty
975 * @since 3.2
977 * Example:
978 * \code
980 * void MyMainWindow::closeEvent( QCloseEvent *e )
982 * // Save settings if auto-save is enabled, and settings have changed
983 * if ( settingsDirty() && autoSaveSettings() )
984 * saveAutoSaveSettings();
985 * ..
987 * \endcode
989 void saveAutoSaveSettings();
991 private slots:
993 * Called when the app is shutting down.
995 void shuttingDown();
997 private:
998 KMenuBar *internalMenuBar();
999 KStatusBar *internalStatusBar();
1000 KHelpMenu *mHelpMenu, *helpMenu2;
1001 KXMLGUIFactory *factory_;
1002 QPtrList<KToolBar> toolbarList;
1003 protected:
1004 virtual void virtual_hook( int id, void* data );
1005 private:
1006 KMainWindowPrivate *d;
1007 void initKMainWindow(const char *name, int cflags);
1010 #define RESTORE(type) { int n = 1;\
1011 while (KMainWindow::canBeRestored(n)){\
1012 (new type)->restore(n);\
1013 n++;}}
1015 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
1018 * These global convenience functions (that come with a varying
1019 * number of template arguments) are a replacement for the RESTORE
1020 * macro provided in earlier versions of KDE. The old RESTORE macro
1021 * is still provided for backwards compatibility. See
1022 * KMainWindow documentation for more.
1024 * \since KDE 3.2
1027 template <typename T>
1028 inline void kRestoreMainWindows() {
1029 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
1030 const QString className = KMainWindow::classNameOfToplevel( n );
1031 if ( className == QString::fromLatin1( T::staticMetaObject()->className() ) )
1032 (new T)->restore( n );
1036 template <typename T0, typename T1>
1037 inline void kRestoreMainWindows() {
1038 const char * classNames[2];
1039 classNames[0] = T0::staticMetaObject()->className();
1040 classNames[1] = T1::staticMetaObject()->className();
1041 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
1042 const QString className = KMainWindow::classNameOfToplevel( n );
1043 if ( className == QString::fromLatin1( classNames[0] ) )
1044 (new T0)->restore( n );
1045 else if ( className == QString::fromLatin1( classNames[1] ) )
1046 (new T1)->restore( n );
1050 template <typename T0, typename T1, typename T2>
1051 inline void kRestoreMainWindows() {
1052 const char * classNames[3];
1053 classNames[0] = T0::staticMetaObject()->className();
1054 classNames[1] = T1::staticMetaObject()->className();
1055 classNames[2] = T2::staticMetaObject()->className();
1056 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
1057 const QString className = KMainWindow::classNameOfToplevel( n );
1058 if ( className == QString::fromLatin1( classNames[0] ) )
1059 (new T0)->restore( n );
1060 else if ( className == QString::fromLatin1( classNames[1] ) )
1061 (new T1)->restore( n );
1062 else if ( className == QString::fromLatin1( classNames[2] ) )
1063 (new T2)->restore( n );
1067 #endif