浏览代码

Fix document tree

Kandrashin Denis 12 年之前
父节点
当前提交
535211f0a1
共有 5 个文件被更改,包括 24 次插入18 次删除
  1. 8 2
      source/fb2html.cpp
  2. 1 1
      source/fb2save.cpp
  3. 3 3
      source/fb2text.cpp
  4. 8 11
      source/fb2tree.cpp
  5. 4 1
      source/fb2utils.cpp

+ 8 - 2
source/fb2html.cpp

@@ -115,8 +115,14 @@ void FbTextElement::getChildren(FbElementList &list)
     FbTextElement child = firstChild();
     while (!child.isNull()) {
         QString tag = child.tagName().toLower();
-        if (tag == "div") {
-            if (child.hasAttribute("class")) list << child;
+        if (tag == "fb:section") {
+            list << child;
+        } else if (tag == "fb:title") {
+            list << child;
+        } else if (tag == "fb:subtitle") {
+            list << child;
+        } else if (tag == "fb:body") {
+            list << child;
         } else if (tag == "img") {
             list << child;
         } else {

+ 1 - 1
source/fb2save.cpp

@@ -315,7 +315,7 @@ FbXmlHandler::NodeHandler * FbSaveHandler::TextHandler::NewTag(const QString &na
         case Code      : tag = "code"          ; break;
         case Sub       : tag = "sub"           ; break;
         case Sup       : tag = "sup"           ; break;
-        default: ;
+        default: if (name.left(3) == "fb:") tag = name.mid(3);
     }
     return new TextHandler(this, name, atts, tag);
 }

+ 3 - 3
source/fb2text.cpp

@@ -69,9 +69,9 @@ void FbNoteView::hint(const QWebElement element, const QRect &rect)
     QString html = element.toOuterXml();
     html.prepend(
         "<body bgcolor=lightyellow style='overflow:hidden;padding:0;margin:0;margin-top:2;'>"
-        "<div class=body fb2_name=notes style='padding:0;margin:0;'>"
+        "<fb:body name=notes style='padding:0;margin:0;'>"
     );
-    html.append("</div></body>");
+    html.append("</fb:body></body>");
     setGeometry(rect);
     setHtml(html, m_url);
     show();
@@ -585,7 +585,7 @@ void FbTextEdit::linkHovered(const QString &link, const QString &title, const QS
         return;
     }
 
-    const QString query = QString("DIV#%1").arg(href);
+    const QString query = QString("fb\\:section#%1").arg(href);
     const QWebElement element = doc().findFirst(query);
     if (element.isNull()) {
         if (m_noteView) m_noteView->hide();

+ 8 - 11
source/fb2tree.cpp

@@ -38,17 +38,14 @@ void FbTreeItem::init()
 {
     m_text = QString();
     m_name = m_element.tagName().toLower();
-    QString style = m_element.attribute("class").toLower();
-    if (m_name == "div") {
-        if (style == "title") {
-            m_text = title();
-            if (m_parent) m_parent->m_text += m_text += " ";
-        } else if (style == "subtitle") {
-            m_text = title();
-        } else if (style == "body") {
-            m_body = m_element.attribute("fb2_name");
-        }
-        if (!style.isEmpty()) m_name = style;
+    if (m_name.left(3) == "fb:") m_name = m_name.mid(3);
+    if (m_name == "title") {
+        m_text = title();
+        if (m_parent) m_parent->m_text += m_text += " ";
+    } else if (m_name == "subtitle") {
+        m_text = title();
+    } else if (m_name == "body") {
+        m_body = m_element.attribute("name");
     } else if (m_name == "img") {
         m_name = "image";
         QUrl url = m_element.attribute("src");

+ 4 - 1
source/fb2utils.cpp

@@ -24,13 +24,16 @@ QString jScript(const QString &filename)
 
 #ifdef QT_DEBUG
     QString filepath = qApp->arguments().first();
+    #ifdef Q_OS_WIN
+    filepath += "/..";
+    #endif
     filepath += "/../../fb2edit/source/js/";
     filepath += filename;
     filepath = QDir::cleanPath(filepath);
 #else
     QString filepath = ":/js/";
     filepath += filename;
-#endif
+#endif // QT_DEBUG
 
     // TODO: throw an exception instead of
     // returning an empty string