Warning, file /office/skrooge/skgbasegui/skgwebview.h was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /***************************************************************************
0002  * SPDX-FileCopyrightText: 2022 S. MANKOWSKI stephane@mankowski.fr
0003  * SPDX-FileCopyrightText: 2022 G. DE BURE support@mankowski.fr
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  ***************************************************************************/
0006 #ifndef SKGWEBVIEW_H
0007 #define SKGWEBVIEW_H
0008 /** @file
0009  * A web viewer with more features.
0010  *
0011  * @author Stephane MANKOWSKI / Guillaume DE BURE
0012  */
0013 #include <qprinter.h>
0014 #ifdef SKG_WEBENGINE
0015 #include <qwebengineview.h>
0016 #endif
0017 #ifdef SKG_WEBKIT
0018 #include <qwebview.h>
0019 #endif
0020 #if !defined(SKG_WEBENGINE) && !defined(SKG_WEBKIT)
0021 #include <qscrollarea.h>
0022 #include <qlabel.h>
0023 #endif
0024 #include "skgbasegui_export.h"
0025 
0026 /**
0027  * This file is a web viewer
0028  */
0029 #ifdef SKG_WEBENGINE
0030 class SKGBASEGUI_EXPORT SKGWebView : public QWebEngineView
0031 #endif
0032 #ifdef SKG_WEBKIT
0033     class SKGBASEGUI_EXPORT SKGWebView : public QWebView
0034 #endif
0035 #if !defined(SKG_WEBENGINE) && !defined(SKG_WEBKIT)
0036         class SKGBASEGUI_EXPORT SKGWebView : public QScrollArea
0037 #endif
0038         {
0039             Q_OBJECT
0040 
0041         public:
0042             /**
0043              * Constructor
0044              * @param iParent the parent
0045              * @param name name
0046              */
0047 #ifdef SKG_WEBENGINE
0048             explicit SKGWebView(QWidget* iParent, const char* name = nullptr, bool iWithContextualMenu = true);
0049 
0050             /**
0051              * To emit that a link is clicked
0052              * @param iURL the url of the link
0053              */
0054             void emitLinkClicked(const QUrl& iURL);
0055 
0056 #endif
0057 #ifdef SKG_WEBKIT
0058             explicit SKGWebView(QWidget* iParent, const char* name = nullptr);
0059 #endif
0060 #if !defined(SKG_WEBENGINE) && !defined(SKG_WEBKIT)
0061             explicit SKGWebView(QWidget* iParent, const char* name = nullptr);
0062 #endif
0063             /**
0064              * Destructor
0065              */
0066             ~SKGWebView() override;
0067 
0068             /**
0069              * Get the current state
0070              * @return a string containing all information needed to set the same state.
0071              * Could be an XML stream
0072              */
0073             virtual QString getState();
0074 
0075             /**
0076              * Set the current state
0077              * MUST BE OVERWRITTEN
0078              * @param iState must be interpreted to set the state of the widget
0079              */
0080             virtual void setState(const QString& iState);
0081 
0082             /**
0083              * Export in the file (PDF, ODT, png, jpeg, …)
0084              * @param iFileName the file name
0085              */
0086             virtual void exportInFile(const QString& iFileName);
0087 
0088 #if !defined(SKG_WEBENGINE) && !defined(SKG_WEBKIT)
0089             /**
0090              * Set html
0091              * @param iFileName the file name
0092              */
0093             virtual void setHtml(const QString& iHtml)
0094             {
0095                 qobject_cast<QLabel*>(widget())->setText(iHtml);
0096             };
0097 #endif
0098 
0099         Q_SIGNALS:
0100             /**
0101              * Emitted when zoom changed
0102              * @param iZoomPosition zoom position (-10<=zoom position<=10)
0103              */
0104             void zoomChanged(int iZoomPosition);
0105 
0106             /**
0107              * Emitted when a file is exported
0108              * @param iFileName the exported file name
0109              */
0110             void fileExporter(const QString& iFileName);
0111 
0112 #ifdef SKG_WEBENGINE
0113             /**
0114              * Emitted when a link is clicked
0115              * @param iURL the url of the link
0116              */
0117             void linkClicked(const QUrl& iURL);
0118 #endif
0119 
0120         public Q_SLOTS:
0121             /**
0122              * Zoom in
0123              */
0124             virtual void onZoomIn();
0125 
0126             /**
0127              * Zoom out
0128              */
0129             virtual void onZoomOut();
0130 
0131             /**
0132              * Fit on scene
0133              */
0134             virtual void onZoomOriginal();
0135 
0136             /**
0137              * Print
0138              */
0139             virtual void onPrint();
0140 
0141             /**
0142              * Export
0143              */
0144             virtual void onExport();
0145 
0146             /**
0147              * Print preview
0148              */
0149             virtual void onPrintPreview();
0150 
0151         protected:
0152 #if defined(SKG_WEBENGINE) || defined(SKG_WEBKIT)
0153             /**
0154              * Contextual event
0155              * @param iEvent the event
0156              */
0157             void contextMenuEvent(QContextMenuEvent* iEvent) override;
0158 #endif
0159 
0160             /**
0161              * Event filtering
0162              * @param iObject object
0163              * @param iEvent event
0164              * @return In your reimplementation of this function, if you want to filter the event out, i.e. stop it being handled further, return true; otherwise return false.
0165              */
0166             bool eventFilter(QObject* iObject, QEvent* iEvent) override;
0167 
0168         private:
0169             Q_DISABLE_COPY(SKGWebView)
0170             QPrinter m_printer;
0171 
0172 #ifdef SKG_WEBENGINE
0173             bool m_ContextualMenu;
0174 #endif
0175 #ifdef SKG_WEBKIT
0176             void openReply(QNetworkReply* reply);
0177 #endif
0178         };
0179 
0180 #endif