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

Allow to download images or html pages

parent ef5e4f94
......@@ -23,6 +23,7 @@
#include <KLocalizedString>
#include <QAction>
#include <QCompleter>
#include <QComboBox>
#include <QDebug>
......@@ -41,6 +42,7 @@
#include <QStackedWidget>
#include <QToolButton>
#include <QVBoxLayout>
#include <QWebEngineDownloadItem>
#include <QWebEngineProfile>
#include <QWebEngineUrlScheme>
#include <QWebEngineView>
......@@ -78,6 +80,11 @@ 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;
}
......@@ -283,6 +290,9 @@ DocumentationPanelWidget::DocumentationPanelWidget(const QString& backend, const
m_textBrowser->findText(QString());
searchForward();
});
// for webenginebrowser for downloading of images or html pages
connect(m_textBrowser->page()->profile(), &QWebEngineProfile::downloadRequested, this, &DocumentationPanelWidget::downloadResource);
}
DocumentationPanelWidget::~DocumentationPanelWidget()
......@@ -356,6 +366,14 @@ void DocumentationPanelWidget::searchBackward()
m_textBrowser->findText(m_findText->text(), QWebEnginePage::FindBackward);
}
void DocumentationPanelWidget::downloadResource(QWebEngineDownloadItem* resource)
{
// default download directory is ~/Downloads on Linux
m_textBrowser->page()->download(resource->url());
resource->accept();
disconnect(m_textBrowser->page()->profile(), &QWebEngineProfile::downloadRequested, this, &DocumentationPanelWidget::downloadResource);
}
void DocumentationPanelWidget::loadDocumentation()
{
const QString& backend = backendName();
......
......@@ -33,6 +33,7 @@ class QLineEdit;
class QStackedWidget;
class QToolButton;
class QUrl;
class QWebEngineDownloadItem;
class QWebEngineView;
class DocumentationPanelWidget : public QWidget
......@@ -65,6 +66,8 @@ class DocumentationPanelWidget : public QWidget
void searchForward();
void searchBackward();
void downloadResource(QWebEngineDownloadItem*); // slot for saving the image to local disk
private:
QHelpEngine* m_engine = nullptr;
QWebEngineView* m_textBrowser = nullptr;
......
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