fb2view.hpp 2.9 KB

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