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 
00031 class KPopupMenu;
00032 class KXMLGUIFactory;
00033 class KConfig;
00034 class KHelpMenu;
00035 class KStatusBar;
00036 class QStatusBar;
00037 class KMenuBar;
00038 class KMWSessionManaged;
00039 class KMainWindowPrivate;
00040 class KAccel;
00041 class KToolBarMenuAction;
00042 class DCOPObject;
00043 
00044 #define KDE_DEFAULT_WINDOWFLAGS WType_TopLevel | WDestructiveClose
00045 
00046 
00098 class KDEUI_EXPORT 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 
00382 
00393     KToolBar *toolBar( const char *name=0 );
00394 
00398     QPtrListIterator<KToolBar> toolBarIterator();
00399 
00404     KAccel *accel();
00405 
00406     void setFrameBorderWidth( int ) {}
00407 
00439     void setAutoSaveSettings( const QString & groupName = QString::fromLatin1("MainWindow"),
00440                               bool saveWindowSize = true );
00441 
00446     void resetAutoSaveSettings();
00447 
00453     bool autoSaveSettings() const;
00454 
00462     QString autoSaveGroup() const;
00463 
00473     void applyMainWindowSettings(KConfig *config, const QString &groupName, bool force);
00474     // KDE4 merge with force=false
00475     void applyMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
00476 
00485     void saveMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
00486 
00505     void setStandardToolBarMenuEnabled( bool enable );
00507     bool isStandardToolBarMenuEnabled() const;
00508 
00509 
00530     void createStandardStatusBarAction();
00531 
00535     enum StandardWindowOptions
00536     {
00542         ToolBar = 1,
00543 
00547         Keys = 2,
00548 
00553         StatusBar = 4,
00554 
00565         Save = 8,
00566 
00571         Create = 16
00572     };
00573 
00585     void setupGUI( int options = ToolBar | Keys | StatusBar | Save | Create, const QString& xmlfile = QString::null );
00586 
00591     KAction *toolBarMenuAction();
00592 
00597     void setupToolbarMenuActions();
00598 
00599     // why do we support old gcc versions? using KXMLGUIBuilder::finalizeGUI;
00601     virtual void finalizeGUI( KXMLGUIClient *client );
00602 
00606     void finalizeGUI( bool force );
00607 
00612     bool initialGeometrySet() const;
00613 
00618     void ignoreInitialGeometry();
00619 
00635     // KDE4 to be removed
00636     QSize sizeForCentralWidgetSize(QSize size) KDE_DEPRECATED;
00637 
00641     // KDE4 remove
00642     virtual void setIcon( const QPixmap & );
00643 
00644 public slots:
00657    int configureToolbars(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow
00658 
00666     virtual void setCaption( const QString &caption );
00676     virtual void setCaption( const QString &caption, bool modified );
00677 
00684     virtual void setPlainCaption( const QString &caption );
00685 
00707     void appHelpActivated( void );
00708 
00715     virtual void slotStateChanged(const QString &newstate);
00716 
00725     void slotStateChanged(const QString &newstate,
00726                           KXMLGUIClient::ReverseStateChange); // KDE 4.0: remove this
00727 
00728 
00736 //     void slotStateChanged(const QString &newstate,
00737 //                           bool reverse); // KDE 4.0: enable this
00738 
00746     void setSettingsDirty();
00747 
00748 protected:
00749     void paintEvent( QPaintEvent* e );
00750     void childEvent( QChildEvent* e);
00751     void resizeEvent( QResizeEvent* e);
00759     virtual void closeEvent ( QCloseEvent *);
00760 
00761     // KDE4 This seems to be flawed to me. Either the app has only one
00762     // mainwindow, so queryClose() is enough, or if it can have more of them,
00763     // then the windows should take care of themselves, and queryExit()
00764     // would be useful only for the annoying 'really quit' dialog, which
00765     // also doesn't make sense in apps with multiple mainwindows.
00766     // And saving configuration in something called queryExit()? IMHO
00767     // one can e.g. use KApplication::shutDown(), which if nothing else
00768     // has at least better fitting name.
00769     // See also KApplication::sessionSaving().
00770     // This stuff should get changed somehow, so that it at least doesn't
00771     // mess with session management.
00799     virtual bool queryExit();
00800 
00835     virtual bool queryClose();
00836 
00850     virtual void saveProperties( KConfig* ) {}
00851 
00855     virtual void readProperties( KConfig* ) {}
00856 
00873     virtual void saveGlobalProperties( KConfig* sessionConfig );
00874 
00880     virtual void readGlobalProperties( KConfig* sessionConfig );
00881     void savePropertiesInternal( KConfig*, int );
00882     bool readPropertiesInternal( KConfig*, int );
00883 
00887     bool settingsDirty() const;
00891     QString settingsGroup() const;
00896     void saveWindowSize( KConfig * config ) const;
00902     void restoreWindowSize( KConfig * config );
00903 
00905     void parseGeometry(bool parsewidth);
00906 
00907 protected slots:
00912    void saveNewToolbarConfig(); // TODO KDE4: make virtual and reimplement in KParts::MainWindow
00913 
00938     virtual void showAboutApplication();
00939 
00963     void saveAutoSaveSettings();
00964 
00965 private slots:
00969     void shuttingDown();
00970 
00971 private:
00972     KMenuBar *internalMenuBar();
00973     KStatusBar *internalStatusBar();
00974     KHelpMenu *mHelpMenu, *helpMenu2;
00975     KXMLGUIFactory *factory_;
00976     QPtrList<KToolBar> toolbarList;
00977 protected:
00978     virtual void virtual_hook( int id, void* data );
00979 private:
00980     KMainWindowPrivate *d;
00981     void initKMainWindow(const char *name, int cflags);
00982 };
00983 
00984 #define RESTORE(type) { int n = 1;\
00985     while (KMainWindow::canBeRestored(n)){\
00986       (new type)->restore(n);\
00987       n++;}}
00988 
00989 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
00990 
01001 template <typename T>
01002 inline void kRestoreMainWindows() {
01003   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01004     const QString className = KMainWindow::classNameOfToplevel( n );
01005     if ( className == QString::fromLatin1( T::staticMetaObject()->className() ) )
01006       (new T)->restore( n );
01007   }
01008 }
01009 
01010 template <typename T0, typename T1>
01011 inline void kRestoreMainWindows() {
01012   const char * classNames[2];
01013   classNames[0] = T0::staticMetaObject()->className();
01014   classNames[1] = T1::staticMetaObject()->className();
01015   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01016     const QString className = KMainWindow::classNameOfToplevel( n );
01017     if ( className == QString::fromLatin1( classNames[0] ) )
01018       (new T0)->restore( n );
01019     else if ( className == QString::fromLatin1( classNames[1] ) )
01020       (new T1)->restore( n );
01021   }
01022 }
01023 
01024 template <typename T0, typename T1, typename T2>
01025 inline void kRestoreMainWindows() {
01026   const char * classNames[3];
01027   classNames[0] = T0::staticMetaObject()->className();
01028   classNames[1] = T1::staticMetaObject()->className();
01029   classNames[2] = T2::staticMetaObject()->className();
01030   for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01031     const QString className = KMainWindow::classNameOfToplevel( n );
01032     if ( className == QString::fromLatin1( classNames[0] ) )
01033       (new T0)->restore( n );
01034     else if ( className == QString::fromLatin1( classNames[1] ) )
01035       (new T1)->restore( n );
01036     else if ( className == QString::fromLatin1( classNames[2] ) )
01037       (new T2)->restore( n );
01038   }
01039 }
01040 
01041 #endif
KDE Logo
This file is part of the documentation for kdeui Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 30 10:12:01 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003