kdeui Library API Documentation

kmainwindow.h

00001 /*
00002     This file is part of the KDE libraries
00003 
00004     This library is free software; you can redistribute it and/or
00005     modify it under the terms of the GNU Library General Public
00006     License version 2 as published by the Free Software Foundation.
00007 
00008     This library is distributed in the hope that it will be useful,
00009     but WITHOUT ANY WARRANTY; without even the implied warranty of
00010     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011     Library General Public License for more details.
00012 
00013     You should have received a copy of the GNU Library General Public License
00014     along with this library; see the file COPYING.LIB.  If not, write to
00015     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00016     Boston, MA 02111-1307, USA.
00017 
00018 
00019 */
00020 
00021 #ifndef KMAINWINDOW_H
00022 #define KMAINWINDOW_H
00023 
00024 #include "kxmlguifactory.h"
00025 #include "kxmlguiclient.h"
00026 #include "kxmlguibuilder.h"
00027 #include <qmainwindow.h>
00028 #include <qmetaobject.h>
00029 #include <ktoolbar.h>
00030 #include <kdemacros.h>
00031 
00032 class KPopupMenu;
00033 class KXMLGUIFactory;
00034 class KConfig;
00035 class KHelpMenu;
00036 class KStatusBar;
00037 class QStatusBar;
00038 class KMenuBar;
00039 class KMWSessionManaged;
00040 class KMainWindowPrivate;
00041 class KAccel;
00042 class KToolBarMenuAction;
00043 class DCOPObject;
00044 
00045 #define KDE_DEFAULT_WINDOWFLAGS WType_TopLevel | WDestructiveClose
00046 
00047 
00098 class KMainWindow : public QMainWindow, public KXMLGUIBuilder, virtual public KXMLGUIClient
00099 {
00100     friend class KMWSessionManaged;
00101     Q_OBJECT
00102 
00103 public:
00136     KMainWindow( QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
00137 
00148     enum CreationFlags
00149     {
00150         NoDCOPObject = 1
00151     };
00152 
00158     KMainWindow( int cflags, QWidget* parent = 0, const char *name = 0, WFlags f = WType_TopLevel | WDestructiveClose );
00159 
00166     virtual ~KMainWindow();
00167 
00192     KPopupMenu* helpMenu( const QString &aboutAppText = QString::null,
00193               bool showWhatsThis = true );
00194 
00217     KPopupMenu* customHelpMenu( bool showWhatsThis = true );
00218 
00285     static bool canBeRestored( int number );
00286 
00294     // KDE 4 return QCString - QObject::className() returns const char*
00295     static const QString classNameOfToplevel( int number );
00296 
00300     // KDE4 remove this method if this has been fixed in Qt
00301     virtual void show();
00302 
00306     // KDE4 remove this method if this has been fixed in Qt
00307     virtual void hide();
00308 
00317     bool restore( int number, bool show = true );
00318 
00319     virtual KXMLGUIFactory *guiFactory();
00320 
00340     void createGUI( const QString &xmlfile = QString::null, bool _conserveMemory = true );
00341 
00348     void setHelpMenuEnabled(bool showHelpMenu = true);
00349 
00353     bool isHelpMenuEnabled();
00354 
00355 
00360      bool hasMenuBar();
00361 
00367     KMenuBar *menuBar();
00368 
00375     KStatusBar *statusBar();
00376 
00380     static QPtrList<KMainWindow>* memberList;
00381 
00392     KToolBar *toolBar( const char *name=0 );
00393 
00397     QPtrListIterator<KToolBar> toolBarIterator();
00398 
00403     KAccel *accel();
00404 
00405     void setFrameBorderWidth( int ) {}
00406 
00438     void setAutoSaveSettings( const QString & groupName = QString::fromLatin1("MainWindow"),
00439                               bool saveWindowSize = true );
00440 
00445     void resetAutoSaveSettings();
00446 
00452     bool autoSaveSettings() const;
00453 
00461     QString autoSaveGroup() const;
00462 
00472     void applyMainWindowSettings(KConfig *config, const QString &groupName, bool force);
00473     // KDE4 merge with force=false
00474     void applyMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
00475 
00484     void saveMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
00485 
00504     void setStandardToolBarMenuEnabled( bool enable );
00506     bool isStandardToolBarMenuEnabled() const;
00507 
00508 
00529     void createStandardStatusBarAction();
00530 
00534     enum StandardWindowOptions
00535     {
00544         ToolBar = 1,
00545 
00549         Keys = 2,
00550 
00555         StatusBar = 4,
00556 
00567         Save = 8,
00568 
00573         Create = 16
00574     };
00575 
00587     void setupGUI( int options = ToolBar | Keys | StatusBar | Save | Create, const QString& xmlfile = QString::null );
00588 
00593     KAction *toolBarMenuAction();
00594 
00599     void setupToolbarMenuActions();
00600 
00601     // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI;
00603     virtual void finalizeGUI( KXMLGUIClient *client );
00604 
00608     void finalizeGUI( bool force );
00609 
00614     bool initialGeometrySet() const;
00615 
00620     void ignoreInitialGeometry();
00621 
00637     // KDE4 to be removed
00638     QSize sizeForCentralWidgetSize(QSize size) KDE_DEPRECATED;
00639 
00643     // KDE4 remove
00644     virtual void setIcon( const QPixmap & );
00645 
00646 public slots:
00659    int configureToolbars(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow
00660 
00668     virtual void setCaption( const QString &caption );
00678     virtual void setCaption( const QString &caption, bool modified );
00679 
00686     virtual void setPlainCaption( const QString &caption );
00687 
00709     void appHelpActivated( void );
00710 
00717     virtual void slotStateChanged(const QString &newstate);
00718 
00727     void slotStateChanged(const QString &newstate,
00728                           KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this
00729 
00730 
00738 //     void slotStateChanged(const QString &newstate,
00739 //                           bool reverse); // KDE 4.0: enable this
00740 
00748     void setSettingsDirty();
00749 
00750 protected:
00751     void paintEvent( QPaintEvent* e );
00752     void childEvent( QChildEvent* e);
00753     void resizeEvent( QResizeEvent* e);
00761     virtual void closeEvent ( QCloseEvent *);
00762 
00763     // KDE4 This seems to be flawed to me. Either the app has only one
00764     // mainwindow, so queryClose() is enough, or if it can have more of them,
00765     // then the windows should take care of themselves, and queryExit()
00766     // would be useful only for the annoying 'really quit' dialog, which
00767     // also doesn't make sense in apps with multiple mainwindows.
00768     // And saving configuration in something called queryExit()? IMHO
00769     // one can e.g. use KApplication::shutDown(), which if nothing else
00770     // has at least better fitting name.
00771     // See also KApplication::sessionSaving().
00772     // This stuff should get changed somehow, so that it at least doesn't
00773     // mess with session management.
00801     virtual bool queryExit();
00802 
00837     virtual bool queryClose();
00838 
00852     virtual void saveProperties( KConfig* ) {}
00853 
00857     virtual void readProperties( KConfig* ) {}
00858 
00875     virtual void saveGlobalProperties( KConfig* sessionConfig );
00876 
00882     virtual void readGlobalProperties( KConfig* sessionConfig );
00883     void savePropertiesInternal( KConfig*, int );
00884     bool readPropertiesInternal( KConfig*, int );
00885 
00889     bool settingsDirty() const;
00893     QString settingsGroup() const;
00898     void saveWindowSize( KConfig * config ) const;
00904     void restoreWindowSize( KConfig * config );
00905 
00907     void parseGeometry(bool parsewidth);
00908 
00909 protected slots:
00914    void saveNewToolbarConfig(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow
00915 
00940     virtual void showAboutApplication();
00941 
00965     void saveAutoSaveSettings();
00966 
00967 private slots:
00971     void shuttingDown();
00972 
00973 private:
00974     KMenuBar *internalMenuBar();
00975     KStatusBar *internalStatusBar();
00976     KHelpMenu *mHelpMenu, *helpMenu2;
00977     KXMLGUIFactory *factory_;
00978     QPtrList<KToolBar> toolbarList;
00979 protected:
00980     virtual void virtual_hook( int id, void* data );
00981 private:
00982     KMainWindowPrivate *d;
00983     void initKMainWindow(const char *name, int cflags);
00984 };
00985 
00986 #define RESTORE(type) { int n = 1;\
00987     while (KMainWindow::canBeRestored(n)){\
00988       (new type)->restore(n);\
00989       n++;}}
00990 
00991 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
00992 
01003 template <typename T>
01004 inline void kRestoreMainWindows() {
01005   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01006     const QString className = KMainWindow::classNameOfToplevel( n );
01007     if ( className == QString::fromLatin1( T::staticMetaObject()->className() ) )
01008       (new T)->restore( n );
01009   }
01010 }
01011 
01012 template <typename T0, typename T1>
01013 inline void kRestoreMainWindows() {
01014   const char * classNames[2];
01015   classNames[0] = T0::staticMetaObject()->className();
01016   classNames[1] = T1::staticMetaObject()->className();
01017   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01018     const QString className = KMainWindow::classNameOfToplevel( n );
01019     if ( className == QString::fromLatin1( classNames[0] ) )
01020       (new T0)->restore( n );
01021     else if ( className == QString::fromLatin1( classNames[1] ) )
01022       (new T1)->restore( n );
01023   }
01024 }
01025 
01026 template <typename T0, typename T1, typename T2>
01027 inline void kRestoreMainWindows() {
01028   const char * classNames[3];
01029   classNames[0] = T0::staticMetaObject()->className();
01030   classNames[1] = T1::staticMetaObject()->className();
01031   classNames[2] = T1::staticMetaObject()->className();
01032   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01033     const QString className = KMainWindow::classNameOfToplevel( n );
01034     if ( className == QString::fromLatin1( classNames[0] ) )
01035       (new T0)->restore( n );
01036     else if ( className == QString::fromLatin1( classNames[1] ) )
01037       (new T1)->restore( n );
01038     else if ( className == QString::fromLatin1( classNames[2] ) )
01039       (new T2)->restore( n );
01040   }
01041 }
01042 
01043 #endif
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sun Jan 15 13:32:54 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003