#ifndef TEXT_PRESENT_H #define TEXT_PRESENT_H #include "libtextedit.h" #include #include #include #include namespace model_text { typedef QList CharStream; class LIBTEXTEDIT_EXPORT CharSetU16 { public: static CharStream combineToU(const QString &buffer); static QString splitToC(const CharStream &buffer); static bool contains(uint32_t code); static uint size(); }; class LIBTEXTEDIT_EXPORT CharFormat { private: qulonglong unique_id; uint32_t point_size; QString fontfamily_store; bool bold_store; bool italic_flag; bool kerning_flag; bool overline_flag; bool underline_flag; double float_Height; QFont::Weight weight_store; public: CharFormat(qulonglong format_id); CharFormat(const CharFormat& other); qulonglong formatID() const; uint32_t pointSize() const; QString fontFamily() const; bool bold() const; bool italic() const; bool kerning() const; bool overline() const; bool underline() const; double floatHeight() const; QFont::Weight weight() const; void setPointSize(uint32_t val); void setFontFamily(const QString &name); void setBold(bool ste); void setItalic(bool ste); void setKerning(bool ste); void setOverline(bool ste); void setUnderline(bool ste); void setFloatHeight(double val); void setWeight(QFont::Weight val); bool operator==(const CharFormat &other); CharFormat &operator=(const CharFormat &other); }; class LIBTEXTEDIT_EXPORT DocFormat { private: std::shared_ptr char_format; double line_height = 20; double indent_char_count = 2; QMargins margins_store = QMargins(5,5,5,5); bool visible_of_additional = false; public: DocFormat(); DocFormat(const DocFormat &other); double lineHeight() const; QMargins margins() const; double indentChars() const; bool additionalVisible() const; std::shared_ptr defaultCharFormat() const; void setLineHeight(double val); void setMargins(const QMargins &val); void setIndentChars(double n); void setAdditionalVisible(bool ste); void setDefaultCharFormat(std::shared_ptr format); DocFormat& operator=(const DocFormat &other); }; class WsBlock; /** * @brief 琛屽唴鍏冪礌 */ class Element { public: enum class Type{ Char, Set }; virtual ~Element() = default; virtual void refer(std::weak_ptr ptr) = 0; virtual std::weak_ptr blockRefer() const = 0; virtual uint32_t blockIndex() const = 0; virtual std::shared_ptr getFormat() const = 0; virtual void bindFormat(std::shared_ptr format) = 0; virtual Type type() const = 0; virtual uint32_t index() const = 0; virtual QString toText() const = 0; virtual uint32_t childCount() const = 0; }; class LIBTEXTEDIT_EXPORT WsChar : public Element { private: uint32_t code_store; std::shared_ptr char_format_refer; public: explicit WsChar(uint32_t code){this->code_store = code;} virtual ~WsChar() = default; uint32_t code() const { return code_store; } static QList convertFrom(const CharStream &codes); // Element interface public: virtual std::shared_ptr getFormat() const override { return this->char_format_refer; } virtual void bindFormat(std::shared_ptr format) override{this->char_format_refer = format;} virtual Type type() const override { return Type::Char; } virtual uint32_t blockIndex() const override; virtual uint32_t index() const override; virtual QString toText() const override { return CharSetU16::splitToC(QList() << code_store); } virtual uint32_t childCount() const override { return 0; } virtual void refer(std::weak_ptr ptr) override; virtual std::weak_ptr blockRefer() const override; }; class LIBTEXTEDIT_EXPORT WsPart : public Element { public: void insertChars(const QList &text, uint32_t offset = -1); QList getChars(uint32_t offset, uint32_t count) const; void delChars(uint32_t offset, uint32_t count); }; class LIBTEXTEDIT_EXPORT WsBlock { private: QList element_store; public: uint32_t blockIndex() const; void addElements(const QList &text, uint32_t offset = UINT32_MAX); QList getElements(uint32_t offset, uint32_t count) const; void delElements(uint32_t offset, uint32_t count); QString toText() const; }; class LIBTEXTEDIT_EXPORT WsDocument : public QObject { Q_OBJECT private: std::shared_ptr document_format; QList> block_store; public: void bindFormat(std::shared_ptr f); std::shared_ptr getFormat() const; void addBlocks(const QList> &blks, uint32_t offset = UINT32_MAX); uint32_t blockCount() const; QList> getBlocks(uint32_t offset, uint32_t count = 1) const; void delBlocks(uint32_t offset, uint32_t count = 1); // void insertText(QList part, uint32_t index = -1); // QList getText(uint32_t index, uint32_t count); // void delText(uint32_t index, uint32_t count); // void select(uint32_t index, uint32_t count); QString toPlainText() const; void setPlainText(const QString &text); // signals: // void blockHasbeenInserted(uint32_t index); // void blockAboutTobeDelete(uint32_t index); // void blockHasbeenChanged(uint32_t index); // void redoAvaliable(); // void undoAvaliable(); // void cursorPosChanged(uint32_t index); // void selectionChanged(uint32_t index, uint32_t count); }; } #endif // TEXT_PRESENT_H