File indexing completed on 2024-05-05 11:56:07

0001 /*
0002     SPDX-License-Identifier: GPL-2.0-or-later
0003     SPDX-FileCopyrightText: 2020 Shubham <aryan100jangid@gmail.com>
0004     SPDX-FileCopyrightText: 2020-2022 Alexander Semke <alexander.semke@web.de>
0005 */
0006 
0007 #include "documentationpanelplugin.h"
0008 #include "documentationpanelwidget.h"
0009 #include "session.h"
0010 
0011 #include <KPluginFactory>
0012 
0013 DocumentationPanelPlugin::DocumentationPanelPlugin(QObject* parent, QList<QVariant> args) : Cantor::PanelPlugin(parent)
0014 {
0015     Q_UNUSED(args);
0016 }
0017 
0018 DocumentationPanelPlugin::~DocumentationPanelPlugin()
0019 {
0020 }
0021 
0022 QWidget* DocumentationPanelPlugin::widget()
0023 {
0024     if(!m_widget)
0025     {
0026         m_widget = new DocumentationPanelWidget(parentWidget());
0027         if (m_cantorShell)
0028             connect(m_cantorShell, SIGNAL(requestDocumentation(QString)), m_widget, SLOT(contextSensitiveHelp(QString)));
0029     }
0030 
0031     return m_widget;
0032 }
0033 
0034 bool DocumentationPanelPlugin::showOnStartup()
0035 {
0036     return true;
0037 }
0038 
0039 void DocumentationPanelPlugin::connectToShell(QObject* cantorShell)
0040 {
0041     m_cantorShell = cantorShell;
0042     connect(cantorShell, SIGNAL(requestDocumentation(QString)), this, SIGNAL(visibilityRequested()));
0043 
0044     // when using cantor in labplot, connectToShell() is called after widget() so we need to connect here, too
0045     if (m_widget)
0046         connect(m_cantorShell, SIGNAL(requestDocumentation(QString)), m_widget, SLOT(contextSensitiveHelp(QString)));
0047 }
0048 
0049 Cantor::PanelPlugin::State DocumentationPanelPlugin::saveState()
0050 {
0051     Cantor::PanelPlugin::State state = PanelPlugin::saveState();
0052     state.inners.append(m_widget->url()); //save the currently shown URL in the web view
0053     return state;
0054 }
0055 
0056 void DocumentationPanelPlugin::restoreState(const Cantor::PanelPlugin::State& state)
0057 {
0058     PanelPlugin::restoreState(state);
0059 
0060     //TODO: when using this panel in LabPlot this function is being called before widget().
0061     //the reason is not completely clear. call widget() here to make sure it's available.
0062     if (!m_widget)
0063         this->widget();
0064 
0065     if(session() && m_widget)
0066     {
0067         m_widget->updateBackend(session()->backend()->name());
0068         if (state.inners.size() == 1)
0069             m_widget->showUrl(state.inners.first().toUrl());
0070     }
0071 }
0072 
0073 K_PLUGIN_FACTORY_WITH_JSON(documentationpanelplugin, "documentationpanelplugin.json", registerPlugin<DocumentationPanelPlugin>();)
0074 #include "documentationpanelplugin.moc"