fb2head.hpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. };
  44. class FbHeadItem: public QObject
  45. {
  46. Q_OBJECT
  47. FB2_BEGIN_KEYLIST
  48. Auth,
  49. Cover,
  50. Image,
  51. Seqn,
  52. FB2_END_KEYLIST
  53. public:
  54. explicit FbHeadItem(QWebElement &element, FbHeadItem *parent = 0);
  55. virtual ~FbHeadItem();
  56. FbHeadItem * append(const QString name);
  57. void remove(int row);
  58. FbHeadItem * item(const QModelIndex &index) const;
  59. FbHeadItem * item(int row) const;
  60. int index(FbHeadItem * child) const {
  61. return m_list.indexOf(child);
  62. }
  63. int count() const {
  64. return m_list.size();
  65. }
  66. FbHeadItem * parent() const {
  67. return m_parent;
  68. }
  69. QString text(int col = 0) const;
  70. void setText(const QString &text);
  71. const QString & id() const {
  72. return m_id;
  73. }
  74. const QString & name() const {
  75. return m_name;
  76. }
  77. QString sub(const QString &key) const;
  78. FbScheme scheme() const;
  79. private:
  80. class HintHash : public QHash<QString, QString>
  81. {
  82. public:
  83. explicit HintHash();
  84. };
  85. private:
  86. void addChildren(QWebElement &parent);
  87. QString value() const;
  88. QString hint() const;
  89. private:
  90. QList<FbHeadItem*> m_list;
  91. QWebElement m_element;
  92. FbHeadItem * m_parent;
  93. QString m_name;
  94. QString m_text;
  95. QString m_id;
  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. signals:
  127. void status(const QString &text);
  128. public slots:
  129. void editCurrent();
  130. void updateTree();
  131. private slots:
  132. void activated(const QModelIndex &index);
  133. void collapsed(const QModelIndex &index);
  134. void appendNode();
  135. void removeNode();
  136. protected:
  137. void currentChanged(const QModelIndex &current, const QModelIndex &previous);
  138. private:
  139. void showStatus(const QModelIndex &current);
  140. private:
  141. FbTextEdit & m_view;
  142. QAction * actionInsert;
  143. QAction * actionModify;
  144. QAction * actionDelete;
  145. };
  146. class FbNodeDlg : public QDialog
  147. {
  148. Q_OBJECT
  149. public:
  150. explicit FbNodeDlg(QWidget *parent, FbScheme scheme, QStringList &list);
  151. QString value() const;
  152. private slots:
  153. void comboChanged(const QString &text);
  154. private:
  155. const FbScheme m_scheme;
  156. QComboBox * m_combo;
  157. QLabel * m_text;
  158. };
  159. class FbAuthorDlg : public QDialog
  160. {
  161. Q_OBJECT
  162. public:
  163. explicit FbAuthorDlg(QWidget *parent);
  164. private:
  165. void add(QFormLayout *layout, const QString &key, const QString &text);
  166. private:
  167. QMap<QString, QLineEdit*> m_fields;
  168. };
  169. #endif // FB2HEAD_H