fb2view.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. QWebElement current();
  65. QString location();
  66. QString status();
  67. bool UndoEnabled();
  68. bool RedoEnabled();
  69. bool CutEnabled();
  70. bool CopyEnabled();
  71. bool BoldChecked();
  72. bool ItalicChecked();
  73. bool StrikeChecked();
  74. bool SubChecked();
  75. bool SupChecked();
  76. protected:
  77. virtual void mouseMoveEvent(QMouseEvent *event);
  78. public slots:
  79. void data(QString name, QByteArray data);
  80. void html(QString name, QString html);
  81. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  82. void insertImage();
  83. void insertNote();
  84. void insertLink();
  85. void insertTitle();
  86. void insertSubtitle();
  87. void zoomIn();
  88. void zoomOut();
  89. void zoomReset();
  90. void find();
  91. private slots:
  92. void fixContents();
  93. void loadFinished();
  94. private:
  95. void execCommand(const QString &cmd, const QString &arg);
  96. Fb2TemporaryFile * file(const QString &name);
  97. Fb2NoteView & noteView();
  98. QWebElement body();
  99. QWebElement doc();
  100. private:
  101. Fb2TemporaryList m_files;
  102. Fb2NoteView *m_noteView;
  103. QThread *m_thread;
  104. QPoint m_point;
  105. };
  106. class Fb2TextFrame : public QFrame
  107. {
  108. Q_OBJECT
  109. public:
  110. explicit Fb2TextFrame(QWidget* parent = 0);
  111. ~Fb2TextFrame();
  112. void hideInspector();
  113. Fb2WebView view;
  114. public slots:
  115. void showInspector();
  116. private:
  117. QDockWidget * dock;
  118. };
  119. #endif // FB2VIEW_H