fb2view.hpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. #ifndef FB2VIEW_H
  2. #define FB2VIEW_H
  3. #include <QResizeEvent>
  4. #include <QTimer>
  5. #include <QThread>
  6. #include <QWebElement>
  7. #include <QWebView>
  8. #include "fb2temp.hpp"
  9. QT_BEGIN_NAMESPACE
  10. class QWebInspector;
  11. QT_END_NAMESPACE
  12. class Fb2NoteView;
  13. class Fb2HtmlHandler : public QObject
  14. {
  15. Q_OBJECT
  16. public:
  17. Fb2HtmlHandler() {}
  18. public slots:
  19. void onNew(const QString &name);
  20. void onTxt(const QString &text);
  21. void onEnd(const QString &name);
  22. void attr(const QString &name, const QString &value);
  23. };
  24. class Fb2BaseWebView : public QWebView
  25. {
  26. Q_OBJECT
  27. public:
  28. Fb2BaseWebView(QWidget* parent = 0)
  29. : QWebView(parent)
  30. {
  31. m_timer.setInterval(100);
  32. m_timer.setSingleShot(true);
  33. connect(&m_timer, SIGNAL(timeout()), SLOT(doResize()));
  34. }
  35. protected slots:
  36. void doResize() {
  37. QResizeEvent event(size(), m_size);
  38. QWebView::resizeEvent(&event);
  39. QWebView::update();
  40. }
  41. protected:
  42. void resizeEvent(QResizeEvent* event) {
  43. if (!m_timer.isActive()) m_size = event->oldSize();
  44. m_timer.start();
  45. }
  46. private:
  47. QTimer m_timer;
  48. QSize m_size;
  49. };
  50. class Fb2WebPage : public QWebPage
  51. {
  52. Q_OBJECT
  53. public:
  54. explicit Fb2WebPage(QObject *parent = 0);
  55. protected:
  56. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  57. };
  58. class Fb2WebView : public Fb2BaseWebView
  59. {
  60. Q_OBJECT
  61. public:
  62. explicit Fb2WebView(QWidget *parent = 0);
  63. virtual ~Fb2WebView();
  64. const Fb2TemporaryList & files() const { return m_files; }
  65. void load(const QString &filename, const QString &xml = QString());
  66. bool save(QByteArray *array, QList<int> *folds = 0);
  67. bool save(QIODevice *device);
  68. bool save(QString *string);
  69. QString toBodyXml();
  70. QString status();
  71. bool UndoEnabled();
  72. bool RedoEnabled();
  73. bool CutEnabled();
  74. bool CopyEnabled();
  75. bool BoldChecked();
  76. bool ItalicChecked();
  77. bool StrikeChecked();
  78. bool SubChecked();
  79. bool SupChecked();
  80. protected:
  81. virtual void mouseMoveEvent(QMouseEvent *event);
  82. signals:
  83. public slots:
  84. QString temp(QString name);
  85. void data(QString name, QByteArray data);
  86. void html(QString name, QString html);
  87. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  88. void showInspector();
  89. void insertImage();
  90. void insertNote();
  91. void insertLink();
  92. void zoomIn();
  93. void zoomOut();
  94. void zoomOrig();
  95. private slots:
  96. void fixContents();
  97. private:
  98. void execCommand(const QString &cmd, const QString &arg);
  99. Fb2TemporaryFile * file(const QString &name);
  100. Fb2NoteView & noteView();
  101. QWebElement doc();
  102. private:
  103. Fb2HtmlHandler handler;
  104. QWebInspector * m_inspector;
  105. Fb2TemporaryList m_files;
  106. Fb2NoteView *m_noteView;
  107. QThread *m_thread;
  108. QPoint m_point;
  109. };
  110. #endif // FB2VIEW_H