fb2text.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef FB2TEXT_H
  2. #define FB2TEXT_H
  3. #include <QFrame>
  4. #include <QResizeEvent>
  5. #include <QTimer>
  6. #include <QThread>
  7. #include <QWebElement>
  8. #include <QWebView>
  9. #include "fb2temp.hpp"
  10. QT_BEGIN_NAMESPACE
  11. class QDockWidget;
  12. class QToolBar;
  13. class QUndoCommand;
  14. class QWebInspector;
  15. QT_END_NAMESPACE
  16. class FbNoteView;
  17. class FbTextElement;
  18. class FbTextBase : public QWebView
  19. {
  20. Q_OBJECT
  21. public:
  22. FbTextBase(QWidget* parent = 0)
  23. : QWebView(parent)
  24. {
  25. m_timer.setInterval(100);
  26. m_timer.setSingleShot(true);
  27. connect(&m_timer, SIGNAL(timeout()), SLOT(doResize()));
  28. }
  29. void addTools(QToolBar *tool);
  30. protected slots:
  31. void doResize() {
  32. QResizeEvent event(size(), m_size);
  33. QWebView::resizeEvent(&event);
  34. QWebView::update();
  35. }
  36. protected:
  37. void resizeEvent(QResizeEvent* event) {
  38. if (!m_timer.isActive()) m_size = event->oldSize();
  39. m_timer.start();
  40. }
  41. private:
  42. QTimer m_timer;
  43. QSize m_size;
  44. };
  45. class FbTextPage : public QWebPage
  46. {
  47. Q_OBJECT
  48. public:
  49. explicit FbTextPage(QObject *parent = 0);
  50. void push(QUndoCommand * command, const QString &text = QString());
  51. FbTextElement element(const QString &location);
  52. FbTextElement current();
  53. QString location();
  54. QString status();
  55. FbTextElement body();
  56. FbTextElement doc();
  57. void appendSection(const FbTextElement &parent);
  58. public slots:
  59. void insertBody();
  60. void insertTitle();
  61. void insertAnnot();
  62. void insertAuthor();
  63. void insertEpigraph();
  64. void insertSubtitle();
  65. void insertSection();
  66. void insertPoem();
  67. void insertStanza();
  68. void insertDate();
  69. protected:
  70. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  71. protected:
  72. static QString div(const QString &style, const QString &text);
  73. static QString p(const QString &text = "<br/>");
  74. void update();
  75. };
  76. class FbTextEdit : public FbTextBase
  77. {
  78. Q_OBJECT
  79. public:
  80. explicit FbTextEdit(QWidget *parent = 0);
  81. virtual ~FbTextEdit();
  82. FbTextPage * page();
  83. FbTemporaryList & files() { return m_files; }
  84. void load(const QString &filename, const QString &xml = QString());
  85. bool save(QIODevice *device, const QString &codec = QString());
  86. bool save(QByteArray *array);
  87. bool save(QString *string);
  88. bool UndoEnabled();
  89. bool RedoEnabled();
  90. bool CutEnabled();
  91. bool CopyEnabled();
  92. bool BoldChecked();
  93. bool ItalicChecked();
  94. bool StrikeChecked();
  95. bool SubChecked();
  96. bool SupChecked();
  97. protected:
  98. virtual void mouseMoveEvent(QMouseEvent *event);
  99. public slots:
  100. void data(QString name, QByteArray data);
  101. void html(QString html);
  102. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  103. void insertImage();
  104. void insertNote();
  105. void insertLink();
  106. void zoomIn();
  107. void zoomOut();
  108. void zoomReset();
  109. void find();
  110. private slots:
  111. void fixContents();
  112. void loadFinished();
  113. private:
  114. void execCommand(const QString &cmd, const QString &arg);
  115. void exec(QUndoCommand *command);
  116. FbTemporaryFile * file(const QString &name);
  117. FbNoteView & noteView();
  118. QWebElement body();
  119. QWebElement doc();
  120. private:
  121. FbTemporaryList m_files;
  122. FbNoteView *m_noteView;
  123. QThread *m_thread;
  124. QPoint m_point;
  125. };
  126. class FbTextFrame : public QFrame
  127. {
  128. Q_OBJECT
  129. public:
  130. explicit FbTextFrame(QWidget* parent = 0);
  131. ~FbTextFrame();
  132. void hideInspector();
  133. FbTextEdit view;
  134. public slots:
  135. void showInspector();
  136. private:
  137. QDockWidget * dock;
  138. };
  139. #endif // FB2TEXT_H