Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:08:17

0001 // Copyright (C) 2019 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 
0004 #ifndef QTEXTDOCUMENT_H
0005 #define QTEXTDOCUMENT_H
0006 
0007 #include <QtGui/qtguiglobal.h>
0008 #include <QtCore/qobject.h>
0009 #include <QtCore/qsize.h>
0010 #include <QtCore/qrect.h>
0011 #include <QtCore/qvariant.h>
0012 #include <QtGui/qfont.h>
0013 #include <QtCore/qurl.h>
0014 #include <QtCore/qcontainerfwd.h>
0015 Q_MOC_INCLUDE(<QtGui/qtextcursor.h>)
0016 
0017 QT_BEGIN_NAMESPACE
0018 
0019 
0020 class QTextFormatCollection;
0021 class QTextListFormat;
0022 class QRect;
0023 class QPainter;
0024 class QPagedPaintDevice;
0025 class QAbstractTextDocumentLayout;
0026 class QPoint;
0027 class QTextObject;
0028 class QTextFormat;
0029 class QTextFrame;
0030 class QTextBlock;
0031 class QVariant;
0032 class QRectF;
0033 class QTextOption;
0034 class QTextCursor;
0035 
0036 namespace Qt
0037 {
0038 #if QT_GUI_REMOVED_SINCE(6, 7)
0039     Q_GUI_EXPORT bool mightBeRichText(const QString&);
0040 #endif
0041     Q_GUI_EXPORT bool mightBeRichText(QAnyStringView);
0042     Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode = WhiteSpacePre);
0043 }
0044 
0045 class Q_GUI_EXPORT QAbstractUndoItem
0046 {
0047 public:
0048     virtual ~QAbstractUndoItem() = 0;
0049     virtual void undo() = 0;
0050     virtual void redo() = 0;
0051 };
0052 
0053 inline QAbstractUndoItem::~QAbstractUndoItem()
0054 {
0055 }
0056 
0057 class QTextDocumentPrivate;
0058 
0059 class Q_GUI_EXPORT QTextDocument : public QObject
0060 {
0061     Q_OBJECT
0062 
0063     Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
0064     Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
0065     Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
0066     Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
0067     Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
0068     Q_PROPERTY(bool layoutEnabled READ isLayoutEnabled WRITE setLayoutEnabled)
0069     Q_PROPERTY(QSizeF size READ size)
0070     Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
0071     Q_PROPERTY(int blockCount READ blockCount)
0072     Q_PROPERTY(qreal indentWidth READ indentWidth WRITE setIndentWidth)
0073 #ifndef QT_NO_CSSPARSER
0074     Q_PROPERTY(QString defaultStyleSheet READ defaultStyleSheet WRITE setDefaultStyleSheet)
0075 #endif
0076     Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
0077     Q_PROPERTY(qreal documentMargin READ documentMargin WRITE setDocumentMargin)
0078     QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
0079     Q_PROPERTY(QUrl baseUrl READ baseUrl WRITE setBaseUrl NOTIFY baseUrlChanged)
0080 
0081 public:
0082     explicit QTextDocument(QObject *parent = nullptr);
0083     explicit QTextDocument(const QString &text, QObject *parent = nullptr);
0084     ~QTextDocument();
0085 
0086     QTextDocument *clone(QObject *parent = nullptr) const;
0087 
0088     bool isEmpty() const;
0089     virtual void clear();
0090 
0091     void setUndoRedoEnabled(bool enable);
0092     bool isUndoRedoEnabled() const;
0093 
0094     bool isUndoAvailable() const;
0095     bool isRedoAvailable() const;
0096 
0097     int availableUndoSteps() const;
0098     int availableRedoSteps() const;
0099 
0100     int revision() const;
0101 
0102     void setDocumentLayout(QAbstractTextDocumentLayout *layout);
0103     QAbstractTextDocumentLayout *documentLayout() const;
0104 
0105     enum MetaInformation {
0106         DocumentTitle,
0107         DocumentUrl,
0108         CssMedia
0109     };
0110     void setMetaInformation(MetaInformation info, const QString &);
0111     QString metaInformation(MetaInformation info) const;
0112 
0113 #ifndef QT_NO_TEXTHTMLPARSER
0114     QString toHtml() const;
0115     void setHtml(const QString &html);
0116 #endif
0117 
0118 #if QT_CONFIG(textmarkdownwriter) || QT_CONFIG(textmarkdownreader)
0119     enum MarkdownFeature {
0120         MarkdownNoHTML = 0x0020 | 0x0040,
0121         MarkdownDialectCommonMark = 0,
0122         MarkdownDialectGitHub = 0x0004 | 0x0008 | 0x0400 | 0x0100 | 0x0200 | 0x0800 | 0x4000
0123     };
0124     Q_DECLARE_FLAGS(MarkdownFeatures, MarkdownFeature)
0125     Q_FLAG(MarkdownFeatures)
0126 #endif
0127 
0128 #if QT_CONFIG(textmarkdownwriter)
0129     QString toMarkdown(MarkdownFeatures features = MarkdownDialectGitHub) const;
0130 #endif
0131 
0132 #if QT_CONFIG(textmarkdownreader)
0133     void setMarkdown(const QString &markdown, MarkdownFeatures features = MarkdownDialectGitHub);
0134 #endif
0135 
0136     QString toRawText() const;
0137     QString toPlainText() const;
0138     void setPlainText(const QString &text);
0139 
0140     QChar characterAt(int pos) const;
0141 
0142     enum FindFlag
0143     {
0144         FindBackward        = 0x00001,
0145         FindCaseSensitively = 0x00002,
0146         FindWholeWords      = 0x00004
0147     };
0148     Q_DECLARE_FLAGS(FindFlags, FindFlag)
0149 
0150     QTextCursor find(const QString &subString, int from = 0, FindFlags options = FindFlags()) const;
0151     QTextCursor find(const QString &subString, const QTextCursor &cursor, FindFlags options = FindFlags()) const;
0152 
0153 #if QT_CONFIG(regularexpression)
0154     QTextCursor find(const QRegularExpression &expr, int from = 0, FindFlags options = FindFlags()) const;
0155     QTextCursor find(const QRegularExpression &expr, const QTextCursor &cursor, FindFlags options = FindFlags()) const;
0156 #endif
0157 
0158     QTextFrame *frameAt(int pos) const;
0159     QTextFrame *rootFrame() const;
0160 
0161     QTextObject *object(int objectIndex) const;
0162     QTextObject *objectForFormat(const QTextFormat &) const;
0163 
0164     QTextBlock findBlock(int pos) const;
0165     QTextBlock findBlockByNumber(int blockNumber) const;
0166     QTextBlock findBlockByLineNumber(int blockNumber) const;
0167     QTextBlock begin() const;
0168     QTextBlock end() const;
0169 
0170     QTextBlock firstBlock() const;
0171     QTextBlock lastBlock() const;
0172 
0173     void setPageSize(const QSizeF &size);
0174     QSizeF pageSize() const;
0175 
0176     void setDefaultFont(const QFont &font);
0177     QFont defaultFont() const;
0178 
0179     void setSuperScriptBaseline(qreal baseline);
0180     qreal superScriptBaseline() const;
0181 
0182     void setSubScriptBaseline(qreal baseline);
0183     qreal subScriptBaseline() const;
0184 
0185     void setBaselineOffset(qreal baseline);
0186     qreal baselineOffset() const;
0187 
0188     int pageCount() const;
0189 
0190     bool isModified() const;
0191 
0192 #ifndef QT_NO_PRINTER
0193     void print(QPagedPaintDevice *printer) const;
0194 #endif
0195 
0196     enum ResourceType {
0197         UnknownResource = 0,
0198         HtmlResource  = 1,
0199         ImageResource = 2,
0200         StyleSheetResource = 3,
0201         MarkdownResource = 4,
0202 
0203         UserResource  = 100
0204     };
0205     Q_ENUM(ResourceType)
0206 
0207     QVariant resource(int type, const QUrl &name) const;
0208     void addResource(int type, const QUrl &name, const QVariant &resource);
0209 
0210     using ResourceProvider = std::function<QVariant(const QUrl&)>;
0211 
0212     QTextDocument::ResourceProvider resourceProvider() const;
0213     void setResourceProvider(const ResourceProvider &provider);
0214 
0215     static QTextDocument::ResourceProvider defaultResourceProvider();
0216     static void setDefaultResourceProvider(const ResourceProvider &provider);
0217 
0218     QList<QTextFormat> allFormats() const;
0219 
0220     void markContentsDirty(int from, int length);
0221 
0222     void setUseDesignMetrics(bool b);
0223     bool useDesignMetrics() const;
0224 
0225     void setLayoutEnabled(bool b);
0226     bool isLayoutEnabled() const;
0227 
0228     void drawContents(QPainter *painter, const QRectF &rect = QRectF());
0229 
0230     void setTextWidth(qreal width);
0231     qreal textWidth() const;
0232 
0233     qreal idealWidth() const;
0234 
0235     qreal indentWidth() const;
0236     void setIndentWidth(qreal width);
0237 
0238     qreal documentMargin() const;
0239     void setDocumentMargin(qreal margin);
0240 
0241     void adjustSize();
0242     QSizeF size() const;
0243 
0244     int blockCount() const;
0245     int lineCount() const;
0246     int characterCount() const;
0247 
0248 #ifndef QT_NO_CSSPARSER
0249     void setDefaultStyleSheet(const QString &sheet);
0250     QString defaultStyleSheet() const;
0251 #endif
0252 
0253     void undo(QTextCursor *cursor);
0254     void redo(QTextCursor *cursor);
0255 
0256     enum Stacks {
0257         UndoStack = 0x01,
0258         RedoStack = 0x02,
0259         UndoAndRedoStacks = UndoStack | RedoStack
0260     };
0261     void clearUndoRedoStacks(Stacks historyToClear = UndoAndRedoStacks);
0262 
0263     int maximumBlockCount() const;
0264     void setMaximumBlockCount(int maximum);
0265 
0266     QTextOption defaultTextOption() const;
0267     void setDefaultTextOption(const QTextOption &option);
0268 
0269     QUrl baseUrl() const;
0270     void setBaseUrl(const QUrl &url);
0271 
0272     Qt::CursorMoveStyle defaultCursorMoveStyle() const;
0273     void setDefaultCursorMoveStyle(Qt::CursorMoveStyle style);
0274 
0275 Q_SIGNALS:
0276     void contentsChange(int from, int charsRemoved, int charsAdded);
0277     void contentsChanged();
0278     void undoAvailable(bool);
0279     void redoAvailable(bool);
0280     void undoCommandAdded();
0281     void modificationChanged(bool m);
0282     void cursorPositionChanged(const QTextCursor &cursor);
0283     void blockCountChanged(int newBlockCount);
0284     void baseUrlChanged(const QUrl &url);
0285     void documentLayoutChanged();
0286 
0287 public Q_SLOTS:
0288     void undo();
0289     void redo();
0290     void appendUndoItem(QAbstractUndoItem *);
0291     void setModified(bool m = true);
0292 
0293 protected:
0294     virtual QTextObject *createObject(const QTextFormat &f);
0295     Q_INVOKABLE virtual QVariant loadResource(int type, const QUrl &name);
0296 
0297     QTextDocument(QTextDocumentPrivate &dd, QObject *parent);
0298 private:
0299     Q_DISABLE_COPY(QTextDocument)
0300     Q_DECLARE_PRIVATE(QTextDocument)
0301     friend class QTextObjectPrivate;
0302 };
0303 
0304 Q_DECLARE_OPERATORS_FOR_FLAGS(QTextDocument::FindFlags)
0305 
0306 QT_END_NAMESPACE
0307 
0308 #endif // QTEXTDOCUMENT_H