fb2html.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 FbTextScheme
  9. {
  10. public:
  11. explicit FbTextScheme();
  12. class Type
  13. {
  14. public:
  15. Type(const QString &name = QString(), int min=0, int max=1): 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() { return m_min; }
  19. int max() { return m_max; }
  20. private:
  21. const QString m_name;
  22. const int m_min;
  23. const int m_max;
  24. };
  25. typedef QList<Type> TypeList;
  26. typedef QMap<QString, TypeList> TypeMap;
  27. private:
  28. TypeMap m_types;
  29. };
  30. class FbTextElement : public QWebElement
  31. {
  32. public:
  33. FbTextElement() {}
  34. FbTextElement(const QWebElement &x) : QWebElement(x) {}
  35. FbTextElement &operator=(const QWebElement &x) { QWebElement::operator=(x); return *this; }
  36. void getChildren(FbElementList &list);
  37. QString location();
  38. public:
  39. bool hasChild(const QString &style) const;
  40. bool isDiv(const QString &style) const;
  41. bool isBody() const;
  42. bool isSection() const;
  43. bool isTitle() const;
  44. bool isStanza() const;
  45. bool hasTitle() const;
  46. public:
  47. FbTextElement findFirst(const QString &selectorQuery) const { return QWebElement::findFirst(selectorQuery); }
  48. FbTextElement parent() const { return QWebElement::parent(); }
  49. FbTextElement firstChild() const { return QWebElement::firstChild(); }
  50. FbTextElement lastChild() const { return QWebElement::lastChild(); }
  51. FbTextElement nextSibling() const { return QWebElement::nextSibling(); }
  52. FbTextElement previousSibling() const { return QWebElement::previousSibling(); }
  53. FbTextElement document() const { return QWebElement::document(); }
  54. public:
  55. void select();
  56. };
  57. class FbInsertCmd : public QUndoCommand
  58. {
  59. public:
  60. explicit FbInsertCmd(const FbTextElement &element);
  61. virtual void undo();
  62. virtual void redo();
  63. private:
  64. FbTextElement m_element;
  65. FbTextElement m_parent;
  66. bool m_inner;
  67. };
  68. class FbDeleteCmd : public QUndoCommand
  69. {
  70. public:
  71. explicit FbDeleteCmd(const FbTextElement &element);
  72. virtual void undo();
  73. virtual void redo();
  74. private:
  75. FbTextElement m_element;
  76. FbTextElement m_parent;
  77. bool m_inner;
  78. };
  79. class FbMoveUpCmd : public QUndoCommand
  80. {
  81. public:
  82. explicit FbMoveUpCmd(const FbTextElement &element);
  83. virtual void undo();
  84. virtual void redo();
  85. private:
  86. FbTextElement m_element;
  87. };
  88. class FbMoveLeftCmd : public QUndoCommand
  89. {
  90. public:
  91. explicit FbMoveLeftCmd(const FbTextElement &element);
  92. virtual void undo();
  93. virtual void redo();
  94. private:
  95. FbTextElement m_element;
  96. FbTextElement m_subling;
  97. FbTextElement m_parent;
  98. };
  99. class FbMoveRightCmd : public QUndoCommand
  100. {
  101. public:
  102. explicit FbMoveRightCmd(const FbTextElement &element);
  103. virtual void undo();
  104. virtual void redo();
  105. private:
  106. FbTextElement m_element;
  107. FbTextElement m_subling;
  108. };
  109. #endif // FB2HTML_H