Kandrashin Denis 12 éve
szülő
commit
9512d129a9
3 módosított fájl, 30 hozzáadás és 27 törlés
  1. 18 17
      source/fb2html.cpp
  2. 4 4
      source/fb2html.h
  3. 8 6
      source/fb2tree.cpp

+ 18 - 17
source/fb2html.cpp

@@ -83,33 +83,39 @@ bool FbTextElement::Sublist::operator!() const
     return m_pos == m_list.end();
 }
 
-bool FbTextElement::Sublist::operator <(const QWebElement &element) const
+bool FbTextElement::Sublist::operator <(const FbTextElement &element) const
 {
-    const QString name = element.attribute("class");
+    const QString name = element.nodeName();
     for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
         if (it->name() == name) return m_pos < it  || element.isNull();
     }
     return false;
 }
 
-bool FbTextElement::Sublist::operator >=(const QWebElement &element) const
+bool FbTextElement::Sublist::operator >=(const FbTextElement &element) const
 {
-    const QString name = element.attribute("class");
+    const QString name = element.nodeName();
     for (TypeList::const_iterator it = m_list.begin(); it != m_list.end(); it++) {
         if (it->name() == name) return m_pos >= it || element.isNull();
     }
     return false;
 }
 
-bool FbTextElement::Sublist::operator !=(const QWebElement &element) const
+bool FbTextElement::Sublist::operator !=(const FbTextElement &element) const
 {
-    return element.isNull() || m_pos->name() != element.attribute("class");
+    return element.isNull() || m_pos->name() != element.nodeName();
 }
 
 //---------------------------------------------------------------------------
 //  FbTextElement
 //---------------------------------------------------------------------------
 
+QString FbTextElement::nodeName() const
+{
+    QString n = tagName().toLower();
+    return n.left(3) == "fb:" ? n.mid(3) : n;
+}
+
 void FbTextElement::getChildren(FbElementList &list)
 {
     FbTextElement child = firstChild();
@@ -140,7 +146,7 @@ bool FbTextElement::hasScheme() const
 const FbTextElement::TypeList * FbTextElement::subtypes() const
 {
     static Scheme scheme;
-    return scheme[attribute("class").toLower()];
+    return scheme[nodeName()];
 }
 
 bool FbTextElement::hasSubtype(const QString &style) const
@@ -202,35 +208,30 @@ bool FbTextElement::hasChild(const QString &style) const
 {
     FbTextElement child = firstChild();
     while (!child.isNull()) {
-        if (child.tagName() == "DIV" && child.attribute("class").toLower() == style) return true;
+        if (child.nodeName() == style) return true;
         child = child.nextSibling();
     }
     return false;
 }
 
-bool FbTextElement::isDiv(const QString &style) const
-{
-    return tagName() == "DIV" && attribute("class").toLower() == style;
-}
-
 bool FbTextElement::isBody() const
 {
-    return isDiv("body");
+    return nodeName() == "body";
 }
 
 bool FbTextElement::isSection() const
 {
-    return isDiv("section");
+    return nodeName() == "section";
 }
 
 bool FbTextElement::isTitle() const
 {
-    return isDiv("title");
+    return nodeName() == "title";
 }
 
 bool FbTextElement::isStanza() const
 {
-    return isDiv("stanza");
+    return nodeName() == "stanza";
 }
 
 bool FbTextElement::hasTitle() const

+ 4 - 4
source/fb2html.h

@@ -46,9 +46,9 @@ private:
         Sublist(const TypeList &list, const QString &name);
         operator bool() const;
         bool operator !() const;
-        bool operator <(const QWebElement &element) const;
-        bool operator >=(const QWebElement &element) const;
-        bool operator !=(const QWebElement &element) const;
+        bool operator <(const FbTextElement &element) const;
+        bool operator >=(const FbTextElement &element) const;
+        bool operator !=(const FbTextElement &element) const;
     private:
         const TypeList &m_list;
         TypeList::const_iterator m_pos;
@@ -60,6 +60,7 @@ public:
     FbTextElement &operator=(const QWebElement &x) { QWebElement::operator=(x); return *this; }
     FbTextElement insertInside(const QString &style, const QString &html);
     FbTextElement child(int index) const;
+    QString nodeName() const;
     void getChildren(FbElementList &list);
     bool hasSubtype(const QString &style) const;
     bool hasScheme() const;
@@ -68,7 +69,6 @@ public:
 
 public:
     bool hasChild(const QString &style) const;
-    bool isDiv(const QString &style) const;
     bool isBody() const;
     bool isSection() const;
     bool isTitle() const;

+ 8 - 6
source/fb2tree.cpp

@@ -535,20 +535,22 @@ void FbTreeView::contextMenu(const QPoint &pos)
     QMenu menu;
     menu.addAction(actionSection);
 
-    if (e.isBody()) {
+    QString n = e.nodeName();
+
+    if (n == "body") {
         if (!e.hasChild("image")) menu.addAction(actionImage);
         if (!e.hasChild("title")) menu.addAction(actionTitle);
         menu.addAction(actionEpigraph);
     }
 
-    if (e.isSection()) {
+    if (n == "section") {
         if (!e.hasChild("title")) menu.addAction(actionTitle);
         menu.addAction(actionEpigraph);
         if (!e.hasChild("image")) menu.addAction(actionImage);
         if (!e.hasChild("annotetion")) menu.addAction(actionAnnot);
     }
 
-    if (e.isDiv("poem")) {
+    if (n == "poem") {
         if (!e.hasChild("title")) menu.addAction(actionTitle);
         menu.addAction(actionEpigraph);
         menu.addAction(actionStanza);
@@ -556,15 +558,15 @@ void FbTreeView::contextMenu(const QPoint &pos)
         if (!e.hasChild("date")) menu.addAction(actionDate);
     }
 
-    if (e.isDiv("stanza")) {
+    if (n == "stanza") {
         if (!e.hasChild("title")) menu.addAction(actionTitle);
     }
 
-    if (e.isDiv("epigraph")) {
+    if (n == "epigraph") {
         menu.addAction(actionAuthor);
     }
 
-    if (e.isDiv("cite")) {
+    if (n == "cite") {
         menu.addAction(actionAuthor);
     }