qwebengineview.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtWebEngine module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #ifndef QWEBENGINEVIEW_H
  40. #define QWEBENGINEVIEW_H
  41. #include <QtGui/qpainter.h>
  42. #include <QtNetwork/qnetworkaccessmanager.h>
  43. #include <QtWidgets/qwidget.h>
  44. #include <QtWebEngineWidgets/qtwebenginewidgetsglobal.h>
  45. #include <QtWebEngineWidgets/qwebenginepage.h>
  46. QT_BEGIN_NAMESPACE
  47. class QContextMenuEvent;
  48. class QUrl;
  49. class QWebEnginePage;
  50. class QWebEngineSettings;
  51. class QWebEngineViewPrivate;
  52. class QWEBENGINEWIDGETS_EXPORT QWebEngineView : public QWidget {
  53. Q_OBJECT
  54. Q_PROPERTY(QString title READ title)
  55. Q_PROPERTY(QUrl url READ url WRITE setUrl)
  56. Q_PROPERTY(QUrl iconUrl READ iconUrl NOTIFY iconUrlChanged)
  57. Q_PROPERTY(QIcon icon READ icon NOTIFY iconChanged)
  58. Q_PROPERTY(QString selectedText READ selectedText)
  59. Q_PROPERTY(bool hasSelection READ hasSelection)
  60. Q_PROPERTY(qreal zoomFactor READ zoomFactor WRITE setZoomFactor)
  61. public:
  62. explicit QWebEngineView(QWidget* parent = Q_NULLPTR);
  63. virtual ~QWebEngineView();
  64. QWebEnginePage* page() const;
  65. void setPage(QWebEnginePage* page);
  66. void load(const QUrl& url);
  67. void setHtml(const QString& html, const QUrl& baseUrl = QUrl());
  68. void setContent(const QByteArray& data, const QString& mimeType = QString(), const QUrl& baseUrl = QUrl());
  69. QWebEngineHistory* history() const;
  70. QString title() const;
  71. void setUrl(const QUrl &url);
  72. QUrl url() const;
  73. QUrl iconUrl() const;
  74. QIcon icon() const;
  75. bool hasSelection() const;
  76. QString selectedText() const;
  77. #ifndef QT_NO_ACTION
  78. QAction* pageAction(QWebEnginePage::WebAction action) const;
  79. #endif
  80. void triggerPageAction(QWebEnginePage::WebAction action, bool checked = false);
  81. qreal zoomFactor() const;
  82. void setZoomFactor(qreal factor);
  83. #ifdef Q_QDOC
  84. void findText(const QString &subString, QWebEnginePage::FindFlags options = QWebEnginePage::FindFlags());
  85. void findText(const QString &subString, QWebEnginePage::FindFlags options, FunctorOrLambda resultCallback);
  86. #else
  87. void findText(const QString &subString, QWebEnginePage::FindFlags options = QWebEnginePage::FindFlags(), const QWebEngineCallback<bool> &resultCallback = QWebEngineCallback<bool>());
  88. #endif
  89. virtual QSize sizeHint() const Q_DECL_OVERRIDE;
  90. QWebEngineSettings *settings() const;
  91. public Q_SLOTS:
  92. void stop();
  93. void back();
  94. void forward();
  95. void reload();
  96. Q_SIGNALS:
  97. void loadStarted();
  98. void loadProgress(int progress);
  99. void loadFinished(bool);
  100. void titleChanged(const QString& title);
  101. void selectionChanged();
  102. void urlChanged(const QUrl&);
  103. void iconUrlChanged(const QUrl&);
  104. void iconChanged(const QIcon&);
  105. void renderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus,
  106. int exitCode);
  107. protected:
  108. virtual QWebEngineView *createWindow(QWebEnginePage::WebWindowType type);
  109. virtual void contextMenuEvent(QContextMenuEvent*) Q_DECL_OVERRIDE;
  110. virtual bool event(QEvent*) Q_DECL_OVERRIDE;
  111. virtual void showEvent(QShowEvent *) Q_DECL_OVERRIDE;
  112. virtual void hideEvent(QHideEvent *) Q_DECL_OVERRIDE;
  113. void dragEnterEvent(QDragEnterEvent *e) Q_DECL_OVERRIDE;
  114. void dragLeaveEvent(QDragLeaveEvent *e) Q_DECL_OVERRIDE;
  115. void dragMoveEvent(QDragMoveEvent *e) Q_DECL_OVERRIDE;
  116. void dropEvent(QDropEvent *e) Q_DECL_OVERRIDE;
  117. private:
  118. Q_DISABLE_COPY(QWebEngineView)
  119. Q_DECLARE_PRIVATE(QWebEngineView)
  120. QScopedPointer<QWebEngineViewPrivate> d_ptr;
  121. friend class QWebEnginePage;
  122. friend class QWebEnginePagePrivate;
  123. };
  124. QT_END_NAMESPACE
  125. #endif // QWEBENGINEVIEW_H