fb2text.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. #ifndef FB2TEXT_H
  2. #define FB2TEXT_H
  3. #include <QAction>
  4. #include <QDockWidget>
  5. #include <QFrame>
  6. #include <QMainWindow>
  7. #include <QResizeEvent>
  8. #include <QTimer>
  9. #include <QThread>
  10. #include <QWebElement>
  11. #include <QWebView>
  12. #include "fb2enum.h"
  13. #include "fb2temp.hpp"
  14. QT_BEGIN_NAMESPACE
  15. class QToolBar;
  16. class QWebInspector;
  17. QT_END_NAMESPACE
  18. class FbNoteView;
  19. class FbReadThread;
  20. class FbTextPage;
  21. class FbDockWidget : public QDockWidget
  22. {
  23. Q_OBJECT
  24. public:
  25. explicit FbDockWidget(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0);
  26. };
  27. class FbTextBase : public QWebView
  28. {
  29. Q_OBJECT
  30. public:
  31. FbTextBase(QWidget *parent = 0)
  32. : QWebView(parent)
  33. {
  34. m_timer.setInterval(100);
  35. m_timer.setSingleShot(true);
  36. connect(&m_timer, SIGNAL(timeout()), SLOT(doResize()));
  37. }
  38. void addTools(QToolBar *tool);
  39. protected slots:
  40. void doResize() {
  41. QResizeEvent event(size(), m_size);
  42. QWebView::resizeEvent(&event);
  43. QWebView::update();
  44. }
  45. protected:
  46. void resizeEvent(QResizeEvent* event) {
  47. if (!m_timer.isActive()) m_size = event->oldSize();
  48. m_timer.start();
  49. }
  50. void keyPressEvent(QKeyEvent *event) {
  51. if (event->key() == Qt::Key_Escape) return;
  52. QWebView::keyPressEvent(event);
  53. }
  54. private:
  55. QTimer m_timer;
  56. QSize m_size;
  57. };
  58. class FbTextEdit : public FbTextBase
  59. {
  60. Q_OBJECT
  61. public:
  62. explicit FbTextEdit(QWidget *parent, QObject *owner);
  63. virtual ~FbTextEdit();
  64. FbTextPage *page();
  65. FbNetworkAccessManager *files();
  66. bool save(QIODevice *device, const QString &codec = QString());
  67. bool save(QByteArray *array);
  68. bool save(QString *string);
  69. QAction * act(Fb::Actions index) const;
  70. void setAction(Fb::Actions index, QAction *action);
  71. void connectActions(QToolBar *tool);
  72. void disconnectActions();
  73. bool BoldChecked();
  74. bool ItalicChecked();
  75. bool StrikeChecked();
  76. bool SubChecked();
  77. bool SupChecked();
  78. protected:
  79. virtual void mouseMoveEvent(QMouseEvent *event);
  80. public slots:
  81. void html(QString html);
  82. void data(QString name, QByteArray data);
  83. void insertImage();
  84. void insertNote();
  85. void insertLink();
  86. void zoomIn();
  87. void zoomOut();
  88. void zoomReset();
  89. void find();
  90. private slots:
  91. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  92. void contextMenu(const QPoint &pos);
  93. void createImgs();
  94. void createTree();
  95. void treeDestroyed();
  96. void imgsDestroyed();
  97. private:
  98. void viewTree();
  99. void viewImgs();
  100. void viewInsp();
  101. bool actionEnabled(QWebPage::WebAction action);
  102. bool actionChecked(QWebPage::WebAction action);
  103. void execCommand(const QString &cmd, const QString &arg);
  104. FbTemporaryFile * file(const QString &name);
  105. FbNoteView & noteView();
  106. QWebElement body();
  107. QWebElement doc();
  108. private:
  109. QMainWindow *m_owner;
  110. FbNoteView *m_noteView;
  111. FbReadThread *m_thread;
  112. QMap<Fb::Actions, QAction*> m_actions;
  113. QDockWidget *dockTree;
  114. QDockWidget *dockImgs;
  115. QPoint m_point;
  116. };
  117. class FbWebFrame : public QFrame
  118. {
  119. Q_OBJECT
  120. public:
  121. explicit FbWebFrame(QWidget *parent = 0);
  122. };
  123. class FbTextFrame : public QFrame
  124. {
  125. Q_OBJECT
  126. public:
  127. explicit FbTextFrame(QWidget *parent, QAction *action);
  128. ~FbTextFrame();
  129. public:
  130. FbTextEdit * view() { return &m_view; }
  131. public slots:
  132. void showInspector();
  133. void hideInspector();
  134. private slots:
  135. void dockDestroyed();
  136. private:
  137. FbTextEdit m_view;
  138. QDockWidget *m_dock;
  139. };
  140. class FbTextAction : public QAction
  141. {
  142. Q_OBJECT
  143. public:
  144. explicit FbTextAction(const QString &text, QWebPage::WebAction action, QObject* parent);
  145. explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, QObject* parent);
  146. public slots:
  147. void updateChecked();
  148. void updateEnabled();
  149. private:
  150. QAction * action(QWebPage::WebAction action);
  151. private:
  152. QWebPage::WebAction m_action;
  153. };
  154. #endif // FB2TEXT_H