Krita Source Code Documentation
Loading...
Searching...
No Matches
kxmlguiwindow.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright
3 (C) 2000 Reginald Stadlbauer (reggie@kde.org)
4 (C) 1997 Stephan Kulow (coolo@kde.org)
5 (C) 1997-2000 Sven Radej (radej@kde.org)
6 (C) 1997-2000 Matthias Ettrich (ettrich@kde.org)
7 (C) 1999 Chris Schlaeger (cs@kde.org)
8 (C) 2002 Joseph Wenninger (jowenn@kde.org)
9 (C) 2005-2006 Hamish Rodda (rodda@kde.org)
10
11 SPDX-License-Identifier: LGPL-2.0-only
12*/
13
14#include "kxmlguiwindow.h"
15
16#include "config-xmlgui.h"
17
18#include "kmainwindow_p.h"
19#include "kactioncollection.h"
20#ifdef HAVE_DBUS
21#include "kmainwindowiface_p.h"
22#endif
23#include "ktoolbarhandler_p.h"
24#include "kxmlguifactory.h"
25#include "kedittoolbar.h"
26#include "khelpmenu.h"
27#include "ktoolbar.h"
28
29#include <QCloseEvent>
30#ifdef HAVE_DBUS
31#include <QDBusConnection>
32#endif
33#include <QDomDocument>
34#include <QLayout>
35#include <QDebug>
36#include <QMenuBar>
37#include <QObject>
38#include <QStatusBar>
39#include <QStyle>
40#include <QWidget>
41
42#include <ktoggleaction.h>
43#include <kstandardaction.h>
44#include <kconfig.h>
45#include <klocalizedstring.h>
46#include <kaboutdata.h>
47#include <ksharedconfig.h>
48#include <kconfiggroup.h>
49
50#include <stdlib.h>
51#include <ctype.h>
52
54{
55public:
57 {
58 // While the GUI factory is adding/removing clients,
59 // don't let KisKMainWindow think those are changes made by the user
60 // #105525
62 }
63
64 bool showHelpMenu: 1;
66
68 KToggleAction *showStatusBarAction;
71};
72
73KXmlGuiWindow::KXmlGuiWindow(QWidget *parent, Qt::WindowFlags f)
75{
77 d->showHelpMenu = true;
78 d->toolBarHandler = 0;
79 d->showStatusBarAction = 0;
80 d->factory = 0;
81#ifdef HAVE_DBUS
83#endif
84}
85
87{
89 if (!d->toolBarHandler) {
90 return 0;
91 }
92
93 return d->toolBarHandler->toolBarMenuAction();
94}
95
97{
99 if (d->toolBarHandler) {
100 d->toolBarHandler->setupActions();
101 }
102}
103
105{
107 delete d->factory;
108}
109
110bool KXmlGuiWindow::event(QEvent *ev)
111{
112 bool ret = KisKMainWindow::event(ev);
113#ifdef HAVE_DBUS
114 if (ev->type() == QEvent::Polish) {
115 QDBusConnection::sessionBus().registerObject(dbusName() + QStringLiteral("/actions"), actionCollection(),
116 QDBusConnection::ExportScriptableSlots |
117 QDBusConnection::ExportScriptableProperties |
118 QDBusConnection::ExportNonScriptableSlots |
119 QDBusConnection::ExportNonScriptableProperties |
120 QDBusConnection::ExportChildObjects);
121 }
122#endif
123 return ret;
124}
125
127{
129 d->showHelpMenu = showHelpMenu;
130}
131
133{
134 K_D(const KXmlGuiWindow);
135 return d->showHelpMenu;
136}
137
139{
141 if (!d->factory) {
142 d->factory = new KisKXMLGUIFactory(this, this);
143 connect(d->factory, SIGNAL(makingChanges(bool)),
144 this, SLOT(_k_slotFactoryMakingChanges(bool)));
145 }
146 return d->factory;
147}
148
150{
152 KConfigGroup cg(KSharedConfig::openConfig(), "");
154 if (!d->toolBarEditor) {
155 d->toolBarEditor = new KisKEditToolBar(guiFactory(), this);
156 d->toolBarEditor->setAttribute(Qt::WA_DeleteOnClose);
157 connect(d->toolBarEditor, SIGNAL(newToolBarConfig()), SLOT(saveNewToolbarConfig()));
158 }
159 d->toolBarEditor->show();
160}
161
163{
164 // createGUI(xmlFile()); // this loses any plugged-in guiclients, so we use remove+add instead.
165
166 guiFactory()->removeClient(this);
167 guiFactory()->addClient(this);
168
169 KConfigGroup cg(KSharedConfig::openConfig(), "");
171}
172
173void KXmlGuiWindow::setupGUI(StandardWindowOptions options, const QString &xmlfile)
174{
175 setupGUI(QSize(), options, xmlfile);
176}
177
178void KXmlGuiWindow::setupGUI(const QSize &defaultSize, StandardWindowOptions options, const QString &xmlfile)
179{
181 if (options & Keys) {
183 SLOT(configureShortcuts()), actionCollection());
184 }
185 if ((options & StatusBar) && statusBar()) {
187 }
188
189 if (options & ToolBar) {
193 }
194
195 d->defaultSize = defaultSize;
196
197 if (options & Create) {
198 createGUI(xmlfile);
199 }
200
201 if (d->defaultSize.isValid()) {
202 resize(d->defaultSize);
203 } else if (isHidden()) {
204 adjustSize();
205 }
206
207 if (options & Save) {
208 const KConfigGroup cg(autoSaveConfigGroup());
209 if (cg.isValid()) {
211 } else {
213 }
214 }
215}
216void KXmlGuiWindow::createGUI(const QString &xmlfile)
217{
219 // disabling the updates prevents unnecessary redraws
220 //setUpdatesEnabled( false );
221
222 // just in case we are rebuilding, let's remove our old client
223 guiFactory()->removeClient(this);
224
225 // make sure to have an empty GUI
226 QMenuBar *mb = menuBar();
227 if (mb) {
228 mb->clear();
229 }
230
231 qDeleteAll(toolBars()); // delete all toolbars
232
233 // don't build a help menu unless the user ask for it
234 if (d->showHelpMenu) {
235 delete d->helpMenu;
236 // we always want a help menu
237 d->helpMenu = new KisKHelpMenu(this, KAboutData::applicationData(), true);
238
240 QAction *helpContentsAction = d->helpMenu->action(KisKHelpMenu::menuHelpContents);
241 QAction *whatsThisAction = d->helpMenu->action(KisKHelpMenu::menuWhatsThis);
242 QAction *reportBugAction = d->helpMenu->action(KisKHelpMenu::menuReportBug);
243 QAction *switchLanguageAction = d->helpMenu->action(KisKHelpMenu::menuSwitchLanguage);
244 QAction *aboutAppAction = d->helpMenu->action(KisKHelpMenu::menuAboutApp);
245 QAction *aboutKdeAction = d->helpMenu->action(KisKHelpMenu::menuAboutKDE);
246
247 if (helpContentsAction) {
248 actions->addAction(helpContentsAction->objectName(), helpContentsAction);
249 }
250 if (whatsThisAction) {
251 actions->addAction(whatsThisAction->objectName(), whatsThisAction);
252 }
253 if (reportBugAction) {
254 actions->addAction(reportBugAction->objectName(), reportBugAction);
255 }
256 if (switchLanguageAction) {
257 actions->addAction(switchLanguageAction->objectName(), switchLanguageAction);
258 }
259 if (aboutAppAction) {
260 actions->addAction(aboutAppAction->objectName(), aboutAppAction);
261 }
262 if (aboutKdeAction) {
263 actions->addAction(aboutKdeAction->objectName(), aboutKdeAction);
264 }
265 }
266
267 const QString windowXmlFile = xmlfile.isNull() ? componentName() + QStringLiteral("ui.xmlgui") : xmlfile;
268
269 // Help beginners who call setXMLFile and then setupGUI...
270 if (!xmlFile().isEmpty() && xmlFile() != windowXmlFile) {
271 qWarning() << "You called setXMLFile(" << xmlFile() << ") and then createGUI or setupGUI,"
272 << "which also calls setXMLFile and will overwrite the file you have previously set.\n"
273 << "You should call createGUI(" << xmlFile() << ") or setupGUI(<options>," << xmlFile() << ") instead.";
274 }
275
276 // we always want to load in our global standards file
278
279 // now, merge in our local xml file.
280 setXMLFile(windowXmlFile, true);
281
282 // make sure we don't have any state saved already
283 setXMLGUIBuildDocument(QDomDocument());
284
285 // do the actual GUI building
286 guiFactory()->reset();
287 guiFactory()->addClient(this);
288
289 // setUpdatesEnabled( true );
290}
291
292void KXmlGuiWindow::slotStateChanged(const QString &newstate)
293{
295}
296
297void KXmlGuiWindow::slotStateChanged(const QString &newstate,
298 bool reverse)
299{
300 stateChanged(newstate,
302}
303
305{
307 if (enable) {
308 if (d->toolBarHandler) {
309 return;
310 }
311
312 d->toolBarHandler = new KDEPrivate::ToolBarHandler(this);
313
314 if (factory()) {
315 factory()->addClient(d->toolBarHandler);
316 }
317 } else {
318 if (!d->toolBarHandler) {
319 return;
320 }
321
322 if (factory()) {
323 factory()->removeClient(d->toolBarHandler);
324 }
325
326 delete d->toolBarHandler;
327 d->toolBarHandler = 0;
328 }
329}
330
332{
333 K_D(const KXmlGuiWindow);
334 return (d->toolBarHandler);
335}
336
338{
340 if (!d->showStatusBarAction) {
341 d->showStatusBarAction = KStandardAction::showStatusbar(this, SLOT(setSettingsDirty()), actionCollection());
342 QStatusBar *sb = statusBar(); // Creates statusbar if it doesn't exist already.
343 connect(d->showStatusBarAction, SIGNAL(toggled(bool)), sb, SLOT(setVisible(bool)));
344 d->showStatusBarAction->setChecked(sb->isHidden());
345 } else {
346 // If the language has changed, we'll need to grab the new text and whatsThis
347 QAction *tmpStatusBar = KStandardAction::showStatusbar(0, 0, 0);
348 d->showStatusBarAction->setText(tmpStatusBar->text());
349 d->showStatusBarAction->setWhatsThis(tmpStatusBar->whatsThis());
350 delete tmpStatusBar;
351 }
352}
353
354void KXmlGuiWindow::finalizeGUI(bool /*force*/)
355{
356 // FIXME: this really needs to be removed with a code more like the one we had on KDE3.
357 // what we need to do here is to position correctly toolbars so they don't overlap.
358 // Also, take in count plugins could provide their own toolbars and those also need to
359 // be restored.
360 if (autoSaveSettings() && autoSaveConfigGroup().isValid()) {
362 }
363}
364
365void KXmlGuiWindow::applyMainWindowSettings(const KConfigGroup &config)
366{
369 QStatusBar *sb = findChild<QStatusBar *>();
370 if (sb && d->showStatusBarAction) {
371 d->showStatusBarAction->setChecked(!sb->isHidden());
372 }
373}
374
375// KDE5 TODO: change it to "using KisKXMLGUIBuilder::finalizeGUI;" in the header
376// and remove the reimplementation
381
382#include "moc_kxmlguiwindow.cpp"
383
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
KisKXMLGUIFactory * factory
KToggleAction * showStatusBarAction
void _k_slotFactoryMakingChanges(bool b)
QPointer< KisKEditToolBar > toolBarEditor
KDEPrivate::ToolBarHandler * toolBarHandler
KDE top level main window with predefined action layout
void createGUI(const QString &xmlfile=QString())
void finalizeGUI(KisKXMLGUIClient *client) override
QAction * toolBarMenuAction()
void createStandardStatusBarAction()
void setStandardToolBarMenuEnabled(bool enable)
void applyMainWindowSettings(const KConfigGroup &config) override
bool isStandardToolBarMenuEnabled() const
void setupToolbarMenuActions()
virtual void slotStateChanged(const QString &newstate)
virtual void configureToolbars()
void setHelpMenuEnabled(bool showHelpMenu=true)
bool event(QEvent *event) override
~KXmlGuiWindow() override
Destructor.
virtual void saveNewToolbarConfig()
virtual KisKXMLGUIFactory * guiFactory()
bool isHelpMenuEnabled() const
KXmlGuiWindow(QWidget *parent=0, Qt::WindowFlags f=Qt::WindowFlags())
void setupGUI(StandardWindowOptions options=Default, const QString &xmlfile=QString())
A container for a set of QAction objects.
Q_INVOKABLE QAction * addAction(const QString &name, QAction *action)
A dialog used to customize or configure toolbars.
Standard KDE help menu with dialog boxes.
Definition khelpmenu.h:106
D-Bus interface to KisKMainWindow.
KDE top level main window
Definition kmainwindow.h:89
QString dbusName() const
void setAutoSaveSettings(const QString &groupName=QLatin1String("MainWindow"), bool saveWindowSize=true)
KConfigGroup autoSaveConfigGroup() const
void saveMainWindowSettings(KConfigGroup &config)
void setSettingsDirty()
virtual void applyMainWindowSettings(const KConfigGroup &config)
bool event(QEvent *event) override
QList< KisToolBar * > toolBars() const
virtual void finalizeGUI(KisKXMLGUIClient *client)
KisKXMLGUIBuilderPrivate *const d
void setXMLGUIBuildDocument(const QDomDocument &doc)
virtual QString xmlFile() const
virtual void stateChanged(const QString &newstate, ReverseStateChange reverse=StateNoReverse)
KisKXMLGUIFactory * factory() const
void setXMLFile(const QString &file, bool merge=false, bool setXMLDoc=true)
virtual QString componentName() const
virtual KisKActionCollection * actionCollection() const
void removeClient(KisKXMLGUIClient *client)
void addClient(KisKXMLGUIClient *client)
#define K_D(Class)
QAction * keyBindings(const QObject *recvr, const char *slot, QObject *parent)
KToggleAction * showStatusbar(const QObject *recvr, const char *slot, QObject *parent)
QAction * configureToolbars(const QObject *recvr, const char *slot, QObject *parent)