MythTV master
mythuiwebbrowser.h
Go to the documentation of this file.
1#ifndef MYTHUI_WEBBROWSER_H_
2#define MYTHUI_WEBBROWSER_H_
3
4// qt
5#include <QtGlobal>
6#include <QUrl>
7#include <QString>
8#include <QElapsedTimer>
9#include <QColor>
10#include <QIcon>
11#include <QWebEngineView>
12#include <QWebEnginePage>
13#include <QWebEngineProfile>
14#include <QNetworkRequest>
15#include <QNetworkReply>
16#include <QWebEngineFullScreenRequest>
17//#include <QWebEngineDownloadRequest>
18
19// mythtv
20#include "mythuitype.h"
21#include "mythuiexp.h"
22
23
24class MythUIScrollBar;
27class MythScreenType;
28
29class MythWebEngineView : public QWebEngineView
30{
31 Q_OBJECT
32
33 public:
34 MythWebEngineView(QWidget *parent, MythUIWebBrowser *parentBrowser);
35 ~MythWebEngineView(void) override;
36
37 bool eventFilter(QObject *obj, QEvent *event) override;
38 void customEvent(QEvent *e) override; // QWidget
39
40
41 protected slots:
42 QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) override; // QWebEngineView
43
44 private:
45 void sendKeyPress(int key, Qt::KeyboardModifiers modifiers, const QString &text = QString());
46 bool handleKeyPress(QKeyEvent *event);
47 void showDownloadMenu(void);
48 void openBusyPopup(const QString &message);
49 void closeBusyPopup(void);
50
51 static bool isMusicFile(const QString &extension, const QString &mimetype);
52 static bool isVideoFile(const QString &extension, const QString &mimetype);
53
54 QString getReplyMimetype(void);
55 static QString getExtensionForMimetype(const QString &mimetype);
56
57 QWebEnginePage *m_webpage {nullptr};
59 QWebEngineProfile *m_profile {nullptr};
60 QNetworkRequest m_downloadRequest;
61 QNetworkReply *m_downloadReply {nullptr};
63 bool m_downloadAndPlay {false};
64};
65
74{
75 Q_OBJECT
76
77 public:
78 MythUIWebBrowser(MythUIType *parent, const QString &name);
79 ~MythUIWebBrowser() override;
80
81 void Init(void);
82
83 void LoadPage(const QUrl& url);
84 void SetHtml(const QString &html, const QUrl &baseUrl = QUrl());
85
86 void LoadUserStyleSheet(const QUrl& url, const QString &name = QString("mythtv"));
87 void RemoveUserStyleSheet(const QString &name);
88
89 void SetHttpUserAgent(const QString &userAgent);
90
91 QWebEngineSettings *GetWebEngineSettings(void);
92 QWebEngineProfile *GetWebEngineProfile(void);
93
94 void Pulse(void) override; // MythUIType
95
96 QIcon GetIcon(void);
97 QUrl GetUrl(void);
98 QString GetTitle(void);
99
100 void SetActive(bool active);
101 bool IsActive(void) const { return m_active; }
102
104 bool IsInputToggled(void) const { return m_inputToggled; }
105 void SetInputToggled(bool inputToggled) { m_inputToggled = inputToggled; }
106
107 void SetZoom(double zoom);
108 float GetZoom(void) const;
109
110 bool CanGoForward(void);
111 bool CanGoBack(void);
112
113 void RunJavaScript(const QString& scriptSource);
114
115 void SendStatusBarMessage(const QString &text);
116
117 void SetDefaultSaveDirectory(const QString &saveDir);
118 QString GetDefaultSaveDirectory(void) { return m_defaultSaveDir; }
119
120 void SetDefaultSaveFilename(const QString &filename);
121 QString GetDefaultSaveFilename(void) { return m_defaultSaveFilename; }
122
123 void HandleMouseAction(const QString &action);
124
125 void UpdateBuffer(void);
126
127 MythScreenType *GetParentScreen(void) { return m_parentScreen; }
128
129 public slots:
130 void Back(void);
131 void Forward(void);
132 void ZoomIn(void);
133 void ZoomOut(void);
134 void Reload(bool useCache = true);
135 void TriggerPageAction(QWebEnginePage::WebAction action, bool checked = false);
136
137 signals:
138 void loadStarted(void);
139 void loadFinished(bool ok);
141 void titleChanged(const QString &title);
142 void statusBarMessage(const QString &text);
143 void iconChanged(const QIcon &icon);
144 void iconUrlChanged(const QUrl &url);
145 void fileDownloaded(QString filename);
146
147 protected slots:
148 void slotLoadStarted(void);
149 void slotLoadFinished(bool Ok);
150 void slotLoadProgress(int progress);
151 void slotTitleChanged(const QString &title);
152 void slotStatusBarMessage(const QString &text);
153 void slotIconChanged(const QIcon &icon);
154 void slotIconUrlChanged(const QUrl &url);
155 void slotScrollPositionChanged(QPointF position);
156 void slotContentsSizeChanged(QSizeF size);
157 void slotLinkClicked(const QUrl &url);
158 void slotTopScreenChanged(MythScreenType *screen);
159 void slotScrollBarShowing(void);
160 void slotScrollBarHiding(void);
161 void slotLosingFocus();
162 void slotTakingFocus();
163 void slotRenderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode);
164 static void slotFullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
165 void slotWindowCloseRequested(void);
166
167 protected:
168 void SetBackgroundColor(QColor color);
169 void ResetScrollBars(void);
170 void UpdateScrollBars(void);
171 bool IsOnTopScreen(void);
172
173 void Finalize(void) override; // MythUIType
174 void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect) override; // MythUIType
175 bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override; // MythUIType
176 void CopyFrom(MythUIType *base) override; // MythUIType
177 void CreateCopy(MythUIType *parent) override; // MythUIType
178
179 MythScreenType *m_parentScreen { nullptr };
180
181 QWebEngineView *m_webEngine { nullptr };
184
185 MythImage *m_image { nullptr };
186
187 bool m_active { false };
188 bool m_wasActive { false };
189 bool m_initialized { false };
190 QElapsedTimer m_lastUpdateTime;
191 int m_updateInterval { 0 };
192
193 qreal m_zoom { 1.0 };
194 QColor m_bgColor;
199
200 bool m_inputToggled { false };
202 int m_mouseKeyCount { 0 };
204
205 MythUIScrollBar *m_horizontalScrollbar { nullptr };
206 MythUIScrollBar *m_verticalScrollbar { nullptr };
207};
208
209#endif
Wrapper around QRect allowing us to handle percentage and other relative values for areas in mythui.
Definition: mythrect.h:18
Screen in which all other widgets are contained and rendered.
Scroll bar widget.
The base class on which all widgets and screens are based.
Definition: mythuitype.h:86
void SetZoom(float zoom)
Definition: mythuitype.cpp:961
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
Definition: mythuitype.cpp:479
virtual void CopyFrom(MythUIType *base)
Copy this widgets state from another.
virtual void Finalize(void)
Perform any post-xml parsing initialisation tasks.
virtual void Pulse(void)
Pulse is called 70 times a second to trigger a single frame of an animation.
Definition: mythuitype.cpp:456
virtual void CreateCopy(MythUIType *parent)
Copy the state of this widget to the one given, it must be of the same type.
virtual bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings)
Parse the xml definition of this widget setting the state of the object accordingly.
Web browsing widget.
MythRect m_actualBrowserArea
void iconUrlChanged(const QUrl &url)
a pages fav icon has changed
void iconChanged(const QIcon &icon)
link hit test messages
MythScreenType * GetParentScreen(void)
bool IsInputToggled(void) const
returns true if all keypresses are to be passed to the web page
void titleChanged(const QString &title)
% of page loaded
void fileDownloaded(QString filename)
a pages fav icon has changed
QString GetDefaultSaveFilename(void)
QElapsedTimer m_lastUpdateTime
void SetInputToggled(bool inputToggled)
void statusBarMessage(const QString &text)
a pages title has changed
void loadProgress(int progress)
a page has finished loading
QString m_defaultSaveFilename
QString GetDefaultSaveDirectory(void)
void slotLoadStarted(void)
a file has been downloaded
QElapsedTimer m_lastMouseActionTime
void loadStarted(void)
bool IsActive(void) const
void loadFinished(bool ok)
a page is starting to load
Subclass of QWebEngineView.
void sendKeyPress(int key, Qt::KeyboardModifiers modifiers, const QString &text=QString())
QString getReplyMimetype(void)
MythWebEngineView(QWidget *parent, MythUIWebBrowser *parentBrowser)
QWebEngineView * createWindow(QWebEnginePage::WebWindowType type) override
QWebEngineProfile * m_profile
QNetworkRequest m_downloadRequest
MythUIWebBrowser * m_parentBrowser
static bool isMusicFile(const QString &extension, const QString &mimetype)
QWebEnginePage * m_webpage
static bool isVideoFile(const QString &extension, const QString &mimetype)
void openBusyPopup(const QString &message)
~MythWebEngineView(void) override
void customEvent(QEvent *e) override
bool eventFilter(QObject *obj, QEvent *event) override
static QString getExtensionForMimetype(const QString &mimetype)
bool handleKeyPress(QKeyEvent *event)
QNetworkReply * m_downloadReply
MythUIBusyDialog * m_busyPopup
bool progress
#define MUI_PUBLIC
Definition: mythuiexp.h:9