fb2text.hpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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 insertSubtitle();
  62. void insertSection();
  63. protected:
  64. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  65. protected:
  66. static QString div(const QString &style, const QString &text);
  67. static QString p(const QString &text = "<br/>");
  68. void update();
  69. };
  70. class FbTextEdit : public FbTextBase
  71. {
  72. Q_OBJECT
  73. public:
  74. explicit FbTextEdit(QWidget *parent = 0);
  75. virtual ~FbTextEdit();
  76. FbTextPage * page();
  77. FbTemporaryList & files() { return m_files; }
  78. void load(const QString &filename, const QString &xml = QString());
  79. bool save(QIODevice *device, const QString &codec = QString());
  80. bool save(QByteArray *array);
  81. bool save(QString *string);
  82. bool UndoEnabled();
  83. bool RedoEnabled();
  84. bool CutEnabled();
  85. bool CopyEnabled();
  86. bool BoldChecked();
  87. bool ItalicChecked();
  88. bool StrikeChecked();
  89. bool SubChecked();
  90. bool SupChecked();
  91. protected:
  92. virtual void mouseMoveEvent(QMouseEvent *event);
  93. public slots:
  94. void data(QString name, QByteArray data);
  95. void html(QString html);
  96. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  97. void insertImage();
  98. void insertNote();
  99. void insertLink();
  100. void zoomIn();
  101. void zoomOut();
  102. void zoomReset();
  103. void find();
  104. private slots:
  105. void fixContents();
  106. void loadFinished();
  107. private:
  108. void execCommand(const QString &cmd, const QString &arg);
  109. void exec(QUndoCommand *command);
  110. FbTemporaryFile * file(const QString &name);
  111. FbNoteView & noteView();
  112. QWebElement body();
  113. QWebElement doc();
  114. private:
  115. FbTemporaryList m_files;
  116. FbNoteView *m_noteView;
  117. QThread *m_thread;
  118. QPoint m_point;
  119. };
  120. class FbTextFrame : public QFrame
  121. {
  122. Q_OBJECT
  123. public:
  124. explicit FbTextFrame(QWidget* parent = 0);
  125. ~FbTextFrame();
  126. void hideInspector();
  127. FbTextEdit view;
  128. public slots:
  129. void showInspector();
  130. private:
  131. QDockWidget * dock;
  132. };
  133. #endif // FB2TEXT_H