fb2head.hpp 5.5 KB

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