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
39 protected:
40 void customEvent(QEvent *e) override; // QWidget
41
42 protected slots:
43 QWebEngineView *createWindow(QWebEnginePage::WebWindowType type) override; // QWebEngineView
44
45 private:
46 void sendKeyPress(int key, Qt::KeyboardModifiers modifiers, const QString &text = QString());
47 bool handleKeyPress(QKeyEvent *event);
48 void showDownloadMenu(void);
49 void openBusyPopup(const QString &message);
50 void closeBusyPopup(void);
51
52 static bool isMusicFile(const QString &extension, const QString &mimetype);
53 static bool isVideoFile(const QString &extension, const QString &mimetype);
54
55 QString getReplyMimetype(void);
56 static QString getExtensionForMimetype(const QString &mimetype);
57
58 QWebEnginePage *m_webpage {nullptr};
60 QWebEngineProfile *m_profile {nullptr};
61 QNetworkRequest m_downloadRequest;
62 QNetworkReply *m_downloadReply {nullptr};
64 bool m_downloadAndPlay {false};
65};
66
75{
76 Q_OBJECT
77
78 public:
79 MythUIWebBrowser(MythUIType *parent, const QString &name);
80 ~MythUIWebBrowser() override;
81
82 void Init(void);
83
84 void LoadPage(const QUrl& url);
85 void SetHtml(const QString &html, const QUrl &baseUrl = QUrl());
86
87 void LoadUserStyleSheet(const QUrl& url, const QString &name = QString("mythtv"));
88 void RemoveUserStyleSheet(const QString &name);
89
90 void SetHttpUserAgent(const QString &userAgent);
91
92 QWebEngineSettings *GetWebEngineSettings(void);
93 QWebEngineProfile *GetWebEngineProfile(void);
94
95 void Pulse(void) override; // MythUIType
96
97 QIcon GetIcon(void);
98 QUrl GetUrl(void);
99 QString GetTitle(void);
100
101 void SetActive(bool active);
102 bool IsActive(void) const { return m_active; }
103
105 bool IsInputToggled(void) const { return m_inputToggled; }
106 void SetInputToggled(bool inputToggled) { m_inputToggled = inputToggled; }
107
108 void SetZoom(double zoom);
109 float GetZoom(void) const;
110
111 bool CanGoForward(void);
112 bool CanGoBack(void);
113
114 void RunJavaScript(const QString& scriptSource);
115
116 void SendStatusBarMessage(const QString &text);
117
118 void SetDefaultSaveDirectory(const QString &saveDir);
119 QString GetDefaultSaveDirectory(void) { return m_defaultSaveDir; }
120
121 void SetDefaultSaveFilename(const QString &filename);
122 QString GetDefaultSaveFilename(void) { return m_defaultSaveFilename; }
123
124 void HandleMouseAction(const QString &action);
125
126 void UpdateBuffer(void);
127
128 MythScreenType *GetParentScreen(void) { return m_parentScreen; }
129
130 public slots:
131 void Back(void);
132 void Forward(void);
133 void ZoomIn(void);
134 void ZoomOut(void);
135 void Reload(bool useCache = true);
136 void TriggerPageAction(QWebEnginePage::WebAction action, bool checked = false);
137
138 signals:
139 void loadStarted(void);
140 void loadFinished(bool ok);
142 void titleChanged(const QString &title);
143 void statusBarMessage(const QString &text);
144 void iconChanged(const QIcon &icon);
145 void iconUrlChanged(const QUrl &url);
146 void fileDownloaded(QString filename);
147
148 protected slots:
149 void slotLoadStarted(void);
150 void slotLoadFinished(bool Ok);
151 void slotLoadProgress(int progress);
152 void slotTitleChanged(const QString &title);
153 void slotStatusBarMessage(const QString &text);
154 void slotIconChanged(const QIcon &icon);
155 void slotIconUrlChanged(const QUrl &url);
156 void slotScrollPositionChanged(QPointF position);
157 void slotContentsSizeChanged(QSizeF size);
158 void slotLinkClicked(const QUrl &url);
159 void slotTopScreenChanged(MythScreenType *screen);
160 void slotScrollBarShowing(void);
161 void slotScrollBarHiding(void);
162 void slotLosingFocus();
163 void slotTakingFocus();
164 void slotRenderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode);
165 static void slotFullScreenRequested(QWebEngineFullScreenRequest fullScreenRequest);
166 void slotWindowCloseRequested(void);
167
168 protected:
169 void SetBackgroundColor(QColor color);
170 void ResetScrollBars(void);
171 void UpdateScrollBars(void);
172 bool IsOnTopScreen(void);
173
174 void Finalize(void) override; // MythUIType
175 void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect) override; // MythUIType
176 bool ParseElement(const QString &filename, QDomElement &element, bool showWarnings) override; // MythUIType
177 void CopyFrom(MythUIType *base) override; // MythUIType
178 void CreateCopy(MythUIType *parent) override; // MythUIType
179
180 MythScreenType *m_parentScreen { nullptr };
181
182 QWebEngineView *m_webEngine { nullptr };
185
186 MythImage *m_image { nullptr };
187
188 bool m_active { false };
189 bool m_wasActive { false };
190 bool m_initialized { false };
191 QElapsedTimer m_lastUpdateTime;
192 int m_updateInterval { 0 };
193
194 qreal m_zoom { 1.0 };
195 QColor m_bgColor;
200
201 bool m_inputToggled { false };
203 int m_mouseKeyCount { 0 };
205
206 MythUIScrollBar *m_horizontalScrollbar { nullptr };
207 MythUIScrollBar *m_verticalScrollbar { nullptr };
208};
209
210#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:97
void SetZoom(float zoom)
Definition: mythuitype.cpp:947
virtual void DrawSelf(MythPainter *p, int xoffset, int yoffset, int alphaMod, QRect clipRect)
Definition: mythuitype.cpp:465
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:442
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
#define MUI_PUBLIC
Definition: mythuiexp.h:9