kdeui
kmainwindow.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
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
00295 static const QString classNameOfToplevel( int number );
00296
00300
00301 virtual void show();
00302
00306
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
00380 KStatusBar *statusBar();
00381
00385 static QPtrList<KMainWindow>* memberList;
00386
00387
00392 static QPtrList<KMainWindow>* getMemberList();
00393
00404 KToolBar *toolBar( const char *name=0 );
00405
00409 QPtrListIterator<KToolBar> toolBarIterator();
00410
00415 KAccel *accel();
00416
00417 void setFrameBorderWidth( int ) {}
00418
00450 void setAutoSaveSettings( const QString & groupName = QString::fromLatin1("MainWindow"),
00451 bool saveWindowSize = true );
00452
00457 void resetAutoSaveSettings();
00458
00464 bool autoSaveSettings() const;
00465
00473 QString autoSaveGroup() const;
00474
00484 void applyMainWindowSettings(KConfig *config, const QString &groupName, bool force);
00485
00486 void applyMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
00487
00496 void saveMainWindowSettings(KConfig *config, const QString &groupName = QString::null);
00497
00516 void setStandardToolBarMenuEnabled( bool enable );
00518 bool isStandardToolBarMenuEnabled() const;
00519
00520
00541 void createStandardStatusBarAction();
00542
00546 enum StandardWindowOptions
00547 {
00553 ToolBar = 1,
00554
00558 Keys = 2,
00559
00564 StatusBar = 4,
00565
00576 Save = 8,
00577
00582 Create = 16
00583 };
00584
00596 void setupGUI( int options = ToolBar | Keys | StatusBar | Save | Create, const QString& xmlfile = QString::null );
00597
00611 void setupGUI( QSize defaultSize, int options = ToolBar | Keys | StatusBar | Save | Create, const QString& xmlfile = QString::null );
00612
00617 KAction *toolBarMenuAction();
00618
00623 void setupToolbarMenuActions();
00624
00625
00627 virtual void finalizeGUI( KXMLGUIClient *client );
00628
00632 void finalizeGUI( bool force );
00633
00638 bool initialGeometrySet() const;
00639
00644 void ignoreInitialGeometry();
00645
00661
00662 QSize sizeForCentralWidgetSize(QSize size) KDE_DEPRECATED;
00663
00667
00668 virtual void setIcon( const QPixmap & );
00669
00670 public slots:
00683 int configureToolbars();
00684
00692 virtual void setCaption( const QString &caption );
00702 virtual void setCaption( const QString &caption, bool modified );
00703
00710 virtual void setPlainCaption( const QString &caption );
00711
00733 void appHelpActivated( void );
00734
00741 virtual void slotStateChanged(const QString &newstate);
00742
00751 void slotStateChanged(const QString &newstate,
00752 KXMLGUIClient::ReverseStateChange);
00753
00754
00762
00763
00764
00772 void setSettingsDirty();
00773
00774 protected:
00775 void paintEvent( QPaintEvent* e );
00776 void childEvent( QChildEvent* e);
00777 void resizeEvent( QResizeEvent* e);
00785 virtual void closeEvent ( QCloseEvent *);
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00825 virtual bool queryExit();
00826
00861 virtual bool queryClose();
00862
00876 virtual void saveProperties( KConfig* ) {}
00877
00881 virtual void readProperties( KConfig* ) {}
00882
00899 virtual void saveGlobalProperties( KConfig* sessionConfig );
00900
00906 virtual void readGlobalProperties( KConfig* sessionConfig );
00907 void savePropertiesInternal( KConfig*, int );
00908 bool readPropertiesInternal( KConfig*, int );
00909
00913 bool settingsDirty() const;
00917 QString settingsGroup() const;
00922 void saveWindowSize( KConfig * config ) const;
00928 void restoreWindowSize( KConfig * config );
00929
00931 void parseGeometry(bool parsewidth);
00932
00933 protected slots:
00938 void saveNewToolbarConfig();
00939
00964 virtual void showAboutApplication();
00965
00989 void saveAutoSaveSettings();
00990
00991 private slots:
00995 void shuttingDown();
00996
00997 private:
00998 KMenuBar *internalMenuBar();
00999 KStatusBar *internalStatusBar();
01000 KHelpMenu *mHelpMenu, *helpMenu2;
01001 KXMLGUIFactory *factory_;
01002 QPtrList<KToolBar> toolbarList;
01003 protected:
01004 virtual void virtual_hook( int id, void* data );
01005 private:
01006 KMainWindowPrivate *d;
01007 void initKMainWindow(const char *name, int cflags);
01008 };
01009
01010 #define RESTORE(type) { int n = 1;\
01011 while (KMainWindow::canBeRestored(n)){\
01012 (new type)->restore(n);\
01013 n++;}}
01014
01015 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
01016
01027 template <typename T>
01028 inline void kRestoreMainWindows() {
01029 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01030 const QString className = KMainWindow::classNameOfToplevel( n );
01031 if ( className == QString::fromLatin1( T::staticMetaObject()->className() ) )
01032 (new T)->restore( n );
01033 }
01034 }
01035
01036 template <typename T0, typename T1>
01037 inline void kRestoreMainWindows() {
01038 const char * classNames[2];
01039 classNames[0] = T0::staticMetaObject()->className();
01040 classNames[1] = T1::staticMetaObject()->className();
01041 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01042 const QString className = KMainWindow::classNameOfToplevel( n );
01043 if ( className == QString::fromLatin1( classNames[0] ) )
01044 (new T0)->restore( n );
01045 else if ( className == QString::fromLatin1( classNames[1] ) )
01046 (new T1)->restore( n );
01047 }
01048 }
01049
01050 template <typename T0, typename T1, typename T2>
01051 inline void kRestoreMainWindows() {
01052 const char * classNames[3];
01053 classNames[0] = T0::staticMetaObject()->className();
01054 classNames[1] = T1::staticMetaObject()->className();
01055 classNames[2] = T2::staticMetaObject()->className();
01056 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
01057 const QString className = KMainWindow::classNameOfToplevel( n );
01058 if ( className == QString::fromLatin1( classNames[0] ) )
01059 (new T0)->restore( n );
01060 else if ( className == QString::fromLatin1( classNames[1] ) )
01061 (new T1)->restore( n );
01062 else if ( className == QString::fromLatin1( classNames[2] ) )
01063 (new T2)->restore( n );
01064 }
01065 }
01066
01067 #endif