1 /*
2     SPDX-FileCopyrightText: 2010 Aleix Pol Gonzalez <aleixpol@kde.org>
3     SPDX-FileCopyrightText: 2016 Igor Kushnir <igorkuo@gmail.com>
4 
5     SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #ifndef KDEVPLATFORM_STANDARDDOCUMENTATIONVIEW_H
9 #define KDEVPLATFORM_STANDARDDOCUMENTATIONVIEW_H
10 
11 #include <QWidget>
12 #include "documentationexport.h"
13 #include "documentationfindwidget.h"
14 #include <interfaces/idocumentation.h>
15 
16 class QNetworkAccessManager;
17 class QMenu;
18 
19 namespace KDevelop
20 {
21 class StandardDocumentationViewPrivate;
22 
23 /**
24  * A standard documentation view, based on QtWebKit or QtWebEngine, depending on your distribution preferences.
25  */
26 class KDEVPLATFORMDOCUMENTATION_EXPORT StandardDocumentationView : public QWidget
27 {
28     Q_OBJECT
29     Q_DISABLE_COPY(StandardDocumentationView)
30 public:
31     explicit StandardDocumentationView(DocumentationFindWidget* findWidget, QWidget* parent = nullptr );
32     ~StandardDocumentationView() override;
33 
34     /**
35      * @brief Enables zoom functionality
36      *
37      * @param configSubGroup KConfigGroup nested group name used to store zoom factor.
38      *        Should uniquely describe current documentation provider.
39      *
40      * @warning Call this function at most once
41      */
42     void initZoom(const QString& configSubGroup);
43 
44     void setDocumentation(const IDocumentation::Ptr& doc);
45 
46     void setOverrideCss(const QUrl &url);
47 
48     void load(const QUrl &url);
49     void setHtml(const QString &html);
50     void setNetworkAccessManager(QNetworkAccessManager* manager);
51 
52     /**
53      *
54      */
55     void setDelegateLinks(bool delegate);
56 
57     QMenu* createStandardContextMenu();
58 
59 Q_SIGNALS:
60     void linkClicked(const QUrl &link);
61     void browseForward();
62     void browseBack();
63 
64 public Q_SLOTS:
65     /**
66      * Search for @p text in the documentation view.
67      */
68     void search(const QString& text, KDevelop::DocumentationFindWidget::FindOptions options);
69     void searchIncremental(const QString& text, KDevelop::DocumentationFindWidget::FindOptions options);
70     void finishSearch();
71 
72     /**
73      * Updates the contents, in case it was initialized with a documentation instance,
74      * doesn't change anything otherwise
75      *
76      * @sa setDocumentation(IDocumentation::Ptr)
77      */
78     void update();
79 
80 protected:
81     void contextMenuEvent(QContextMenuEvent* event) override;
82     bool eventFilter(QObject* object, QEvent* event) override;
83 
84 private Q_SLOTS:
85     void updateZoomFactor(double zoomFactor);
86 
87 private:
88     void keyReleaseEvent(QKeyEvent* event) override;
89 
90 private:
91     const QScopedPointer<class StandardDocumentationViewPrivate> d_ptr;
92     Q_DECLARE_PRIVATE(StandardDocumentationView)
93 };
94 
95 }
96 #endif // KDEVPLATFORM_STANDARDDOCUMENTATIONVIEW_H
97