fb2head.hpp 3.7 KB

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