fb2view.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. protected:
  45. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  46. };
  47. class Fb2WebView : public Fb2BaseWebView
  48. {
  49. Q_OBJECT
  50. public:
  51. explicit Fb2WebView(QWidget *parent = 0);
  52. virtual ~Fb2WebView();
  53. Fb2TemporaryList & files() { return m_files; }
  54. void load(const QString &filename, const QString &xml = QString());
  55. bool save(QIODevice *device, const QString &codec = QString());
  56. bool save(QByteArray *array);
  57. bool save(QString *string);
  58. QString toBodyXml();
  59. QString status();
  60. bool UndoEnabled();
  61. bool RedoEnabled();
  62. bool CutEnabled();
  63. bool CopyEnabled();
  64. bool BoldChecked();
  65. bool ItalicChecked();
  66. bool StrikeChecked();
  67. bool SubChecked();
  68. bool SupChecked();
  69. protected:
  70. virtual void mouseMoveEvent(QMouseEvent *event);
  71. public slots:
  72. void data(QString name, QByteArray data);
  73. void html(QString name, QString html);
  74. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  75. void showInspector();
  76. void insertImage();
  77. void insertNote();
  78. void insertLink();
  79. void zoomIn();
  80. void zoomOut();
  81. void zoomReset();
  82. void find();
  83. private slots:
  84. void fixContents();
  85. private:
  86. void execCommand(const QString &cmd, const QString &arg);
  87. Fb2TemporaryFile * file(const QString &name);
  88. Fb2NoteView & noteView();
  89. QWebElement doc();
  90. private:
  91. QWebInspector * m_inspector;
  92. Fb2TemporaryList m_files;
  93. Fb2NoteView *m_noteView;
  94. QThread *m_thread;
  95. QPoint m_point;
  96. };
  97. #endif // FB2VIEW_H