File indexing completed on 2024-04-14 03:47:54

0001 // SPDX-License-Identifier: LGPL-2.1-or-later
0002 //
0003 // SPDX-FileCopyrightText: 2012 Illya Kovalevskyy <illya.kovalevskyy@gmail.com>
0004 //
0005 
0006 #ifndef MARBLEWEBVIEW_H
0007 #define MARBLEWEBVIEW_H
0008 
0009 #include <QWebEngineView>
0010 #include <QWebEnginePage>
0011 #include <QPaintEvent>
0012 
0013 #include "marble_export.h"
0014 
0015 class MARBLE_EXPORT MarbleWebPage : public QWebEnginePage
0016 {
0017     Q_OBJECT
0018 public:
0019     explicit MarbleWebPage(QObject *parent = nullptr)  : QWebEnginePage(parent){}
0020 
0021 Q_SIGNALS:
0022     void linkClicked(const QUrl & url);
0023 protected:
0024     bool acceptNavigationRequest(const QUrl &url, QWebEnginePage::NavigationType type, bool isMainFrame) override {
0025         Q_UNUSED(isMainFrame)
0026         if (type == QWebEnginePage::NavigationTypeLinkClicked) {
0027             emit linkClicked(url);
0028             return false;
0029         }
0030         return true;
0031     }
0032 };
0033 
0034 class MARBLE_EXPORT MarbleWebView : public QWebEngineView
0035 {
0036     Q_OBJECT
0037 public:
0038     explicit MarbleWebView(QWidget *parent = nullptr);
0039 
0040 protected:
0041     void contextMenuEvent(QContextMenuEvent *event) override;
0042     void keyPressEvent(QKeyEvent *event) override;
0043 
0044 private Q_SLOTS:
0045     void copySelectedText();
0046 
0047 private:
0048     QMenu *m_contextMenu;
0049     QAction *m_copyAction;
0050 };
0051 
0052 #endif // MARBLEWEBVIEW_H