fb2view.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 Fb2BaseWebView : public QWebView
  14. {
  15. Q_OBJECT
  16. public:
  17. Fb2BaseWebView(QWidget* parent = 0)
  18. : QWebView(parent)
  19. {
  20. m_timer.setInterval(100);
  21. m_timer.setSingleShot(true);
  22. connect(&m_timer, SIGNAL(timeout()), SLOT(doResize()));
  23. }
  24. protected slots:
  25. void doResize() {
  26. QResizeEvent event(size(), m_size);
  27. QWebView::resizeEvent(&event);
  28. QWebView::update();
  29. }
  30. protected:
  31. void resizeEvent(QResizeEvent* event) {
  32. if (!m_timer.isActive()) m_size = event->oldSize();
  33. m_timer.start();
  34. }
  35. private:
  36. QTimer m_timer;
  37. QSize m_size;
  38. };
  39. class Fb2WebPage : public QWebPage
  40. {
  41. Q_OBJECT
  42. public:
  43. explicit Fb2WebPage(QObject *parent = 0);
  44. QWebElement body();
  45. QWebElement doc();
  46. public slots:
  47. void insertBody();
  48. protected:
  49. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  50. };
  51. class Fb2WebView : public Fb2BaseWebView
  52. {
  53. Q_OBJECT
  54. public:
  55. explicit Fb2WebView(QWidget *parent = 0);
  56. virtual ~Fb2WebView();
  57. Fb2TemporaryList & files() { return m_files; }
  58. void load(const QString &filename, const QString &xml = QString());
  59. bool save(QIODevice *device, const QString &codec = QString());
  60. bool save(QByteArray *array);
  61. bool save(QString *string);
  62. QString status();
  63. bool UndoEnabled();
  64. bool RedoEnabled();
  65. bool CutEnabled();
  66. bool CopyEnabled();
  67. bool BoldChecked();
  68. bool ItalicChecked();
  69. bool StrikeChecked();
  70. bool SubChecked();
  71. bool SupChecked();
  72. protected:
  73. virtual void mouseMoveEvent(QMouseEvent *event);
  74. public slots:
  75. void data(QString name, QByteArray data);
  76. void html(QString name, QString html);
  77. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  78. void showInspector();
  79. void insertImage();
  80. void insertNote();
  81. void insertLink();
  82. void insertTitle();
  83. void zoomIn();
  84. void zoomOut();
  85. void zoomReset();
  86. void find();
  87. private slots:
  88. void fixContents();
  89. void loadFinished();
  90. private:
  91. void execCommand(const QString &cmd, const QString &arg);
  92. Fb2TemporaryFile * file(const QString &name);
  93. Fb2NoteView & noteView();
  94. QWebElement body();
  95. QWebElement doc();
  96. private:
  97. QWebInspector * m_inspector;
  98. Fb2TemporaryList m_files;
  99. Fb2NoteView *m_noteView;
  100. QThread *m_thread;
  101. QPoint m_point;
  102. };
  103. #endif // FB2VIEW_H