fb2text.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 = {});
  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(QString *string, int &anchor, int &focus);
  66. bool save(QByteArray *array);
  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. signals:
  82. void modificationChanged(bool changed);
  83. protected:
  84. virtual void mouseMoveEvent(QMouseEvent *event);
  85. public slots:
  86. void viewContents(bool show);
  87. void viewPictures(bool show);
  88. void viewFootnotes(bool show);
  89. void viewInspector(bool show);
  90. void insertImage();
  91. void insertNote();
  92. void insertLink();
  93. void find();
  94. #ifdef QT_DEBUG
  95. public slots:
  96. void exportHtml();
  97. #endif // QT_DEBUG
  98. private slots:
  99. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  100. void contextMenu(const QPoint &pos);
  101. void cleanChanged(bool clean);
  102. void treeDestroyed();
  103. void imgsDestroyed();
  104. void noteDestroyed();
  105. void zoomIn();
  106. void zoomOut();
  107. void zoomReset();
  108. private:
  109. bool actionEnabled(QWebPage::WebAction action);
  110. bool actionChecked(QWebPage::WebAction action);
  111. void execCommand(const QString &cmd, const QString &arg);
  112. FbBinary * file(const QString &name);
  113. FbNoteView & noteView();
  114. private:
  115. QMainWindow *m_owner;
  116. FbNoteView *m_noteView;
  117. FbReadThread *m_thread;
  118. FbActionMap m_actions;
  119. QDockWidget *dockTree;
  120. QDockWidget *dockNote;
  121. QDockWidget *dockImgs;
  122. QDockWidget *dockInsp;
  123. QPoint m_point;
  124. };
  125. class FbTextFrame : public QFrame
  126. {
  127. Q_OBJECT
  128. public:
  129. explicit FbTextFrame(QWidget *parent = 0);
  130. };
  131. class FbTextAction : public QAction
  132. {
  133. Q_OBJECT
  134. public:
  135. explicit FbTextAction(const QString &text, QWebPage::WebAction action, FbTextEdit* parent);
  136. explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, FbTextEdit *parent);
  137. void connectAction();
  138. void disconnectAction();
  139. private slots:
  140. void updateAction();
  141. private:
  142. QAction * action();
  143. private:
  144. QWebPage::WebAction m_action;
  145. FbTextEdit *m_parent;
  146. };
  147. #endif // FB2TEXT_H