Răsfoiți Sursa

Test JavaScript HTML export

Kandrashin Denis 13 ani în urmă
părinte
comite
d8308d596c
5 a modificat fișierele cu 54 adăugiri și 1 ștergeri
  1. 4 1
      fb2edit.pro
  2. 23 0
      source/fb2view.cpp
  3. 14 0
      source/fb2view.hpp
  4. 12 0
      source/js/export.js
  5. 1 0
      source/js/javascript.qrc

+ 4 - 1
fb2edit.pro

@@ -47,7 +47,10 @@ LIBS += -lqscintilla2
 
 
 OTHER_FILES += \
 OTHER_FILES += \
     source/res/style.css \
     source/res/style.css \
-    source/res/blank.fb2
+    source/res/blank.fb2 \
+    source/js/export.js \
+    source/js/set_cursor.js \
+    source/js/get_status.js
 
 
 if (win32) {
 if (win32) {
 
 

+ 23 - 0
source/fb2view.cpp

@@ -15,6 +15,26 @@
 #include <QWebFrame>
 #include <QWebFrame>
 #include <QWebPage>
 #include <QWebPage>
 
 
+void Fb2HtmlHandler::onNew(const QString &name)
+{
+    qCritical() << "New: " << name;
+}
+
+void Fb2HtmlHandler::onTxt(const QString &text)
+{
+    qCritical() << "Txt: " << text;
+}
+
+void Fb2HtmlHandler::onEnd(const QString &name)
+{
+    qCritical() << "End: " << name;
+}
+
+void Fb2HtmlHandler::attr(const QString &name, const QString &value)
+{
+    qCritical() << "Attr: " << name << " = " << value;
+}
+
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 //  Fb2NoteView
 //  Fb2NoteView
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
@@ -311,6 +331,9 @@ void Fb2WebView::insertNote()
 
 
 void Fb2WebView::insertLink()
 void Fb2WebView::insertLink()
 {
 {
+    static const QString javascript = FB2::read(":/js/export.js");
+    page()->mainFrame()->addToJavaScriptWindowObject("handler", &handler);
+    page()->mainFrame()->evaluateJavaScript(javascript);
 }
 }
 
 
 void Fb2WebView::execCommand(const QString &cmd, const QString &arg)
 void Fb2WebView::execCommand(const QString &cmd, const QString &arg)

+ 14 - 0
source/fb2view.hpp

@@ -15,6 +15,19 @@ QT_END_NAMESPACE
 
 
 class Fb2NoteView;
 class Fb2NoteView;
 
 
+class Fb2HtmlHandler : public QObject
+{
+    Q_OBJECT
+
+public:
+    Fb2HtmlHandler() {}
+public slots:
+    void onNew(const QString &name);
+    void onTxt(const QString &text);
+    void onEnd(const QString &name);
+    void attr(const QString &name, const QString &value);
+};
+
 class Fb2BaseWebView : public QWebView
 class Fb2BaseWebView : public QWebView
 {
 {
     Q_OBJECT
     Q_OBJECT
@@ -110,6 +123,7 @@ private:
     QWebElement doc();
     QWebElement doc();
 
 
 private:
 private:
+    Fb2HtmlHandler handler;
     QWebInspector * m_inspector;
     QWebInspector * m_inspector;
     Fb2TemporaryList m_files;
     Fb2TemporaryList m_files;
     Fb2NoteView *m_noteView;
     Fb2NoteView *m_noteView;

+ 12 - 0
source/js/export.js

@@ -0,0 +1,12 @@
+(f = function(node) {
+    if (node.nodeName === "#text") {
+        handler.onTxt(node.data);
+    } else {
+        handler.onNew(node.nodeName);
+        var atts = node.attributes;
+        var count = atts.length;
+        for (var i = 0; i < count; i++) handler.attr(atts[i].name, atts[i].value);
+        for (var n = node.firstChild; n !== null; n = n.nextSibling) f(n);
+        handler.onEnd(node.nodeName);
+    }
+})(document.body);

+ 1 - 0
source/js/javascript.qrc

@@ -3,5 +3,6 @@
         <file alias="jquery.js">../../3rdparty/jQuery/jquery.js</file>
         <file alias="jquery.js">../../3rdparty/jQuery/jquery.js</file>
         <file>set_cursor.js</file>
         <file>set_cursor.js</file>
         <file>get_status.js</file>
         <file>get_status.js</file>
+        <file>export.js</file>
     </qresource>
     </qresource>
 </RCC>
 </RCC>