fb2text.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 "fb2temp.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. FbNetworkAccessManager *files();
  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. protected:
  80. virtual void mouseMoveEvent(QMouseEvent *event);
  81. public slots:
  82. void html(QString html);
  83. void data(QString name, QByteArray data);
  84. void viewContents(bool show);
  85. void viewPictures(bool show);
  86. void viewInspector(bool show);
  87. void insertImage();
  88. void insertNote();
  89. void insertLink();
  90. void find();
  91. private slots:
  92. void linkHovered(const QString &link, const QString &title, const QString &textContent);
  93. void contextMenu(const QPoint &pos);
  94. void treeDestroyed();
  95. void imgsDestroyed();
  96. void zoomIn();
  97. void zoomOut();
  98. void zoomReset();
  99. private:
  100. bool actionEnabled(QWebPage::WebAction action);
  101. bool actionChecked(QWebPage::WebAction action);
  102. void execCommand(const QString &cmd, const QString &arg);
  103. FbTemporaryFile * file(const QString &name);
  104. FbNoteView & noteView();
  105. QWebElement body();
  106. QWebElement doc();
  107. private:
  108. QMainWindow *m_owner;
  109. FbNoteView *m_noteView;
  110. FbReadThread *m_thread;
  111. FbActionMap m_actions;
  112. QDockWidget *dockTree;
  113. QDockWidget *dockImgs;
  114. QDockWidget *dockInsp;
  115. QPoint m_point;
  116. };
  117. class FbTextFrame : public QFrame
  118. {
  119. Q_OBJECT
  120. public:
  121. explicit FbTextFrame(QWidget *parent = 0);
  122. };
  123. class FbTextAction : public QAction
  124. {
  125. Q_OBJECT
  126. public:
  127. explicit FbTextAction(const QString &text, QWebPage::WebAction action, FbTextEdit* parent);
  128. explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, FbTextEdit *parent);
  129. void connectAction();
  130. void disconnectAction();
  131. private slots:
  132. void updateAction();
  133. private:
  134. QAction * action(QWebPage::WebAction action);
  135. private:
  136. QWebPage::WebAction m_action;
  137. FbTextEdit *m_parent;
  138. };
  139. #endif // FB2TEXT_H