Commit 73a0fa04 authored by Alexander Semke's avatar Alexander Semke
Browse files

More cleanup in the documentation code.

parent 5326340f
......@@ -17,7 +17,7 @@
---
Copyright (C) 2009 Alexander Rieder <alexanderrieder@gmail.com>
Copyright (C) 2012 Martin Kuettler <martin.kuettler@gmail.com>
Copyright (C) 2018-2019 Alexander Semke <alexander.semke@web.de>
Copyright (C) 2018-2020 Alexander Semke <alexander.semke@web.de>
*/
#include "commandentry.h"
......
......@@ -16,6 +16,7 @@
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
Copyright (C) 2020 Alexander Semke <alexander.semke@web.de>
*/
#include "cassert"
......@@ -23,8 +24,6 @@
#include "documentationpanelplugin.h"
#include "session.h"
#include <QIcon>
DocumentationPanelPlugin::DocumentationPanelPlugin(QObject* parent, QList<QVariant> args) : Cantor::PanelPlugin(parent)
{
Q_UNUSED(args);
......@@ -50,16 +49,6 @@ bool DocumentationPanelPlugin::showOnStartup()
return true;
}
QIcon DocumentationPanelPlugin::icon() const
{
return QIcon::fromTheme(m_backendIcon);
}
QString DocumentationPanelPlugin::backendName() const
{
return m_backendName;
}
void DocumentationPanelPlugin::connectToShell(QObject* cantorShell)
{
m_cantorShell = cantorShell;
......@@ -69,29 +58,14 @@ void DocumentationPanelPlugin::connectToShell(QObject* cantorShell)
Cantor::PanelPlugin::State DocumentationPanelPlugin::saveState()
{
Cantor::PanelPlugin::State state = PanelPlugin::saveState();
state.inners.append(m_backendName);
state.inners.append(m_backendIcon);
return state;
}
void DocumentationPanelPlugin::restoreState(const Cantor::PanelPlugin::State& state)
{
PanelPlugin::restoreState(state);
if(state.inners.size() > 0)
{
assert(state.inners.size() == 2);
m_backendName = state.inners[0].toString();
m_backendIcon = state.inners[1].toString();
}
else if(session())
{
m_backendName = session()->backend()->name();
m_backendIcon = session()->backend()->icon();
if(m_widget)
m_widget->updateBackend(m_backendName, m_backendIcon);
}
if(session() && m_widget)
m_widget->updateBackend(session()->backend()->name());
}
K_PLUGIN_FACTORY_WITH_JSON(documentationpanelplugin, "documentationpanelplugin.json", registerPlugin<DocumentationPanelPlugin>();)
......
......@@ -16,6 +16,7 @@
---
Copyright (C) 2020 Shubham <aryan100jangid@gmail.com>
Copyright (C) 2020 Alexander Semke <alexander.semke@web.de>
*/
#ifndef _DOCUMENTATIONPANELPLUGIN_H
......@@ -34,26 +35,15 @@ class DocumentationPanelPlugin : public Cantor::PanelPlugin
~DocumentationPanelPlugin() override;
QWidget* widget() override;
bool showOnStartup() override;
/** @return icon of the current backend **/
QIcon icon() const;
/** @return name of the current backend **/
QString backendName() const;
void connectToShell(QObject* cantorShell) override;
Cantor::PanelPlugin::State saveState() override;
void restoreState(const Cantor::PanelPlugin::State& state) override;
private:
DocumentationPanelWidget* m_widget = nullptr;
QObject* m_cantorShell = nullptr;
QString m_backendName;
QString m_backendIcon;
};
#endif /* _DOCUMENTATIONPANELPLUGIN_H */
......@@ -124,8 +124,9 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
resetZoom->setEnabled(false);
});
// Later on, add Contents, Browser and Index on this stacked widget whenever setBackend() is called
//stack widget containing the web view and the content widget (will be added later in updateBacked())
m_stackedWidget = new QStackedWidget(this);
m_stackedWidget->addWidget(m_webEngineView);
/////////////////////////////////
// Find in Page widget layout //
......@@ -174,7 +175,8 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
vlayout->addWidget(m_stackedWidget);
vlayout->addWidget(findPageWidgetContainer);
connect(m_documentationSelector, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &DocumentationPanelWidget::updateDocumentation);
connect(m_documentationSelector, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &DocumentationPanelWidget::updateDocumentation);
connect(m_stackedWidget, &QStackedWidget::currentChanged, [=]{
//disable Home and Search in Page buttons when stackwidget shows contents widget, enable when shows web browser
......@@ -225,7 +227,8 @@ DocumentationPanelWidget::DocumentationPanelWidget(QWidget* parent) : QWidget(pa
});
// for webenginebrowser for downloading of images or html pages
connect(m_webEngineView->page()->profile(), &QWebEngineProfile::downloadRequested, this, &DocumentationPanelWidget::downloadResource);
connect(m_webEngineView->page()->profile(), &QWebEngineProfile::downloadRequested,
this, &DocumentationPanelWidget::downloadResource);
}
DocumentationPanelWidget::~DocumentationPanelWidget()
......@@ -241,10 +244,9 @@ DocumentationPanelWidget::~DocumentationPanelWidget()
delete m_documentationSelector;
}
void DocumentationPanelWidget::updateBackend(const QString& newBackend, const QString& icon)
void DocumentationPanelWidget::updateBackend(const QString& newBackend)
{
Q_UNUSED(icon)
qDebug()<<"update backend " << newBackend;
//nothing to do if the same backend was provided
if(m_backend == newBackend)
return;
......@@ -273,7 +275,16 @@ void DocumentationPanelWidget::updateBackend(const QString& newBackend, const QS
//TODO: restore from the saved state the previously selected documentation in m_documentationSelector for the current backend
if (!m_docNames.isEmpty())
m_documentationSelector->setCurrentIndex(0);
updateDocumentation();
if (!m_docNames.isEmpty())
{
m_webEngineView->show();
m_stackedWidget->setCurrentIndex(1);
}
else
m_webEngineView->hide();
}
/*!
......@@ -286,12 +297,11 @@ void DocumentationPanelWidget::updateDocumentation()
if (m_initializing)
return;
//remove the currently shown widgets
if(m_stackedWidget->count())
//remove the currently shown content widget, will be replaced with the new one after
//the help engine was initialized with the new documentation file
if(m_contentWidget)
{
for(int i = m_stackedWidget->count(); i >= 0; i--)
m_stackedWidget->removeWidget(m_stackedWidget->widget(i));
m_stackedWidget->removeWidget(m_contentWidget);
m_search->clear();
}
......@@ -305,11 +315,10 @@ void DocumentationPanelWidget::updateDocumentation()
if (m_docNames.isEmpty())
{
m_webEngineView->hide();
m_contentWidget = nullptr;
m_indexWidget = nullptr;
return;
}
else
m_webEngineView->show();
//initialize the Qt Help engine and provide the proper help collection file for the current backend
//and for the currently selected documentation for this backend
......@@ -327,12 +336,12 @@ void DocumentationPanelWidget::updateDocumentation()
//index widget
m_indexWidget = m_engine->indexWidget();
connect(m_indexWidget, &QHelpIndexWidget::linkActivated, this, &DocumentationPanelWidget::displayHelp);
connect(m_indexWidget, &QHelpIndexWidget::linkActivated, this, &DocumentationPanelWidget::showUrl);
//content widget
m_contentWidget = m_engine->contentWidget();
connect(m_contentWidget, &QHelpContentWidget::linkActivated, this, &DocumentationPanelWidget::displayHelp);
connect(m_contentWidget, &QHelpContentWidget::linkActivated, [=]{ m_stackedWidget->setCurrentIndex(1); });
m_stackedWidget->addWidget(m_contentWidget);
connect(m_contentWidget, &QHelpContentWidget::linkActivated, this, &DocumentationPanelWidget::showUrl);
//search widget
auto* completer = new QCompleter(m_indexWidget->model(), m_search);
......@@ -341,13 +350,6 @@ void DocumentationPanelWidget::updateDocumentation()
completer->setCaseSensitivity(Qt::CaseInsensitive);
connect(completer, QOverload<const QModelIndex&>::of(&QCompleter::activated), this, &DocumentationPanelWidget::returnPressed);
//add the widgets to the display area
m_stackedWidget->addWidget(m_contentWidget);
m_stackedWidget->addWidget(m_webEngineView);
/* Adding the index widget to implement the logic for context sensitive help
* This widget would be NEVER shown*/
m_stackedWidget->addWidget(m_indexWidget);
// handle the URL scheme handler
//m_webEngineView->page()->profile()->removeUrlScheme("qthelp");
m_webEngineView->page()->profile()->removeAllUrlSchemeHandlers(); // remove previously installed scheme handler and then install new one
......@@ -364,11 +366,15 @@ void DocumentationPanelWidget::updateDocumentation()
}
}
void DocumentationPanelWidget::displayHelp(const QUrl& url)
void DocumentationPanelWidget::showUrl(const QUrl& url)
{
qDebug() << url;
m_webEngineView->load(url);
m_webEngineView->show();
m_stackedWidget->setCurrentIndex(0); //show the web engine view
}
const QUrl& DocumentationPanelWidget::url() const
{
return QUrl();
}
void DocumentationPanelWidget::returnPressed()
......@@ -385,10 +391,8 @@ void DocumentationPanelWidget::contextSensitiveHelp(const QString& keyword)
{
qDebug() << "requested the documentation for the keyword " << keyword;
// First make sure we have display browser as the current widget on the QStackedWidget
m_webEngineView->hide();
m_stackedWidget->setCurrentIndex(1);
m_webEngineView->show();
//make sure first we show the web view in the stack widget
m_stackedWidget->setCurrentIndex(0);
m_indexWidget->filterIndices(keyword); // filter exactly, no wildcards
m_indexWidget->activateCurrentItem(); // this internally emitts the QHelpIndexWidget::linkActivated signal
......
......@@ -46,13 +46,16 @@ class DocumentationPanelWidget : public QWidget
DocumentationPanelWidget(QWidget*);
~DocumentationPanelWidget();
void updateBackend(const QString&, const QString&);
void updateBackend(const QString&);
const QUrl& url() const;
public Q_SLOTS:
void showUrl(const QUrl&);
Q_SIGNALS:
void zoomFactorChanged();
private Q_SLOTS:
void displayHelp(const QUrl&);
void contextSensitiveHelp(const QString&);
void returnPressed();
......
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