digiKam
htmlwidget_qwebengine.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2009-12-01
7  * Description : Widget for displaying HTML in the backends - QtWebEngine version
8  *
9  * Copyright (C) 2010-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2009-2011 by Michael G. Hansen <mike at mghansen dot de>
11  * Copyright (C) 2015 by Mohamed_Anwer <m_dot_anwer at gmx dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_HTML_WIDGET_QWEBENGINE_H
27 #define DIGIKAM_HTML_WIDGET_QWEBENGINE_H
28 
29 // Qt includes
30 
31 #include <QTimer>
32 #include <QWebEngineView>
33 #include <QWebEnginePage>
34 
35 // Local includes
36 
37 #include "geoifacecommon.h"
38 #include "geoifacetypes.h"
39 #include "geocoordinates.h"
40 
41 namespace Digikam
42 {
43 
44 class HTMLWidget;
45 
46 class HTMLWidgetPage : public QWebEnginePage
47 {
48  Q_OBJECT
49 
50 public:
51 
52  explicit HTMLWidgetPage(HTMLWidget* const parent = nullptr);
53  ~HTMLWidgetPage() override;
54 
55 Q_SIGNALS:
56 
57  void signalHTMLEvents(const QStringList& events);
58 
59 private Q_SLOTS:
60 
61  void slotSendHTMLEvents();
62 
63 protected:
64 
65  void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel, const QString&, int, const QString&) override;
66 
67 private:
68 
69  QStringList m_events;
70  QTimer* m_timer;
71 };
72 
73 // -------------------------------------------------------------------
74 
75 class HTMLWidget : public QWebEngineView
76 {
77  Q_OBJECT
78 
79 public:
80 
81  explicit HTMLWidget(QWidget* const parent = nullptr);
82  ~HTMLWidget() override;
83 
84  void loadInitialHTML(const QString& initialHTML);
85  QVariant runScript(const QString& scriptCode, bool async = true);
86  bool runScript2Coordinates(const QString& scriptCode, GeoCoordinates* const coordinates);
87  void mouseModeChanged(const GeoMouseModes mouseMode);
88  void setSelectionRectangle(const GeoCoordinates::Pair& searchCoordinates);
90  void centerOn(const qreal west, const qreal north, const qreal east, const qreal south,
91  const bool useSaneZoomLevel = true);
92  void setSharedGeoIfaceObject(GeoIfaceSharedData* const sharedData);
93 
94 Q_SIGNALS:
95 
96  void signalHTMLEvents(const QStringList& events);
99 
100 protected:
101 
102  bool eventFilter(QObject*, QEvent*) override;
103 
104 protected Q_SLOTS:
105 
106  void slotHTMLCompleted(bool ok);
107  void progress(int progress);
108 
109 private:
110 
111  class Private;
112  Private* const d;
113 
115 };
116 
117 } // namespace Digikam
118 
119 #endif // DIGIKAM_HTML_WIDGET_QWEBENGINE_H
Definition: geocoordinates.h:49
QPair< GeoCoordinates, GeoCoordinates > Pair
Definition: geocoordinates.h:64
Definition: geoifacecommon.h:213
Definition: htmlwidget_qwebengine.h:47
HTMLWidgetPage(HTMLWidget *const parent=nullptr)
Definition: htmlwidget_qwebengine.cpp:45
void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel, const QString &, int, const QString &) override
Definition: htmlwidget_qwebengine.cpp:61
~HTMLWidgetPage() override
Definition: htmlwidget_qwebengine.cpp:57
void signalHTMLEvents(const QStringList &events)
Definition: htmlwidget_qwebengine.h:76
QVariant runScript(const QString &scriptCode, bool async=true)
Wrapper around executeScript to catch more errors.
Definition: htmlwidget_qwebengine.cpp:180
void loadInitialHTML(const QString &initialHTML)
~HTMLWidget() override
Definition: htmlwidget_qwebengine.cpp:159
void selectionHasBeenMade(const Digikam::GeoCoordinates::Pair &coordinatesRect)
void slotHTMLCompleted(bool ok)
Definition: htmlwidget_qwebengine.cpp:169
void setSharedGeoIfaceObject(GeoIfaceSharedData *const sharedData)
Definition: htmlwidget_qwebengine.cpp:435
void setSelectionRectangle(const GeoCoordinates::Pair &searchCoordinates)
Definition: htmlwidget_qwebengine.cpp:379
void progress(int progress)
Definition: htmlwidget_qwebengine.cpp:164
void centerOn(const qreal west, const qreal north, const qreal east, const qreal south, const bool useSaneZoomLevel=true)
Definition: htmlwidget_qwebengine.cpp:417
void mouseModeChanged(const GeoMouseModes mouseMode)
Definition: htmlwidget_qwebengine.cpp:401
void removeSelectionRectangle()
Definition: htmlwidget_qwebengine.cpp:396
HTMLWidget(QWidget *const parent=nullptr)
Definition: htmlwidget_qwebengine.cpp:125
void signalHTMLEvents(const QStringList &events)
bool runScript2Coordinates(const QString &scriptCode, GeoCoordinates *const coordinates)
Execute a script which returns coordinates and parse these.
Definition: htmlwidget_qwebengine.cpp:222
void signalJavaScriptReady()
bool eventFilter(QObject *, QEvent *) override
Definition: htmlwidget_qwebengine.cpp:229
Definition: datefolderview.cpp:43