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