fb2text.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #ifndef FB2TEXT_H
  2. #define FB2TEXT_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. void update();
  48. Fb2TextElement element(const QString &location);
  49. Fb2TextElement current();
  50. QString location();
  51. QString status();
  52. Fb2TextElement body();
  53. Fb2TextElement doc();
  54. public slots:
  55. void insertBody();
  56. void insertTitle();
  57. void insertSubtitle();
  58. protected:
  59. virtual bool acceptNavigationRequest(QWebFrame *frame, const QNetworkRequest &request, NavigationType type);
  60. };
  61. class Fb2TextEdit : public Fb2TextBase
  62. {
  63. Q_OBJECT
  64. public:
  65. explicit Fb2TextEdit(QWidget *parent = 0);
  66. virtual ~Fb2TextEdit();
  67. Fb2TextPage * page();
  68. Fb2TemporaryList & files() { return m_files; }
  69. void load(const QString &filename, const QString &xml = QString());
  70. bool save(QIODevice *device, const QString &codec = QString());
  71. bool save(QByteArray *array);
  72. bool save(QString *string);
  73. bool UndoEnabled();
  74. bool RedoEnabled();
  75. bool CutEnabled();
  76. bool CopyEnabled();
  77. bool BoldChecked();
  78. bool ItalicChecked();
  79. bool StrikeChecked();
  80. bool SubChecked();
  81. bool SupChecked();
  82. protected:
  83. virtual void mouseMoveEvent(QMouseEvent *event);
  84. public slots:
  85. void data(QString name, QByteArray data);
  86. void html(QString name, QString html);
  87. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  88. void insertImage();
  89. void insertNote();
  90. void insertLink();
  91. void zoomIn();
  92. void zoomOut();
  93. void zoomReset();
  94. void find();
  95. private slots:
  96. void fixContents();
  97. void loadFinished();
  98. private:
  99. void execCommand(const QString &cmd, const QString &arg);
  100. Fb2TemporaryFile * file(const QString &name);
  101. Fb2NoteView & noteView();
  102. QWebElement body();
  103. QWebElement doc();
  104. private:
  105. Fb2TemporaryList m_files;
  106. Fb2NoteView *m_noteView;
  107. QThread *m_thread;
  108. QPoint m_point;
  109. };
  110. class Fb2TextFrame : public QFrame
  111. {
  112. Q_OBJECT
  113. public:
  114. explicit Fb2TextFrame(QWidget* parent = 0);
  115. ~Fb2TextFrame();
  116. void hideInspector();
  117. Fb2TextEdit view;
  118. public slots:
  119. void showInspector();
  120. private:
  121. QDockWidget * dock;
  122. };
  123. #endif // FB2TEXT_H