fb2view.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #ifndef FB2VIEW_H
  2. #define FB2VIEW_H
  3. #include <QFrame>
  4. #include <QResizeEvent>
  5. #include <QTimer>
  6. #include <QThread>
  7. #include <QWebElement>
  8. #include <QWebView>
  9. #include "fb2temp.hpp"
  10. QT_BEGIN_NAMESPACE
  11. class QWebInspector;
  12. class QDockWidget;
  13. QT_END_NAMESPACE
  14. class Fb2NoteView;
  15. class Fb2TextElement;
  16. class Fb2TextBase : public QWebView
  17. {
  18. Q_OBJECT
  19. public:
  20. Fb2TextBase(QWidget* parent = 0)
  21. : QWebView(parent)
  22. {
  23. m_timer.setInterval(100);
  24. m_timer.setSingleShot(true);
  25. connect(&m_timer, SIGNAL(timeout()), SLOT(doResize()));
  26. }
  27. protected slots:
  28. void doResize() {
  29. QResizeEvent event(size(), m_size);
  30. QWebView::resizeEvent(&event);
  31. QWebView::update();
  32. }
  33. protected:
  34. void resizeEvent(QResizeEvent* event) {
  35. if (!m_timer.isActive()) m_size = event->oldSize();
  36. m_timer.start();
  37. }
  38. private:
  39. QTimer m_timer;
  40. QSize m_size;
  41. };
  42. class Fb2TextPage : public QWebPage
  43. {
  44. Q_OBJECT
  45. public:
  46. explicit Fb2TextPage(QObject *parent = 0);
  47. Fb2TextElement element(const QString &location);
  48. Fb2TextElement current();
  49. QString location();
  50. QString status();
  51. Fb2TextElement body();
  52. Fb2TextElement doc();
  53. public slots:
  54. void insertBody();
  55. void insertSubtitle();
  56. protected:
  57. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  58. };
  59. class Fb2TextEdit : public Fb2TextBase
  60. {
  61. Q_OBJECT
  62. public:
  63. explicit Fb2TextEdit(QWidget *parent = 0);
  64. virtual ~Fb2TextEdit();
  65. Fb2TextPage * page();
  66. Fb2TemporaryList & files() { return m_files; }
  67. void load(const QString &filename, const QString &xml = QString());
  68. bool save(QIODevice *device, const QString &codec = QString());
  69. bool save(QByteArray *array);
  70. bool save(QString *string);
  71. bool UndoEnabled();
  72. bool RedoEnabled();
  73. bool CutEnabled();
  74. bool CopyEnabled();
  75. bool BoldChecked();
  76. bool ItalicChecked();
  77. bool StrikeChecked();
  78. bool SubChecked();
  79. bool SupChecked();
  80. protected:
  81. virtual void mouseMoveEvent(QMouseEvent *event);
  82. public slots:
  83. void data(QString name, QByteArray data);
  84. void html(QString name, QString html);
  85. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  86. void insertImage();
  87. void insertNote();
  88. void insertLink();
  89. void insertTitle();
  90. void zoomIn();
  91. void zoomOut();
  92. void zoomReset();
  93. void find();
  94. private slots:
  95. void fixContents();
  96. void loadFinished();
  97. private:
  98. void execCommand(const QString &cmd, const QString &arg);
  99. Fb2TemporaryFile * file(const QString &name);
  100. Fb2NoteView & noteView();
  101. QWebElement body();
  102. QWebElement doc();
  103. private:
  104. Fb2TemporaryList m_files;
  105. Fb2NoteView *m_noteView;
  106. QThread *m_thread;
  107. QPoint m_point;
  108. };
  109. class Fb2TextFrame : public QFrame
  110. {
  111. Q_OBJECT
  112. public:
  113. explicit Fb2TextFrame(QWidget* parent = 0);
  114. ~Fb2TextFrame();
  115. void hideInspector();
  116. Fb2TextEdit view;
  117. public slots:
  118. void showInspector();
  119. private:
  120. QDockWidget * dock;
  121. };
  122. #endif // FB2VIEW_H