From 22489137ae9a66274201e8278a778c959af9602d Mon Sep 17 00:00:00 2001 From: Le Tan Date: Sat, 1 Sep 2018 11:05:03 +0800 Subject: [PATCH] MathJaxPreview: fix preview while using local mathjax --- src/dialog/vsettingsdialog.cpp | 1 + src/utils/vutils.cpp | 3 ++- src/vdocument.cpp | 1 - src/vdocument.h | 2 -- src/vmathjaxpreviewhelper.cpp | 6 +++++- src/vmathjaxwebdocument.cpp | 8 ++++++++ src/vmathjaxwebdocument.h | 2 ++ 7 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/dialog/vsettingsdialog.cpp b/src/dialog/vsettingsdialog.cpp index dc35ca6f..8f098498 100644 --- a/src/dialog/vsettingsdialog.cpp +++ b/src/dialog/vsettingsdialog.cpp @@ -1041,6 +1041,7 @@ VMarkdownTab::VMarkdownTab(QWidget *p_parent) m_mathjaxConfigEdit = new VLineEdit(); m_mathjaxConfigEdit->setToolTip(tr("Location of MathJax JavaScript and its configuration " "(restart VNote to make it work in in-place preview)")); + m_mathjaxConfigEdit->setPlaceholderText(tr("Need to prepend \"file://\" to local path")); // PlantUML. m_plantUMLModeCombo = VUtils::getComboBox(); diff --git a/src/utils/vutils.cpp b/src/utils/vutils.cpp index e7989319..6d01b00a 100644 --- a/src/utils/vutils.cpp +++ b/src/utils/vutils.cpp @@ -908,8 +908,9 @@ with 2em, if there are Chinese characters in it, the font will be a mess. QString VUtils::generateMathJaxPreviewTemplate() { + QString mj = g_config->getMathjaxJavascript(); QString templ = VNote::generateMathJaxPreviewTemplate(); - templ.replace(HtmlHolder::c_JSHolder, g_config->getMathjaxJavascript()); + templ.replace(HtmlHolder::c_JSHolder, mj); QString extraFile; diff --git a/src/vdocument.cpp b/src/vdocument.cpp index cc904d6c..db1b0ed8 100644 --- a/src/vdocument.cpp +++ b/src/vdocument.cpp @@ -67,7 +67,6 @@ void VDocument::setHtml(const QString &html) void VDocument::setLog(const QString &p_log) { qDebug() << "JS:" << p_log; - emit logChanged(p_log); } void VDocument::keyPressEvent(int p_key, bool p_ctrl, bool p_shift, bool p_meta) diff --git a/src/vdocument.h b/src/vdocument.h index b9cc90c0..3b300aab 100644 --- a/src/vdocument.h +++ b/src/vdocument.h @@ -139,8 +139,6 @@ signals: void htmlChanged(const QString &html); - void logChanged(const QString &p_log); - void keyPressed(int p_key, bool p_ctrl, bool p_shift, bool p_meta); void requestHighlightText(const QString &p_text, int p_id, unsigned long long p_timeStamp); diff --git a/src/vmathjaxpreviewhelper.cpp b/src/vmathjaxpreviewhelper.cpp index df4598a8..62c741bf 100644 --- a/src/vmathjaxpreviewhelper.cpp +++ b/src/vmathjaxpreviewhelper.cpp @@ -5,6 +5,9 @@ #include "utils/vutils.h" #include "vmathjaxwebdocument.h" +#include "vconfigmanager.h" + +extern VConfigManager *g_config; VMathJaxPreviewHelper::VMathJaxPreviewHelper(QWidget *p_parentWidget, QObject *p_parent) : QObject(p_parent), @@ -67,7 +70,8 @@ void VMathJaxPreviewHelper::doInit() // setHtml() will change focus if it is not disabled. m_webView->setEnabled(false); - m_webView->setHtml(VUtils::generateMathJaxPreviewTemplate(), QUrl("qrc:/resources")); + QUrl baseUrl(QUrl::fromLocalFile(g_config->getDocumentPathOrHomePath() + QDir::separator())); + m_webView->setHtml(VUtils::generateMathJaxPreviewTemplate(), baseUrl); m_webView->setEnabled(true); } diff --git a/src/vmathjaxwebdocument.cpp b/src/vmathjaxwebdocument.cpp index 5584edcd..6f2d87ce 100644 --- a/src/vmathjaxwebdocument.cpp +++ b/src/vmathjaxwebdocument.cpp @@ -1,5 +1,7 @@ #include "vmathjaxwebdocument.h" +#include + VMathJaxWebDocument::VMathJaxWebDocument(QObject *p_parent) : QObject(p_parent) { @@ -44,3 +46,9 @@ void VMathJaxWebDocument::previewDiagram(int p_identifier, p_lang, p_text); } + +void VMathJaxWebDocument::setLog(const QString &p_log) +{ + qDebug() << "JS:" << p_log; +} + diff --git a/src/vmathjaxwebdocument.h b/src/vmathjaxwebdocument.h index 43768ba0..7216dfdd 100644 --- a/src/vmathjaxwebdocument.h +++ b/src/vmathjaxwebdocument.h @@ -38,6 +38,8 @@ public slots: const QString &p_format, const QString &p_data); + void setLog(const QString &p_log); + signals: void requestPreviewMathJax(int p_identifier, int p_id,