KDEUI
kmainwindow.h
Go to the documentation of this file.
00001 /* 00002 This file is part of the KDE libraries 00003 Copyright 00004 (C) 2000 Reginald Stadlbauer (reggie@kde.org) 00005 (C) 1997 Stephan Kulow (coolo@kde.org) 00006 (C) 1997-2000 Sven Radej (radej@kde.org) 00007 (C) 1997-2000 Matthias Ettrich (ettrich@kde.org) 00008 (C) 1999 Chris Schlaeger (cs@kde.org) 00009 (C) 2002 Joseph Wenninger (jowenn@kde.org) 00010 (C) 2005-2006 Hamish Rodda (rodda@kde.org) 00011 (C) 2000-2008 David Faure (faure@kde.org) 00012 00013 This library is free software; you can redistribute it and/or 00014 modify it under the terms of the GNU Library General Public 00015 License version 2 as published by the Free Software Foundation. 00016 00017 This library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 Library General Public License for more details. 00021 00022 You should have received a copy of the GNU Library General Public License 00023 along with this library; see the file COPYING.LIB. If not, write to 00024 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00025 Boston, MA 02110-1301, USA. 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 // internal, not public API, may change any time 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 // This is mostly from KDE3. TODO KDE5: remove the constructor parameter. 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 // KDE4 This seems to be flawed to me. Either the app has only one 00499 // mainwindow, so queryClose() is enough, or if it can have more of them, 00500 // then the windows should take care of themselves, and queryExit() 00501 // would be useful only for the annoying 'really quit' dialog, which 00502 // also doesn't make sense in apps with multiple mainwindows. 00503 // And saving configuration in something called queryExit()? IMHO 00504 // one can e.g. use QCoreApplication::aboutToQuit(), which if nothing else 00505 // has at least better fitting name. 00506 // See also KApplication::sessionSaving(). 00507 // This stuff should get changed somehow, so that it at least doesn't 00508 // mess with session management. 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 00725 #define RESTORE(type) { int n = 1;\ 00726 while (KMainWindow::canBeRestored(n)){\ 00727 (new type)->restore(n);\ 00728 n++;}} 00729 00736 #define KDE_RESTORE_MAIN_WINDOWS_NUM_TEMPLATE_ARGS 3 00737 00774 template <typename T> 00775 inline void kRestoreMainWindows() { 00776 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) { 00777 const QString className = KMainWindow::classNameOfToplevel( n ); 00778 if ( className == QLatin1String( T::staticMetaObject.className() ) ) 00779 (new T)->restore( n ); 00780 } 00781 } 00782 00783 template <typename T0, typename T1> 00784 inline void kRestoreMainWindows() { 00785 const char * classNames[2]; 00786 classNames[0] = T0::staticMetaObject.className(); 00787 classNames[1] = T1::staticMetaObject.className(); 00788 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) { 00789 const QString className = KMainWindow::classNameOfToplevel( n ); 00790 if ( className == QLatin1String( classNames[0] ) ) 00791 (new T0)->restore( n ); 00792 else if ( className == QLatin1String( classNames[1] ) ) 00793 (new T1)->restore( n ); 00794 } 00795 } 00796 00797 template <typename T0, typename T1, typename T2> 00798 inline void kRestoreMainWindows() { 00799 const char * classNames[3]; 00800 classNames[0] = T0::staticMetaObject.className(); 00801 classNames[1] = T1::staticMetaObject.className(); 00802 classNames[2] = T2::staticMetaObject.className(); 00803 for ( int n = 1 ; KMainWindow::canBeRestored( n ) ; ++n ) { 00804 const QString className = KMainWindow::classNameOfToplevel( n ); 00805 if ( className == QLatin1String( classNames[0] ) ) 00806 (new T0)->restore( n ); 00807 else if ( className == QLatin1String( classNames[1] ) ) 00808 (new T1)->restore( n ); 00809 else if ( className == QLatin1String( classNames[2] ) ) 00810 (new T2)->restore( n ); 00811 } 00812 } 00813 00814 #endif
KDE 4.6 API Reference