File indexing completed on 2024-04-28 11:20:49
0001 /* 0002 SPDX-License-Identifier: GPL-2.0-or-later 0003 SPDX-FileCopyrightText: 2020 Shubham <aryan100jangid@gmail.com> 0004 SPDX-FileCopyrightText: 2020-2021 Alexander Semke <alexander.semke@web.de> 0005 */ 0006 0007 #ifndef _DOCUMENTATIONPANELWIDGET_H 0008 #define _DOCUMENTATIONPANELWIDGET_H 0009 0010 #include <QBuffer> 0011 #include <QHelpEngine> 0012 #include <QWebEngineUrlRequestJob> 0013 #include <QWebEngineUrlSchemeHandler> 0014 #include <QWidget> 0015 0016 class QComboBox; 0017 class QHelpContentWidget; 0018 class QHelpIndexWidget; 0019 class QLineEdit; 0020 class QStackedWidget; 0021 class QToolButton; 0022 class QUrl; 0023 class QWebEngineDownloadItem; 0024 class QWebEngineView; 0025 0026 class DocumentationPanelWidget : public QWidget 0027 { 0028 Q_OBJECT 0029 0030 public: 0031 DocumentationPanelWidget(QWidget*); 0032 ~DocumentationPanelWidget(); 0033 0034 void updateBackend(const QString&); 0035 QUrl url() const; 0036 0037 public Q_SLOTS: 0038 void showUrl(const QUrl&); 0039 0040 Q_SIGNALS: 0041 void zoomFactorChanged(); 0042 0043 private Q_SLOTS: 0044 void contextSensitiveHelp(const QString&); 0045 void returnPressed(); 0046 0047 // SLOTS for Find in Page widget 0048 void searchForward(); 0049 void searchBackward(); 0050 0051 void downloadResource(QWebEngineDownloadItem*); // slot for saving the image or html to local disk 0052 0053 private: 0054 void updateDocumentation(); 0055 0056 QHelpEngine* m_engine = nullptr; 0057 QWebEngineView* m_webEngineView = nullptr; 0058 QStackedWidget* m_stackedWidget = nullptr; 0059 QHelpIndexWidget* m_indexWidget = nullptr; 0060 QHelpContentWidget* m_contentWidget = nullptr; 0061 QString m_backend; 0062 QStringList m_docNames; 0063 QStringList m_docPaths; 0064 bool m_initializing = false; 0065 0066 // member variables for find in page text widget 0067 QLineEdit* m_search = nullptr; // for searching through keywords 0068 QLineEdit* m_findText = nullptr; // for find in page text widget 0069 QToolButton* m_matchCase = nullptr; 0070 0071 QComboBox* m_documentationSelector = nullptr; 0072 QString m_currentQchFileName; 0073 }; 0074 0075 // class for handling of custom url scheme ie. qthelp:// inside QWebEngineView 0076 class QtHelpSchemeHandler : public QWebEngineUrlSchemeHandler 0077 { 0078 Q_OBJECT 0079 0080 public: 0081 QtHelpSchemeHandler(QHelpEngine* helpEngine) : m_HelpEngine(helpEngine) 0082 { 0083 } 0084 0085 virtual void requestStarted(QWebEngineUrlRequestJob* job) override 0086 { 0087 auto url = job->requestUrl(); 0088 auto data = new QByteArray; 0089 *data = m_HelpEngine->fileData(url); 0090 auto buffer = new QBuffer(data); 0091 if (url.scheme() == QLatin1String("qthelp")) { 0092 job->reply("text/html", buffer); 0093 } 0094 } 0095 0096 private: 0097 QHelpEngine* m_HelpEngine; 0098 }; 0099 0100 #endif /* _DOCUMENTATIONPANELWIDGET_H */