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

KParts

  • sources
  • kde-4.14
  • kdelibs
  • kparts
mainwindow.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE project
2  Copyright (C) 1999 Simon Hausmann <hausmann@kde.org>
3  (C) 1999 David Faure <faure@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Library General Public License for more details.
14 
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 */
20 
21 #include "mainwindow.h"
22 #include <kedittoolbar.h>
23 #include <kparts/event.h>
24 #include <kparts/part.h>
25 #include <kparts/plugin.h>
26 #include <kcomponentdata.h>
27 #include <kstatusbar.h>
28 #include <khelpmenu.h>
29 #include <kstandarddirs.h>
30 #include <QtGui/QApplication>
31 #include <kxmlguifactory.h>
32 #include <kconfiggroup.h>
33 
34 #include <kdebug.h>
35 
36 #include <assert.h>
37 
38 using namespace KParts;
39 
40 namespace KParts
41 {
42 class MainWindowPrivate
43 {
44 public:
45  MainWindowPrivate()
46  : m_activePart(0),
47  m_bShellGUIActivated(false),
48  m_helpMenu(0)
49  {
50  }
51  ~MainWindowPrivate()
52  {
53  }
54 
55  QPointer<Part> m_activePart;
56  bool m_bShellGUIActivated;
57  KHelpMenu *m_helpMenu;
58 };
59 }
60 
61 MainWindow::MainWindow( QWidget* parent, Qt::WindowFlags f )
62  : KXmlGuiWindow( parent, f ), d(new MainWindowPrivate())
63 {
64  PartBase::setPartObject( this );
65 }
66 
67 #ifndef KDE_NO_DEPRECATED
68 MainWindow::MainWindow( QWidget* parent, const char *name, Qt::WindowFlags f )
69  : KXmlGuiWindow( parent, f ),d(new MainWindowPrivate())
70 {
71  setObjectName( name );
72  PartBase::setPartObject( this );
73 }
74 #endif
75 
76 MainWindow::~MainWindow()
77 {
78  delete d;
79 }
80 
81 void MainWindow::createGUI( Part * part )
82 {
83 #if 0
84  kDebug(1000) << "part=" << part
85  << ( part ? part->metaObject()->className() : "" )
86  << ( part ? part->objectName() : "" );
87 #endif
88  KXMLGUIFactory *factory = guiFactory();
89 
90  assert( factory );
91 
92  if ( d->m_activePart )
93  {
94 #if 0
95  kDebug(1000) << "deactivating GUI for" << d->m_activePart
96  << d->m_activePart->metaObject()->className()
97  << d->m_activePart->objectName();
98 #endif
99 
100  GUIActivateEvent ev( false );
101  QApplication::sendEvent( d->m_activePart, &ev );
102 
103  factory->removeClient( d->m_activePart );
104 
105  disconnect( d->m_activePart, SIGNAL(setWindowCaption(QString)),
106  this, SLOT(setCaption(QString)) );
107  disconnect( d->m_activePart, SIGNAL(setStatusBarText(QString)),
108  this, SLOT(slotSetStatusBarText(QString)) );
109  }
110 
111  if ( !d->m_bShellGUIActivated )
112  {
113  loadPlugins( this, this, KGlobal::mainComponent() );
114  createShellGUI();
115  d->m_bShellGUIActivated = true;
116  }
117 
118  if ( part )
119  {
120  // do this before sending the activate event
121  connect( part, SIGNAL(setWindowCaption(QString)),
122  this, SLOT(setCaption(QString)) );
123  connect( part, SIGNAL(setStatusBarText(QString)),
124  this, SLOT(slotSetStatusBarText(QString)) );
125 
126  factory->addClient( part );
127 
128  GUIActivateEvent ev( true );
129  QApplication::sendEvent( part, &ev );
130  }
131 
132  d->m_activePart = part;
133 }
134 
135 void MainWindow::slotSetStatusBarText( const QString & text )
136 {
137  statusBar()->showMessage( text );
138 }
139 
140 void MainWindow::createShellGUI( bool create )
141 {
142  assert( d->m_bShellGUIActivated != create );
143  d->m_bShellGUIActivated = create;
144  if ( create )
145  {
146  if ( isHelpMenuEnabled() && !d->m_helpMenu )
147  d->m_helpMenu = new KHelpMenu( this, componentData().aboutData(), true, actionCollection() );
148 
149  QString f = xmlFile();
150  setXMLFile( KStandardDirs::locate( "config", "ui/ui_standards.rc", componentData() ) );
151  if ( !f.isEmpty() )
152  setXMLFile( f, true );
153  else
154  {
155  QString auto_file( componentData().componentName() + "ui.rc" );
156  setXMLFile( auto_file, true );
157  }
158 
159  GUIActivateEvent ev( true );
160  QApplication::sendEvent( this, &ev );
161 
162  guiFactory()->addClient( this );
163  }
164  else
165  {
166  GUIActivateEvent ev( false );
167  QApplication::sendEvent( this, &ev );
168 
169  guiFactory()->removeClient( this );
170  }
171 }
172 
173 void KParts::MainWindow::saveNewToolbarConfig()
174 {
175  createGUI(d->m_activePart);
176  KConfigGroup cg(KGlobal::config(), QString());
177  applyMainWindowSettings(cg);
178 }
179 
180 void KParts::MainWindow::configureToolbars()
181 {
182  // No difference with base class anymore.
183  KXmlGuiWindow::configureToolbars();
184 }
185 
186 #include "mainwindow.moc"
KXmlGuiWindow::configureToolbars
virtual void configureToolbars()
QWidget
QWidget::create
void create(WId window, bool initializeWindow, bool destroyOldWindow)
KXMLGUIClient::actionCollection
virtual KActionCollection * actionCollection() const
kdebug.h
KXMLGUIFactory::removeClient
void removeClient(KXMLGUIClient *client)
QStatusBar::showMessage
void showMessage(const QString &message, int timeout)
KStandardDirs::locate
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
KXMLGUIFactory::addClient
void addClient(KXMLGUIClient *client)
QPointer
KParts::PartBase::setPartObject
void setPartObject(QObject *object)
Internal method.
Definition: part.cpp:123
KParts::MainWindow::createGUI
void createGUI(KParts::Part *part)
Create the GUI (by merging the host's and the active part's) You must call this in order to see any G...
Definition: mainwindow.cpp:81
plugin.h
kxmlguifactory.h
QObject::metaObject
virtual const QMetaObject * metaObject() const
KXMLGUIClient::setXMLFile
virtual void setXMLFile(const QString &file, bool merge=false, bool setXMLDoc=true)
KXMLGUIClient::factory
KXMLGUIFactory * factory() const
KXMLGUIClient::xmlFile
virtual QString xmlFile() const
KParts::Part
Base class for parts.
Definition: part.h:215
kstatusbar.h
kDebug
static QDebug kDebug(bool cond, int area=KDE_DEFAULT_DEBUG_AREA)
QObject::disconnect
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
KGlobal::config
KSharedConfigPtr config()
KParts::MainWindow::~MainWindow
virtual ~MainWindow()
Destructor.
Definition: mainwindow.cpp:76
KHelpMenu
KXmlGuiWindow
KXMLGUIClient::componentData
virtual KComponentData componentData() const
khelpmenu.h
QObject::setObjectName
void setObjectName(const QString &name)
QString::isEmpty
bool isEmpty() const
QCoreApplication::sendEvent
bool sendEvent(QObject *receiver, QEvent *event)
mainwindow.h
QString
kedittoolbar.h
KParts::GUIActivateEvent
This event is sent to a Part when its GUI has been activated or deactivated.
Definition: event.h:59
KMainWindow::setCaption
virtual void setCaption(const QString &caption)
KXmlGuiWindow::guiFactory
virtual KXMLGUIFactory * guiFactory()
KXMLGUIFactory
QMetaObject::className
const char * className() const
KConfigGroup
event.h
KMainWindow::statusBar
KStatusBar * statusBar()
kstandarddirs.h
KParts::MainWindow::slotSetStatusBarText
virtual void slotSetStatusBarText(const QString &)
Called when the active part wants to change the statusbar message Reimplement if your mainwindow has ...
Definition: mainwindow.cpp:135
KGlobal::mainComponent
const KComponentData & mainComponent()
KParts::PartBase::loadPlugins
void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const KComponentData &componentData)
Load the Plugins honoring the PluginLoadingMode.
Definition: part.cpp:156
KParts::MainWindow::configureToolbars
virtual void configureToolbars()
Definition: mainwindow.cpp:180
Qt::WindowFlags
typedef WindowFlags
KParts::MainWindow::createShellGUI
virtual void createShellGUI(bool create=true)
Definition: mainwindow.cpp:140
kcomponentdata.h
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KParts::MainWindow::saveNewToolbarConfig
void saveNewToolbarConfig()
Rebuilds the GUI after KEditToolbar changed the toolbar layout.
Definition: mainwindow.cpp:173
KXmlGuiWindow::isHelpMenuEnabled
bool isHelpMenuEnabled() const
KParts::MainWindow::MainWindow
MainWindow(QWidget *parent=0, Qt::WindowFlags f=KDE_DEFAULT_WINDOWFLAGS)
Constructor, same signature as KMainWindow.
Definition: mainwindow.cpp:61
part.h
kconfiggroup.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:25:36 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KParts

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • 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

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal