fb2html.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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() { return m_min; }
  18. int max() { return m_max; }
  19. private:
  20. const QString m_name;
  21. const int m_min;
  22. const 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 QWebElement &element) const;
  41. private:
  42. const TypeList &m_list;
  43. TypeList::const_iterator m_pos;
  44. };
  45. public:
  46. FbTextElement() {}
  47. FbTextElement(const QWebElement &x) : QWebElement(x) {}
  48. FbTextElement &operator=(const QWebElement &x) { QWebElement::operator=(x); return *this; }
  49. FbTextElement insertInside(const QString &style, const QString &html);
  50. void getChildren(FbElementList &list);
  51. QString location();
  52. public:
  53. bool hasChild(const QString &style) const;
  54. bool isDiv(const QString &style) const;
  55. bool isBody() const;
  56. bool isSection() const;
  57. bool isTitle() const;
  58. bool isStanza() const;
  59. bool hasTitle() const;
  60. public:
  61. FbTextElement findFirst(const QString &selectorQuery) const { return QWebElement::findFirst(selectorQuery); }
  62. FbTextElement parent() const { return QWebElement::parent(); }
  63. FbTextElement firstChild() const { return QWebElement::firstChild(); }
  64. FbTextElement lastChild() const { return QWebElement::lastChild(); }
  65. FbTextElement nextSibling() const { return QWebElement::nextSibling(); }
  66. FbTextElement previousSibling() const { return QWebElement::previousSibling(); }
  67. FbTextElement document() const { return QWebElement::document(); }
  68. public:
  69. void select();
  70. private:
  71. const TypeList *subtypes() const;
  72. TypeList::const_iterator subtype(const TypeList &list, const QString &style);
  73. };
  74. class FbInsertCmd : public QUndoCommand
  75. {
  76. public:
  77. explicit FbInsertCmd(const FbTextElement &element);
  78. virtual void undo();
  79. virtual void redo();
  80. private:
  81. FbTextElement m_element;
  82. FbTextElement m_parent;
  83. bool m_inner;
  84. };
  85. class FbDeleteCmd : public QUndoCommand
  86. {
  87. public:
  88. explicit FbDeleteCmd(const FbTextElement &element);
  89. virtual void undo();
  90. virtual void redo();
  91. private:
  92. FbTextElement m_element;
  93. FbTextElement m_parent;
  94. bool m_inner;
  95. };
  96. class FbMoveUpCmd : public QUndoCommand
  97. {
  98. public:
  99. explicit FbMoveUpCmd(const FbTextElement &element);
  100. virtual void undo();
  101. virtual void redo();
  102. private:
  103. FbTextElement m_element;
  104. };
  105. class FbMoveLeftCmd : public QUndoCommand
  106. {
  107. public:
  108. explicit FbMoveLeftCmd(const FbTextElement &element);
  109. virtual void undo();
  110. virtual void redo();
  111. private:
  112. FbTextElement m_element;
  113. FbTextElement m_subling;
  114. FbTextElement m_parent;
  115. };
  116. class FbMoveRightCmd : public QUndoCommand
  117. {
  118. public:
  119. explicit FbMoveRightCmd(const FbTextElement &element);
  120. virtual void undo();
  121. virtual void redo();
  122. private:
  123. FbTextElement m_element;
  124. FbTextElement m_subling;
  125. };
  126. #endif // FB2HTML_H