fb2head.hpp 4.4 KB

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