|
@@ -5,21 +5,21 @@
|
|
|
#include <QAbstractScrollArea>
|
|
|
#include <QScrollBar>
|
|
|
#include <QPainter>
|
|
|
-#include <QWebEngineProfile>
|
|
|
#include <QWebEngineSettings>
|
|
|
//#include <QTimer>
|
|
|
#include <QEventLoop>
|
|
|
|
|
|
#include "comtools.h"
|
|
|
|
|
|
-#include "qspwebengineurlrequestinterceptor.h"
|
|
|
-#include "qspwebengineurlschemehandler.h"
|
|
|
-#include "qspexecwebengineurlschemehandler.h"
|
|
|
+//#include "qspwebengineurlrequestinterceptor.h"
|
|
|
|
|
|
QspWebBox::QspWebBox(QWidget *parent) : QWebEngineView(parent)
|
|
|
{
|
|
|
+ m_isQuit = false;
|
|
|
settings()->setDefaultTextEncoding("utf-8");
|
|
|
setFocusPolicy(Qt::NoFocus);
|
|
|
+ settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false);
|
|
|
+ settings()->setUnknownUrlSchemePolicy(QWebEngineSettings::AllowAllUnknownUrlSchemes);
|
|
|
//setFrameStyle(QFrame::NoFrame);
|
|
|
//setFrameShadow(QFrame::Plain);
|
|
|
setContextMenuPolicy( Qt::NoContextMenu );
|
|
@@ -29,19 +29,26 @@ QspWebBox::QspWebBox(QWidget *parent) : QWebEngineView(parent)
|
|
|
m_videoFix = true;
|
|
|
m_font = font();
|
|
|
//setOpenLinks(false);
|
|
|
- profile = new QWebEngineProfile(this);
|
|
|
//QspWebEngineUrlRequestInterceptor *qwuri = new QspWebEngineUrlRequestInterceptor(this);
|
|
|
//profile->setRequestInterceptor(qwuri);
|
|
|
- qweush = new QspWebEngineUrlSchemeHandler(this);
|
|
|
- profile->installUrlSchemeHandler(QByteArray("qsp"), qweush);
|
|
|
- QspExecWebEngineUrlSchemeHandler *qeweush = new QspExecWebEngineUrlSchemeHandler(this);
|
|
|
- profile->installUrlSchemeHandler(QByteArray("exec"), qeweush);
|
|
|
- QWebEnginePage * page = new QWebEnginePage(profile, this);
|
|
|
- setPage(page);
|
|
|
- QWebChannel *channel = new QWebChannel(page);
|
|
|
+ profile.installUrlSchemeHandler(QByteArray("qsp"), &qweush);
|
|
|
+ profile.installUrlSchemeHandler(QByteArray("exec"), &qeweush);
|
|
|
+ page()->triggerAction(QWebEnginePage::Stop);
|
|
|
+ page()->deleteLater();
|
|
|
+ QWebEnginePage * newpage = new QWebEnginePage(&profile, this);
|
|
|
+ QWebChannel *channel = new QWebChannel(newpage);
|
|
|
channel->registerObject(QStringLiteral("qsp"), &qspJS);
|
|
|
- page->setWebChannel(channel);
|
|
|
- connect(qeweush, SIGNAL(qspLinkClicked(QUrl)), this, SLOT(OnQspLinkClicked(QUrl)));
|
|
|
+ newpage->setWebChannel(channel);
|
|
|
+ newpage->settings()->setDefaultTextEncoding("utf-8");
|
|
|
+ newpage->settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false);
|
|
|
+ newpage->settings()->setUnknownUrlSchemePolicy(QWebEngineSettings::AllowAllUnknownUrlSchemes);
|
|
|
+ page()->deleteLater();
|
|
|
+ setPage(newpage);
|
|
|
+ connect(&qeweush, SIGNAL(qspLinkClicked(QUrl)), this, SLOT(OnQspLinkClicked(QUrl)));
|
|
|
+ QEventLoop loop;
|
|
|
+ connect(page(), SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
|
|
|
+ page()->load(QUrl("qsp:/"));
|
|
|
+ loop.exec();
|
|
|
}
|
|
|
|
|
|
QspWebBox::~QspWebBox()
|
|
@@ -60,6 +67,8 @@ void QspWebBox::SetIsHtml(bool isHtml)
|
|
|
|
|
|
void QspWebBox::RefreshUI(bool isScroll)
|
|
|
{
|
|
|
+ if(m_isQuit)
|
|
|
+ return;
|
|
|
QString color(QSPTools::GetHexColor(GetForegroundColor()));
|
|
|
QString str = m_text;
|
|
|
QString text;
|
|
@@ -117,21 +126,26 @@ void QspWebBox::RefreshUI(bool isScroll)
|
|
|
|
|
|
text = QSPTools::HtmlizeWhitespaces(m_isUseHtml ? text : QSPTools::ProceedAsPlain(text));
|
|
|
if(showPlainText)
|
|
|
- qweush->SetPlainText(text);
|
|
|
+ qweush.SetPlainText(text);
|
|
|
else
|
|
|
- qweush->SetHtml(text);
|
|
|
+ qweush.SetHtml(text);
|
|
|
|
|
|
QString url_str = QByteArray::fromPercentEncoding(url().toString().toUtf8());
|
|
|
if(url_str.compare("qsp:" , Qt::CaseInsensitive) != 0 && url_str.compare("qsp:/" , Qt::CaseInsensitive) != 0)
|
|
|
{
|
|
|
- QWebEnginePage * newpage = new QWebEnginePage(profile, this);
|
|
|
+ page()->triggerAction(QWebEnginePage::Stop);
|
|
|
+ page()->deleteLater();
|
|
|
+ QWebEnginePage * newpage = new QWebEnginePage(&profile, this);
|
|
|
+ QWebChannel *channel = new QWebChannel(newpage);
|
|
|
+ channel->registerObject(QStringLiteral("qsp"), &qspJS);
|
|
|
+ newpage->setWebChannel(channel);
|
|
|
+ newpage->settings()->setDefaultTextEncoding("utf-8");
|
|
|
+ newpage->settings()->setAttribute(QWebEngineSettings::PlaybackRequiresUserGesture, false);
|
|
|
+ newpage->settings()->setUnknownUrlSchemePolicy(QWebEngineSettings::AllowAllUnknownUrlSchemes);
|
|
|
setPage(newpage);
|
|
|
QEventLoop loop;
|
|
|
connect(page(), SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
|
|
|
page()->load(QUrl("qsp:/"));
|
|
|
- QWebChannel *channel = new QWebChannel(newpage);
|
|
|
- channel->registerObject(QStringLiteral("qsp"), &qspJS);
|
|
|
- newpage->setWebChannel(channel);
|
|
|
loop.exec();
|
|
|
}
|
|
|
page()->triggerAction(QWebEnginePage::ReloadAndBypassCache);
|
|
@@ -152,7 +166,7 @@ void QspWebBox::RefreshUI(bool isScroll)
|
|
|
|
|
|
void QspWebBox::LoadBackImage(const QString& fileName)
|
|
|
{
|
|
|
- qweush->SetBackgroundImage(fileName);
|
|
|
+ qweush.SetBackgroundImage(fileName);
|
|
|
QFileInfo file(m_path + fileName);
|
|
|
QString path(file.absoluteFilePath());
|
|
|
}
|
|
@@ -176,7 +190,7 @@ void QspWebBox::SetTextFont(const QFont& new_font)
|
|
|
if (m_font != new_font)
|
|
|
{
|
|
|
m_font = new_font;
|
|
|
- qweush->SetTextFont(new_font);
|
|
|
+ qweush.SetTextFont(new_font);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -185,7 +199,7 @@ bool QspWebBox::SetLinkColor(const QColor &color)
|
|
|
if(m_linkColor != color)
|
|
|
{
|
|
|
m_linkColor = color;
|
|
|
- qweush->SetLinkColor(color);
|
|
|
+ qweush.SetLinkColor(color);
|
|
|
RefreshUI();
|
|
|
return true;
|
|
|
}
|
|
@@ -195,7 +209,7 @@ bool QspWebBox::SetLinkColor(const QColor &color)
|
|
|
void QspWebBox::SetGamePath(const QString &path)
|
|
|
{
|
|
|
m_path = path;
|
|
|
- qweush->SetGamePath(path);
|
|
|
+ qweush.SetGamePath(path);
|
|
|
}
|
|
|
|
|
|
//Returns the background color of the window.
|
|
@@ -216,7 +230,7 @@ bool QspWebBox::SetBackgroundColor(const QColor &color)
|
|
|
if(m_backColor != color)
|
|
|
{
|
|
|
m_backColor = color;
|
|
|
- qweush->SetBackgroundColor(color);
|
|
|
+ qweush.SetBackgroundColor(color);
|
|
|
RefreshUI();
|
|
|
return true;
|
|
|
}
|
|
@@ -228,7 +242,7 @@ bool QspWebBox::SetForegroundColor(const QColor &color)
|
|
|
if(m_fontColor != color)
|
|
|
{
|
|
|
m_fontColor = color;
|
|
|
- qweush->SetForegroundColor(color);
|
|
|
+ qweush.SetForegroundColor(color);
|
|
|
RefreshUI();
|
|
|
return true;
|
|
|
}
|
|
@@ -251,7 +265,7 @@ void QspWebBox::SetHead(const QString &head)
|
|
|
if(m_head != head)
|
|
|
{
|
|
|
m_head = head;
|
|
|
- qweush->SetHead(head);
|
|
|
+ qweush.SetHead(head);
|
|
|
RefreshUI();
|
|
|
}
|
|
|
}
|
|
@@ -261,7 +275,7 @@ void QspWebBox::SetFontType(const int fontType)
|
|
|
if(m_fontType != fontType)
|
|
|
{
|
|
|
m_fontType = fontType;
|
|
|
- qweush->SetFontType(fontType);
|
|
|
+ qweush.SetFontType(fontType);
|
|
|
RefreshUI();
|
|
|
}
|
|
|
}
|
|
@@ -271,14 +285,27 @@ void QspWebBox::SetSizeType(const int sizeType)
|
|
|
if(m_sizeType != sizeType)
|
|
|
{
|
|
|
m_sizeType = sizeType;
|
|
|
- qweush->SetSizeType(sizeType);
|
|
|
+ qweush.SetSizeType(sizeType);
|
|
|
RefreshUI();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void QspWebBox::SetCustomCSS(bool customCSS)
|
|
|
{
|
|
|
- qweush->SetCustomCSS(customCSS);
|
|
|
+ qweush.SetCustomCSS(customCSS);
|
|
|
+}
|
|
|
+
|
|
|
+void QspWebBox::Quit()
|
|
|
+{
|
|
|
+ m_isQuit = true;
|
|
|
+ page()->triggerAction(QWebEnginePage::Stop);
|
|
|
+ page()->deleteLater();
|
|
|
+ QWebEnginePage * newpage = new QWebEnginePage(this);
|
|
|
+ setPage(newpage);
|
|
|
+ QEventLoop loop;
|
|
|
+ connect(page(), SIGNAL(loadFinished(bool)), &loop, SLOT(quit()));
|
|
|
+ page()->load(QUrl("about:blank"));
|
|
|
+ loop.exec();
|
|
|
}
|
|
|
|
|
|
void QspWebBox::OnQspLinkClicked(QUrl url)
|