fb2head.hpp 5.2 KB

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