Browse Source

check if custom.css exists

Sonnix 5 years ago
parent
commit
4a5756db28
7 changed files with 28 additions and 1 deletions
  1. 11 0
      mainwindow.cpp
  2. 1 0
      qsptextbox.h
  3. 5 0
      qspwebbox.cpp
  4. 1 0
      qspwebbox.h
  5. 1 0
      qspwebbox_webkit.h
  6. 7 1
      qspwebengineurlschemehandler.cpp
  7. 2 0
      qspwebengineurlschemehandler.h

+ 11 - 0
mainwindow.cpp

@@ -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;

+ 1 - 0
qsptextbox.h

@@ -66,6 +66,7 @@ public:
     void SetHead(const QString &head) {};
     void SetFontType(const int fontType) {};
     void SetSizeType(const int sizeType) {};
+    void SetCustomCSS(bool customCSS) {};
 #endif
 
 private:

+ 5 - 0
qspwebbox.cpp

@@ -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);

+ 1 - 0
qspwebbox.h

@@ -45,6 +45,7 @@ public:
     void SetHead(const QString &head);
     void SetFontType(const int fontType);
     void SetSizeType(const int sizeType);
+    void SetCustomCSS(bool customCSS);
 
 private:
     // Fields

+ 1 - 0
qspwebbox_webkit.h

@@ -46,6 +46,7 @@ public:
     void SetHead(const QString &head) {};
     void SetFontType(const int fontType) {};
     void SetSizeType(const int sizeType) {};
+    void SetCustomCSS(bool customCSS) {};
 
 private:
     // Fields

+ 7 - 1
qspwebengineurlschemehandler.cpp

@@ -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);
@@ -139,3 +140,8 @@ void QspWebEngineUrlSchemeHandler::SetSizeType(const int sizeType)
 {
     m_sizeType = sizeType;
 }
+
+void QspWebEngineUrlSchemeHandler::SetCustomCSS(bool customCSS)
+{
+    m_isCustomCSS = customCSS;
+}

+ 2 - 0
qspwebengineurlschemehandler.h

@@ -26,6 +26,7 @@ public:
     void SetHead(const QString &head);
     void SetFontType(const int fontType);
     void SetSizeType(const int sizeType);
+    void SetCustomCSS(bool customCSS);
 
 private:
     QString  m_text;
@@ -39,6 +40,7 @@ private:
     bool m_isUseHtml = true;
     int m_fontType = 0;
     int m_sizeType = 0;
+    bool m_isCustomCSS = false;
 };
 
 #endif // QSPWEBENGINEURLSCHEMEHANDLER_H