fb2page.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #ifndef FB2PAGE_HPP
  2. #define FB2PAGE_HPP
  3. #include <QAction>
  4. #include <QUndoCommand>
  5. #include <QWebPage>
  6. class FbStore;
  7. class FbTextElement;
  8. class FbNetworkAccessManager;
  9. #include "fb2logs.hpp"
  10. #include "fb2mode.h"
  11. class FbTextLogger : public QObject
  12. {
  13. Q_OBJECT
  14. public:
  15. explicit FbTextLogger(QObject *parent = 0) : QObject(parent) {}
  16. public slots:
  17. void trace(const QString &text);
  18. };
  19. class FbTextPage : public QWebPage
  20. {
  21. Q_OBJECT
  22. public:
  23. explicit FbTextPage(QObject *parent = 0);
  24. FbNetworkAccessManager *manager();
  25. bool read(const QString &html);
  26. bool read(QIODevice *device);
  27. void push(QUndoCommand * command, const QString &text = QString());
  28. FbTextElement element(const QString &location);
  29. FbTextElement current();
  30. QString location();
  31. FbTextElement body();
  32. FbTextElement doc();
  33. FbTextElement appendSection(const FbTextElement &parent);
  34. FbTextElement appendTitle(const FbTextElement &parent);
  35. FbTextElement appendText(const FbTextElement &parent);
  36. static QUrl createUrl();
  37. signals:
  38. void status(const QString &text);
  39. void warning(int row, int col, const QString &msg);
  40. void error(int row, int col, const QString &msg);
  41. void fatal(int row, int col, const QString &msg);
  42. public slots:
  43. void html(const QString &html, FbStore *store);
  44. void insertBody();
  45. void insertTitle();
  46. void insertAnnot();
  47. void insertAuthor();
  48. void insertEpigraph();
  49. void insertSubtitle();
  50. void insertSection();
  51. void insertPoem();
  52. void insertStanza();
  53. void insertDate();
  54. void insertText();
  55. void createSection();
  56. void deleteSection();
  57. void createTitle();
  58. protected:
  59. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  60. void createBlock(const QString &name);
  61. protected:
  62. static QString block(const QString &name);
  63. static QString block(const QString &name, const QString &text);
  64. static QString p(const QString &text = "<br/>");
  65. void update();
  66. private slots:
  67. void loadFinished();
  68. void fixContents();
  69. void showStatus();
  70. private:
  71. QUrl getStyleSheetUrl();
  72. private:
  73. FbActionMap m_actions;
  74. FbTextLogger m_logger;
  75. QString m_html;
  76. };
  77. #endif // FB2PAGE_HPP