rich_text_handler.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. #ifndef RICH_TEXT_HANDLER_HPP
  3. #define RICH_TEXT_HANDLER_HPP
  4. #include <QtGui/QTextCharFormat>
  5. #include <QtCore/QTextCodec>
  6. #include <QQuickTextDocument>
  7. #include <QTextDocument>
  8. #include <QTextCursor>
  9. class RichTextHandler : public QObject {
  10. Q_OBJECT;
  11. QQuickItem* target = nullptr;
  12. QTextDocument* target_doc = nullptr;
  13. int cursor_pos = -1,
  14. start_pos = -1,
  15. end_pos = -1;
  16. QTextCursor textCursor() const;
  17. void mergeFormatOnWordOrSelection(const QTextCharFormat &format);
  18. Q_PROPERTY(QQuickItem* target READ getTarget WRITE setTarget NOTIFY targetChanged)
  19. Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
  20. Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
  21. Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)
  22. public:
  23. RichTextHandler(QObject* parent = nullptr);
  24. QQuickItem* getTarget() const;
  25. public slots:
  26. void setTarget(QQuickItem* target);
  27. signals:
  28. void targetChanged(QQuickItem* target);
  29. };
  30. /*
  31. Q_PROPERTY(QQuickItem *target READ target WRITE setTarget NOTIFY targetChanged)
  32. Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
  33. Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
  34. Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)
  35. Q_PROPERTY(QColor textColor READ textColor WRITE setTextColor NOTIFY textColorChanged)
  36. Q_PROPERTY(QString fontFamily READ fontFamily WRITE setFontFamily NOTIFY fontFamilyChanged)
  37. Q_PROPERTY(Qt::Alignment alignment READ alignment WRITE setAlignment NOTIFY alignmentChanged)
  38. Q_PROPERTY(bool bold READ bold WRITE setBold NOTIFY boldChanged)
  39. Q_PROPERTY(bool italic READ italic WRITE setItalic NOTIFY italicChanged)
  40. Q_PROPERTY(bool underline READ underline WRITE setUnderline NOTIFY underlineChanged)
  41. Q_PROPERTY(int fontSize READ fontSize WRITE setFontSize NOTIFY fontSizeChanged)
  42. Q_PROPERTY(QStringList defaultFontSizes READ defaultFontSizes NOTIFY defaultFontSizesChanged)
  43. Q_PROPERTY(QUrl fileUrl READ fileUrl WRITE setFileUrl NOTIFY fileUrlChanged)
  44. Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
  45. Q_PROPERTY(QString documentTitle READ documentTitle WRITE setDocumentTitle NOTIFY documentTitleChanged)
  46. */
  47. #endif // RICH_TEXT_HANDLER_HPP
  48. */