Browse Source

allow custom head elements

Sonnix 5 years ago
parent
commit
ad1504e10a

+ 22 - 0
callbacks_gui.cpp

@@ -25,12 +25,15 @@ MainWindow *QSPCallBacks::m_frame;
 bool QSPCallBacks::m_isHtml;
 QSPSounds QSPCallBacks::m_sounds;
 float QSPCallBacks::m_volumeCoeff;
+bool QSPCallBacks::m_isAllowHTML5Extras;
 
 void QSPCallBacks::Init(MainWindow *frame)
 {
 	m_frame = frame;
     m_volumeCoeff = 1.0f;
 
+    m_isAllowHTML5Extras = false;
+
 	QSPSetCallBack(QSP_CALL_SETTIMER, (QSP_CALLBACK)&SetTimer);
 	QSPSetCallBack(QSP_CALL_REFRESHINT, (QSP_CALLBACK)&RefreshInt);
 	QSPSetCallBack(QSP_CALL_SETINPUTSTRTEXT, (QSP_CALLBACK)&SetInputStrText);
@@ -88,6 +91,13 @@ void QSPCallBacks::RefreshInt(QSP_BOOL isRedraw)
 	if (QSPIsVarsDescChanged())
 	{
         m_frame->EnableControls(false, true);
+        if(m_isAllowHTML5Extras)
+        {
+            if (QSPGetVarValues(QSP_FMT("SETSTATHEAD"), 0, &numVal, &strVal) && strVal)
+                m_frame->GetVars()->SetHead(QSPTools::qspStrToQt(strVal));
+            else
+                 m_frame->GetVars()->SetHead(QString(""));
+        }
         m_frame->GetVars()->SetText(QSPTools::qspStrToQt(varsDesc), isScroll);
         m_frame->EnableControls(true, true);
 	}
@@ -102,6 +112,13 @@ void QSPCallBacks::RefreshInt(QSP_BOOL isRedraw)
     if (QSPIsMainDescChanged())
     {
         m_frame->EnableControls(false, true);
+        if(m_isAllowHTML5Extras)
+        {
+            if (QSPGetVarValues(QSP_FMT("SETMAINDESCHEAD"), 0, &numVal, &strVal) && strVal)
+                m_frame->GetDesc()->SetHead(QSPTools::qspStrToQt(strVal));
+            else
+                 m_frame->GetDesc()->SetHead(QString(""));
+        }
         m_frame->GetDesc()->SetText(QSPTools::qspStrToQt(mainDesc), isScroll);
         m_frame->EnableControls(true, true);
 	}
@@ -440,6 +457,11 @@ void QSPCallBacks::SetOverallVolume(float coeff)
     }
 }
 
+void QSPCallBacks::SetAllowHTML5Extras(bool HTML5Extras)
+{
+    m_isAllowHTML5Extras = HTML5Extras;
+}
+
 void QSPCallBacks::UpdateSounds()
 {
     QMediaPlayer *snd;

+ 2 - 0
callbacks_gui.h

@@ -40,6 +40,7 @@ public:
     static void Init(MainWindow *frame);
     static void DeInit();
     static void SetOverallVolume(float coeff);
+    static void SetAllowHTML5Extras(bool HTML5Extras);
 
     // CallBacks
     static void RefreshInt(QSP_BOOL isRedraw);
@@ -73,6 +74,7 @@ private:
     static bool m_isHtml;
     static QSPSounds m_sounds;
     static float m_volumeCoeff;
+    static bool m_isAllowHTML5Extras;
 };
 
 #endif

+ 17 - 3
mainwindow.cpp

@@ -88,7 +88,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
     m_defaultLinkColor = m_linkColor;
     m_defaultFontColor = m_fontColor;
 
-    m_font = QFont( "Sans", 12 );
+    m_font = QFont( "Sans", 12 , QFont::Normal );
+    m_font.setStyle(QFont::StyleNormal);
     m_font.setStyleHint( QFont::SansSerif );
     m_defaultFont = m_font;
     m_isUseFontSize = false;
@@ -107,6 +108,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
     perGameConfig = false;
     autostartLastGame = false;
 
+    m_isAllowHTML5Extras = false;
+
     langid = QObject::tr("__LANGID__");
     if(langid == QStringLiteral("__LANGID__"))
         langid = QLocale::system().name();
@@ -127,6 +130,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent)
 
     QSPInit();
     QSPCallBacks::Init(this);
+    QSPCallBacks::SetAllowHTML5Extras(m_isAllowHTML5Extras);
 
     if(autostartLastGame)
         OpenGameFile(lastGame);
@@ -410,6 +414,12 @@ void MainWindow::SetVideoFix(bool isFix)
 #endif
 }
 
+void MainWindow::SetAllowHTML5Extras(bool HTML5Extras)
+{
+    m_isAllowHTML5Extras = HTML5Extras;
+    QSPCallBacks::SetAllowHTML5Extras(m_isAllowHTML5Extras);
+}
+
 void MainWindow::LoadSettings(QString filePath)
 {
     QSettings *settings;
@@ -465,7 +475,9 @@ void MainWindow::LoadSettings(QString filePath)
     m_volume = settings->value("application/volume", m_volume).toFloat();
     SetOverallVolume(m_volume);
 
-    m_isShowHotkeys = settings->value("application/m_isShowHotkeys", m_isShowHotkeys).toBool();
+    m_isShowHotkeys = settings->value("application/isShowHotkeys", m_isShowHotkeys).toBool();
+
+    m_isAllowHTML5Extras = settings->value("application/isAllowHTML5Extras", m_isAllowHTML5Extras).toBool();
 
     langid = settings->value("application/language", langid).toString();
 
@@ -516,7 +528,9 @@ void MainWindow::SaveSettings(QString filePath)
 
     settings->setValue("application/volume", m_volume);
 
-    settings->setValue("application/m_isShowHotkeys", m_isShowHotkeys);
+    settings->setValue("application/isShowHotkeys", m_isShowHotkeys);
+
+    settings->setValue("application/isAllowHTML5Extras", m_isAllowHTML5Extras);
 
     settings->setValue("application/language", langid);
 

+ 3 - 0
mainwindow.h

@@ -124,6 +124,8 @@ public:
     void SetDisableVideo(bool isDisableVideo);
     bool GetVideoFix() { return m_videoFix; }
     void SetVideoFix(bool isFix);
+    void SetAllowHTML5Extras(bool HTML5Extras);
+    bool GetAllowHTML5Extras() { return m_isAllowHTML5Extras; }
 
 private:
     void CreateMenuBar();
@@ -212,6 +214,7 @@ private:
     QString langid;
     bool disableVideo;
     bool m_videoFix;
+    bool m_isAllowHTML5Extras;
 
 public slots:
     void OpenGameFile(const QString& path);

+ 2 - 0
optionsdialog.cpp

@@ -38,6 +38,7 @@ OptionsDialog::OptionsDialog(QWidget *parent) :
     ui->checkBox_autostart->setChecked(mw->GetAutostart());
     ui->horizontalSlider_volume->setValue(mw->GetOverallVolume() * 100);
     ui->checkBox_videoFix->setChecked(mw->GetVideoFix());
+    ui->checkBox_HTML5Extras->setChecked(mw->GetAllowHTML5Extras());
 
     QDirIterator qmIt(QCoreApplication::applicationDirPath(), QStringList() << "*.qm", QDir::Files);
     while(qmIt.hasNext())
@@ -142,6 +143,7 @@ void OptionsDialog::on_pushButton_ok_clicked()
     mw->SetPerGameConfig(ui->checkBox_perGameConfig->isChecked());
     mw->SetAutostart(ui->checkBox_autostart->isChecked());
     mw->SetVideoFix(ui->checkBox_videoFix->isChecked());
+    mw->SetAllowHTML5Extras(ui->checkBox_HTML5Extras->isChecked());
     if(ui->comboBox_language->count() > 0)
         mw->SetLangID(ui->comboBox_language->itemData(ui->comboBox_language->currentIndex()).toString());
     if(mw->GetOverallVolume() != ui->horizontalSlider_volume->value() / 100)

+ 7 - 0
optionsdialog.ui

@@ -297,6 +297,13 @@
        </property>
       </widget>
      </item>
+     <item row="11" column="0">
+      <widget class="QCheckBox" name="checkBox_HTML5Extras">
+       <property name="text">
+        <string>HTML5 Extras (experimental)</string>
+       </property>
+      </widget>
+     </item>
     </layout>
    </item>
    <item>

+ 1 - 0
qsptextbox.h

@@ -62,6 +62,7 @@ public:
 #ifndef _WEBBOX_COMMON
     void SetBackgroundImage(const QImage& bmpBg);
     void LoadBackImage(const QString& fileName);
+    void SetHead(const QString &head) {};
 #endif
 
 private:

+ 10 - 0
qspwebbox.cpp

@@ -238,6 +238,16 @@ void QspWebBox::SetVideoFix(bool isFix)
     m_videoFix = isFix;
 }
 
+void QspWebBox::SetHead(const QString &head)
+{
+    if(m_head != head)
+    {
+        m_head = head;
+        qweush->SetHead(head);
+        RefreshUI();
+    }
+}
+
 void QspWebBox::OnQspLinkClicked(QUrl url)
 {
     emit qspLinkClicked(url);

+ 2 - 0
qspwebbox.h

@@ -42,6 +42,7 @@ public:
     bool SetForegroundColor(const QColor& color);
     void SetShowPlainText(bool isPlain);
     void SetVideoFix(bool isFix);
+    void SetHead(const QString &head);
 
 private:
     // Fields
@@ -51,6 +52,7 @@ private:
     QString m_imagePath;
     QFont m_font;
     QString m_text;
+    QString m_head;
     int m_posX;
     int m_posY;
     QColor m_linkColor;

+ 1 - 0
qspwebbox_webkit.h

@@ -42,6 +42,7 @@ public:
     bool SetForegroundColor(const QColor& color);
     void SetShowPlainText(bool isPlain);
     void SetVideoFix(bool isFix);
+    void SetHead(const QString &head) {};
 
 private:
     // Fields

+ 8 - 1
qspwebengineurlschemehandler.cpp

@@ -32,7 +32,9 @@ void QspWebEngineUrlSchemeHandler::requestStarted(QWebEngineUrlRequestJob *reque
         replystr.append(QString("background: url(%1) no-repeat center center fixed;\nbackground-size: cover;\n").arg(m_bmpBg));
     if(m_linkColor.isValid())
         replystr.append(QString("}\na:link {\ncolor: %1;\n").arg(m_linkColor.name()));
-    replystr.append("}\n</style></head>\n<body>\n");
+    replystr.append("}\n</style>\n");
+    replystr.append(m_head);
+    replystr.append("</head>\n<body>\n");
     replystr.append(m_text);
     replystr.append("</body>\n</html>");
 
@@ -109,3 +111,8 @@ void QspWebEngineUrlSchemeHandler::SetTextFont(const QFont &new_font)
 {
     m_font = new_font;
 }
+
+void QspWebEngineUrlSchemeHandler::SetHead(const QString &head)
+{
+    m_head = head;
+}

+ 2 - 0
qspwebengineurlschemehandler.h

@@ -23,11 +23,13 @@ public:
     void SetForegroundColor(const QColor& color);
     void SetBackgroundImage(const QString &path);
     void SetTextFont(const QFont& new_font);
+    void SetHead(const QString &head);
 
 private:
     QString  m_text;
     QString m_path;
     QString m_bmpBg;
+    QString m_head;
     QColor m_linkColor;
     QColor m_backColor;
     QColor m_fontColor;