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 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:
00148 explicit KMainWindow( QWidget* parent = 0, Qt::WindowFlags f = KDE_DEFAULT_WINDOWFLAGS );
00149
00156 virtual ~KMainWindow();
00157
00182 KMenu* helpMenu( const QString &aboutAppText = QString(),
00183 bool showWhatsThis = true );
00184
00207 KMenu* customHelpMenu( bool showWhatsThis = true );
00208
00275 static bool canBeRestored( int number );
00276
00284 static const QString classNameOfToplevel( int number );
00285
00294 bool restore( int number, bool show = true );
00295
00299 bool hasMenuBar();
00300
00306 KMenuBar *menuBar();
00307
00319 KStatusBar *statusBar();
00320
00321
00325 static QList<KMainWindow*> memberList();
00326
00337 KToolBar *toolBar( const QString& name = QString() );
00338
00342 QList<KToolBar*> toolBars() const;
00343
00375 void setAutoSaveSettings( const QString & groupName = QLatin1String("MainWindow"),
00376 bool saveWindowSize = true );
00377
00383 void setAutoSaveSettings(const KConfigGroup & group,
00384 bool saveWindowSize = true);
00385
00390 void resetAutoSaveSettings();
00391
00396 bool autoSaveSettings() const;
00397
00407 QString autoSaveGroup() const;
00408
00415 KConfigGroup autoSaveConfigGroup() const;
00416
00424 virtual void applyMainWindowSettings( const KConfigGroup &config, bool force = false);
00425
00432 void saveMainWindowSettings(const KConfigGroup &config);
00433
00438 bool initialGeometrySet() const;
00439
00444 void ignoreInitialGeometry();
00445
00450 QString dbusName() const;
00451
00452 public Q_SLOTS:
00460 virtual void setCaption( const QString &caption );
00470 virtual void setCaption( const QString &caption, bool modified );
00471
00478 virtual void setPlainCaption( const QString &caption );
00479
00499 void appHelpActivated( void );
00500
00508 void setSettingsDirty();
00509
00510 protected:
00516 virtual bool event( QEvent * event );
00517
00525 virtual void closeEvent ( QCloseEvent *);
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00565 virtual bool queryExit();
00566
00601 virtual bool queryClose();
00602
00614 virtual void saveProperties( KConfigGroup & ) {}
00615
00619 virtual void readProperties( const KConfigGroup & ) {}
00620
00637 virtual void saveGlobalProperties( KConfig* sessionConfig );
00638
00644 virtual void readGlobalProperties( KConfig* sessionConfig );
00645 void savePropertiesInternal( KConfig*, int );
00646 bool readPropertiesInternal( KConfig*, int );
00647
00651 bool settingsDirty() const;
00655 void saveWindowSize( const KConfigGroup &config ) const;
00660 void restoreWindowSize( const KConfigGroup & config );
00661
00663 void parseGeometry(bool parsewidth);
00664
00665 protected Q_SLOTS:
00690 virtual void showAboutApplication();
00691
00713 void saveAutoSaveSettings();
00714
00715 protected:
00716 KMainWindow(KMainWindowPrivate &dd, QWidget *parent, Qt::WFlags f);
00717
00718 KMainWindowPrivate * const k_ptr;
00719 private:
00720 Q_PRIVATE_SLOT(k_func(), void _k_shuttingDown())
00721 Q_PRIVATE_SLOT(k_func(), void _k_slotSettingsChanged(int))
00722 };
00723
00724 #define RESTORE(type) { int n = 1;\
00725 while (KMainWindow::canBeRestored(n)){\
00726 (new type)->restore(n);\
00727 n++;}}
00728
00729 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3
00730
00738 template <typename T>
00739 inline void kRestoreMainWindows() {
00740 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00741 const QString className = KMainWindow::classNameOfToplevel( n );
00742 if ( className == QLatin1String( T::staticMetaObject.className() ) )
00743 (new T)->restore( n );
00744 }
00745 }
00746
00747 template <typename T0, typename T1>
00748 inline void kRestoreMainWindows() {
00749 const char * classNames[2];
00750 classNames[0] = T0::staticMetaObject.className();
00751 classNames[1] = T1::staticMetaObject.className();
00752 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00753 const QString className = KMainWindow::classNameOfToplevel( n );
00754 if ( className == QLatin1String( classNames[0] ) )
00755 (new T0)->restore( n );
00756 else if ( className == QLatin1String( classNames[1] ) )
00757 (new T1)->restore( n );
00758 }
00759 }
00760
00761 template <typename T0, typename T1, typename T2>
00762 inline void kRestoreMainWindows() {
00763 const char * classNames[3];
00764 classNames[0] = T0::staticMetaObject.className();
00765 classNames[1] = T1::staticMetaObject.className();
00766 classNames[2] = T2::staticMetaObject.className();
00767 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) {
00768 const QString className = KMainWindow::classNameOfToplevel( n );
00769 if ( className == QLatin1String( classNames[0] ) )
00770 (new T0)->restore( n );
00771 else if ( className == QLatin1String( classNames[1] ) )
00772 (new T1)->restore( n );
00773 else if ( className == QLatin1String( classNames[2] ) )
00774 (new T2)->restore( n );
00775 }
00776 }
00777
00778 #endif