Skip to content

Commit

Permalink
check if custom.css exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Sonnix1 committed Jul 24, 2018
1 parent 3cf2f4b commit 4a5756d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 1 deletion.
11 changes: 11 additions & 0 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,17 @@ void MainWindow::OpenGameFile(const QString &path)
ApplyFontColor(m_defaultFontColor);
if(!m_isUseFont)
ApplyFont(m_defaultFont, 0, 0);
QFileInfo cssFile(filePath + "custom.css");
if(cssFile.exists() && cssFile.isFile())
{
_mainDescTextBox->SetCustomCSS(true);
_descTextBox->SetCustomCSS(true);
}
else
{
_mainDescTextBox->SetCustomCSS(false);
_descTextBox->SetCustomCSS(false);
}
UpdateGamePath(filePath);
OnNewGame();
if (m_isQuit) return;
Expand Down
1 change: 1 addition & 0 deletions qsptextbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class QspTextBox : public QTextBrowser
void SetHead(const QString &head) {};
void SetFontType(const int fontType) {};
void SetSizeType(const int sizeType) {};
void SetCustomCSS(bool customCSS) {};
#endif

private:
Expand Down
5 changes: 5 additions & 0 deletions qspwebbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ void QspWebBox::SetSizeType(const int sizeType)
}
}

void QspWebBox::SetCustomCSS(bool customCSS)
{
qweush->SetCustomCSS(customCSS);
}

void QspWebBox::OnQspLinkClicked(QUrl url)
{
emit qspLinkClicked(url);
Expand Down
1 change: 1 addition & 0 deletions qspwebbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class QspWebBox : public QWebEngineView
void SetHead(const QString &head);
void SetFontType(const int fontType);
void SetSizeType(const int sizeType);
void SetCustomCSS(bool customCSS);

private:
// Fields
Expand Down
1 change: 1 addition & 0 deletions qspwebbox_webkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class QspWebBox : public QWebView
void SetHead(const QString &head) {};
void SetFontType(const int fontType) {};
void SetSizeType(const int sizeType) {};
void SetCustomCSS(bool customCSS) {};

private:
// Fields
Expand Down
8 changes: 7 additions & 1 deletion qspwebengineurlschemehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ void QspWebEngineUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *reque
if(m_linkColor.isValid())
replystr.append(QString("}\na:link {\ncolor: %1;\n").arg(m_linkColor.name()));
replystr.append("}\n</style>\n");
replystr.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"custom.css\">");
if(m_isCustomCSS)
replystr.append("<link rel=\"stylesheet\" type=\"text/css\" href=\"custom.css\">");
replystr.append(m_head);
replystr.append("</head>\n<body>\n");
replystr.append(m_text);
Expand Down Expand Up @@ -139,3 +140,8 @@ void QspWebEngineUrlSchemeHandler::SetSizeType(const int sizeType)
{
m_sizeType = sizeType;
}

void QspWebEngineUrlSchemeHandler::SetCustomCSS(bool customCSS)
{
m_isCustomCSS = customCSS;
}
2 changes: 2 additions & 0 deletions qspwebengineurlschemehandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class QspWebEngineUrlSchemeHandler : public QWebEngineUrlSchemeHandler
void SetHead(const QString &head);
void SetFontType(const int fontType);
void SetSizeType(const int sizeType);
void SetCustomCSS(bool customCSS);

private:
QString m_text;
Expand All @@ -39,6 +40,7 @@ class QspWebEngineUrlSchemeHandler : public QWebEngineUrlSchemeHandler
bool m_isUseHtml = true;
int m_fontType = 0;
int m_sizeType = 0;
bool m_isCustomCSS = false;
};

#endif // QSPWEBENGINEURLSCHEMEHANDLER_H

0 comments on commit 4a5756d

Please sign in to comment.