File indexing completed on 2024-05-05 04:37:32

0001 /*
0002     SPDX-FileCopyrightText: 2010 Aleix Pol Gonzalez <aleixpol@kde.org>
0003     SPDX-FileCopyrightText: 2016 Igor Kushnir <igorkuo@gmail.com>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-or-later
0006 */
0007 
0008 #ifndef KDEVPLATFORM_STANDARDDOCUMENTATIONVIEW_H
0009 #define KDEVPLATFORM_STANDARDDOCUMENTATIONVIEW_H
0010 
0011 #include <QWidget>
0012 #include "documentationexport.h"
0013 #include "documentationfindwidget.h"
0014 #include <interfaces/idocumentation.h>
0015 
0016 class QNetworkAccessManager;
0017 class QMenu;
0018 
0019 namespace KDevelop
0020 {
0021 class StandardDocumentationViewPrivate;
0022 
0023 /**
0024  * A standard documentation view, based on QtWebKit or QtWebEngine, depending on your distribution preferences.
0025  */
0026 class KDEVPLATFORMDOCUMENTATION_EXPORT StandardDocumentationView : public QWidget
0027 {
0028     Q_OBJECT
0029     Q_DISABLE_COPY(StandardDocumentationView)
0030 public:
0031     static void registerCustomUrlSchemes();
0032 
0033     explicit StandardDocumentationView(DocumentationFindWidget* findWidget, QWidget* parent = nullptr );
0034     ~StandardDocumentationView() override;
0035 
0036     /**
0037      * @brief Enables zoom functionality
0038      *
0039      * @param configSubGroup KConfigGroup nested group name used to store zoom factor.
0040      *        Should uniquely describe current documentation provider.
0041      *
0042      * @warning Call this function at most once
0043      */
0044     void initZoom(const QString& configSubGroup);
0045 
0046     void setDocumentation(const IDocumentation::Ptr& doc);
0047 
0048     // NOTE: prefer overriding CSS by embedding a <style> element into HTML code directly instead of calling
0049     //       setOverrideCss*(). These functions, in case of Qt WebEngine, inject CSS code via JavaScript, which
0050     //       causes reloading and flickering of large pages. See for example kdevmanpage's class StyleSheetFixer.
0051 
0052     /**
0053      * Specifies the location of a user stylesheet to load with every web page
0054      *
0055      * @note each call to this function or setOverrideCssCode() overwrites any previously specified style
0056      */
0057     void setOverrideCssFile(const QString& cssFilePath);
0058     /**
0059      * Inject the specified UTF-8-encoded CSS code into each web page
0060      *
0061      * @note each call to this function or setOverrideCssFile() overwrites any previously specified style
0062      */
0063     void setOverrideCssCode(const QByteArray& cssCode);
0064 
0065     void load(const QUrl &url);
0066     void setHtml(const QString &html);
0067     void setNetworkAccessManager(QNetworkAccessManager* manager);
0068 
0069     /**
0070      *
0071      */
0072     void setDelegateLinks(bool delegate);
0073 
0074     QMenu* createStandardContextMenu();
0075 
0076 Q_SIGNALS:
0077     void linkClicked(const QUrl &link);
0078     void browseForward();
0079     void browseBack();
0080 
0081 public Q_SLOTS:
0082     /**
0083      * Search for @p text in the documentation view.
0084      */
0085     void search(const QString& text, KDevelop::DocumentationFindWidget::FindOptions options);
0086     void searchIncremental(const QString& text, KDevelop::DocumentationFindWidget::FindOptions options);
0087     void finishSearch();
0088 
0089     /**
0090      * Updates the contents, in case it was initialized with a documentation instance,
0091      * doesn't change anything otherwise
0092      *
0093      * @sa setDocumentation(IDocumentation::Ptr)
0094      */
0095     void update();
0096 
0097 protected:
0098     void contextMenuEvent(QContextMenuEvent* event) override;
0099     bool eventFilter(QObject* object, QEvent* event) override;
0100 
0101 private Q_SLOTS:
0102     void updateZoomFactor(double zoomFactor);
0103 
0104 private:
0105     void keyReleaseEvent(QKeyEvent* event) override;
0106 
0107 private:
0108     const QScopedPointer<class StandardDocumentationViewPrivate> d_ptr;
0109     Q_DECLARE_PRIVATE(StandardDocumentationView)
0110 };
0111 
0112 }
0113 #endif // KDEVPLATFORM_STANDARDDOCUMENTATIONVIEW_H