Browse Source

Append <body> element

Kandrashin Denis 13 years ago
parent
commit
ee495b014b
4 changed files with 33 additions and 9 deletions
  1. 1 0
      source/fb2main.cpp
  2. 1 1
      source/fb2tree.cpp
  3. 23 7
      source/fb2view.cpp
  4. 8 1
      source/fb2view.hpp

+ 1 - 0
source/fb2main.cpp

@@ -665,6 +665,7 @@ void Fb2MainWindow::viewText()
     connect(actionNote, SIGNAL(triggered()), textEdit, SLOT(insertNote()));
     connect(actionNote, SIGNAL(triggered()), textEdit, SLOT(insertNote()));
     connect(actionLink, SIGNAL(triggered()), textEdit, SLOT(insertLink()));
     connect(actionLink, SIGNAL(triggered()), textEdit, SLOT(insertLink()));
     connect(actionTitle, SIGNAL(triggered()), textEdit, SLOT(insertTitle()));
     connect(actionTitle, SIGNAL(triggered()), textEdit, SLOT(insertTitle()));
+    connect(actionBody, SIGNAL(triggered()), textEdit->page(), SLOT(insertBody()));
 
 
     connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
     connect(actionZoomIn, SIGNAL(triggered()), textEdit, SLOT(zoomIn()));
     connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));
     connect(actionZoomOut, SIGNAL(triggered()), textEdit, SLOT(zoomOut()));

+ 1 - 1
source/fb2tree.cpp

@@ -31,7 +31,7 @@ Fb2TreeItem::Fb2TreeItem(QWebElement &element, Fb2TreeItem *parent, int number)
         } else if (style == "subtitle") {
         } else if (style == "subtitle") {
             m_text = title(element);
             m_text = title(element);
         } else if (style == "body") {
         } else if (style == "body") {
-            QString name = element.attribute("name");
+            QString name = element.attribute("fb2_name");
             if (!name.isEmpty()) style += " name=" + name;
             if (!name.isEmpty()) style += " name=" + name;
         }
         }
         if (!style.isEmpty()) m_name = style;
         if (!style.isEmpty()) m_name = style;

+ 23 - 7
source/fb2view.cpp

@@ -86,6 +86,23 @@ bool Fb2WebPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest
     return QWebPage::acceptNavigationRequest(frame, request, type);
     return QWebPage::acceptNavigationRequest(frame, request, type);
 }
 }
 
 
+QWebElement Fb2WebPage::body()
+{
+    return doc().findFirst("body");
+}
+
+QWebElement Fb2WebPage::doc()
+{
+    return mainFrame()->documentElement();
+}
+
+void Fb2WebPage::insertBody()
+{
+    body().appendInside("<div class=body><div class=section><p>text</p></div></div>");
+    QWebElement element = body().lastChild();
+    emit contentsChanged();
+}
+
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 //  Fb2WebView
 //  Fb2WebView
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
@@ -128,16 +145,14 @@ Fb2NoteView & Fb2WebView::noteView()
     return *m_noteView;
     return *m_noteView;
 }
 }
 
 
-QWebElement Fb2WebView::doc()
+QWebElement Fb2WebView::body()
 {
 {
-    return page()->mainFrame()->documentElement();
+    return doc().findFirst("body");
 }
 }
 
 
-QString Fb2WebView::toBodyXml()
+QWebElement Fb2WebView::doc()
 {
 {
-    QWebElement body = doc().findFirst("body");
-    if (body.isNull()) return QString();
-    return body.toOuterXml();
+    return page()->mainFrame()->documentElement();
 }
 }
 
 
 void Fb2WebView::fixContents()
 void Fb2WebView::fixContents()
@@ -311,7 +326,7 @@ void Fb2WebView::insertImage()
 
 
     QByteArray data = file.readAll();
     QByteArray data = file.readAll();
     QString name = m_files.add(path, data);
     QString name = m_files.add(path, data);
-    execCommand("insertImage", name.prepend("fb2:"));
+    execCommand("insertImage", name.prepend("#"));
 }
 }
 
 
 void Fb2WebView::insertNote()
 void Fb2WebView::insertNote()
@@ -358,3 +373,4 @@ void Fb2WebView::insertTitle()
     static const QString javascript = FB2::read(":/js/insert_title.js");
     static const QString javascript = FB2::read(":/js/insert_title.js");
     page()->mainFrame()->evaluateJavaScript(javascript);
     page()->mainFrame()->evaluateJavaScript(javascript);
 }
 }
+

+ 8 - 1
source/fb2view.hpp

@@ -53,8 +53,15 @@ class Fb2WebPage : public QWebPage
 public:
 public:
     explicit Fb2WebPage(QObject *parent = 0);
     explicit Fb2WebPage(QObject *parent = 0);
 
 
+public slots:
+    void insertBody();
+
 protected:
 protected:
     virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
     virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
+
+private:
+    QWebElement body();
+    QWebElement doc();
 };
 };
 
 
 class Fb2WebView : public Fb2BaseWebView
 class Fb2WebView : public Fb2BaseWebView
@@ -73,7 +80,6 @@ public:
     bool save(QIODevice *device, const QString &codec = QString());
     bool save(QIODevice *device, const QString &codec = QString());
     bool save(QByteArray *array);
     bool save(QByteArray *array);
     bool save(QString *string);
     bool save(QString *string);
-    QString toBodyXml();
     QString status();
     QString status();
 
 
     bool UndoEnabled();
     bool UndoEnabled();
@@ -111,6 +117,7 @@ private:
     void execCommand(const QString &cmd, const QString &arg);
     void execCommand(const QString &cmd, const QString &arg);
     Fb2TemporaryFile * file(const QString &name);
     Fb2TemporaryFile * file(const QString &name);
     Fb2NoteView & noteView();
     Fb2NoteView & noteView();
+    QWebElement body();
     QWebElement doc();
     QWebElement doc();
 
 
 private:
 private: