Commit 787d5d30 authored by Shubham  .'s avatar Shubham .
Browse files

Use QWebEngineView as display area and change layout to horizontal

parent ef67d370
......@@ -24,7 +24,10 @@ find_package(Qt5 5.8.0 CONFIG REQUIRED
Xml
XmlPatterns
Test
Help)
Help
WebKitWidgets
WebEngine
WebEngineWidgets)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED
Config
......
......@@ -38,7 +38,7 @@ ecm_add_app_icon(cantor_SRCS ICONS ${ICONS_SRCS})
add_executable(cantor ${cantor_SRCS})
target_link_libraries(cantor KF5::Parts KF5::NewStuff KF5::ConfigCore KF5::CoreAddons KF5::ConfigGui
KF5::Crash KF5::XmlGui cantorlibs cantor_config)
KF5::Crash KF5::XmlGui Qt5::WebEngine cantorlibs cantor_config)
########### install files ###############
install(TARGETS cantor ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} )
......
......@@ -32,6 +32,7 @@
#include <QFileInfo>
#include <QDir>
#include <QDebug>
#include <QtWebEngine>
#include "settings.h"
......@@ -40,6 +41,8 @@ static const char description[] =
int main(int argc, char **argv)
{
QtWebEngine::initialize();
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
// Add our custom plugins path, where we install our plugins, if it isn't default path
......
......@@ -9,4 +9,7 @@ target_link_libraries(cantor_documentationpanelplugin
Qt5::Widgets
Qt5::Help
Qt5::Gui
Qt5::Core)
Qt5::Core
Qt5::WebKitWidgets
Qt5::WebEngine
Qt5::WebEngineWidgets)
......@@ -34,10 +34,11 @@
#include <QHelpIndexWidget>
#include <QIcon>
#include <QPointer>
#include <QSplitter>
#include <QStandardPaths>
#include <QTabWidget>
#include <QTextBrowser>
#include <QUrl>
#include <QWebEngineView>
DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) :QWidget(parent), m_engine(nullptr)
{
......@@ -45,12 +46,12 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) :QWidget(par
const QString fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("documentation/") + backendName + QLatin1String("/help.qhc"));
m_engine = new QHelpEngine(fileName, this);
if( !m_engine->setupData() )
if(!m_engine->setupData())
{
qWarning() << "Couldn't setup QtHelp Collection file";
}
QPointer<QTabWidget> tabWidget = new QTabWidget(this);
QTabWidget* tabWidget = new QTabWidget(this);
tabWidget->setMaximumWidth(1000);
tabWidget->setMinimumWidth(500);
tabWidget->setMovable(true);
......@@ -58,26 +59,51 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) :QWidget(par
tabWidget->addTab(m_engine->indexWidget(), i18n("Index"));
tabWidget->addTab(m_engine->contentWidget(), i18n("Contents"));
// later add properties like contextmenu event, keyevent, mousevent to the browser
QWebEngineView* textBrowser = new QWebEngineView(this);
QByteArray contents = m_engine->fileData(QUrl(QLatin1String("qthelp://org.kde.cantor/doc/maxima.html#SEC_Top")));
textBrowser->setContent(contents);
textBrowser->show();
QPointer<QTextBrowser> textBrowser = new QTextBrowser(parentWidget());
connect(m_engine->contentWidget(), SIGNAL(linkActivated(QUrl)), this, SLOT(displayHelp(QUrl)));
connect(m_engine->indexWidget(), SIGNAL(linkActivated(QUrl, QString)), this, SLOT(displayHelp(QUrl)));
connect(m_engine->contentWidget(), SIGNAL(linkActivated(QUrl)), textBrowser, SLOT(setSource(QUrl)));
connect(m_engine->indexWidget(), SIGNAL(linkActivated(QUrl, QString)), textBrowser, SLOT(setSource(QUrl)));
QSplitter* splitter = new QSplitter(Qt::Horizontal, this);
splitter->addWidget(tabWidget);
splitter->addWidget(textBrowser);
QVBoxLayout* layout = new QVBoxLayout(this);
layout->addWidget(tabWidget, 1);
layout->addWidget(textBrowser, 2);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(splitter);
loadDocumentation();
}
void DocumentationPanelWidget::displayHelp(const QUrl& url)
{
// Add code to display the backends help from the qhc files
}
void DocumentationPanelWidget::loadDocumentation()
{
//1. Get the backend name
//2. Load their documentation
const QString backendName = QLatin1String("maxima");
const QString fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("documentation/") + backendName + QLatin1String("/help.qch"));
m_engine->registerDocumentation(fileName);
}
void DocumentationPanelWidget::unloadDocumentation()
{
//1. Get the backend name
//2. Unload their documentation
//Call this function when the user changes the current backend
const QString backendName = QLatin1String("maxima");
const QString fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("documentation/") + backendName + QLatin1String("/help.qch"));
m_engine->unregisterDocumentation(fileName);
}
QIcon DocumentationPanelWidget::icon() const
{
// return backend's icon
......
......@@ -25,12 +25,14 @@
#include <QWidget>
class QHelpEngine;
class QUrl;
class DocumentationPanelWidget : public QWidget
{
Q_OBJECT
public:
DocumentationPanelWidget(QWidget* parent);
DocumentationPanelWidget(QWidget*);
~DocumentationPanelWidget() override = default;
/** @return icon of the current backend **/
......@@ -40,7 +42,10 @@ class DocumentationPanelWidget : public QWidget
QString name() const;
void loadDocumentation();
/** @return local paths to all QCH files found in cantor/admin/documentation directory **/
void unloadDocumentation();
public Q_SLOTS:
void displayHelp(const QUrl&);
private:
QPointer<QHelpEngine> m_engine;
......
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