Guest User

TextEditHeader

a guest
Aug 9th, 2016
50
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ifndef _MTEXTEDIT_H_
  2. #define _MTEXTEDIT_H_
  3.  
  4. #include <QTextBrowser>
  5. #include <QPointer>
  6. #include <QWidget>
  7. #include <QTextCursor>
  8. #include <QSet>
  9. class QAbstractItemModel;
  10. class QTextDocument;
  11. class QTextCharFormat;
  12. class QMimeData;
  13. class QImage;
  14. class MTextEdit : public QTextBrowser
  15. {
  16.     Q_OBJECT
  17. public:
  18.     MTextEdit(QWidget *parent=nullptr);
  19.     virtual ~MTextEdit() = default;  
  20.     QByteArray save() const;
  21.     void load(const QByteArray& source);
  22.     const unsigned int& fontSize() const;
  23.     void setFontSize(const unsigned int& val);
  24.     const QColor& fgColor() const;
  25.     const QColor& bgColor() const;
  26.     void setFgColor(const QColor& val);
  27.     void setBgColor(const QColor& val);
  28. public slots:
  29.     void setText(const QString &text);
  30.     QString toHtml() const;
  31.     QAction* undoAction();
  32.     QAction* redoAction();
  33.     QAction* cutAction();
  34.     QAction* copyAction();
  35.     QAction* pasteAction();
  36.     QAction* boldAction();
  37.     QAction* italicAction();
  38.     QAction* underlineAction();
  39.     QAction* strikeoutAction();
  40.     QAction* orderedListAction();
  41.     QAction* unorderedListAction();
  42.     QAction* increaseIndentAction();
  43.     QAction* decreaseIndentAction();
  44.     QAction* imageAction();
  45. signals:
  46.     void fontSizeChanged(unsigned int sz);
  47.     void fgColorChanged(const QColor &c);
  48.     void bgColorChanged(const QColor &c);
  49. protected:
  50.     virtual void focusInEvent(QFocusEvent *e) override;
  51.     void dropImage(const QImage& image);
  52.     void dropDocument(const QUrl& origFilePath);
  53.     void createActions();
  54.     virtual bool canInsertFromMimeData(const QMimeData *source) const override;
  55.     virtual void insertFromMimeData(const QMimeData *source) override;
  56.     virtual  QMimeData *createMimeDataFromSelection() const override;
  57.     void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
  58.     void fontChanged(const QFont &f);
  59.     void list(bool checked, QTextListFormat::Style style);
  60.     void indent(int delta);
  61. protected slots:
  62.     void textBold();
  63.     void textUnderline();
  64.     void textStrikeout();
  65.     void textItalic();
  66.     void textSize();
  67.     void textFgColor(const QColor& col);
  68.     void textBgColor(const QColor& col);
  69.     void listBullet(bool checked);
  70.     void listOrdered(bool checked);
  71.     void slotCurrentCharFormatChanged(const QTextCharFormat &format);
  72.     void slotCursorPositionChanged();
  73.     void slotClipboardDataChanged();
  74.     void urlActivated(const QUrl &link);
  75.    
  76.     void increaseIndentation();
  77.     void decreaseIndentation();
  78.     void insertImage();
  79. private:
  80.     quint32 m_imageCounter;
  81.     QPointer<QTextList> m_lastBlockList;
  82.     QAction* m_undoAction;
  83.     QAction* m_redoAction;
  84.     QAction* m_cutAction;
  85.     QAction* m_copyAction;
  86.     QAction* m_pasteAction;
  87.     QAction* m_boldAction;
  88.     QAction* m_italicAction;
  89.     QAction* m_underlineAction;
  90.     QAction* m_strikeoutAction;
  91.     QAction *m_orderedListAction;
  92.     QAction *m_unorderedListAction;
  93.     QAction *m_increaseIndentAction;
  94.     QAction *m_decreaseIndentAction;
  95.     QAction *m_imageAction;
  96.     QAbstractItemModel* m_fontsModel;
  97.     unsigned int m_fontSize;
  98.     QColor m_fgColor;
  99.     QColor m_bgColor;
  100.     QSet<QString> m_imageList;
  101. };
  102.  
  103. #endif
RAW Paste Data