fb2html.h 4.3 KB

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