fb2html.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. #ifndef FB2HTML_H
  2. #define FB2HTML_H
  3. #include <QUndoCommand>
  4. #include <QWebElement>
  5. class FbTextPage;
  6. class FbTextElement;
  7. typedef QList<FbTextElement> FbElementList;
  8. class FbTextElement : public QWebElement
  9. {
  10. private:
  11. class Type
  12. {
  13. public:
  14. Type(const QString &name): m_name(name), m_min(0), m_max(0) {}
  15. Type(const QString &name, int min, int max): m_name(name), m_min(min), m_max(max) {}
  16. Type(const Type &t): m_name(t.m_name), m_min(t.m_min), m_max(t.m_max) {}
  17. const QString & name() const { return m_name; }
  18. int min() const { return m_min; }
  19. int max() const { return m_max; }
  20. private:
  21. QString m_name;
  22. int m_min;
  23. int m_max;
  24. };
  25. typedef QList<Type> TypeList;
  26. typedef QMap<QString, TypeList> TypeMap;
  27. class Scheme
  28. {
  29. public:
  30. explicit Scheme();
  31. const TypeList * operator[](const QString &name) const;
  32. private:
  33. TypeMap m_types;
  34. };
  35. class Sublist
  36. {
  37. public:
  38. Sublist(const TypeList &list, const QString &name);
  39. operator bool() const;
  40. bool operator !() const;
  41. bool operator <(const FbTextElement &element) const;
  42. private:
  43. const TypeList &m_list;
  44. TypeList::const_iterator m_pos;
  45. };
  46. public:
  47. FbTextElement() {}
  48. FbTextElement(const QWebElement &x) : QWebElement(x) {}
  49. FbTextElement &operator=(const QWebElement &x) { QWebElement::operator=(x); return *this; }
  50. FbTextElement insertInside(const QString &style, const QString &html);
  51. FbTextElement child(int index) const;
  52. QString nodeName() const;
  53. void getChildren(FbElementList &list);
  54. bool hasSubtype(const QString &style) const;
  55. bool hasScheme() const;
  56. QString location();
  57. int childIndex() const;
  58. int index() const;
  59. public:
  60. FbTextElement operator[](const QString &name);
  61. bool hasChild(const QString &style) const;
  62. bool isBody() const;
  63. bool isSection() const;
  64. bool isTitle() const;
  65. bool isStanza() const;
  66. bool hasTitle() const;
  67. public:
  68. FbTextElement findFirst(const QString &selectorQuery) const { return QWebElement::findFirst(selectorQuery); }
  69. FbTextElement parent() const { return QWebElement::parent(); }
  70. FbTextElement firstChild() const { return QWebElement::firstChild(); }
  71. FbTextElement lastChild() const { return QWebElement::lastChild(); }
  72. FbTextElement nextSibling() const { return QWebElement::nextSibling(); }
  73. FbTextElement previousSibling() const { return QWebElement::previousSibling(); }
  74. FbTextElement document() const { return QWebElement::document(); }
  75. public:
  76. void select();
  77. private:
  78. const TypeList *subtypes() const;
  79. TypeList::const_iterator subtype(const TypeList &list, const QString &style);
  80. };
  81. class FbInsertCmd : public QUndoCommand
  82. {
  83. public:
  84. explicit FbInsertCmd(const FbTextElement &element);
  85. virtual void undo();
  86. virtual void redo();
  87. private:
  88. FbTextElement m_element;
  89. FbTextElement m_parent;
  90. bool m_inner;
  91. };
  92. class FbReplaceCmd : public QUndoCommand
  93. {
  94. public:
  95. explicit FbReplaceCmd(const FbTextElement &original, const FbTextElement &duplicate);
  96. virtual void undo();
  97. virtual void redo();
  98. private:
  99. FbTextElement m_original;
  100. FbTextElement m_duplicate;
  101. bool m_update;
  102. };
  103. class FbDeleteCmd : public QUndoCommand
  104. {
  105. public:
  106. explicit FbDeleteCmd(const FbTextElement &element);
  107. virtual void undo();
  108. virtual void redo();
  109. private:
  110. FbTextElement m_element;
  111. FbTextElement m_parent;
  112. bool m_inner;
  113. };
  114. class FbMoveUpCmd : public QUndoCommand
  115. {
  116. public:
  117. explicit FbMoveUpCmd(const FbTextElement &element);
  118. virtual void undo();
  119. virtual void redo();
  120. private:
  121. FbTextElement m_element;
  122. };
  123. class FbMoveLeftCmd : public QUndoCommand
  124. {
  125. public:
  126. explicit FbMoveLeftCmd(const FbTextElement &element);
  127. virtual void undo();
  128. virtual void redo();
  129. private:
  130. FbTextElement m_element;
  131. FbTextElement m_subling;
  132. FbTextElement m_parent;
  133. };
  134. class FbMoveRightCmd : public QUndoCommand
  135. {
  136. public:
  137. explicit FbMoveRightCmd(const FbTextElement &element);
  138. virtual void undo();
  139. virtual void redo();
  140. private:
  141. FbTextElement m_element;
  142. FbTextElement m_subling;
  143. };
  144. #endif // FB2HTML_H