File indexing completed on 2024-05-05 16:27:23

0001 /* This file is part of KGraphViewer.
0002    Copyright (C) 2005-2007 Gael de Chalendar <kleag@free.fr>
0003 
0004    KGraphViewer is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU General Public
0006    License as published by the Free Software Foundation, version 2.
0007 
0008    This program is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011    General Public License for more details.
0012 
0013    You should have received a copy of the GNU General Public License
0014    along with this program; if not, write to the Free Software
0015    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
0016    02110-1301, USA
0017 */
0018 
0019 #include "kgraphviewer.h"
0020 #include "kgraphviewerConfigDialog.h"
0021 #include "kgraphviewer_debug.h"
0022 #include "kgraphviewersettings.h"
0023 #include "part/kgraphviewer_interface.h"
0024 #include "ui_preferencesOpenInExistingWindow.h"
0025 #include "ui_preferencesParsing.h"
0026 #include "ui_preferencesReload.h"
0027 #include "ui_preferencesReopenPreviouslyOpenedFiles.h"
0028 
0029 #include <kwidgetsaddons_version.h>
0030 #include <KActionCollection>
0031 #include <KColorScheme>
0032 #include <KParts/ReadOnlyPart>
0033 #include <KPluginFactory>
0034 #include <KService>
0035 #include <QDBusConnection>
0036 #include <QDebug>
0037 #include <QFileDialog>
0038 #include <QIcon>
0039 #include <QStandardPaths>
0040 #include <QStatusBar>
0041 #include <QTabWidget>
0042 #include <QUrl>
0043 #include <iostream>
0044 #include <kconfig.h>
0045 #include <kconfigdialog.h>
0046 #include <kedittoolbar.h>
0047 #include <klocalizedstring.h>
0048 #include <kmessagebox.h>
0049 #include <kparts/partmanager.h>
0050 #include <krecentfilesaction.h>
0051 #include <kstandardaction.h>
0052 #include <ktoggleaction.h>
0053 #include <ktoolbar.h>
0054 #include <stdio.h>
0055 #include <stdlib.h>
0056 
0057 KGraphViewerWindow::KGraphViewerWindow()
0058     : KParts::MainWindow()
0059     , m_rfa(nullptr)
0060 {
0061     // set the shell's ui resource file
0062     setXMLFile("kgraphviewerui.rc");
0063 
0064     //   std::cerr << "Creating tab widget" << std::endl;
0065     m_widget = new QTabWidget(this);
0066     m_widget->setTabsClosable(true);
0067     connect(m_widget, &QTabWidget::tabCloseRequested, this, static_cast<void (KGraphViewerWindow::*)(int)>(&KGraphViewerWindow::close));
0068     connect(m_widget, &QTabWidget::currentChanged, this, &KGraphViewerWindow::newTabSelectedSlot);
0069 
0070     setCentralWidget(m_widget);
0071 
0072     if (QDBusConnection::sessionBus().registerService("org.kde.kgraphviewer")) {
0073         qCDebug(KGRAPHVIEWER_LOG) << "Service Registered successfully";
0074         QDBusConnection::sessionBus().registerObject("/", this, QDBusConnection::ExportAllSlots);
0075 
0076     } else {
0077         qCDebug(KGRAPHVIEWER_LOG) << "Failed to register service...";
0078     }
0079 
0080     // this routine will find and load our Part.  it finds the Part by
0081     // name which is a bad idea usually.. but it's alright in this
0082     // case since our Part is made for this Shell
0083 
0084     // Create a KParts part manager, to handle part activation/deactivation
0085     m_manager = new KParts::PartManager(this);
0086 
0087     // When the manager says the active part changes, the window updates (recreates) the GUI
0088     connect(m_manager, &KParts::PartManager::activePartChanged, this, &KGraphViewerWindow::createGUI);
0089 
0090     setupGUI(ToolBar | Keys | StatusBar | Save);
0091 
0092     // then, setup our actions
0093     setupActions();
0094 
0095     // Creates the GUI with a null part to make appear the main app menus and tools
0096     createGUI(nullptr);
0097 }
0098 
0099 KGraphViewerWindow::~KGraphViewerWindow()
0100 {
0101     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0102     if (m_rfa)
0103         m_rfa->saveEntries(KConfigGroup(config, "kgraphviewer recent files"));
0104 
0105     // delete partsmanager explicitly, to avoid activePartChanged being emitted from here
0106     delete m_manager;
0107 }
0108 
0109 void KGraphViewerWindow::reloadPreviousFiles()
0110 {
0111     QStringList previouslyOpenedFiles = KGraphViewerSettings::previouslyOpenedFiles();
0112     if ((previouslyOpenedFiles.empty() == false) &&
0113 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0114         (KMessageBox::questionTwoActions(this,
0115 #else
0116         (KMessageBox::questionYesNo(this,
0117 #endif
0118                                     i18n("Do you want to reload files from the previous session?"),
0119                                     i18n("Session Restore"),
0120                                     KGuiItem(i18nc("@action:button", "Reload"), QStringLiteral("document-open")),
0121                                     KGuiItem(i18nc("@action:button", "Do Not Reload"), QStringLiteral("dialog-cancel")),
0122                                     "reopenPreviouslyOpenedFilesMode")
0123 #if KWIDGETSADDONS_VERSION >= QT_VERSION_CHECK(5, 100, 0)
0124         == KMessageBox::PrimaryAction)) {
0125 #else
0126         == KMessageBox::Yes)) {
0127 #endif
0128         QStringList::const_iterator it, it_end;
0129         it = previouslyOpenedFiles.constBegin();
0130         it_end = previouslyOpenedFiles.constEnd();
0131         for (; it != it_end; it++) {
0132             openUrl(*it);
0133         }
0134         KGraphViewerSettings::self()->save();
0135     }
0136 }
0137 
0138 void KGraphViewerWindow::openUrl(const QUrl &url)
0139 {
0140     qCDebug(KGRAPHVIEWER_LOG) << url;
0141     KPluginFactory *factory = KPluginFactory::loadFactory(KPluginMetaData("kgraphviewerpart")).plugin;
0142     if (!factory) {
0143         // if we couldn't find our Part, we exit since the Shell by
0144         // itself can't do anything useful
0145         KMessageBox::error(this, i18n("Could not find the KGraphViewer part."));
0146         qApp->quit();
0147         // we return here, cause kapp->quit() only means "exit the
0148         // next time we enter the event loop...
0149         return;
0150     }
0151     KParts::ReadOnlyPart *part = factory->create<KParts::ReadOnlyPart>(this);
0152     KGraphViewer::KGraphViewerInterface *kgv = qobject_cast<KGraphViewer::KGraphViewerInterface *>(part);
0153     if (!kgv) {
0154         // This should not happen
0155         qCWarning(KGRAPHVIEWER_LOG) << "Failed to get KPart";
0156         return;
0157     }
0158     kgv->setBackgroundColor(KGraphViewerSettings::backgroundColor());
0159     (KGraphViewerSettings::parsingMode() == "external") ? kgv->setLayoutMethod(KGraphViewer::KGraphViewerInterface::ExternalProgram) : kgv->setLayoutMethod(KGraphViewer::KGraphViewerInterface::InternalLibrary);
0160 
0161     if (part) {
0162         QString fileName = url.url();
0163         QWidget *w = part->widget();
0164 
0165         part->openUrl(url);
0166 
0167         if (m_rfa) {
0168             m_rfa->addUrl(url);
0169             KSharedConfig::Ptr config = KSharedConfig::openConfig();
0170             m_rfa->saveEntries(KConfigGroup(config, "kgraphviewer recent files"));
0171         }
0172 
0173         m_openedFiles.push_back(fileName);
0174         m_tabsPartsMap[w] = part;
0175         m_tabsFilesMap[w] = fileName;
0176         connect(this, SIGNAL(hide(KParts::Part *)), part, SLOT(slotHide(KParts::Part *)));
0177 
0178         connect(part, SIGNAL(hoverEnter(QString)), this, SLOT(slotHoverEnter(QString)));
0179         connect(part, SIGNAL(hoverLeave(QString)), this, SLOT(slotHoverLeave(QString)));
0180 
0181         m_manager->addPart(part, true);
0182         const QString label = fileName.section('/', -1, -1);
0183         m_widget->addTab(w, QIcon::fromTheme("kgraphviewer"), label);
0184         m_widget->setCurrentWidget(w);
0185         m_closeAction->setEnabled(true);
0186     }
0187 }
0188 
0189 void KGraphViewerWindow::fileOpen()
0190 {
0191     qCDebug(KGRAPHVIEWER_LOG);
0192     // this slot is called whenever the File->Open menu is selected,
0193     // the Open shortcut is pressed (usually CTRL+O) or the Open toolbar
0194     // button is clicked
0195     QFileDialog fileDialog(this);
0196     fileDialog.setMimeTypeFilters(QStringList(QStringLiteral("text/vnd.graphviz")));
0197     fileDialog.setAcceptMode(QFileDialog::AcceptOpen);
0198     fileDialog.setFileMode(QFileDialog::ExistingFiles);
0199     if (fileDialog.exec() != QFileDialog::Accepted) {
0200         return;
0201     }
0202 
0203     for (const QUrl &url : fileDialog.selectedUrls()) {
0204         openUrl(url);
0205     }
0206 }
0207 
0208 void KGraphViewerWindow::setupActions()
0209 {
0210     // create our actions
0211     QAction *newAction = actionCollection()->addAction(KStandardAction::New, "file_new", this, SLOT(fileNew()));
0212     newAction->setWhatsThis(i18n("Opens a new empty KGraphViewer window."));
0213 
0214     QAction *openAction = actionCollection()->addAction(KStandardAction::Open, "file_open", this, SLOT(fileOpen()));
0215     openAction->setWhatsThis(i18n("Shows the file open dialog to choose a Graphviz DOT file to open."));
0216 
0217     m_rfa = KStandardAction::openRecent(this, SLOT(slotURLSelected(QUrl)), this);
0218     actionCollection()->addAction(m_rfa->objectName(), m_rfa);
0219     m_rfa->setWhatsThis(i18n("This lists files which you have opened recently, and allows you to easily open them again."));
0220 
0221     KSharedConfig::Ptr config = KSharedConfig::openConfig();
0222     m_rfa->loadEntries(KConfigGroup(config, "kgraphviewer recent files"));
0223 
0224     m_closeAction = actionCollection()->addAction(KStandardAction::Close, "file_close", this, SLOT(close()));
0225     m_closeAction->setWhatsThis(i18n("Closes the current file"));
0226     m_closeAction->setEnabled(false);
0227 
0228     QAction *quitAction = actionCollection()->addAction(KStandardAction::Quit, "file_quit", qApp, SLOT(quit()));
0229     quitAction->setWhatsThis(i18n("Quits KGraphViewer."));
0230 
0231     m_statusbarAction = KStandardAction::showStatusbar(this, SLOT(optionsShowStatusbar()), this);
0232     m_statusbarAction->setWhatsThis(i18n("Shows or hides the status bar."));
0233 
0234     QAction *ctAction = actionCollection()->addAction(KStandardAction::ConfigureToolbars, "options_configure_toolbars", this, SLOT(optionsConfigureToolbars()));
0235     ctAction->setWhatsThis(i18n("Toolbar configuration."));
0236 
0237     QAction *configureAction = actionCollection()->addAction(KStandardAction::Preferences, "options_configure", this, SLOT(optionsConfigure()));
0238     configureAction->setWhatsThis(i18n("Main KGraphViewer configuration options."));
0239 }
0240 
0241 void KGraphViewerWindow::closeEvent(QCloseEvent *event)
0242 {
0243     KGraphViewerSettings::setPreviouslyOpenedFiles(m_openedFiles);
0244     KGraphViewerSettings::self()->save();
0245     KParts::MainWindow::closeEvent(event);
0246 }
0247 
0248 void KGraphViewerWindow::fileNew()
0249 {
0250     // this slot is called whenever the File->New menu is selected,
0251     // the New shortcut is pressed (usually CTRL+N) or the New toolbar
0252     // button is clicked
0253 
0254     (new KGraphViewerWindow())->show();
0255 }
0256 
0257 void KGraphViewerWindow::optionsShowToolbar()
0258 {
0259     // this is all very cut and paste code for showing/hiding the
0260     // toolbar
0261     if (m_toolbarAction->isChecked())
0262         toolBar()->show();
0263     else
0264         toolBar()->hide();
0265 }
0266 
0267 void KGraphViewerWindow::optionsShowStatusbar()
0268 {
0269     // this is all very cut and paste code for showing/hiding the
0270     // statusbar
0271     if (m_statusbarAction->isChecked())
0272         statusBar()->show();
0273     else
0274         statusBar()->hide();
0275 }
0276 
0277 void KGraphViewerWindow::optionsConfigureToolbars()
0278 {
0279     KConfigGroup group(KConfigGroup(KSharedConfig::openConfig(), "kgraphviewer"));
0280     KMainWindow::saveMainWindowSettings(group);
0281 
0282     // use the standard toolbar editor
0283     KEditToolBar dlg(factory());
0284     connect(&dlg, &KEditToolBar::newToolBarConfig, this, &KGraphViewerWindow::applyNewToolbarConfig);
0285     dlg.exec();
0286 }
0287 
0288 void KGraphViewerWindow::optionsConfigure()
0289 {
0290     // An instance of your dialog could be already created and could be cached,
0291     // in which case you want to display the cached dialog instead of creating
0292     // another one
0293     if (KgvConfigurationDialog::showDialog("settings"))
0294         return;
0295 
0296     // KConfigDialog didn't find an instance of this dialog, so lets create it :
0297     KgvConfigurationDialog *dialog = new KgvConfigurationDialog(this, "settings", KGraphViewerSettings::self());
0298     connect(dialog, &KgvConfigurationDialog::backgroundColorChanged, this, &KGraphViewerWindow::slotBackgroundColorChanged);
0299     Ui::KGraphViewerPreferencesParsingWidget *parsingWidget = dialog->parsingWidget;
0300     qCDebug(KGRAPHVIEWER_LOG) << KGraphViewerSettings::parsingMode();
0301     if (KGraphViewerSettings::parsingMode() == "external") {
0302         parsingWidget->external->setChecked(true);
0303     } else if (KGraphViewerSettings::parsingMode() == "internal") {
0304         parsingWidget->internal->setChecked(true);
0305     }
0306     connect(parsingWidget->external, &QRadioButton::toggled, this, &KGraphViewerWindow::slotParsingModeExternalToggled);
0307     connect(parsingWidget->internal, &QRadioButton::toggled, this, &KGraphViewerWindow::slotParsingModeInternalToggled);
0308 
0309     Ui::KGraphViewerPreferencesReloadWidget *reloadWidget = dialog->reloadWidget;
0310     qCDebug(KGRAPHVIEWER_LOG) << KGraphViewerSettings::reloadOnChangeMode();
0311     if (KGraphViewerSettings::reloadOnChangeMode() == "true") {
0312         reloadWidget->yes->setChecked(true);
0313     } else if (KGraphViewerSettings::reloadOnChangeMode() == "false") {
0314         reloadWidget->no->setChecked(true);
0315     } else // if (KGraphViewerSettings::reloadOnChangeMode() == "ask")
0316     {
0317         reloadWidget->ask->setChecked(true);
0318     }
0319 
0320     connect(reloadWidget->yes, &QRadioButton::toggled, this, &KGraphViewerWindow::slotReloadOnChangeModeYesToggled);
0321     connect(reloadWidget->no, &QRadioButton::toggled, this, &KGraphViewerWindow::slotReloadOnChangeModeNoToggled);
0322     connect(reloadWidget->ask, &QRadioButton::toggled, this, &KGraphViewerWindow::slotReloadOnChangeModeAskToggled);
0323 
0324     Ui::KGraphViewerPreferencesOpenInExistingWindowWidget *openingWidget = dialog->openingWidget;
0325     if (KGraphViewerSettings::openInExistingWindowMode() == "true") {
0326         openingWidget->yes->setChecked(true);
0327     } else if (KGraphViewerSettings::openInExistingWindowMode() == "false") {
0328         openingWidget->no->setChecked(true);
0329     } else // if (KGraphViewerSettings::openInExistingWindowMode() == "ask")
0330     {
0331         openingWidget->ask->setChecked(true);
0332     }
0333 
0334     connect(openingWidget->yes, &QRadioButton::toggled, this, &KGraphViewerWindow::slotOpenInExistingWindowModeYesToggled);
0335     connect(openingWidget->no, &QRadioButton::toggled, this, &KGraphViewerWindow::slotOpenInExistingWindowModeNoToggled);
0336     connect(openingWidget->ask, &QRadioButton::toggled, this, &KGraphViewerWindow::slotOpenInExistingWindowModeAskToggled);
0337 
0338     Ui::KGraphViewerPreferencesReopenPreviouslyOpenedFilesWidget *reopeningWidget = dialog->reopeningWidget;
0339     if (KGraphViewerSettings::reopenPreviouslyOpenedFilesMode() == "true") {
0340         reopeningWidget->yes->setChecked(true);
0341     } else if (KGraphViewerSettings::reopenPreviouslyOpenedFilesMode() == "false") {
0342         reopeningWidget->no->setChecked(true);
0343     } else // if (KGraphViewerSettings::reopenPreviouslyOpenedFilesMode() == "ask")
0344     {
0345         reopeningWidget->ask->setChecked(true);
0346     }
0347 
0348     connect(reopeningWidget->yes, &QRadioButton::toggled, this, &KGraphViewerWindow::slotReopenPreviouslyOpenedFilesModeYesToggled);
0349     connect(reopeningWidget->no, &QRadioButton::toggled, this, &KGraphViewerWindow::slotReopenPreviouslyOpenedFilesModeNoToggled);
0350     connect(reopeningWidget->ask, &QRadioButton::toggled, this, &KGraphViewerWindow::slotReopenPreviouslyOpenedFilesModeAskToggled);
0351 
0352     dialog->show();
0353 }
0354 
0355 void KGraphViewerWindow::applyNewToolbarConfig()
0356 {
0357     applyMainWindowSettings(KSharedConfig::openConfig()->group("kgraphviewer"));
0358 }
0359 
0360 void KGraphViewerWindow::slotReloadOnChangeModeYesToggled(bool value)
0361 {
0362     qCDebug(KGRAPHVIEWER_LOG);
0363     if (value) {
0364         KGraphViewerSettings::setReloadOnChangeMode("true");
0365     }
0366     //   qCDebug(KGRAPHVIEWER_LOG) << "emitting";
0367     //   emit(settingsChanged());
0368     KGraphViewerSettings::self()->save();
0369 }
0370 
0371 void KGraphViewerWindow::slotReloadOnChangeModeNoToggled(bool value)
0372 {
0373     qCDebug(KGRAPHVIEWER_LOG);
0374     if (value) {
0375         KGraphViewerSettings::setReloadOnChangeMode("false");
0376     }
0377     //   qCDebug(KGRAPHVIEWER_LOG) << "emitting";
0378     //   emit(settingsChanged());
0379     KGraphViewerSettings::self()->save();
0380 }
0381 
0382 void KGraphViewerWindow::slotReloadOnChangeModeAskToggled(bool value)
0383 {
0384     qCDebug(KGRAPHVIEWER_LOG);
0385     if (value) {
0386         KGraphViewerSettings::setReloadOnChangeMode("ask");
0387     }
0388     //   qCDebug(KGRAPHVIEWER_LOG) << "emitting";
0389     //   emit(settingsChanged());
0390     KGraphViewerSettings::self()->save();
0391 }
0392 
0393 void KGraphViewerWindow::slotOpenInExistingWindowModeYesToggled(bool value)
0394 {
0395     qCDebug(KGRAPHVIEWER_LOG) << value;
0396     if (value) {
0397         KGraphViewerSettings::setOpenInExistingWindowMode("true");
0398     }
0399     KGraphViewerSettings::self()->save();
0400 }
0401 
0402 void KGraphViewerWindow::slotOpenInExistingWindowModeNoToggled(bool value)
0403 {
0404     qCDebug(KGRAPHVIEWER_LOG) << value;
0405     if (value) {
0406         KGraphViewerSettings::setOpenInExistingWindowMode("false");
0407     }
0408     KGraphViewerSettings::self()->save();
0409 }
0410 
0411 void KGraphViewerWindow::slotOpenInExistingWindowModeAskToggled(bool value)
0412 {
0413     qCDebug(KGRAPHVIEWER_LOG) << value;
0414     if (value) {
0415         KGraphViewerSettings::setOpenInExistingWindowMode("ask");
0416     }
0417     KGraphViewerSettings::self()->save();
0418 }
0419 
0420 void KGraphViewerWindow::slotReopenPreviouslyOpenedFilesModeYesToggled(bool value)
0421 {
0422     qCDebug(KGRAPHVIEWER_LOG) << value;
0423     if (value) {
0424         KGraphViewerSettings::setReopenPreviouslyOpenedFilesMode("true");
0425     }
0426     KGraphViewerSettings::self()->save();
0427 }
0428 
0429 void KGraphViewerWindow::slotReopenPreviouslyOpenedFilesModeNoToggled(bool value)
0430 {
0431     qCDebug(KGRAPHVIEWER_LOG) << value;
0432     if (value) {
0433         KGraphViewerSettings::setReopenPreviouslyOpenedFilesMode("false");
0434     }
0435     KGraphViewerSettings::self()->save();
0436 }
0437 
0438 void KGraphViewerWindow::slotReopenPreviouslyOpenedFilesModeAskToggled(bool value)
0439 {
0440     qCDebug(KGRAPHVIEWER_LOG) << value;
0441     if (value) {
0442         KGraphViewerSettings::setReopenPreviouslyOpenedFilesMode("ask");
0443     }
0444     KGraphViewerSettings::self()->save();
0445 }
0446 
0447 void KGraphViewerWindow::slotParsingModeExternalToggled(bool value)
0448 {
0449     qCDebug(KGRAPHVIEWER_LOG);
0450     if (value) {
0451         KGraphViewerSettings::setParsingMode("external");
0452     }
0453     //   qCDebug(KGRAPHVIEWER_LOG) << "emitting";
0454     //   emit(settingsChanged());
0455     KGraphViewerSettings::self()->save();
0456 }
0457 
0458 void KGraphViewerWindow::slotParsingModeInternalToggled(bool value)
0459 {
0460     qCDebug(KGRAPHVIEWER_LOG);
0461     if (value) {
0462         KGraphViewerSettings::setParsingMode("internal");
0463     }
0464     //   qCDebug(KGRAPHVIEWER_LOG) << "emitting";
0465     //   emit(settingsChanged());
0466     KGraphViewerSettings::self()->save();
0467 }
0468 
0469 void KGraphViewerWindow::slotURLSelected(const QUrl &url)
0470 {
0471     openUrl(url);
0472 }
0473 
0474 void KGraphViewerWindow::close(int index)
0475 {
0476     QWidget *tab = m_widget->widget(index);
0477     m_openedFiles.removeAll(m_tabsFilesMap[tab]);
0478     m_widget->removeTab(index);
0479     tab->hide();
0480     KParts::Part *part = m_tabsPartsMap[tab];
0481     m_manager->removePart(part);
0482     m_tabsPartsMap.remove(tab);
0483     m_tabsFilesMap.remove(tab);
0484     delete part;
0485     part = nullptr;
0486     /*  delete tab;
0487       tab = nullptr;*/
0488     m_closeAction->setEnabled(m_widget->count() > 0);
0489 }
0490 
0491 void KGraphViewerWindow::close()
0492 {
0493     int currentPage = m_widget->currentIndex();
0494     if (currentPage != -1) {
0495         close(currentPage);
0496     }
0497 }
0498 
0499 void KGraphViewerWindow::newTabSelectedSlot(int index)
0500 {
0501     emit(hide((KParts::Part *)(m_manager->activePart())));
0502 
0503     QWidget *tab = m_widget->widget(index);
0504     if (tab) {
0505         m_manager->setActivePart(m_tabsPartsMap[tab]);
0506     }
0507 }
0508 
0509 void KGraphViewerWindow::slotHoverEnter(const QString &id)
0510 {
0511     qCDebug(KGRAPHVIEWER_LOG) << id;
0512     statusBar()->showMessage(id);
0513 }
0514 
0515 void KGraphViewerWindow::slotHoverLeave(const QString &id)
0516 {
0517     qCDebug(KGRAPHVIEWER_LOG) << id;
0518     statusBar()->showMessage("");
0519 }
0520 
0521 void KGraphViewerWindow::slotBackgroundColorChanged(const QColor &)
0522 {
0523     qCDebug(KGRAPHVIEWER_LOG);
0524     for (KParts::Part *part : m_tabsPartsMap) {
0525         KGraphViewer::KGraphViewerInterface *kgv = qobject_cast<KGraphViewer::KGraphViewerInterface *>(part);
0526         if (!kgv) {
0527             // This should not happen
0528             return;
0529         }
0530         kgv->setBackgroundColor(KGraphViewerSettings::backgroundColor());
0531     }
0532 }
0533 
0534 #include "moc_kgraphviewer.cpp"