fb2view.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef FB2VIEW_H
  2. #define FB2VIEW_H
  3. #include <QHash>
  4. #include <QResizeEvent>
  5. #include <QTimer>
  6. #include <QThread>
  7. #include <QWebView>
  8. class Fb2BaseWebView : public QWebView
  9. {
  10. Q_OBJECT
  11. public:
  12. Fb2BaseWebView(QWidget* parent = 0)
  13. : QWebView(parent)
  14. {
  15. m_timer.setInterval(100);
  16. m_timer.setSingleShot(true);
  17. connect(&m_timer, SIGNAL(timeout()), SLOT(doResize()));
  18. }
  19. protected slots:
  20. void doResize() {
  21. QResizeEvent event(size(), m_size);
  22. QWebView::resizeEvent(&event);
  23. QWebView::update();
  24. }
  25. protected:
  26. void resizeEvent(QResizeEvent* event) {
  27. if (!m_timer.isActive()) m_size = event->oldSize();
  28. m_timer.start();
  29. }
  30. private:
  31. QTimer m_timer;
  32. QSize m_size;
  33. };
  34. class Fb2WebView : public Fb2BaseWebView
  35. {
  36. Q_OBJECT
  37. public:
  38. explicit Fb2WebView(QWidget *parent = 0);
  39. virtual ~Fb2WebView();
  40. bool load(const QString &filename);
  41. bool UndoEnabled();
  42. bool RedoEnabled();
  43. bool CutEnabled();
  44. bool CopyEnabled();
  45. bool BoldChecked();
  46. bool ItalicChecked();
  47. bool StrikeChecked();
  48. bool SubChecked();
  49. bool SupChecked();
  50. signals:
  51. public slots:
  52. void file(QString name, QString path);
  53. void html(QString name, QString html);
  54. /*
  55. void Undo();
  56. void Redo();
  57. void Cut();
  58. void Copy();
  59. void Paste();
  60. void Bold();
  61. void Italic();
  62. void Strike();
  63. */
  64. void zoomIn();
  65. void zoomOut();
  66. void zoomOrig();
  67. private slots:
  68. void fixContents();
  69. private:
  70. typedef QHash<QString, QString> StringHash;
  71. StringHash m_files;
  72. QThread *m_thread;
  73. };
  74. #endif // FB2VIEW_H