fb2view.hpp 2.5 KB

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