fb2page.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #ifndef FB2PAGE_HPP
  2. #define FB2PAGE_HPP
  3. #include <QAction>
  4. #include <QUndoCommand>
  5. #include <QWebPage>
  6. class FbTextElement;
  7. class FbNetworkAccessManager;
  8. #include "fb2mode.h"
  9. class FbTextLogger : public QObject
  10. {
  11. Q_OBJECT
  12. public:
  13. explicit FbTextLogger(QObject *parent = 0) : QObject(parent) {}
  14. public slots:
  15. void trace(const QString &text);
  16. };
  17. class FbTextPage : public QWebPage
  18. {
  19. Q_OBJECT
  20. public:
  21. explicit FbTextPage(QObject *parent = 0);
  22. FbNetworkAccessManager *temp();
  23. bool load(const QString &filename, const QString &xml = QString());
  24. void push(QUndoCommand * command, const QString &text = QString());
  25. FbTextElement element(const QString &location);
  26. FbTextElement current();
  27. QString location();
  28. QString status();
  29. FbTextElement body();
  30. FbTextElement doc();
  31. FbTextElement appendSection(const FbTextElement &parent);
  32. FbTextElement appendTitle(const FbTextElement &parent);
  33. public slots:
  34. void html(const QString &html, const QUrl &url);
  35. void insertBody();
  36. void insertTitle();
  37. void insertAnnot();
  38. void insertAuthor();
  39. void insertEpigraph();
  40. void insertSubtitle();
  41. void insertSection();
  42. void insertPoem();
  43. void insertStanza();
  44. void insertDate();
  45. void insertText();
  46. void createSection();
  47. void deleteSection();
  48. void createTitle();
  49. protected:
  50. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  51. void createBlock(const QString &name);
  52. protected:
  53. static QString block(const QString &name);
  54. static QString block(const QString &name, const QString &text);
  55. static QString p(const QString &text = "<br/>");
  56. void update();
  57. private slots:
  58. void onTimer();
  59. void binary(const QString &name, const QByteArray &data);
  60. void loadFinished();
  61. void fixContents();
  62. private:
  63. FbActionMap m_actions;
  64. FbTextLogger m_logger;
  65. QString m_html;
  66. };
  67. #endif // FB2PAGE_HPP