Commit 82c65df8 authored by Shubham  .'s avatar Shubham .
Browse files

Add DocumentationPanelPlugin and DocumentationPanelWidget classes

parent 43bb25f1
......@@ -23,7 +23,8 @@ find_package(Qt5 5.8.0 CONFIG REQUIRED
Svg
Xml
XmlPatterns
Test)
Test
Help)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED
Config
......
......@@ -12,3 +12,4 @@ endfunction()
add_subdirectory(helppanel)
add_subdirectory(variablemgr)
add_subdirectory(documentationpanel)
set( DocumentationPanelPlugin_SRCS
documentationpanelplugin.cpp
documentationpanelwidget.cpp
)
add_panel(documentationpanelplugin ${DocumentationPanelPlugin_SRCS})
target_link_libraries(cantor_documentationpanelplugin
Qt5::Widgets
Qt5::Help
Qt5::Gui
Qt5::Core)
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#include "documentationpanelplugin.h"
#include "documentationpanelwidget.h"
DocumentationPanelPlugin::DocumentationPanelPlugin(QObject* parent, QList<QVariant> args) : Cantor::PanelPlugin(parent), m_widget(nullptr)
{
Q_UNUSED(args);
m_showAtStart = true;
}
DocumentationPanelPlugin::~DocumentationPanelPlugin()
{
delete m_widget;
}
void DocumentationPanelPlugin::onSessionChanged()
{
if(m_widget)
m_widget->setSession(session());
}
QWidget* DocumentationPanelPlugin::widget()
{
if(m_widget == nullptr)
{
m_widget = new DocumentationPanelWidget(session(), parentWidget());
//connect(m_widget.data(), &DocumentationPanelWidget::runCommand, this, &DocumentationPanelPlugin::requestRunCommand);
}
return m_widget;
}
bool DocumentationPanelPlugin::showOnStartup()
{
return m_showAtStart;
}
void DocumentationPanelPlugin::setShowOnStartup(bool value)
{
m_showAtStart = value;
}
K_PLUGIN_FACTORY_WITH_JSON(variablemanagerplugin, "documentationpanelplugin.json", registerPlugin<DocumentationPanelPlugin>();)
#include "documentationpanelplugin.moc"
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#ifndef _DOCUMENTATIONPANELPLUGIN_H
#define _DOCUMENTATIPNPANELPLUGIN_H
#include "panelplugin.h"
#include "documentationpanelwidget.h"
class DocumentationPanelWidget;
class DocumentationPanelPlugin : public Cantor::PanelPlugin
{
Q_OBJECT
public:
DocumentationPanelPlugin( QObject* parent, QList<QVariant> args);
~DocumentationPanelPlugin() override;
QWidget* widget() override;
bool showOnStartup() override;
void setShowOnStartup(bool);
protected:
void onSessionChanged() override;
private:
bool m_showAtStart;
QPointer<DocumentationPanelWidget> m_widget;
};
#endif /* _DOCUMENTATIPNPANELPLUGIN_H */
{
"KPlugin": {
"Dependencies": [],
"Description": "A panel to display the official documentation of various backends",
"Icon": "",
"Id": "DocumentationPanel",
"License": "GPL",
"Name": "Documentation",
"ServiceTypes": [
"Cantor/PanelPlugin"
]
},
"RequiredExtensions": ""
}
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#include "cantor_macros.h"
#include "documentationpanelplugin.h"
#include "session.h"
#include <KLocalizedString>
#include <QApplication>
#include <QByteArray>
#include <QDebug>
#include <QDir>
#include <QHelpContentWidget>
#include <QHelpEngine>
#include <QHelpIndexWidget>
#include <QIcon>
#include <QPointer>
#include <QSplitter>
#include <QTabWidget>
#include <QTextBrowser>
#include <QUrl>
#include <QVBoxLayout>
DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWidget* parent) :QWidget(parent), m_engine(nullptr)
{
addWidgets();
setSession(session);
}
void DocumentationPanelWidget::setSession(Cantor::Session* session)
{
m_session=session;
/*if(session)
{
m_model=session->variableDataModel();
if(m_table)
m_table->setModel(m_model);
}*/
}
void DocumentationPanelWidget::addWidgets()
{
QPointer<QTabWidget> m_tabWidget;
QPointer<QSplitter> m_splitter;
QPointer<QTextBrowser> m_textBrowser;
//m_engine = new QHelpEngine(QApplication::applicationDirPath() + QLatin1String("/documentation/maxima_help_collection.qhc"), this);
m_engine = new QHelpEngine(QApplication::applicationDirPath() + QLatin1String("admin/documentation/maxima_help_collection.qhc"), this);
m_engine->setupData();
QByteArray helpData = m_engine->fileData(QUrl(QLatin1String("qthelp://org.kde.cantor/doc/maxima_7.html#SEC36")));
if (!helpData.isEmpty())
qDebug() << helpData;
m_tabWidget = new QTabWidget;
m_tabWidget->setMaximumWidth(1000);
m_tabWidget->addTab(m_engine->indexWidget(), i18n("Index"));
m_tabWidget->addTab(m_engine->contentWidget(), i18n("Contents"));
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(m_tabWidget, 1);
}
void DocumentationPanelWidget::loadDocumentation()
{
if(m_path.isEmpty()) {
return;
}
const QStringList files = qchFiles();
if(files.isEmpty()) {
qWarning() << "could not find QCH file in directory" << m_path;
return;
}
for (const QString& fileName : files) {
QString fileNamespace = QHelpEngineCore::namespaceName(fileName);
if (!fileNamespace.isEmpty() && !m_engine->registeredDocumentations().contains(fileNamespace)) {
qDebug() << "loading doc" << fileName << fileNamespace;
if(!m_engine->registerDocumentation(fileName))
qCritical() << "error >> " << fileName << m_engine->error();
}
}
}
//search for QCH
QStringList DocumentationPanelWidget::qchFiles() const
{
QStringList files;
const QVector<QString> paths{ // test directories
m_path,
m_path + QLatin1String("/qch/"),
};
for (const auto& path : paths) {
QDir d(path);
if(path.isEmpty() || !d.exists()) {
continue;
}
const auto fileInfos = d.entryInfoList(QDir::Files);
for (const auto& file : fileInfos) {
files << file.absoluteFilePath();
}
}
if (files.isEmpty()) {
qDebug() << "no QCH file found at all";
}
return files;
}
QIcon DocumentationPanelWidget::icon() const
{
// determine backend name and then reurn it's icon
//return QIcon::fromTheme(QStringLiteral("maxima"));
return QIcon();
}
QString DocumentationPanelWidget::name() const
{
// return the help name of the backend
return i18n("Maxima Help");
}
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
*/
#ifndef _DOCUMENTATIONPANELWIDGET_H
#define _DOCUMENTATIONPANELWIDGET_H
#include <QPointer>
#include <QWidget>
namespace Cantor{
class Session;
}
class QHelpEngine;
class QSplitter;
class QTabWidget;
class QTextBrowser;
class DocumentationPanelWidget : public QWidget
{
Q_OBJECT
public:
DocumentationPanelWidget( Cantor::Session* session, QWidget* parent );
~DocumentationPanelWidget() override = default;
void setSession(Cantor::Session* session);
void addWidgets();
QIcon icon() const;
QString name() const;
void loadDocumentation();
/** @return local paths to all QCH files found in cantor/admin/documentation directory **/
QStringList qchFiles() const;
private:
Cantor::Session* m_session;
QPointer<QHelpEngine> m_engine;
QString m_path; // path to local QCH files
};
#endif /* _DOCUMENTATIONPANELWIDGET_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment