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
00105 class KDEUI_EXPORT KMainWindow : public QMainWindow
00106 {
00107 friend class KMWSessionManager;
00108 friend class DockResizeListener;
00109 KDEUI_DECLARE_PRIVATE(KMainWindow)
00110 Q_OBJECT
00111 Q_PROPERTY( bool hasMenuBar READ hasMenuBar )
00112 Q_PROPERTY( bool autoSaveSettings READ autoSaveSettings )
00113 Q_PROPERTY( QString autoSaveGroup READ autoSaveGroup )
00114 Q_PROPERTY( bool initialGeometrySet READ initialGeometrySet )
00115
00116 public:
00149 explicit KMainWindow( QWidget* parent = 0, Qt::WindowFlags f = KDE_DEFAULT_WINDOWFLAGS );
00150
00157 virtual ~KMainWindow();
00158
00183 KMenu* helpMenu( const QString &aboutAppText = QString(),
00184 bool showWhatsThis = true );
00185
00208 KMenu* customHelpMenu( bool showWhatsThis = true );
00209
00276 static bool canBeRestored( int number );
00277
00285 static const QString classNameOfToplevel( int number );
00286
00295 bool restore( int number, bool show = true );
00296
00300 bool hasMenuBar();
00301
00307 KMenuBar *menuBar();
00308
00320 KStatusBar *statusBar();
00321
00322
00326 static QList<KMainWindow*> memberList();
00327
00338 KToolBar *toolBar( const QString& name = QString() );
00339
00343 QList<KToolBar*> toolBars() const;
00344
00376 void setAutoSaveSettings( const QString & groupName = QLatin1String("MainWindow"),
00377 bool saveWindowSize = true );
00378
00384 void setAutoSaveSettings(const KConfigGroup & group,
00385 bool saveWindowSize = true);
00386
00391 void resetAutoSaveSettings();
00392
00397 bool autoSaveSettings() const;
00398
00408 QString autoSaveGroup() const;
00409
00416 KConfigGroup autoSaveConfigGroup() const;
00417
00425 virtual void applyMainWindowSettings( const KConfigGroup &config, bool force = false);
00426
00433 void saveMainWindowSettings(const KConfigGroup &config);
00434
00439 bool initialGeometrySet() const;
00440
00445 void ignoreInitialGeometry();
00446
00451 QString dbusName() const;
00452
00453 public Q_SLOTS:
00461 virtual void setCaption( const QString &caption );
00471 virtual void setCaption( const QString &caption, bool modified );
00472
00479 virtual void setPlainCaption( const QString &caption );
00480
00500 void appHelpActivated( void );
00501
00509 void setSettingsDirty();
00510
00511 protected:
00517 virtual bool event( QEvent * event );
00518
00526 virtual void closeEvent ( QCloseEvent *);
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00566 virtual bool queryExit();
00567
00602 virtual bool queryClose();
00603
00615 virtual void saveProperties( KConfigGroup & ) {}
00616
00620 virtual void readProperties( const KConfigGroup & ) {}
00621
00638 virtual void saveGlobalProperties( KConfig* sessionConfig );
00639
00645 virtual void readGlobalProperties( KConfig* sessionConfig );
00646 void savePropertiesInternal( KConfig*, int );
00647 bool readPropertiesInternal( KConfig*, int );
00648
00652 bool settingsDirty() const;
00656 void saveWindowSize( const KConfigGroup &config ) const;
00661 void restoreWindowSize( const KConfigGroup & config );
00662
00664 void parseGeometry(bool parsewidth);
00665
00666 protected Q_SLOTS:
00691 virtual void showAboutApplication();
00692
00714 void saveAutoSaveSettings();
00715
00716 protected:
00717 KMainWindow(KMainWindowPrivate &dd, QWidget *parent, Qt::WFlags f);
00718
00719 KMainWindowPrivate * const k_ptr;
00720 private:
00721 Q_PRIVATE_SLOT(k_func(), void _k_shuttingDown())
00722 Q_PRIVATE_SLOT(k_func(), void _k_slotSettingsChanged(int))
00723 Q_PRIVATE_SLOT(k_func(), void _k_slotSaveAutoSaveSize())
00724 };
00725
00726 #define RESTORE(type) { int n = 1;\
00727 while (KMainWindow::canBeRestored(n)){\
00728 (new type)->restore(n);\
00729 n++;}}
00730
00731 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
00732
00740 template <typename T>
00741 inline void kRestoreMainWindows() {
00742 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00743 const QString className = KMainWindow::classNameOfToplevel( n );
00744 if ( className == QLatin1String( T::staticMetaObject.className() ) )
00745 (new T)->restore( n );
00746 }
00747 }
00748
00749 template <typename T0, typename T1>
00750 inline void kRestoreMainWindows() {
00751 const char * classNames[2];
00752 classNames[0] = T0::staticMetaObject.className();
00753 classNames[1] = T1::staticMetaObject.className();
00754 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00755 const QString className = KMainWindow::classNameOfToplevel( n );
00756 if ( className == QLatin1String( classNames[0] ) )
00757 (new T0)->restore( n );
00758 else if ( className == QLatin1String( classNames[1] ) )
00759 (new T1)->restore( n );
00760 }
00761 }
00762
00763 template <typename T0, typename T1, typename T2>
00764 inline void kRestoreMainWindows() {
00765 const char * classNames[3];
00766 classNames[0] = T0::staticMetaObject.className();
00767 classNames[1] = T1::staticMetaObject.className();
00768 classNames[2] = T2::staticMetaObject.className();
00769 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00770 const QString className = KMainWindow::classNameOfToplevel( n );
00771 if ( className == QLatin1String( classNames[0] ) )
00772 (new T0)->restore( n );
00773 else if ( className == QLatin1String( classNames[1] ) )
00774 (new T1)->restore( n );
00775 else if ( className == QLatin1String( classNames[2] ) )
00776 (new T2)->restore( n );
00777 }
00778 }
00779
00780 #endif