KParts

mainwindow.cpp
1/*
2 This file is part of the KDE project
3 SPDX-FileCopyrightText: 1999 Simon Hausmann <hausmann@kde.org>
4 SPDX-FileCopyrightText: 1999 David Faure <faure@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "mainwindow.h"
10
11#include "guiactivateevent.h"
12#include "part.h"
13
14#include <KAboutData>
15#include <KActionCollection>
16#include <KConfigGroup>
17#include <KEditToolBar>
18#include <KHelpMenu>
19#include <KSharedConfig>
20#include <KXMLGUIFactory>
21
22#include <QAction>
23#include <QApplication>
24#include <QPointer>
25#include <QStatusBar>
26
27using namespace KParts;
28
29namespace KParts
30{
31class MainWindowPrivate
32{
33public:
34 MainWindowPrivate()
35 : m_activePart(nullptr)
36 {
37 }
38 ~MainWindowPrivate()
39 {
40 }
41
42 QPointer<Part> m_activePart;
43 bool m_bShellGUIActivated = false;
44 KHelpMenu *m_helpMenu = nullptr;
45 bool m_manageWindowTitle = true;
46};
47}
48
50 : KXmlGuiWindow(parent, f)
51 , d(new MainWindowPrivate())
52{
54}
55
56MainWindow::~MainWindow() = default;
57
59{
60#if 0
61 // qDebug() << "part=" << part
62 << (part ? part->metaObject()->className() : "")
63 << (part ? part->objectName() : "");
64#endif
65 KXMLGUIFactory *factory = guiFactory();
66
67 Q_ASSERT(factory);
68
69 if (d->m_activePart) {
70#if 0
71 // qDebug() << "deactivating GUI for" << d->m_activePart
72 << d->m_activePart->metaObject()->className()
73 << d->m_activePart->objectName();
74#endif
75
76 GUIActivateEvent ev(false);
77 QApplication::sendEvent(d->m_activePart, &ev);
78
79 factory->removeClient(d->m_activePart);
80
81 disconnect(d->m_activePart.data(), &Part::setWindowCaption, this, static_cast<void (MainWindow::*)(const QString &)>(&MainWindow::setCaption));
83 }
84
85 if (!d->m_bShellGUIActivated) {
86 createShellGUI();
87 d->m_bShellGUIActivated = true;
88 }
89
90 if (part) {
91 // do this before sending the activate event
92 if (d->m_manageWindowTitle) {
93 connect(part, &Part::setWindowCaption, this, static_cast<void (MainWindow::*)(const QString &)>(&MainWindow::setCaption));
94 }
96
97 factory->addClient(part);
98
99 GUIActivateEvent ev(true);
100 QApplication::sendEvent(part, &ev);
101 }
102
103 d->m_activePart = part;
104}
105
107{
108 statusBar()->showMessage(text);
109}
110
111void MainWindow::createShellGUI(bool create)
112{
113 Q_ASSERT(d->m_bShellGUIActivated != create);
114 d->m_bShellGUIActivated = create;
115 if (create) {
116 if (isHelpMenuEnabled() && !d->m_helpMenu) {
117 d->m_helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true);
118
120 QAction *helpContentsAction = d->m_helpMenu->action(KHelpMenu::menuHelpContents);
121 QAction *whatsThisAction = d->m_helpMenu->action(KHelpMenu::menuWhatsThis);
122 QAction *reportBugAction = d->m_helpMenu->action(KHelpMenu::menuReportBug);
123 QAction *switchLanguageAction = d->m_helpMenu->action(KHelpMenu::menuSwitchLanguage);
124 QAction *aboutAppAction = d->m_helpMenu->action(KHelpMenu::menuAboutApp);
125 QAction *aboutKdeAction = d->m_helpMenu->action(KHelpMenu::menuAboutKDE);
126 QAction *donateAction = d->m_helpMenu->action(KHelpMenu::menuDonate);
127
128 if (helpContentsAction) {
129 actions->addAction(helpContentsAction->objectName(), helpContentsAction);
130 }
131 if (whatsThisAction) {
132 actions->addAction(whatsThisAction->objectName(), whatsThisAction);
133 }
134 if (reportBugAction) {
135 actions->addAction(reportBugAction->objectName(), reportBugAction);
136 }
137 if (switchLanguageAction) {
138 actions->addAction(switchLanguageAction->objectName(), switchLanguageAction);
139 }
140 if (aboutAppAction) {
141 actions->addAction(aboutAppAction->objectName(), aboutAppAction);
142 }
143 if (aboutKdeAction) {
144 actions->addAction(aboutKdeAction->objectName(), aboutKdeAction);
145 }
146 if (donateAction) {
147 actions->addAction(donateAction->objectName(), donateAction);
148 }
149 }
150
151 QString f = xmlFile();
153 if (!f.isEmpty()) {
154 setXMLFile(f, true);
155 } else {
156 QString auto_file(componentName() + QLatin1String("ui.rc"));
157 setXMLFile(auto_file, true);
158 }
159
160 GUIActivateEvent ev(true);
161 QApplication::sendEvent(this, &ev);
162
163 guiFactory()->addClient(this);
164
166 } else {
167 GUIActivateEvent ev(false);
168 QApplication::sendEvent(this, &ev);
169
170 guiFactory()->removeClient(this);
171 }
172}
173
175{
176 d->m_manageWindowTitle = enabled;
177}
178
180{
181 createGUI(d->m_activePart);
183 applyMainWindowSettings(cg);
184}
185
186void KParts::MainWindow::configureToolbars()
187{
188 // No difference with base class anymore.
190}
191
192#include "moc_mainwindow.cpp"
static KAboutData applicationData()
virtual void setCaption(const QString &caption)
This event is sent to a Part when its GUI has been activated or deactivated.
A KPart-aware main window, whose user interface is described in XML.
Definition mainwindow.h:51
~MainWindow() override
Destructor.
MainWindow(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor, same signature as KMainWindow.
void saveNewToolbarConfig() override
Rebuilds the GUI after KEditToolBar changed the toolbar layout.
void setWindowTitleHandling(bool enabled)
Enable or disable the automatic setting of window titles by the part's document title.
virtual void slotSetStatusBarText(const QString &)
Called when the active part wants to change the statusbar message Reimplement if your mainwindow has ...
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...
void setPartObject(QObject *object)
Internal method.
Definition partbase.cpp:26
Base class for parts.
Definition part.h:57
void setWindowCaption(const QString &caption)
Emitted by the part, to set the caption of the window(s) hosting this part.
void setStatusBarText(const QString &text)
Emitted by the part, to set a text in the statusbar of the window(s) hosting this part.
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
virtual QString xmlFile() const
virtual QString componentName() const
static QString standardsXmlFileLocation()
virtual KActionCollection * actionCollection() const
virtual void setXMLFile(const QString &file, bool merge=false, bool setXMLDoc=true)
KXMLGUIFactory * factory() const
void removeClient(KXMLGUIClient *client)
void addClient(KXMLGUIClient *client)
virtual void configureToolbars()
void checkAmbiguousShortcuts()
bool isHelpMenuEnabled() const
The KParts namespace,.
bool sendEvent(QObject *receiver, QEvent *event)
QStatusBar * statusBar() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool disconnect(const QMetaObject::Connection &connection)
virtual const QMetaObject * metaObject() const const
void showMessage(const QString &message, int timeout)
bool isEmpty() const const
typedef WindowFlags
QList< QAction * > actions() const const
void create(WId window, bool initializeWindow, bool destroyOldWindow)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:11:50 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.