KDE3Support
dockmainwindow3.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
00022 #include "dockmainwindow3.h"
00023 #include <kparts/event.h>
00024 #include <kparts/part.h>
00025 #include <kparts/plugin.h>
00026 #include <kstatusbar.h>
00027 #include <kcomponentdata.h>
00028 #include <khelpmenu.h>
00029 #include <kstandarddirs.h>
00030 #include <QtGui/QApplication>
00031
00032 #include <kdebug.h>
00033 #include <kxmlguifactory.h>
00034
00035 #include <assert.h>
00036
00037 using namespace KParts;
00038
00039 namespace KParts
00040 {
00041 class DockMainWindow3Private
00042 {
00043 public:
00044 DockMainWindow3Private()
00045 {
00046 m_activePart = 0;
00047 m_bShellGUIActivated = false;
00048 m_helpMenu = 0;
00049 }
00050 ~DockMainWindow3Private()
00051 {
00052 }
00053
00054 QPointer<Part> m_activePart;
00055 bool m_bShellGUIActivated;
00056 KHelpMenu *m_helpMenu;
00057 };
00058 }
00059
00060 DockMainWindow3::DockMainWindow3( QWidget* parent, const char *name, Qt::WFlags f )
00061 : K3DockMainWindow( parent, name, f )
00062 {
00063 d = new DockMainWindow3Private();
00064 PartBase::setPartObject( this );
00065 setAttribute( Qt::WA_DeleteOnClose );
00066 }
00067
00068 DockMainWindow3::~DockMainWindow3()
00069 {
00070 delete d;
00071 }
00072
00073 void DockMainWindow3::createGUI( Part * part )
00074 {
00075 kDebug(1000) << QString("DockMainWindow3::createGUI for %1").arg(part?part->name():"0L");
00076
00077 KXMLGUIFactory *factory = guiFactory();
00078
00079 setUpdatesEnabled( false );
00080
00081 Q3PtrList<Plugin> plugins;
00082
00083 if ( d->m_activePart )
00084 {
00085 kDebug(1000) << QString("deactivating GUI for %1").arg(d->m_activePart->name());
00086
00087 GUIActivateEvent ev( false );
00088 QApplication::sendEvent( d->m_activePart, &ev );
00089
00090 factory->removeClient( d->m_activePart );
00091
00092 disconnect( d->m_activePart, SIGNAL( setWindowCaption( const QString & ) ),
00093 this, SLOT( setCaption( const QString & ) ) );
00094 disconnect( d->m_activePart, SIGNAL( setStatusBarText( const QString & ) ),
00095 this, SLOT( slotSetStatusBarText( const QString & ) ) );
00096 }
00097
00098 if ( !d->m_bShellGUIActivated )
00099 {
00100 loadPlugins( this, this, KGlobal::mainComponent() );
00101 createShellGUI();
00102 d->m_bShellGUIActivated = true;
00103 }
00104
00105 if ( part )
00106 {
00107
00108 connect( part, SIGNAL( setWindowCaption( const QString & ) ),
00109 this, SLOT( setCaption( const QString & ) ) );
00110 connect( part, SIGNAL( setStatusBarText( const QString & ) ),
00111 this, SLOT( slotSetStatusBarText( const QString & ) ) );
00112
00113 factory->addClient( part );
00114
00115 GUIActivateEvent ev( true );
00116 QApplication::sendEvent( part, &ev );
00117
00118 }
00119
00120 setUpdatesEnabled( true );
00121
00122 d->m_activePart = part;
00123 }
00124
00125 void DockMainWindow3::slotSetStatusBarText( const QString & text )
00126 {
00127 statusBar()->message( text );
00128 }
00129
00130 void DockMainWindow3::createShellGUI( bool create )
00131 {
00132 assert( d->m_bShellGUIActivated != create );
00133 d->m_bShellGUIActivated = create;
00134 if ( create )
00135 {
00136 if ( isHelpMenuEnabled() )
00137 d->m_helpMenu = new KHelpMenu( this, componentData().aboutData(), true, actionCollection() );
00138
00139 QString f = xmlFile();
00140 setXMLFile( KStandardDirs::locate( "config", "ui/ui_standards.rc", componentData() ) );
00141 if ( !f.isEmpty() )
00142 setXMLFile( f, true );
00143 else
00144 {
00145 QString auto_file( componentData().componentName() + "ui.rc" );
00146 setXMLFile( auto_file, true );
00147 }
00148
00149 GUIActivateEvent ev( true );
00150 QApplication::sendEvent( this, &ev );
00151
00152 guiFactory()->addClient( this );
00153
00154 }
00155 else
00156 {
00157 GUIActivateEvent ev( false );
00158 QApplication::sendEvent( this, &ev );
00159
00160 guiFactory()->removeClient( this );
00161 }
00162 }
00163
00164 #include "dockmainwindow3.moc"