File indexing completed on 2025-01-05 03:58:35

0001 /* ============================================================
0002  *
0003  * This file is a part of digiKam project
0004  * https://www.digikam.org
0005  *
0006  * Date        : 2009-12-01
0007  * Description : Widget for displaying HTML in the backends - QtWebEngine version
0008  *
0009  * SPDX-FileCopyrightText: 2010-2024 by Gilles Caulier <caulier dot gilles at gmail dot com>
0010  * SPDX-FileCopyrightText: 2009-2011 by Michael G. Hansen <mike at mghansen dot de>
0011  * SPDX-FileCopyrightText: 2015      by Mohamed_Anwer <m_dot_anwer at gmx dot com>
0012  *
0013  * SPDX-License-Identifier: GPL-2.0-or-later
0014  *
0015  * ============================================================ */
0016 
0017 #ifndef DIGIKAM_HTML_WIDGET_QWEBENGINE_H
0018 #define DIGIKAM_HTML_WIDGET_QWEBENGINE_H
0019 
0020 // Qt includes
0021 
0022 #include <QTimer>
0023 #include <QWebEngineView>
0024 #include <QWebEnginePage>
0025 
0026 // Local includes
0027 
0028 #include "geoifacecommon.h"
0029 #include "geoifacetypes.h"
0030 #include "geocoordinates.h"
0031 
0032 namespace Digikam
0033 {
0034 
0035 class HTMLWidget;
0036 
0037 class HTMLWidgetPage : public QWebEnginePage
0038 {
0039     Q_OBJECT
0040 
0041 public:
0042 
0043     explicit HTMLWidgetPage(HTMLWidget* const parent = nullptr);
0044     ~HTMLWidgetPage() override;
0045 
0046 Q_SIGNALS:
0047 
0048     void signalHTMLEvents(const QStringList& events);
0049     void signalMessageEvent(const QString& message);
0050 
0051 private Q_SLOTS:
0052 
0053     void slotSendHTMLEvents();
0054 
0055 protected:
0056 
0057     void javaScriptConsoleMessage(JavaScriptConsoleMessageLevel, const QString&, int, const QString&) override;
0058 
0059 private:
0060 
0061     QStringList m_events;
0062     QString     m_message;
0063     QTimer*     m_timer;
0064 };
0065 
0066 // -------------------------------------------------------------------
0067 
0068 class HTMLWidget : public QWebEngineView
0069 {
0070     Q_OBJECT
0071 
0072 public:
0073 
0074     explicit HTMLWidget(QWidget* const parent = nullptr);
0075     ~HTMLWidget() override;
0076 
0077     void loadInitialHTML(const QString& initialHTML);
0078     QVariant runScript(const QString& scriptCode, bool async = true);
0079     bool runScript2Coordinates(const QString& scriptCode, GeoCoordinates* const coordinates);
0080     void mouseModeChanged(const GeoMouseModes mouseMode);
0081     void setSelectionRectangle(const GeoCoordinates::Pair& searchCoordinates);
0082     void removeSelectionRectangle();
0083     void centerOn(const qreal west, const qreal north, const qreal east, const qreal south,
0084                   const bool useSaneZoomLevel = true);
0085     void setSharedGeoIfaceObject(GeoIfaceSharedData* const sharedData);
0086 
0087 Q_SIGNALS:
0088 
0089     void signalHTMLEvents(const QStringList& events);
0090     void signalMessageEvent(const QString& message);
0091     void signalJavaScriptReady();
0092     void selectionHasBeenMade(const Digikam::GeoCoordinates::Pair& coordinatesRect);
0093 
0094 protected:
0095 
0096     bool eventFilter(QObject*, QEvent*) override;
0097 
0098 protected Q_SLOTS:
0099 
0100     void slotHTMLCompleted(bool ok);
0101     void progress(int progress);
0102 
0103 private:
0104 
0105     class Private;
0106     Private* const      d;
0107 
0108     GeoIfaceSharedData* s;
0109 };
0110 
0111 } // namespace Digikam
0112 
0113 #endif // DIGIKAM_HTML_WIDGET_QWEBENGINE_H