fb2text.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #ifndef FB2TEXT_H
  2. #define FB2TEXT_H
  3. #include <QAction>
  4. #include <QDockWidget>
  5. #include <QFrame>
  6. #include <QResizeEvent>
  7. #include <QTimer>
  8. #include <QWebElement>
  9. #include <QWebView>
  10. #include "fb2mode.h"
  11. #include "fb2imgs.hpp"
  12. QT_BEGIN_NAMESPACE
  13. class QMainWindow;
  14. class QToolBar;
  15. QT_END_NAMESPACE
  16. class FbNoteView;
  17. class FbReadThread;
  18. class FbTextPage;
  19. class FbDockWidget : public QDockWidget
  20. {
  21. Q_OBJECT
  22. public:
  23. explicit FbDockWidget(const QString &title, QWidget *parent = 0, Qt::WindowFlags flags = 0);
  24. };
  25. class FbTextBase : public QWebView
  26. {
  27. Q_OBJECT
  28. public:
  29. FbTextBase(QWidget *parent = 0)
  30. : QWebView(parent)
  31. {
  32. m_timer.setInterval(100);
  33. m_timer.setSingleShot(true);
  34. connect(&m_timer, SIGNAL(timeout()), SLOT(doResize()));
  35. }
  36. void addTools(QToolBar *tool);
  37. protected slots:
  38. void doResize() {
  39. QResizeEvent event(size(), m_size);
  40. QWebView::resizeEvent(&event);
  41. QWebView::update();
  42. }
  43. protected:
  44. void resizeEvent(QResizeEvent* event) {
  45. if (!m_timer.isActive()) m_size = event->oldSize();
  46. m_timer.start();
  47. }
  48. void keyPressEvent(QKeyEvent *event) {
  49. if (event->key() == Qt::Key_Escape) return;
  50. QWebView::keyPressEvent(event);
  51. }
  52. private:
  53. QTimer m_timer;
  54. QSize m_size;
  55. };
  56. class FbTextEdit : public FbTextBase
  57. {
  58. Q_OBJECT
  59. public:
  60. explicit FbTextEdit(QWidget *parent, QObject *owner);
  61. virtual ~FbTextEdit();
  62. FbTextPage *page();
  63. FbStore *store();
  64. bool save(QIODevice *device, const QString &codec = QString());
  65. bool save(QByteArray *array);
  66. bool save(QString *string);
  67. QString toHtml();
  68. QAction * act(Fb::Actions index) const;
  69. QAction * pAct(QWebPage::WebAction index) const;
  70. void setAction(Fb::Actions index, QAction *action);
  71. void connectActions(QToolBar *tool);
  72. void disconnectActions();
  73. void hideDocks();
  74. bool BoldChecked();
  75. bool ItalicChecked();
  76. bool StrikeChecked();
  77. bool SubChecked();
  78. bool SupChecked();
  79. QWebElement body();
  80. QWebElement doc();
  81. protected:
  82. virtual void mouseMoveEvent(QMouseEvent *event);
  83. public slots:
  84. void viewContents(bool show);
  85. void viewPictures(bool show);
  86. void viewFootnotes(bool show);
  87. void viewInspector(bool show);
  88. void insertImage();
  89. void insertNote();
  90. void insertLink();
  91. void find();
  92. private slots:
  93. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  94. void contextMenu(const QPoint &pos);
  95. void treeDestroyed();
  96. void imgsDestroyed();
  97. void noteDestroyed();
  98. void zoomIn();
  99. void zoomOut();
  100. void zoomReset();
  101. private:
  102. bool actionEnabled(QWebPage::WebAction action);
  103. bool actionChecked(QWebPage::WebAction action);
  104. void execCommand(const QString &cmd, const QString &arg);
  105. FbBinary * file(const QString &name);
  106. FbNoteView & noteView();
  107. private:
  108. QMainWindow *m_owner;
  109. FbNoteView *m_noteView;
  110. FbReadThread *m_thread;
  111. FbActionMap m_actions;
  112. QDockWidget *dockTree;
  113. QDockWidget *dockNote;
  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