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
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef KMAINWINDOW_H
00030 #define KMAINWINDOW_H
00031
00032 #include <kdeui_export.h>
00033
00034 #include <QtGui/QMainWindow>
00035 #include <QtCore/QMetaClassInfo>
00036
00037 class KMenu;
00038 class KConfig;
00039 class KConfigGroup;
00040 class KStatusBar;
00041 class KMenuBar;
00042 class KMWSessionManager;
00043 class KMainWindowPrivate;
00044 class KToolBar;
00045
00046
00047 #define KDEUI_DECLARE_PRIVATE(classname) \
00048 inline classname ## Private *k_func() { return reinterpret_cast<classname ## Private *>(k_ptr); } \
00049 inline const classname ## Private *k_func() const { return reinterpret_cast<classname ## Private *>(k_ptr); } \
00050 friend class classname ## Private;
00051
00052 #define KDE_DEFAULT_WINDOWFLAGS 0
00053
00105 class KDEUI_EXPORT KMainWindow : public QMainWindow
00106 {
00107 friend class KMWSessionManager;
00108 KDEUI_DECLARE_PRIVATE(KMainWindow)
00109 Q_OBJECT
00110 Q_PROPERTY( bool hasMenuBar READ hasMenuBar )
00111 Q_PROPERTY( bool autoSaveSettings READ autoSaveSettings )
00112 Q_PROPERTY( QString autoSaveGroup READ autoSaveGroup )
00113 Q_PROPERTY( bool initialGeometrySet READ initialGeometrySet )
00114
00115 public:
00150 explicit KMainWindow( QWidget* parent = 0, Qt::WindowFlags f = KDE_DEFAULT_WINDOWFLAGS );
00151
00158 virtual ~KMainWindow();
00159
00184 KMenu* helpMenu( const QString &aboutAppText = QString(),
00185 bool showWhatsThis = true );
00186
00209 KMenu* customHelpMenu( bool showWhatsThis = true );
00210
00277 static bool canBeRestored( int number );
00278
00286 static const QString classNameOfToplevel( int number );
00287
00296 bool restore( int number, bool show = true );
00297
00301 bool hasMenuBar();
00302
00308 KMenuBar *menuBar();
00309
00321 KStatusBar *statusBar();
00322
00323
00327 static QList<KMainWindow*> memberList();
00328
00339 KToolBar *toolBar( const QString& name = QString() );
00340
00344 QList<KToolBar*> toolBars() const;
00345
00377 void setAutoSaveSettings( const QString & groupName = QLatin1String("MainWindow"),
00378 bool saveWindowSize = true );
00379
00384 void resetAutoSaveSettings();
00385
00390 bool autoSaveSettings() const;
00391
00398 QString autoSaveGroup() const;
00399
00407 virtual void applyMainWindowSettings( const KConfigGroup &config, bool force = false);
00408
00415 void saveMainWindowSettings(const KConfigGroup &config);
00416
00421 bool initialGeometrySet() const;
00422
00427 void ignoreInitialGeometry();
00428
00433 QString dbusName() const;
00434
00435 public Q_SLOTS:
00443 virtual void setCaption( const QString &caption );
00453 virtual void setCaption( const QString &caption, bool modified );
00454
00461 virtual void setPlainCaption( const QString &caption );
00462
00482 void appHelpActivated( void );
00483
00491 void setSettingsDirty();
00492
00493 protected:
00499 virtual bool event( QEvent * event );
00500
00508 virtual void closeEvent ( QCloseEvent *);
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00548 virtual bool queryExit();
00549
00584 virtual bool queryClose();
00585
00597 virtual void saveProperties( KConfigGroup & ) {}
00598
00602 virtual void readProperties( const KConfigGroup & ) {}
00603
00620 virtual void saveGlobalProperties( KConfig* sessionConfig );
00621
00627 virtual void readGlobalProperties( KConfig* sessionConfig );
00628 void savePropertiesInternal( KConfig*, int );
00629 bool readPropertiesInternal( KConfig*, int );
00630
00634 bool settingsDirty() const;
00638 void saveWindowSize( const KConfigGroup &config ) const;
00643 void restoreWindowSize( const KConfigGroup & config );
00644
00646 void parseGeometry(bool parsewidth);
00647
00648 protected Q_SLOTS:
00673 virtual void showAboutApplication();
00674
00696 void saveAutoSaveSettings();
00697
00698 protected:
00699 KMainWindow(KMainWindowPrivate &dd, QWidget *parent, Qt::WFlags f);
00700
00701 KMainWindowPrivate * const k_ptr;
00702 private:
00703 Q_PRIVATE_SLOT(k_func(), void _k_shuttingDown())
00704 };
00705
00706 #define RESTORE(type) { int n = 1;\
00707 while (KMainWindow::canBeRestored(n)){\
00708 (new type)->restore(n);\
00709 n++;}}
00710
00711 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
00712
00720 template <typename T>
00721 inline void kRestoreMainWindows() {
00722 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00723 const QString className = KMainWindow::classNameOfToplevel( n );
00724 if ( className == QLatin1String( T::staticMetaObject.className() ) )
00725 (new T)->restore( n );
00726 }
00727 }
00728
00729 template <typename T0, typename T1>
00730 inline void kRestoreMainWindows() {
00731 const char * classNames[2];
00732 classNames[0] = T0::staticMetaObject.className();
00733 classNames[1] = T1::staticMetaObject.className();
00734 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00735 const QString className = KMainWindow::classNameOfToplevel( n );
00736 if ( className == QLatin1String( classNames[0] ) )
00737 (new T0)->restore( n );
00738 else if ( className == QLatin1String( classNames[1] ) )
00739 (new T1)->restore( n );
00740 }
00741 }
00742
00743 template <typename T0, typename T1, typename T2>
00744 inline void kRestoreMainWindows() {
00745 const char * classNames[3];
00746 classNames[0] = T0::staticMetaObject.className();
00747 classNames[1] = T1::staticMetaObject.className();
00748 classNames[2] = T2::staticMetaObject.className();
00749 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00750 const QString className = KMainWindow::classNameOfToplevel( n );
00751 if ( className == QLatin1String( classNames[0] ) )
00752 (new T0)->restore( n );
00753 else if ( className == QLatin1String( classNames[1] ) )
00754 (new T1)->restore( n );
00755 else if ( className == QLatin1String( classNames[2] ) )
00756 (new T2)->restore( n );
00757 }
00758 }
00759
00760 #endif