fb2dock.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef FB2DOCK_H
  2. #define FB2DOCK_H
  3. #include <QAction>
  4. #include <QIcon>
  5. #include <QMenu>
  6. #include <QStackedWidget>
  7. #include <QToolBar>
  8. #include <QIODevice>
  9. #include "fb2mode.h"
  10. class FbTextEdit;
  11. class FbHeadEdit;
  12. class FbCodeEdit;
  13. class FbMainDock : public QStackedWidget
  14. {
  15. Q_OBJECT
  16. public:
  17. explicit FbMainDock(QWidget *parent = 0);
  18. FbTextEdit * text() { return m_text; }
  19. FbHeadEdit * head() { return m_head; }
  20. FbCodeEdit * code() { return m_code; }
  21. bool load(const QString &filename);
  22. bool save(QIODevice *device, const QString &codec = QString());
  23. Fb::Mode mode() const { return m_mode; }
  24. void switchMode(Fb::Mode mode);
  25. void setMode(Fb::Mode mode);
  26. void setTool(QToolBar *tool) { m_tool = tool; }
  27. void addAction(Fb::Mode mode, QAction *action);
  28. void addMenu(QMenu *menu);
  29. bool isModified() const;
  30. signals:
  31. void modificationChanged(bool changed);
  32. void status(const QString &text);
  33. private slots:
  34. void textChanged(bool changed);
  35. void error(int row, int col);
  36. private:
  37. void enableMenu(bool value);
  38. void setModeText();
  39. void setModeHead();
  40. void setModeCode();
  41. void setModeHtml();
  42. private:
  43. QFrame *textFrame;
  44. QMap<Fb::Mode, QAction*> m_actions;
  45. QList<QMenu*> m_menus;
  46. FbTextEdit *m_text;
  47. FbHeadEdit *m_head;
  48. FbCodeEdit *m_code;
  49. QToolBar *m_tool;
  50. bool isSwitched;
  51. Fb::Mode m_mode;
  52. };
  53. class FbModeAction : public QAction
  54. {
  55. Q_OBJECT
  56. public:
  57. explicit FbModeAction(FbMainDock *parent, Fb::Mode mode, const QIcon &icon, const QString &text);
  58. explicit FbModeAction(FbMainDock *parent, Fb::Mode mode, const QString &text);
  59. private slots:
  60. void switchMode();
  61. private:
  62. FbMainDock * m_dock;
  63. Fb::Mode m_mode;
  64. };
  65. #endif // FB2DOCK_H