Commit b12e534f authored by Shubham  .'s avatar Shubham .
Browse files

Refactor

parent 0e26e356
......@@ -33,20 +33,11 @@ DocumentationPanelPlugin::~DocumentationPanelPlugin()
delete m_widget;
}
void DocumentationPanelPlugin::onSessionChanged()
QWidget* DocumentationPanelPlugin::widget()
{
m_backendName = session()->backend()->name();
m_backendIcon = session()->backend()->icon();
if(m_widget)
{
m_widget->setBackend(m_backendName);
m_widget->setBackendIcon(m_backendIcon);
}
}
QWidget* DocumentationPanelPlugin::widget()
{
if(!m_widget)
{
m_widget = new DocumentationPanelWidget(m_backendName, m_backendIcon, parentWidget());
......
......@@ -43,9 +43,6 @@ class DocumentationPanelPlugin : public Cantor::PanelPlugin
/** @return name of the current backend **/
QString backendName() const;
protected:
void onSessionChanged() override;
private:
QPointer<DocumentationPanelWidget> m_widget;
QString m_backendName;
......
......@@ -27,7 +27,6 @@
#include <QAction>
#include <QCompleter>
#include <QComboBox>
#include <QDebug>
#include <QFrame>
#include <QHBoxLayout>
#include <QHelpContentWidget>
......@@ -51,24 +50,11 @@
DocumentationPanelWidget::DocumentationPanelWidget(const QString& backend, const QString& backendIcon, QWidget* parent) :QWidget(parent)
{
m_backend = backend;
m_icon = backendIcon;
const QString& fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("documentation/") + m_backend + QLatin1String("/help.qhc"));
m_engine = new QHelpEngine(fileName, this);
m_index = m_engine->indexWidget();
if(!m_engine->setupData())
{
qWarning() << "Couldn't setup QtHelp Engine";
qWarning() << m_engine->error();
}
if(m_backend != QLatin1String("Octave"))
{
m_engine->setProperty("_q_readonly", QVariant::fromValue<bool>(true));
}
// initialize the Help engine
initHelpEngine();
// register the Qt help files
loadDocumentation();
m_textBrowser = new QWebEngineView(this);
......@@ -81,14 +67,15 @@ DocumentationPanelWidget::DocumentationPanelWidget(const QString& backend, const
QWebEngineUrlScheme qthelp("qthelp");
QWebEngineUrlScheme::registerScheme(qthelp);
m_textBrowser->page()->profile()->installUrlSchemeHandler("qthelp", new QtHelpSchemeHandler(m_engine));
m_textBrowser->page()->action(QWebEnginePage::ViewSource)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::OpenLinkInNewTab)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::OpenLinkInNewWindow)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::DownloadLinkToDisk)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::Reload)->setVisible(false);
qthelpRegistered = true;
}
m_textBrowser->page()->action(QWebEnginePage::ViewSource)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::OpenLinkInNewTab)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::OpenLinkInNewWindow)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::DownloadLinkToDisk)->setVisible(false);
m_textBrowser->page()->action(QWebEnginePage::Reload)->setVisible(false);
// set initial page contents, otherwise page is blank
if(m_backend == QLatin1String("Maxima"))
{
......@@ -111,7 +98,7 @@ DocumentationPanelWidget::DocumentationPanelWidget(const QString& backend, const
QComboBox* documentationSelector = new QComboBox(this);
// iterate through the available docs for current backend, for example python may have matplotlib, scikitlearn etc
documentationSelector->addItem(QIcon::fromTheme(m_icon), m_backend);
documentationSelector->addItem(QIcon::fromTheme(backendIcon), m_backend);
// real time searcher
m_search = new QLineEdit(this);
......@@ -196,7 +183,6 @@ DocumentationPanelWidget::DocumentationPanelWidget(const QString& backend, const
label->setText(i18n("Find:"));
m_findText = new QLineEdit(this);
m_findText->setPlaceholderText(i18nc("@info:placeholder", "Search..."));
m_findText->setClearButtonEnabled(true);
QToolButton* next = new QToolButton(this);
......@@ -309,14 +295,23 @@ DocumentationPanelWidget::~DocumentationPanelWidget()
//delete m_index; this crashes
}
void DocumentationPanelWidget::setBackend(const QString& backend)
void DocumentationPanelWidget::initHelpEngine()
{
m_backend = backend;
}
const QString& fileName = QStandardPaths::locate(QStandardPaths::AppDataLocation, QLatin1String("documentation/") + m_backend + QLatin1String("/help.qhc"));
void DocumentationPanelWidget::setBackendIcon(const QString& icon)
{
m_icon = icon;
m_engine = new QHelpEngine(fileName, this);
m_index = m_engine->indexWidget();
if(!m_engine->setupData())
{
qWarning() << "Couldn't setup QtHelp Engine";
qWarning() << m_engine->error();
}
if(m_backend != QLatin1String("Octave"))
{
m_engine->setProperty("_q_readonly", QVariant::fromValue<bool>(true));
}
}
void DocumentationPanelWidget::displayHelp(const QUrl& url)
......
......@@ -44,11 +44,6 @@ class DocumentationPanelWidget : public QWidget
DocumentationPanelWidget(const QString& backend, const QString& backendIcon, QWidget* parent);
~DocumentationPanelWidget();
void setBackend(const QString&);
void setBackendIcon(const QString&);
void loadDocumentation();
Q_SIGNALS:
void activateBrowser();
void zoomFactorChanged();
......@@ -64,13 +59,16 @@ class DocumentationPanelWidget : public QWidget
void downloadResource(QWebEngineDownloadItem*); // slot for saving the image or html to local disk
private:
void initHelpEngine();
void loadDocumentation();
private:
QHelpEngine* m_engine = nullptr;
QWebEngineView* m_textBrowser = nullptr;
QStackedWidget* m_displayArea = nullptr;
QHelpIndexWidget* m_index = nullptr;
QString m_backend;
QString m_icon;
// member variables for find in page text widget
QLineEdit* m_search = nullptr; // for searching through keywords
......
......@@ -472,8 +472,9 @@ void WorksheetTextItem::keyPressEvent(QKeyEvent *event)
qDebug() << "Tab";
break;
case Qt::Key_F2:
if(textCursor().hasSelection())
{
const QString& keyword = textCursor().block().text();
QString keyword = textCursor().selectedText();
emit worksheet()->requestDocumentation(keyword);
}
break;
......
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