fb2head.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. #ifndef FB2HEAD_H
  2. #define FB2HEAD_H
  3. #include <QAbstractItemModel>
  4. #include <QDialog>
  5. #include <QDomDocument>
  6. #include <QDomElement>
  7. #include <QMap>
  8. #include <QTreeView>
  9. #include <QWebElement>
  10. #include <QWebView>
  11. QT_BEGIN_NAMESPACE
  12. class QAction;
  13. class QComboBox;
  14. class QFormLayout;
  15. class QLabel;
  16. class QToolBar;
  17. class QLineEdit;
  18. QT_END_NAMESPACE
  19. #include "fb2xml.h"
  20. class FbTextEdit;
  21. class FbScheme : public QDomElement
  22. {
  23. FB2_BEGIN_KEYLIST
  24. XsElement,
  25. XsChoice,
  26. XsComplexType,
  27. XsSequence,
  28. FB2_END_KEYLIST
  29. private:
  30. class Fb : public QDomDocument { public: Fb(); };
  31. public:
  32. FbScheme() {}
  33. FbScheme(const FbScheme &x) : QDomElement(x) {}
  34. FbScheme(const QDomElement &x) : QDomElement(x) {}
  35. FbScheme& operator=(const FbScheme &x) { QDomElement::operator=(x); return *this; }
  36. static const QDomDocument & fb2();
  37. FbScheme element(const QString &name) const;
  38. void items(QStringList &list) const;
  39. bool hasItems() const;
  40. QString info() const;
  41. QString type() const;
  42. private:
  43. FbScheme typeScheme() const;
  44. FbScheme item(const QString &name) const;
  45. };
  46. class FbHeadItem: public QObject
  47. {
  48. Q_OBJECT
  49. FB2_BEGIN_KEYLIST
  50. Auth,
  51. Cover,
  52. Image,
  53. Seqn,
  54. FB2_END_KEYLIST
  55. public:
  56. explicit FbHeadItem(QWebElement &element, FbHeadItem *parent = 0);
  57. virtual ~FbHeadItem();
  58. FbHeadItem * append(const QString name);
  59. void remove(int row);
  60. FbHeadItem * item(const QModelIndex &index) const;
  61. FbHeadItem * item(int row) const;
  62. int index(FbHeadItem * child) const {
  63. return m_list.indexOf(child);
  64. }
  65. int count() const {
  66. return m_list.size();
  67. }
  68. FbHeadItem * parent() const {
  69. return m_parent;
  70. }
  71. QWebElement element() const {
  72. return m_element;
  73. }
  74. QString text(int col = 0) const;
  75. void setText(const QString &text);
  76. const QString & name() const {
  77. return m_name;
  78. }
  79. QString sub(const QString &key) const;
  80. FbScheme scheme() const;
  81. private:
  82. class HintHash : public QHash<QString, QString>
  83. {
  84. public:
  85. explicit HintHash();
  86. };
  87. private:
  88. void addChildren(QWebElement &parent);
  89. QString value() const;
  90. QString hint() const;
  91. private:
  92. QList<FbHeadItem*> m_list;
  93. QWebElement m_element;
  94. FbHeadItem * m_parent;
  95. QString m_name;
  96. };
  97. class FbHeadModel: public QAbstractItemModel
  98. {
  99. Q_OBJECT
  100. public:
  101. explicit FbHeadModel(QWebView &view, QObject *parent = 0);
  102. virtual ~FbHeadModel();
  103. void expand(QTreeView *view);
  104. FbHeadItem * item(const QModelIndex &index) const;
  105. QModelIndex append(const QModelIndex &parent, const QString &name);
  106. void remove(const QModelIndex &index);
  107. public:
  108. Qt::ItemFlags flags(const QModelIndex &index) const;
  109. QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  110. QModelIndex parent(const QModelIndex &child) const;
  111. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  112. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  113. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  114. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  115. bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
  116. private:
  117. QWebView & m_view;
  118. FbHeadItem * m_root;
  119. };
  120. class FbHeadView : public QTreeView
  121. {
  122. Q_OBJECT
  123. public:
  124. explicit FbHeadView(FbTextEdit *view, QWidget *parent = 0);
  125. void initToolbar(QToolBar &toolbar);
  126. FbHeadModel * model() const;
  127. signals:
  128. void status(const QString &text);
  129. public slots:
  130. void editCurrent(const QModelIndex &index);
  131. void updateTree();
  132. private slots:
  133. void activated(const QModelIndex &index);
  134. void collapsed(const QModelIndex &index);
  135. void appendNode();
  136. void removeNode();
  137. protected:
  138. void currentChanged(const QModelIndex &current, const QModelIndex &previous);
  139. private:
  140. void showStatus(const QModelIndex &current);
  141. private:
  142. FbTextEdit & m_view;
  143. QAction * actionInsert;
  144. QAction * actionModify;
  145. QAction * actionDelete;
  146. };
  147. class FbNodeDlg : public QDialog
  148. {
  149. Q_OBJECT
  150. public:
  151. explicit FbNodeDlg(QWidget *parent, const FbScheme &scheme, const QStringList &list);
  152. QString value() const;
  153. private slots:
  154. void comboChanged(const QString &text);
  155. private:
  156. const FbScheme &m_scheme;
  157. QComboBox * m_combo;
  158. QLabel * m_text;
  159. };
  160. class FbNodeEditDlg : public QDialog
  161. {
  162. Q_OBJECT
  163. public:
  164. explicit FbNodeEditDlg(QWidget *parent, const FbScheme &scheme, const QWebElement &element);
  165. private:
  166. const FbScheme &m_scheme;
  167. QWebElement m_element;
  168. };
  169. class FbAuthorDlg : public QDialog
  170. {
  171. Q_OBJECT
  172. public:
  173. explicit FbAuthorDlg(QWidget *parent);
  174. private:
  175. void add(QFormLayout *layout, const QString &key, const QString &text);
  176. private:
  177. QMap<QString, QLineEdit*> m_fields;
  178. };
  179. #endif // FB2HEAD_H