fb2head.hpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. QString info() const;
  40. QString type() const;
  41. private:
  42. FbScheme typeScheme() const;
  43. FbScheme item(const QString &name) const;
  44. };
  45. class FbHeadItem: public QObject
  46. {
  47. Q_OBJECT
  48. FB2_BEGIN_KEYLIST
  49. Auth,
  50. Cover,
  51. Image,
  52. Seqn,
  53. FB2_END_KEYLIST
  54. public:
  55. explicit FbHeadItem(QWebElement &element, FbHeadItem *parent = 0);
  56. virtual ~FbHeadItem();
  57. FbHeadItem * append(const QString name);
  58. void remove(int row);
  59. FbHeadItem * item(const QModelIndex &index) const;
  60. FbHeadItem * item(int row) const;
  61. int index(FbHeadItem * child) const {
  62. return m_list.indexOf(child);
  63. }
  64. int count() const {
  65. return m_list.size();
  66. }
  67. FbHeadItem * parent() const {
  68. return m_parent;
  69. }
  70. QWebElement element() const {
  71. return m_element;
  72. }
  73. QString text(int col = 0) const;
  74. void setText(const QString &text);
  75. const QString & id() const {
  76. return m_id;
  77. }
  78. const QString & name() const {
  79. return m_name;
  80. }
  81. QString sub(const QString &key) const;
  82. FbScheme scheme() const;
  83. private:
  84. class HintHash : public QHash<QString, QString>
  85. {
  86. public:
  87. explicit HintHash();
  88. };
  89. private:
  90. void addChildren(QWebElement &parent);
  91. QString value() const;
  92. QString hint() const;
  93. private:
  94. QList<FbHeadItem*> m_list;
  95. QWebElement m_element;
  96. FbHeadItem * m_parent;
  97. QString m_name;
  98. QString m_text;
  99. QString m_id;
  100. };
  101. class FbHeadModel: public QAbstractItemModel
  102. {
  103. Q_OBJECT
  104. public:
  105. explicit FbHeadModel(QWebView &view, QObject *parent = 0);
  106. virtual ~FbHeadModel();
  107. void expand(QTreeView *view);
  108. FbHeadItem * item(const QModelIndex &index) const;
  109. QModelIndex append(const QModelIndex &parent, const QString &name);
  110. void remove(const QModelIndex &index);
  111. public:
  112. Qt::ItemFlags flags(const QModelIndex &index) const;
  113. QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  114. QModelIndex parent(const QModelIndex &child) const;
  115. int rowCount(const QModelIndex &parent = QModelIndex()) const;
  116. int columnCount(const QModelIndex &parent = QModelIndex()) const;
  117. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  118. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  119. bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
  120. private:
  121. QWebView & m_view;
  122. FbHeadItem * m_root;
  123. };
  124. class FbHeadView : public QTreeView
  125. {
  126. Q_OBJECT
  127. public:
  128. explicit FbHeadView(FbTextEdit *view, QWidget *parent = 0);
  129. void initToolbar(QToolBar &toolbar);
  130. signals:
  131. void status(const QString &text);
  132. public slots:
  133. void editCurrent(const QModelIndex &index);
  134. void updateTree();
  135. private slots:
  136. void activated(const QModelIndex &index);
  137. void collapsed(const QModelIndex &index);
  138. void appendNode();
  139. void removeNode();
  140. protected:
  141. void currentChanged(const QModelIndex &current, const QModelIndex &previous);
  142. private:
  143. void showStatus(const QModelIndex &current);
  144. private:
  145. FbTextEdit & m_view;
  146. QAction * actionInsert;
  147. QAction * actionModify;
  148. QAction * actionDelete;
  149. };
  150. class FbNodeDlg : public QDialog
  151. {
  152. Q_OBJECT
  153. public:
  154. explicit FbNodeDlg(QWidget *parent, const FbScheme &scheme, const QStringList &list);
  155. QString value() const;
  156. private slots:
  157. void comboChanged(const QString &text);
  158. private:
  159. const FbScheme &m_scheme;
  160. QComboBox * m_combo;
  161. QLabel * m_text;
  162. };
  163. class FbNodeEditDlg : public QDialog
  164. {
  165. Q_OBJECT
  166. public:
  167. explicit FbNodeEditDlg(QWidget *parent, const FbScheme &scheme, const QWebElement &element);
  168. private:
  169. const FbScheme &m_scheme;
  170. QWebElement m_element;
  171. };
  172. class FbAuthorDlg : public QDialog
  173. {
  174. Q_OBJECT
  175. public:
  176. explicit FbAuthorDlg(QWidget *parent);
  177. private:
  178. void add(QFormLayout *layout, const QString &key, const QString &text);
  179. private:
  180. QMap<QString, QLineEdit*> m_fields;
  181. };
  182. #endif // FB2HEAD_H