fb2view.hpp 2.4 KB

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