Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Education
Cantor
Commits
f7941e18
Commit
f7941e18
authored
Jul 08, 2020
by
Shubham .
Browse files
Make links, images, gifs working
parent
9c940ed4
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/panelplugins/documentationpanel/documentationpanelwidget.cpp
View file @
f7941e18
...
...
@@ -37,12 +37,15 @@
#include <QSplitter>
#include <QStandardPaths>
#include <QTabWidget>
#include <QWebEngineProfile>
#include <QWebEngineUrlScheme>
#include <QWebEngineView>
DocumentationPanelWidget
::
DocumentationPanelWidget
(
Cantor
::
Session
*
session
,
QWidget
*
parent
)
:
QWidget
(
parent
),
m_backend
(
QString
())
{
m_backend
=
session
->
backend
()
->
name
();
const
QString
fileName
=
QStandardPaths
::
locate
(
QStandardPaths
::
AppDataLocation
,
QLatin1String
(
"documentation/"
)
+
m_backend
+
QLatin1String
(
"/help.qhc"
));
m_engine
=
new
QHelpEngine
(
fileName
,
this
);
if
(
!
m_engine
->
setupData
())
...
...
@@ -73,20 +76,20 @@ DocumentationPanelWidget::DocumentationPanelWidget(Cantor::Session* session, QWi
tabWidget
->
addTab
(
container
,
i18n
(
"Search"
));
m_textBrowser
=
new
QWebEngineView
(
this
);
QWebEngineUrlScheme
qthelp
(
"qthelp"
);
QWebEngineUrlScheme
::
registerScheme
(
qthelp
);
m_textBrowser
->
page
()
->
profile
()
->
installUrlSchemeHandler
(
"qthelp"
,
new
QtHelpSchemeHandler
(
m_engine
));
// set initial page contents, otherwise page is blank
QByteArray
contents
;
if
(
m_backend
==
QLatin1String
(
"Maxima"
))
{
contents
=
m_engine
->
fileData
(
QUrl
(
QLatin1String
(
"qthelp://org.kde.cantor/doc/maxima.html#SEC_Top"
)));
m_textBrowser
->
load
(
QUrl
(
QLatin1String
(
"qthelp://org.kde.cantor/doc/maxima.html#SEC_Top"
)));
}
else
if
(
m_backend
==
QLatin1String
(
"Octave"
))
{
contents
=
m_engine
->
fileData
(
QUrl
(
QLatin1String
(
"qthelp://org.octave.interpreter-1.0/doc/octave.html/index.html"
)));
m_textBrowser
->
load
(
QUrl
(
QLatin1String
(
"qthelp://org.octave.interpreter-1.0/doc/octave.html/index.html"
)));
}
m_textBrowser
->
setContent
(
contents
,
QLatin1String
(
"text/html;charset=UTF-8"
));
m_textBrowser
->
show
();
QSplitter
*
splitter
=
new
QSplitter
(
Qt
::
Horizontal
,
this
);
...
...
@@ -116,8 +119,7 @@ void DocumentationPanelWidget::setSession(Cantor::Session* session)
void
DocumentationPanelWidget
::
displayHelp
(
const
QUrl
&
url
)
{
const
QByteArray
contents
=
m_engine
->
fileData
(
url
);
m_textBrowser
->
setContent
(
contents
,
QLatin1String
(
"text/html;charset=UTF-8"
));
m_textBrowser
->
load
(
url
);
m_textBrowser
->
show
();
qDebug
()
<<
url
;
...
...
src/panelplugins/documentationpanel/documentationpanelwidget.h
View file @
f7941e18
...
...
@@ -21,6 +21,10 @@
#ifndef _DOCUMENTATIONPANELWIDGET_H
#define _DOCUMENTATIONPANELWIDGET_H
#include <QBuffer>
#include <QHelpEngine>
#include <QWebEngineUrlRequestJob>
#include <QWebEngineUrlSchemeHandler>
#include <QWidget>
namespace
Cantor
{
...
...
@@ -60,4 +64,29 @@ class DocumentationPanelWidget : public QWidget
QString
m_backend
;
};
// class for handling of custom url scheme ie. qthelp:// inside QWebEngineView
class
QtHelpSchemeHandler
:
public
QWebEngineUrlSchemeHandler
{
Q_OBJECT
public:
QtHelpSchemeHandler
(
QHelpEngine
*
helpEngine
)
:
m_HelpEngine
(
helpEngine
)
{
}
virtual
void
requestStarted
(
QWebEngineUrlRequestJob
*
job
)
override
{
auto
url
=
job
->
requestUrl
();
auto
data
=
new
QByteArray
;
*
data
=
m_HelpEngine
->
fileData
(
url
);
auto
buffer
=
new
QBuffer
(
data
);
if
(
url
.
scheme
()
==
QLatin1String
(
"qthelp"
))
{
job
->
reply
(
"text/html"
,
buffer
);
}
}
private:
QHelpEngine
*
m_HelpEngine
;
};
#endif
/* _DOCUMENTATIONPANELWIDGET_H */
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment