fb2head.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #ifndef FB2HEAD_H
  2. #define FB2HEAD_H
  3. #include <QAbstractItemModel>
  4. #include <QTreeView>
  5. #include <QWebElement>
  6. #include <QWebView>
  7. #include "fb2xml.h"
  8. class Fb2WebView;
  9. class Fb2HeadItem: public QObject
  10. {
  11. Q_OBJECT
  12. FB2_BEGIN_KEYLIST
  13. Auth,
  14. Cover,
  15. Image,
  16. Seqn,
  17. FB2_END_KEYLIST
  18. public:
  19. explicit Fb2HeadItem(QWebElement &element, Fb2HeadItem *parent = 0);
  20. virtual ~Fb2HeadItem();
  21. Fb2HeadItem * item(const QModelIndex &index) const;
  22. Fb2HeadItem * item(int row) const;
  23. int index(Fb2HeadItem * child) const {
  24. return m_list.indexOf(child);
  25. }
  26. int count() const {
  27. return m_list.size();
  28. }
  29. Fb2HeadItem * parent() const {
  30. return m_parent;
  31. }
  32. QString text(int col = 0) const;
  33. void setText(const QString &text);
  34. const QString & id() const {
  35. return m_id;
  36. }
  37. const QString & name() const {
  38. return m_name;
  39. }
  40. QString sub(const QString &key) const;
  41. private:
  42. class HintHash : public QHash<QString, QString>
  43. {
  44. public:
  45. explicit HintHash();
  46. };
  47. private:
  48. void addChildren(QWebElement &parent);
  49. QString value() const;
  50. QString hint() const;
  51. private:
  52. QList<Fb2HeadItem*> m_list;
  53. QWebElement m_element;
  54. QString m_name;
  55. QString m_text;
  56. Fb2HeadItem * m_parent;
  57. QString m_id;
  58. };
  59. class Fb2HeadModel: public QAbstractItemModel
  60. {
  61. Q_OBJECT
  62. public:
  63. explicit Fb2HeadModel(QWebView &view, QObject *parent = 0);
  64. virtual ~Fb2HeadModel();
  65. void select(const QModelIndex &index);
  66. void expand(QTreeView *view);
  67. public:
  68. virtual Qt::ItemFlags flags(const QModelIndex &index) const;
  69. virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
  70. virtual QModelIndex parent(const QModelIndex &child) const;
  71. virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
  72. virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
  73. virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
  74. virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const;
  75. virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
  76. protected:
  77. Fb2HeadItem * item(const QModelIndex &index) const;
  78. private:
  79. QWebView & m_view;
  80. Fb2HeadItem * m_root;
  81. };
  82. class Fb2HeadView : public QTreeView
  83. {
  84. Q_OBJECT
  85. public:
  86. explicit Fb2HeadView(Fb2WebView &view, QWidget *parent = 0);
  87. public slots:
  88. void editCurrent();
  89. void updateTree();
  90. private slots:
  91. void activated(const QModelIndex &index);
  92. private:
  93. Fb2WebView & m_view;
  94. };
  95. #endif // FB2HEAD_H