fb2view.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. 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 insertImage();
  71. void zoomIn();
  72. void zoomOut();
  73. void zoomOrig();
  74. private slots:
  75. void fixContents();
  76. private:
  77. void execCommand(const QString &cmd, const QString &arg);
  78. Fb2TemporaryFile * file(const QString &name);
  79. QWebElement doc();
  80. private:
  81. Fb2TemporaryList m_files;
  82. QThread *m_thread;
  83. };
  84. #endif // FB2VIEW_H