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
00030 #ifndef KMAINWINDOW_H
00031 #define KMAINWINDOW_H
00032
00033 #include <kdeui_export.h>
00034
00035 #include <QtGui/QMainWindow>
00036 #include <QtCore/QMetaClassInfo>
00037
00038 class KMenu;
00039 class KConfig;
00040 class KConfigGroup;
00041 class KStatusBar;
00042 class KMenuBar;
00043 class KMWSessionManager;
00044 class KMainWindowPrivate;
00045 class KToolBar;
00046
00047
00048 #define KDEUI_DECLARE_PRIVATE(classname) \
00049 inline classname ## Private *k_func() { return reinterpret_cast<classname ## Private *>(k_ptr); } \
00050 inline const classname ## Private *k_func() const { return reinterpret_cast<classname ## Private *>(k_ptr); } \
00051 friend class classname ## Private;
00052
00053
00054 #define KDE_DEFAULT_WINDOWFLAGS 0
00055
00106 class KDEUI_EXPORT KMainWindow : public QMainWindow
00107 {
00108 friend class KMWSessionManager;
00109 friend class DockResizeListener;
00110 KDEUI_DECLARE_PRIVATE(KMainWindow)
00111 Q_OBJECT
00112 Q_PROPERTY( bool hasMenuBar READ hasMenuBar )
00113 Q_PROPERTY( bool autoSaveSettings READ autoSaveSettings )
00114 Q_PROPERTY( QString autoSaveGroup READ autoSaveGroup )
00115 Q_PROPERTY( bool initialGeometrySet READ initialGeometrySet )
00116
00117 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
00216 static bool canBeRestored( int number );
00217
00225 static const QString classNameOfToplevel( int number );
00226
00265 bool restore( int number, bool show = true );
00266
00270 bool hasMenuBar();
00271
00277 KMenuBar *menuBar();
00278
00290 KStatusBar *statusBar();
00291
00292
00296 static QList<KMainWindow*> memberList();
00297
00308 KToolBar *toolBar( const QString& name = QString() );
00309
00313 QList<KToolBar*> toolBars() const;
00314
00346 void setAutoSaveSettings( const QString & groupName = QLatin1String("MainWindow"),
00347 bool saveWindowSize = true );
00348
00354 void setAutoSaveSettings(const KConfigGroup & group,
00355 bool saveWindowSize = true);
00356
00361 void resetAutoSaveSettings();
00362
00367 bool autoSaveSettings() const;
00368
00378 QString autoSaveGroup() const;
00379
00386 KConfigGroup autoSaveConfigGroup() const;
00387
00395 virtual void applyMainWindowSettings( const KConfigGroup &config, bool forceGlobal = false);
00396
00403 void saveMainWindowSettings(const KConfigGroup &config);
00404
00409 bool initialGeometrySet() const;
00410
00415 void ignoreInitialGeometry();
00416
00421 QString dbusName() const;
00422
00423 public Q_SLOTS:
00431 virtual void setCaption( const QString &caption );
00441 virtual void setCaption( const QString &caption, bool modified );
00442
00449 virtual void setPlainCaption( const QString &caption );
00450
00470 void appHelpActivated( void );
00471
00479 void setSettingsDirty();
00480
00481 protected:
00487 virtual bool event( QEvent * event );
00488
00496 virtual void closeEvent ( QCloseEvent *);
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00536 virtual bool queryExit();
00537
00572 virtual bool queryClose();
00573
00585 virtual void saveProperties( KConfigGroup & ) {}
00586
00592 virtual void readProperties( const KConfigGroup & ) {}
00593
00610 virtual void saveGlobalProperties( KConfig* sessionConfig );
00611
00617 virtual void readGlobalProperties( KConfig* sessionConfig );
00618 void savePropertiesInternal( KConfig*, int );
00619 bool readPropertiesInternal( KConfig*, int );
00620
00624 bool settingsDirty() const;
00628 void saveWindowSize( const KConfigGroup &config ) const;
00633 void restoreWindowSize( const KConfigGroup & config );
00634
00636 void parseGeometry(bool parsewidth);
00637
00638 protected Q_SLOTS:
00663 virtual void showAboutApplication();
00664
00686 void saveAutoSaveSettings();
00687
00688 protected:
00689 KMainWindow(KMainWindowPrivate &dd, QWidget *parent, Qt::WFlags f);
00690
00691 KMainWindowPrivate * const k_ptr;
00692 private:
00693 Q_PRIVATE_SLOT(k_func(), void _k_shuttingDown())
00694 Q_PRIVATE_SLOT(k_func(), void _k_slotSettingsChanged(int))
00695 Q_PRIVATE_SLOT(k_func(), void _k_slotSaveAutoSaveSize())
00696 };
00697
00723 #define RESTORE(type) { int n = 1;\
00724 while (KMainWindow::canBeRestored(n)){\
00725 (new type)->restore(n);\
00726 n++;}}
00727
00732 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
00733
00770 template <typename T>
00771 inline void kRestoreMainWindows() {
00772 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00773 const QString className = KMainWindow::classNameOfToplevel( n );
00774 if ( className == QLatin1String( T::staticMetaObject.className() ) )
00775 (new T)->restore( n );
00776 }
00777 }
00778
00779 template <typename T0, typename T1>
00780 inline void kRestoreMainWindows() {
00781 const char * classNames[2];
00782 classNames[0] = T0::staticMetaObject.className();
00783 classNames[1] = T1::staticMetaObject.className();
00784 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00785 const QString className = KMainWindow::classNameOfToplevel( n );
00786 if ( className == QLatin1String( classNames[0] ) )
00787 (new T0)->restore( n );
00788 else if ( className == QLatin1String( classNames[1] ) )
00789 (new T1)->restore( n );
00790 }
00791 }
00792
00793 template <typename T0, typename T1, typename T2>
00794 inline void kRestoreMainWindows() {
00795 const char * classNames[3];
00796 classNames[0] = T0::staticMetaObject.className();
00797 classNames[1] = T1::staticMetaObject.className();
00798 classNames[2] = T2::staticMetaObject.className();
00799 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00800 const QString className = KMainWindow::classNameOfToplevel( n );
00801 if ( className == QLatin1String( classNames[0] ) )
00802 (new T0)->restore( n );
00803 else if ( className == QLatin1String( classNames[1] ) )
00804 (new T1)->restore( n );
00805 else if ( className == QLatin1String( classNames[2] ) )
00806 (new T2)->restore( n );
00807 }
00808 }
00809
00810 #endif