Browse Source

Document tree: insert simple test

Kandrashin Denis 12 years ago
parent
commit
931593a60c
9 changed files with 47 additions and 10 deletions
  1. 1 1
      source/fb2html.cpp
  2. 17 2
      source/fb2page.cpp
  3. 2 0
      source/fb2page.hpp
  4. 2 2
      source/fb2read.cpp
  5. 3 3
      source/fb2save.cpp
  6. 1 1
      source/fb2save.hpp
  7. 1 1
      source/fb2text.cpp
  8. 18 0
      source/fb2tree.cpp
  9. 2 0
      source/fb2tree.hpp

+ 1 - 1
source/fb2html.cpp

@@ -88,7 +88,7 @@ bool FbTextElement::Sublist::operator!() const
 bool FbTextElement::Sublist::operator <(const FbTextElement &element) const
 {
     if (element.isNull()) return true;
-    const QString name = element.nodeName();
+    const QString name = element.tagName();
     for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
         if (it->name() == name) return m_pos < it;
     }

+ 17 - 2
source/fb2page.cpp

@@ -38,6 +38,9 @@ FbTextPage::FbTextPage(QObject *parent)
     s->setAttribute(QWebSettings::ZoomTextOnly, true);
     s->setUserStyleSheetUrl(QUrl::fromLocalFile(":style.css"));
 
+    QString html = block("body", block("section", p()));
+    mainFrame()->setHtml(html, createUrl());
+
     setContentEditable(true);
     setNetworkAccessManager(new FbNetworkAccessManager(this));
     connect(this, SIGNAL(loadFinished(bool)), SLOT(loadFinished()));
@@ -76,8 +79,7 @@ bool FbTextPage::load(const QString &filename, const QString &xml)
 
 void FbTextPage::onTimer()
 {
-    static int number = 0;
-    QUrl url(QString("fb2:/%1/").arg(number++));
+    QUrl url = createUrl();
     temp()->setPath(url.path());
     mainFrame()->setHtml(m_html, url);
 }
@@ -98,6 +100,12 @@ bool FbTextPage::acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest
     return QWebPage::acceptNavigationRequest(frame, request, type);
 }
 
+QUrl FbTextPage::createUrl()
+{
+    static int number = 0;
+    return QString("fb2:/%1/").arg(number++);
+}
+
 QString FbTextPage::block(const QString &name)
 {
     return block(name, p());
@@ -158,6 +166,13 @@ FbTextElement FbTextPage::appendTitle(const FbTextElement &parent)
     return element;
 }
 
+FbTextElement FbTextPage::appendText(const FbTextElement &parent)
+{
+    FbTextElement element = parent;
+    element.appendInside(p());
+    return element.lastChild();
+}
+
 void FbTextPage::insertBody()
 {
     QString html = block("body", block("title", p()) + block("section", block("title", p()) + p()));

+ 2 - 0
source/fb2page.hpp

@@ -41,6 +41,8 @@ public:
 
     FbTextElement appendSection(const FbTextElement &parent);
     FbTextElement appendTitle(const FbTextElement &parent);
+    FbTextElement appendText(const FbTextElement &parent);
+    static QUrl createUrl();
 
 public slots:
     void html(const QString &html, const QUrl &url);

+ 2 - 2
source/fb2read.cpp

@@ -1,6 +1,7 @@
 #include <QtGui>
 #include <QtDebug>
 
+#include "fb2page.hpp"
 #include "fb2read.hpp"
 #include "fb2xml2.h"
 
@@ -19,8 +20,7 @@ void FbReadThread::run()
 {
 
     sleep(1);
-    static int number = 0;
-    QUrl url(QString("fb2:/%1/").arg(number++));
+    QUrl url = FbTextPage::createUrl();
     emit html(m_html, url);
     deleteLater();
 }

+ 3 - 3
source/fb2save.cpp

@@ -387,15 +387,15 @@ FbSaveHandler::RootHandler::RootHandler(FbSaveWriter &writer, const QString &nam
 
 FbXmlHandler::NodeHandler * FbSaveHandler::RootHandler::NewTag(const QString &name, const QXmlAttributes &atts)
 {
-    return name == "body" ? new BodyHandler(m_writer, name, atts) : NULL;
+    return name == "body" ? new BodyHandler(m_writer, name) : NULL;
 }
 
 //---------------------------------------------------------------------------
 //  FbSaveHandler::BodyHandler
 //---------------------------------------------------------------------------
 
-FbSaveHandler::BodyHandler::BodyHandler(FbSaveWriter &writer, const QString &name, const QXmlAttributes &atts)
-    : TextHandler(writer, name, atts, "FictionBook")
+FbSaveHandler::BodyHandler::BodyHandler(FbSaveWriter &writer, const QString &name)
+    : TextHandler(writer, name, QXmlAttributes(), "FictionBook")
 {
     m_writer.writeAttribute("xmlns", "http://www.gribuser.ru/xml/fictionbook/2.0");
     m_writer.writeAttribute("xmlns:l", "http://www.w3.org/1999/xlink");

+ 1 - 1
source/fb2save.hpp

@@ -142,7 +142,7 @@ private:
     class BodyHandler : public TextHandler
     {
     public:
-        explicit BodyHandler(FbSaveWriter &writer, const QString &name, const QXmlAttributes &atts);
+        explicit BodyHandler(FbSaveWriter &writer, const QString &name);
     protected:
         virtual void EndTag(const QString &name);
     };

+ 1 - 1
source/fb2text.cpp

@@ -497,7 +497,7 @@ void FbTextEdit::html(QString html)
     if (!m_thread) return;
     static int number = 0;
     QWebSettings::clearMemoryCaches();
-    QUrl url(QString("fb2:/%1/").arg(number++));
+    QUrl url = FbTextPage::createUrl();
     FbTextPage *page = m_thread->page();
     setPage(page);
     page->setParent(this);

+ 18 - 0
source/fb2tree.cpp

@@ -464,6 +464,9 @@ void FbTreeView::initActions(QToolBar *toolbar)
     actionAuthor = act = new QAction(tr("+ Author"), this);
     connect(act, SIGNAL(triggered()), SLOT(insertAuthor()));
 
+    actionText = act = new QAction(tr("+ Simple text"), this);
+    connect(act, SIGNAL(triggered()), SLOT(insertText()));
+
     actionDate = act = new QAction(tr("+ Date"), this);
     connect(act, SIGNAL(triggered()), SLOT(insertDate()));
 
@@ -567,6 +570,7 @@ void FbTreeView::contextMenu(const QPoint &pos)
         menu.addAction(actionEpigraph);
         if (!e.hasChild("IMG")) menu.addAction(actionImage);
         if (!e.hasChild("FB:ANNOTATION")) menu.addAction(actionAnnot);
+        menu.addAction(actionText);
     }
 
     if (tag == "FB:POEM") {
@@ -695,6 +699,20 @@ void FbTreeView::insertTitle()
     append(index, element);
 }
 
+void FbTreeView::insertText()
+{
+    FbTreeModel * m = model();
+    if (!m) return;
+
+    QModelIndex index = currentIndex();
+    FbTreeItem * item = m->item(index);
+    if (!item) return;
+
+    FbTextElement element = item->element();
+    if (!element.isSection()) return;
+    m_view.page()->appendText(element).select();
+}
+
 void FbTreeView::insertAuthor()
 {
 }

+ 2 - 0
source/fb2tree.hpp

@@ -155,6 +155,7 @@ private slots:
     void insertAnnot();
     void insertStanza();
     void insertDate();
+    void insertText();
     void deleteNode();
 
     void moveUp();
@@ -183,6 +184,7 @@ private:
         *actionStanza,
         *actionImage,
         *actionAnnot,
+        *actionText,
         *actionDate,
         *actionCut,
         *actionCopy,