fb2text.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. 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 treeDestroyed();
  94. void imgsDestroyed();
  95. void viewTree(bool show);
  96. void viewImgs(bool show);
  97. void viewInsp(bool show);
  98. private:
  99. bool actionEnabled(QWebPage::WebAction action);
  100. bool actionChecked(QWebPage::WebAction action);
  101. void execCommand(const QString &cmd, const QString &arg);
  102. FbTemporaryFile * file(const QString &name);
  103. FbNoteView & noteView();
  104. QWebElement body();
  105. QWebElement doc();
  106. private:
  107. QMainWindow *m_owner;
  108. FbNoteView *m_noteView;
  109. FbReadThread *m_thread;
  110. FbActionMap m_actions;
  111. QDockWidget *dockTree;
  112. QDockWidget *dockImgs;
  113. QDockWidget *dockInsp;
  114. QPoint m_point;
  115. };
  116. class FbWebFrame : public QFrame
  117. {
  118. Q_OBJECT
  119. public:
  120. explicit FbWebFrame(QWidget *parent = 0);
  121. };
  122. class FbTextAction : public QAction
  123. {
  124. Q_OBJECT
  125. public:
  126. explicit FbTextAction(const QString &text, QWebPage::WebAction action, FbTextEdit* parent);
  127. explicit FbTextAction(const QIcon &icon, const QString &text, QWebPage::WebAction action, FbTextEdit *parent);
  128. public slots:
  129. void updateChecked();
  130. void updateEnabled();
  131. private:
  132. QAction * action(QWebPage::WebAction action);
  133. private:
  134. QWebPage::WebAction m_action;
  135. FbTextEdit *m_parent;
  136. };
  137. #endif // FB2TEXT_H