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

KParts

  • 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
38using namespace KParts;
39
40namespace KParts
41{
42class MainWindowPrivate
43{
44public:
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
61MainWindow::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
68MainWindow::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
76MainWindow::~MainWindow()
77{
78 delete d;
79}
80
81void 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
135void MainWindow::slotSetStatusBarText( const QString & text )
136{
137 statusBar()->showMessage( text );
138}
139
140void 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
173void KParts::MainWindow::saveNewToolbarConfig()
174{
175 createGUI(d->m_activePart);
176 KConfigGroup cg(KGlobal::config(), QString());
177 applyMainWindowSettings(cg);
178}
179
180void KParts::MainWindow::configureToolbars()
181{
182 // No difference with base class anymore.
183 KXmlGuiWindow::configureToolbars();
184}
185
186#include "mainwindow.moc"
KConfigGroup
KHelpMenu
KMainWindow::statusBar
KStatusBar * statusBar()
KMainWindow::setCaption
virtual void setCaption(const QString &caption)
KParts::GUIActivateEvent
This event is sent to a Part when its GUI has been activated or deactivated.
Definition: event.h:60
KParts::MainWindow::MainWindow
MainWindow(QWidget *parent=0, Qt::WindowFlags f=KDE_DEFAULT_WINDOWFLAGS)
Constructor, same signature as KMainWindow.
Definition: mainwindow.cpp:61
KParts::MainWindow::saveNewToolbarConfig
void saveNewToolbarConfig()
Rebuilds the GUI after KEditToolbar changed the toolbar layout.
Definition: mainwindow.cpp:173
KParts::MainWindow::createShellGUI
virtual void createShellGUI(bool create=true)
Definition: mainwindow.cpp:140
KParts::MainWindow::~MainWindow
virtual ~MainWindow()
Destructor.
Definition: mainwindow.cpp:76
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
KParts::MainWindow::configureToolbars
virtual void configureToolbars()
Definition: mainwindow.cpp:180
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
KParts::PartBase::setPartObject
void setPartObject(QObject *object)
Internal method.
Definition: part.cpp:123
KParts::PartBase::loadPlugins
void loadPlugins(QObject *parent, KXMLGUIClient *parentGUIClient, const KComponentData &componentData)
Load the Plugins honoring the PluginLoadingMode.
Definition: part.cpp:156
KParts::Part
Base class for parts.
Definition: part.h:216
KStandardDirs::locate
static QString locate(const char *type, const QString &filename, const KComponentData &cData=KGlobal::mainComponent())
KXMLGUIClient::xmlFile
virtual QString xmlFile() const
KXMLGUIClient::actionCollection
virtual KActionCollection * actionCollection() const
KXMLGUIClient::setXMLFile
virtual void setXMLFile(const QString &file, bool merge=false, bool setXMLDoc=true)
KXMLGUIClient::componentData
virtual KComponentData componentData() const
KXMLGUIClient::factory
KXMLGUIFactory * factory() const
KXMLGUIFactory
KXMLGUIFactory::removeClient
void removeClient(KXMLGUIClient *client)
KXMLGUIFactory::addClient
void addClient(KXMLGUIClient *client)
KXmlGuiWindow
KXmlGuiWindow::guiFactory
virtual KXMLGUIFactory * guiFactory()
KXmlGuiWindow::configureToolbars
virtual void configureToolbars()
KXmlGuiWindow::isHelpMenuEnabled
bool isHelpMenuEnabled() const
QWidget
event.h
kDebug
#define kDebug
kcomponentdata.h
kconfiggroup.h
kdebug.h
kedittoolbar.h
khelpmenu.h
kstandarddirs.h
kstatusbar.h
kxmlguifactory.h
mainwindow.h
KGlobal::mainComponent
const KComponentData & mainComponent()
KGlobal::config
KSharedConfigPtr config()
KParts
name
const char * name(StandardAction id)
create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
part.h
plugin.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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