fb2view.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef FB2VIEW_H
  2. #define FB2VIEW_H
  3. #include <QHash>
  4. #include <QResizeEvent>
  5. #include <QTimer>
  6. #include <QThread>
  7. #include <QWebElement>
  8. #include <QWebView>
  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. void load(const QString &filename);
  50. QString toBodyXml();
  51. QString toXml();
  52. bool UndoEnabled();
  53. bool RedoEnabled();
  54. bool CutEnabled();
  55. bool CopyEnabled();
  56. bool BoldChecked();
  57. bool ItalicChecked();
  58. bool StrikeChecked();
  59. bool SubChecked();
  60. bool SupChecked();
  61. signals:
  62. public slots:
  63. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  64. void file(QString name, QString path);
  65. void html(QString name, QString html);
  66. void zoomIn();
  67. void zoomOut();
  68. void zoomOrig();
  69. private slots:
  70. void fixContents();
  71. private:
  72. QWebElement doc();
  73. private:
  74. typedef QHash<QString, QString> StringHash;
  75. StringHash m_files;
  76. QThread *m_thread;
  77. };
  78. #endif // FB2VIEW_H