KParts
mainwindow.cpp
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 #include "mainwindow.h"
00022 #include <kedittoolbar.h>
00023 #include <kparts/event.h>
00024 #include <kparts/part.h>
00025 #include <kparts/plugin.h>
00026 #include <kcomponentdata.h>
00027 #include <kstatusbar.h>
00028 #include <khelpmenu.h>
00029 #include <kstandarddirs.h>
00030 #include <QtGui/QApplication>
00031 #include <kxmlguifactory.h>
00032 #include <kconfiggroup.h>
00033
00034 #include <kdebug.h>
00035
00036 #include <assert.h>
00037
00038 using namespace KParts;
00039
00040 namespace KParts
00041 {
00042 class MainWindowPrivate
00043 {
00044 public:
00045 MainWindowPrivate()
00046 : m_activePart(0),
00047 m_bShellGUIActivated(false),
00048 m_helpMenu(0)
00049 {
00050 }
00051 ~MainWindowPrivate()
00052 {
00053 }
00054
00055 QPointer<Part> m_activePart;
00056 bool m_bShellGUIActivated;
00057 KHelpMenu *m_helpMenu;
00058 };
00059 }
00060
00061 MainWindow::MainWindow( QWidget* parent, Qt::WindowFlags f )
00062 : KXmlGuiWindow( parent, f ), d(new MainWindowPrivate())
00063 {
00064 PartBase::setPartObject( this );
00065 }
00066
00067 MainWindow::MainWindow( QWidget* parent, const char *name, Qt::WindowFlags f )
00068 : KXmlGuiWindow( parent, f ),d(new MainWindowPrivate())
00069 {
00070 setObjectName( name );
00071 PartBase::setPartObject( this );
00072 }
00073
00074 MainWindow::~MainWindow()
00075 {
00076 delete d;
00077 }
00078
00079 void MainWindow::createGUI( Part * part )
00080 {
00081 kDebug(1000) << "MainWindow::createGUI, part=" << part << " "
00082 << ( part ? part->metaObject()->className() : "" )
00083 << " " << ( part ? part->objectName() : "" )
00084 << endl;
00085
00086 KXMLGUIFactory *factory = guiFactory();
00087
00088 assert( factory );
00089
00090 if (autoSaveSettings() && settingsDirty()) {
00091
00092
00093
00094 saveAutoSaveSettings();
00095 }
00096
00097 if ( d->m_activePart )
00098 {
00099 kDebug(1000) << "deactivating GUI for " << d->m_activePart << " "
00100 << d->m_activePart->metaObject()->className()
00101 << " " << d->m_activePart->objectName() << endl;
00102
00103 GUIActivateEvent ev( false );
00104 QApplication::sendEvent( d->m_activePart, &ev );
00105
00106 factory->removeClient( d->m_activePart );
00107
00108 disconnect( d->m_activePart, SIGNAL( setWindowCaption( const QString & ) ),
00109 this, SLOT( setCaption( const QString & ) ) );
00110 disconnect( d->m_activePart, SIGNAL( setStatusBarText( const QString & ) ),
00111 this, SLOT( slotSetStatusBarText( const QString & ) ) );
00112 }
00113
00114 if ( !d->m_bShellGUIActivated )
00115 {
00116 loadPlugins( this, this, KGlobal::mainComponent() );
00117 createShellGUI();
00118 d->m_bShellGUIActivated = true;
00119 }
00120
00121 if ( part )
00122 {
00123
00124 connect( part, SIGNAL( setWindowCaption( const QString & ) ),
00125 this, SLOT( setCaption( const QString & ) ) );
00126 connect( part, SIGNAL( setStatusBarText( const QString & ) ),
00127 this, SLOT( slotSetStatusBarText( const QString & ) ) );
00128
00129 factory->addClient( part );
00130
00131 GUIActivateEvent ev( true );
00132 QApplication::sendEvent( part, &ev );
00133
00134
00135
00136
00137
00138
00139 if ( autoSaveSettings() ) {
00140 QWidget *focus = QApplication::focusWidget();
00141 applyMainWindowSettings(autoSaveConfigGroup());
00142
00143
00144
00145 if (focus)
00146 focus->setFocus();
00147 }
00148 }
00149
00150 d->m_activePart = part;
00151 }
00152
00153 void MainWindow::slotSetStatusBarText( const QString & text )
00154 {
00155 statusBar()->showMessage( text );
00156 }
00157
00158 void MainWindow::createShellGUI( bool create )
00159 {
00160 assert( d->m_bShellGUIActivated != create );
00161 d->m_bShellGUIActivated = create;
00162 if ( create )
00163 {
00164 if ( isHelpMenuEnabled() && !d->m_helpMenu )
00165 d->m_helpMenu = new KHelpMenu( this, componentData().aboutData(), true, actionCollection() );
00166
00167 QString f = xmlFile();
00168 setXMLFile( KStandardDirs::locate( "config", "ui/ui_standards.rc", componentData() ) );
00169 if ( !f.isEmpty() )
00170 setXMLFile( f, true );
00171 else
00172 {
00173 QString auto_file( componentData().componentName() + "ui.rc" );
00174 setXMLFile( auto_file, true );
00175 }
00176
00177 GUIActivateEvent ev( true );
00178 QApplication::sendEvent( this, &ev );
00179
00180 guiFactory()->addClient( this );
00181 }
00182 else
00183 {
00184 GUIActivateEvent ev( false );
00185 QApplication::sendEvent( this, &ev );
00186
00187 guiFactory()->removeClient( this );
00188 }
00189 }
00190
00191 void KParts::MainWindow::saveNewToolbarConfig()
00192 {
00193 createGUI(d->m_activePart);
00194 KConfigGroup cg(KGlobal::config(), QString());
00195 applyMainWindowSettings(cg);
00196 }
00197
00198 void KParts::MainWindow::configureToolbars()
00199 {
00200
00201 KXmlGuiWindow::configureToolbars();
00202 }
00203
00204 #include "mainwindow.moc"