fb2text.hpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 "fb2mode.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. QAction * pAct(QWebPage::WebAction index) const;
  71. void setAction(Fb::Actions index, QAction *action);
  72. void connectActions(QToolBar *tool);
  73. void disconnectActions();
  74. void hideDocks();
  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 html(QString html);
  84. void data(QString name, QByteArray data);
  85. void insertImage();
  86. void insertNote();
  87. void insertLink();
  88. void find();
  89. private slots:
  90. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  91. void contextMenu(const QPoint &pos);
  92. void treeDestroyed();
  93. void imgsDestroyed();
  94. void viewContents(bool show);
  95. void viewPictures(bool show);
  96. void viewInspector(bool show);
  97. void zoomIn();
  98. void zoomOut();
  99. void zoomReset();
  100. private:
  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. FbActionMap m_actions;
  113. QDockWidget *dockTree;
  114. QDockWidget *dockImgs;
  115. QDockWidget *dockInsp;
  116. QPoint m_point;
  117. };
  118. class FbTextFrame : public QFrame
  119. {
  120. Q_OBJECT
  121. public:
  122. explicit FbTextFrame(QWidget *parent = 0);
  123. };
  124. class FbTextAction : public QAction
  125. {
  126. Q_OBJECT
  127. public:
  128. explicit FbTextAction(const QString &text, QWebPage::WebAction action, FbTextEdit* parent);
  129. explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, FbTextEdit *parent);
  130. void connectAction();
  131. void disconnectAction();
  132. private slots:
  133. void updateAction();
  134. private:
  135. QAction * action(QWebPage::WebAction action);
  136. private:
  137. QWebPage::WebAction m_action;
  138. FbTextEdit *m_parent;
  139. };
  140. #endif // FB2TEXT_H