123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- #ifndef FB2HTML_H
- #define FB2HTML_H
- #include <QUndoCommand>
- #include <QWebElement>
- class FbTextPage;
- class FbTextElement;
- typedef QList<FbTextElement> FbElementList;
- class FbTextElement : public QWebElement
- {
- private:
- class Type
- {
- public:
- Type(const QString &name): m_name(name), m_min(0), m_max(0) {}
- Type(const QString &name, int min, int max): m_name(name), m_min(min), m_max(max) {}
- Type(const Type &t): m_name(t.m_name), m_min(t.m_min), m_max(t.m_max) {}
- const QString & name() const { return m_name; }
- int min() const { return m_min; }
- int max() const { return m_max; }
- private:
- QString m_name;
- int m_min;
- int m_max;
- };
- typedef QList<Type> TypeList;
- typedef QMap<QString, TypeList> TypeMap;
- class Scheme
- {
- public:
- explicit Scheme();
- const TypeList * operator[](const QString &name) const;
- private:
- TypeMap m_types;
- };
- class Sublist
- {
- public:
- Sublist(const TypeList &list, const QString &name);
- operator bool() const;
- bool operator !() const;
- bool operator <(const FbTextElement &element) const;
- private:
- const TypeList &m_list;
- TypeList::const_iterator m_pos;
- };
- public:
- FbTextElement() {}
- FbTextElement(const QWebElement &x) : QWebElement(x) {}
- 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;
- QString location();
- int childIndex() const;
- int index() const;
- public:
- FbTextElement operator[](const QString &name);
- bool hasChild(const QString &style) const;
- bool isBody() const;
- bool isSection() const;
- bool isTitle() const;
- bool isStanza() const;
- bool hasTitle() const;
- public:
- FbTextElement findFirst(const QString &selectorQuery) const { return QWebElement::findFirst(selectorQuery); }
- FbTextElement parent() const { return QWebElement::parent(); }
- FbTextElement firstChild() const { return QWebElement::firstChild(); }
- FbTextElement lastChild() const { return QWebElement::lastChild(); }
- FbTextElement nextSibling() const { return QWebElement::nextSibling(); }
- FbTextElement previousSibling() const { return QWebElement::previousSibling(); }
- FbTextElement document() const { return QWebElement::document(); }
- public:
- void select();
- private:
- const TypeList *subtypes() const;
- TypeList::const_iterator subtype(const TypeList &list, const QString &style);
- };
- class FbInsertCmd : public QUndoCommand
- {
- public:
- explicit FbInsertCmd(const FbTextElement &element);
- virtual void undo();
- virtual void redo();
- private:
- FbTextElement m_element;
- FbTextElement m_parent;
- bool m_inner;
- };
- class FbReplaceCmd : public QUndoCommand
- {
- public:
- explicit FbReplaceCmd(const FbTextElement &original, const FbTextElement &duplicate);
- virtual void undo();
- virtual void redo();
- private:
- FbTextElement m_original;
- FbTextElement m_duplicate;
- bool m_update;
- };
- class FbDeleteCmd : public QUndoCommand
- {
- public:
- explicit FbDeleteCmd(const FbTextElement &element);
- virtual void undo();
- virtual void redo();
- private:
- FbTextElement m_element;
- FbTextElement m_parent;
- bool m_inner;
- };
- class FbMoveUpCmd : public QUndoCommand
- {
- public:
- explicit FbMoveUpCmd(const FbTextElement &element);
- virtual void undo();
- virtual void redo();
- private:
- FbTextElement m_element;
- };
- class FbMoveLeftCmd : public QUndoCommand
- {
- public:
- explicit FbMoveLeftCmd(const FbTextElement &element);
- virtual void undo();
- virtual void redo();
- private:
- FbTextElement m_element;
- FbTextElement m_subling;
- FbTextElement m_parent;
- };
- class FbMoveRightCmd : public QUndoCommand
- {
- public:
- explicit FbMoveRightCmd(const FbTextElement &element);
- virtual void undo();
- virtual void redo();
- private:
- FbTextElement m_element;
- FbTextElement m_subling;
- };
- #endif // FB2HTML_H
|