fb2head.hpp 3.4 KB

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