fb2page.hpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. QAction * act(Fb::Actions index) const;
  30. void setAction(Fb::Actions index, QAction *action);
  31. void connectActions();
  32. void disconnectActions();
  33. FbTextElement body();
  34. FbTextElement doc();
  35. FbTextElement appendSection(const FbTextElement &parent);
  36. FbTextElement appendTitle(const FbTextElement &parent);
  37. public slots:
  38. void html(const QString &html, const QUrl &url);
  39. void insertBody();
  40. void insertTitle();
  41. void insertAnnot();
  42. void insertAuthor();
  43. void insertEpigraph();
  44. void insertSubtitle();
  45. void insertSection();
  46. void insertPoem();
  47. void insertStanza();
  48. void insertDate();
  49. void insertText();
  50. void createSection();
  51. void deleteSection();
  52. void createTitle();
  53. protected:
  54. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  55. void createBlock(const QString &name);
  56. protected:
  57. static QString block(const QString &name);
  58. static QString block(const QString &name, const QString &text);
  59. static QString p(const QString &text = "<br/>");
  60. void update();
  61. private slots:
  62. void onTimer();
  63. void binary(const QString &name, const QByteArray &data);
  64. void loadFinished();
  65. void fixContents();
  66. private:
  67. FbActionMap m_actions;
  68. FbTextLogger m_logger;
  69. QString m_html;
  70. };
  71. #endif // FB2PAGE_HPP