fb2view.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef FB2VIEW_H
  2. #define FB2VIEW_H
  3. #include <QByteArray>
  4. #include <QHash>
  5. #include <QResizeEvent>
  6. #include <QTemporaryFile>
  7. #include <QTimer>
  8. #include <QThread>
  9. #include <QWebElement>
  10. #include <QWebView>
  11. class Fb2BaseWebView : public QWebView
  12. {
  13. Q_OBJECT
  14. public:
  15. Fb2BaseWebView(QWidget* parent = 0)
  16. : QWebView(parent)
  17. {
  18. m_timer.setInterval(100);
  19. m_timer.setSingleShot(true);
  20. connect(&m_timer, SIGNAL(timeout()), SLOT(doResize()));
  21. }
  22. protected slots:
  23. void doResize() {
  24. QResizeEvent event(size(), m_size);
  25. QWebView::resizeEvent(&event);
  26. QWebView::update();
  27. }
  28. protected:
  29. void resizeEvent(QResizeEvent* event) {
  30. if (!m_timer.isActive()) m_size = event->oldSize();
  31. m_timer.start();
  32. }
  33. private:
  34. QTimer m_timer;
  35. QSize m_size;
  36. };
  37. class Fb2WebPage : public QWebPage
  38. {
  39. Q_OBJECT
  40. public:
  41. explicit Fb2WebPage(QObject *parent = 0);
  42. protected:
  43. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  44. };
  45. class Fb2WebView : public Fb2BaseWebView
  46. {
  47. Q_OBJECT
  48. public:
  49. explicit Fb2WebView(QWidget *parent = 0);
  50. virtual ~Fb2WebView();
  51. void load(const QString &filename);
  52. bool save(const QString &filename);
  53. QString toBodyXml();
  54. QString toXml();
  55. bool UndoEnabled();
  56. bool RedoEnabled();
  57. bool CutEnabled();
  58. bool CopyEnabled();
  59. bool BoldChecked();
  60. bool ItalicChecked();
  61. bool StrikeChecked();
  62. bool SubChecked();
  63. bool SupChecked();
  64. signals:
  65. public slots:
  66. QString temp(QString name);
  67. void data(QString name, QByteArray data);
  68. void html(QString name, QString html);
  69. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  70. void zoomIn();
  71. void zoomOut();
  72. void zoomOrig();
  73. private slots:
  74. void fixContents();
  75. private:
  76. QTemporaryFile * file(const QString &name);
  77. QWebElement doc();
  78. private:
  79. typedef QHash<QString, QTemporaryFile*> TemporaryHash;
  80. TemporaryHash m_files;
  81. QThread *m_thread;
  82. };
  83. #endif // FB2VIEW_H