fb2page.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 read(const QString &html);
  24. bool read(QIODevice &device);
  25. void push(QUndoCommand * command, const QString &text = QString());
  26. FbTextElement element(const QString &location);
  27. FbTextElement current();
  28. QString location();
  29. QString status();
  30. FbTextElement body();
  31. FbTextElement doc();
  32. FbTextElement appendSection(const FbTextElement &parent);
  33. FbTextElement appendTitle(const FbTextElement &parent);
  34. FbTextElement appendText(const FbTextElement &parent);
  35. static QUrl createUrl();
  36. public slots:
  37. void html(QObject *temp, const QString &html);
  38. void insertBody();
  39. void insertTitle();
  40. void insertAnnot();
  41. void insertAuthor();
  42. void insertEpigraph();
  43. void insertSubtitle();
  44. void insertSection();
  45. void insertPoem();
  46. void insertStanza();
  47. void insertDate();
  48. void insertText();
  49. void createSection();
  50. void deleteSection();
  51. void createTitle();
  52. protected:
  53. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  54. void createBlock(const QString &name);
  55. protected:
  56. static QString block(const QString &name);
  57. static QString block(const QString &name, const QString &text);
  58. static QString p(const QString &text = "<br/>");
  59. void update();
  60. private slots:
  61. void loadFinished();
  62. void fixContents();
  63. private:
  64. FbActionMap m_actions;
  65. FbTextLogger m_logger;
  66. QString m_html;
  67. };
  68. #endif // FB2PAGE_HPP