• Skip to content
  • Skip to link menu
KDE 4.6 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

KParts

mainwindow.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002    Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
00003              (C) 1999 David Faure <faure@kde.org>
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public License
00016    along with this library; see the file COPYING.LIB.  If not, write to
00017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018    Boston, MA 02110-1301, USA.
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 #ifndef KDE_NO_DEPRECATED
00068 MainWindow::MainWindow( QWidget* parent, const char *name, Qt::WindowFlags f )
00069   : KXmlGuiWindow( parent, f ),d(new MainWindowPrivate())
00070 {
00071   setObjectName( name );
00072   PartBase::setPartObject( this );
00073 }
00074 #endif
00075 
00076 MainWindow::~MainWindow()
00077 {
00078   delete d;
00079 }
00080 
00081 void MainWindow::createGUI( Part * part )
00082 {
00083 #if 0
00084   kDebug(1000) << "part=" << part
00085                 << ( part ? part->metaObject()->className() : "" )
00086                 << ( part ? part->objectName() : "" );
00087 #endif
00088   KXMLGUIFactory *factory = guiFactory();
00089 
00090   assert( factory );
00091 
00092   if ( d->m_activePart )
00093   {
00094 #if 0
00095     kDebug(1000) << "deactivating GUI for" << d->m_activePart
00096                   << d->m_activePart->metaObject()->className()
00097                   << d->m_activePart->objectName();
00098 #endif
00099 
00100     GUIActivateEvent ev( false );
00101     QApplication::sendEvent( d->m_activePart, &ev );
00102 
00103     factory->removeClient( d->m_activePart );
00104 
00105     disconnect( d->m_activePart, SIGNAL( setWindowCaption( const QString & ) ),
00106              this, SLOT( setCaption( const QString & ) ) );
00107     disconnect( d->m_activePart, SIGNAL( setStatusBarText( const QString & ) ),
00108              this, SLOT( slotSetStatusBarText( const QString & ) ) );
00109   }
00110 
00111   if ( !d->m_bShellGUIActivated )
00112   {
00113     loadPlugins( this, this, KGlobal::mainComponent() );
00114     createShellGUI();
00115     d->m_bShellGUIActivated = true;
00116   }
00117 
00118   if ( part )
00119   {
00120     // do this before sending the activate event
00121     connect( part, SIGNAL( setWindowCaption( const QString & ) ),
00122              this, SLOT( setCaption( const QString & ) ) );
00123     connect( part, SIGNAL( setStatusBarText( const QString & ) ),
00124              this, SLOT( slotSetStatusBarText( const QString & ) ) );
00125 
00126     factory->addClient( part );
00127 
00128     GUIActivateEvent ev( true );
00129     QApplication::sendEvent( part, &ev );
00130   }
00131 
00132   d->m_activePart = part;
00133 }
00134 
00135 void MainWindow::slotSetStatusBarText( const QString & text )
00136 {
00137   statusBar()->showMessage( text );
00138 }
00139 
00140 void MainWindow::createShellGUI( bool create )
00141 {
00142     assert( d->m_bShellGUIActivated != create );
00143     d->m_bShellGUIActivated = create;
00144     if ( create )
00145     {
00146         if ( isHelpMenuEnabled() && !d->m_helpMenu )
00147             d->m_helpMenu = new KHelpMenu( this, componentData().aboutData(), true, actionCollection() );
00148 
00149         QString f = xmlFile();
00150         setXMLFile( KStandardDirs::locate( "config", "ui/ui_standards.rc", componentData() ) );
00151         if ( !f.isEmpty() )
00152             setXMLFile( f, true );
00153         else
00154         {
00155             QString auto_file( componentData().componentName() + "ui.rc" );
00156             setXMLFile( auto_file, true );
00157         }
00158 
00159         GUIActivateEvent ev( true );
00160         QApplication::sendEvent( this, &ev );
00161 
00162         guiFactory()->addClient( this );
00163     }
00164     else
00165     {
00166         GUIActivateEvent ev( false );
00167         QApplication::sendEvent( this, &ev );
00168 
00169         guiFactory()->removeClient( this );
00170     }
00171 }
00172 
00173 void KParts::MainWindow::saveNewToolbarConfig()
00174 {
00175     createGUI(d->m_activePart);
00176     KConfigGroup cg(KGlobal::config(), QString());
00177     applyMainWindowSettings(cg);
00178 }
00179 
00180 void KParts::MainWindow::configureToolbars()
00181 {
00182     // No difference with base class anymore.
00183     KXmlGuiWindow::configureToolbars();
00184 }
00185 
00186 #include "mainwindow.moc"

KParts

Skip menu "KParts"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.3
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal