[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the QtGui module of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 15 | **
|
---|
| 16 | ** GNU Lesser General Public License Usage
|
---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
| 20 | ** packaging of this file. Please review the following information to
|
---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
| 23 | **
|
---|
[561] | 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
[2] | 27 | **
|
---|
| 28 | ** GNU General Public License Usage
|
---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 32 | ** packaging of this file. Please review the following information to
|
---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
| 35 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 38 | ** $QT_END_LICENSE$
|
---|
| 39 | **
|
---|
| 40 | ****************************************************************************/
|
---|
| 41 |
|
---|
| 42 | #ifndef QTEXTDOCUMENT_H
|
---|
| 43 | #define QTEXTDOCUMENT_H
|
---|
| 44 |
|
---|
| 45 | #include <QtCore/qobject.h>
|
---|
| 46 | #include <QtCore/qsize.h>
|
---|
| 47 | #include <QtCore/qrect.h>
|
---|
| 48 | #include <QtGui/qfont.h>
|
---|
| 49 |
|
---|
| 50 | QT_BEGIN_HEADER
|
---|
| 51 |
|
---|
| 52 | QT_BEGIN_NAMESPACE
|
---|
| 53 |
|
---|
| 54 | QT_MODULE(Gui)
|
---|
| 55 |
|
---|
| 56 | class QTextFormatCollection;
|
---|
| 57 | class QTextListFormat;
|
---|
| 58 | class QRect;
|
---|
| 59 | class QPainter;
|
---|
| 60 | class QPrinter;
|
---|
| 61 | class QAbstractTextDocumentLayout;
|
---|
| 62 | class QPoint;
|
---|
| 63 | class QTextCursor;
|
---|
| 64 | class QTextObject;
|
---|
| 65 | class QTextFormat;
|
---|
| 66 | class QTextFrame;
|
---|
| 67 | class QTextBlock;
|
---|
| 68 | class QTextCodec;
|
---|
| 69 | class QUrl;
|
---|
| 70 | class QVariant;
|
---|
| 71 | class QRectF;
|
---|
| 72 | class QTextOption;
|
---|
| 73 |
|
---|
| 74 | template<typename T> class QVector;
|
---|
| 75 |
|
---|
| 76 | namespace Qt
|
---|
| 77 | {
|
---|
| 78 | enum HitTestAccuracy { ExactHit, FuzzyHit };
|
---|
| 79 | enum WhiteSpaceMode {
|
---|
| 80 | WhiteSpaceNormal,
|
---|
| 81 | WhiteSpacePre,
|
---|
| 82 | WhiteSpaceNoWrap,
|
---|
| 83 | WhiteSpaceModeUndefined = -1
|
---|
| 84 | };
|
---|
| 85 |
|
---|
| 86 | Q_GUI_EXPORT bool mightBeRichText(const QString&);
|
---|
| 87 | Q_GUI_EXPORT QString escape(const QString& plain);
|
---|
| 88 | Q_GUI_EXPORT QString convertFromPlainText(const QString &plain, WhiteSpaceMode mode = WhiteSpacePre);
|
---|
| 89 |
|
---|
| 90 | #ifndef QT_NO_TEXTCODEC
|
---|
| 91 | Q_GUI_EXPORT QTextCodec *codecForHtml(const QByteArray &ba);
|
---|
| 92 | #endif
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | class Q_GUI_EXPORT QAbstractUndoItem
|
---|
| 96 | {
|
---|
| 97 | public:
|
---|
| 98 | virtual ~QAbstractUndoItem() = 0;
|
---|
| 99 | virtual void undo() = 0;
|
---|
| 100 | virtual void redo() = 0;
|
---|
| 101 | };
|
---|
| 102 |
|
---|
| 103 | inline QAbstractUndoItem::~QAbstractUndoItem()
|
---|
| 104 | {
|
---|
| 105 | }
|
---|
| 106 |
|
---|
| 107 | class QTextDocumentPrivate;
|
---|
| 108 |
|
---|
| 109 | class Q_GUI_EXPORT QTextDocument : public QObject
|
---|
| 110 | {
|
---|
| 111 | Q_OBJECT
|
---|
| 112 |
|
---|
| 113 | Q_PROPERTY(bool undoRedoEnabled READ isUndoRedoEnabled WRITE setUndoRedoEnabled)
|
---|
| 114 | Q_PROPERTY(bool modified READ isModified WRITE setModified DESIGNABLE false)
|
---|
| 115 | Q_PROPERTY(QSizeF pageSize READ pageSize WRITE setPageSize)
|
---|
| 116 | Q_PROPERTY(QFont defaultFont READ defaultFont WRITE setDefaultFont)
|
---|
| 117 | Q_PROPERTY(bool useDesignMetrics READ useDesignMetrics WRITE setUseDesignMetrics)
|
---|
| 118 | Q_PROPERTY(QSizeF size READ size)
|
---|
| 119 | Q_PROPERTY(qreal textWidth READ textWidth WRITE setTextWidth)
|
---|
| 120 | Q_PROPERTY(int blockCount READ blockCount)
|
---|
| 121 | Q_PROPERTY(qreal indentWidth READ indentWidth WRITE setIndentWidth)
|
---|
| 122 | #ifndef QT_NO_CSSPARSER
|
---|
| 123 | Q_PROPERTY(QString defaultStyleSheet READ defaultStyleSheet WRITE setDefaultStyleSheet)
|
---|
| 124 | #endif
|
---|
| 125 | Q_PROPERTY(int maximumBlockCount READ maximumBlockCount WRITE setMaximumBlockCount)
|
---|
| 126 | Q_PROPERTY(qreal documentMargin READ documentMargin WRITE setDocumentMargin)
|
---|
| 127 | QDOC_PROPERTY(QTextOption defaultTextOption READ defaultTextOption WRITE setDefaultTextOption)
|
---|
| 128 |
|
---|
| 129 | public:
|
---|
| 130 | explicit QTextDocument(QObject *parent = 0);
|
---|
| 131 | explicit QTextDocument(const QString &text, QObject *parent = 0);
|
---|
| 132 | ~QTextDocument();
|
---|
| 133 |
|
---|
| 134 | QTextDocument *clone(QObject *parent = 0) const;
|
---|
| 135 |
|
---|
| 136 | bool isEmpty() const;
|
---|
| 137 | virtual void clear();
|
---|
| 138 |
|
---|
| 139 | void setUndoRedoEnabled(bool enable);
|
---|
| 140 | bool isUndoRedoEnabled() const;
|
---|
| 141 |
|
---|
| 142 | bool isUndoAvailable() const;
|
---|
| 143 | bool isRedoAvailable() const;
|
---|
| 144 |
|
---|
[561] | 145 | int availableUndoSteps() const;
|
---|
| 146 | int availableRedoSteps() const;
|
---|
| 147 |
|
---|
[2] | 148 | int revision() const;
|
---|
| 149 |
|
---|
| 150 | void setDocumentLayout(QAbstractTextDocumentLayout *layout);
|
---|
| 151 | QAbstractTextDocumentLayout *documentLayout() const;
|
---|
| 152 |
|
---|
| 153 | enum MetaInformation {
|
---|
| 154 | DocumentTitle,
|
---|
| 155 | DocumentUrl
|
---|
| 156 | };
|
---|
| 157 | void setMetaInformation(MetaInformation info, const QString &);
|
---|
| 158 | QString metaInformation(MetaInformation info) const;
|
---|
| 159 |
|
---|
| 160 | #ifndef QT_NO_TEXTHTMLPARSER
|
---|
| 161 | QString toHtml(const QByteArray &encoding = QByteArray()) const;
|
---|
| 162 | void setHtml(const QString &html);
|
---|
| 163 | #endif
|
---|
| 164 |
|
---|
| 165 | QString toPlainText() const;
|
---|
| 166 | void setPlainText(const QString &text);
|
---|
| 167 |
|
---|
| 168 | QChar characterAt(int pos) const;
|
---|
| 169 |
|
---|
| 170 | enum FindFlag
|
---|
| 171 | {
|
---|
| 172 | FindBackward = 0x00001,
|
---|
| 173 | FindCaseSensitively = 0x00002,
|
---|
| 174 | FindWholeWords = 0x00004
|
---|
| 175 | };
|
---|
| 176 | Q_DECLARE_FLAGS(FindFlags, FindFlag)
|
---|
| 177 |
|
---|
| 178 | QTextCursor find(const QString &subString, int from = 0, FindFlags options = 0) const;
|
---|
| 179 | QTextCursor find(const QString &subString, const QTextCursor &from, FindFlags options = 0) const;
|
---|
| 180 |
|
---|
| 181 | QTextCursor find(const QRegExp &expr, int from = 0, FindFlags options = 0) const;
|
---|
| 182 | QTextCursor find(const QRegExp &expr, const QTextCursor &from, FindFlags options = 0) const;
|
---|
| 183 |
|
---|
| 184 | QTextFrame *frameAt(int pos) const;
|
---|
| 185 | QTextFrame *rootFrame() const;
|
---|
| 186 |
|
---|
| 187 | QTextObject *object(int objectIndex) const;
|
---|
| 188 | QTextObject *objectForFormat(const QTextFormat &) const;
|
---|
| 189 |
|
---|
| 190 | QTextBlock findBlock(int pos) const;
|
---|
| 191 | QTextBlock findBlockByNumber(int blockNumber) const;
|
---|
| 192 | QTextBlock findBlockByLineNumber(int blockNumber) const;
|
---|
| 193 | QTextBlock begin() const;
|
---|
| 194 | QTextBlock end() const;
|
---|
| 195 |
|
---|
| 196 | QTextBlock firstBlock() const;
|
---|
| 197 | QTextBlock lastBlock() const;
|
---|
| 198 |
|
---|
| 199 | void setPageSize(const QSizeF &size);
|
---|
| 200 | QSizeF pageSize() const;
|
---|
| 201 |
|
---|
| 202 | void setDefaultFont(const QFont &font);
|
---|
| 203 | QFont defaultFont() const;
|
---|
| 204 |
|
---|
| 205 | int pageCount() const;
|
---|
| 206 |
|
---|
| 207 | bool isModified() const;
|
---|
| 208 |
|
---|
| 209 | #ifndef QT_NO_PRINTER
|
---|
| 210 | void print(QPrinter *printer) const;
|
---|
| 211 | #endif
|
---|
| 212 |
|
---|
| 213 | enum ResourceType {
|
---|
| 214 | HtmlResource = 1,
|
---|
| 215 | ImageResource = 2,
|
---|
| 216 | StyleSheetResource = 3,
|
---|
| 217 |
|
---|
| 218 | UserResource = 100
|
---|
| 219 | };
|
---|
| 220 |
|
---|
| 221 | QVariant resource(int type, const QUrl &name) const;
|
---|
| 222 | void addResource(int type, const QUrl &name, const QVariant &resource);
|
---|
| 223 |
|
---|
| 224 | QVector<QTextFormat> allFormats() const;
|
---|
| 225 |
|
---|
| 226 | void markContentsDirty(int from, int length);
|
---|
| 227 |
|
---|
| 228 | void setUseDesignMetrics(bool b);
|
---|
| 229 | bool useDesignMetrics() const;
|
---|
| 230 |
|
---|
| 231 | void drawContents(QPainter *painter, const QRectF &rect = QRectF());
|
---|
| 232 |
|
---|
| 233 | void setTextWidth(qreal width);
|
---|
| 234 | qreal textWidth() const;
|
---|
| 235 |
|
---|
| 236 | qreal idealWidth() const;
|
---|
| 237 |
|
---|
| 238 | qreal indentWidth() const;
|
---|
| 239 | void setIndentWidth(qreal width);
|
---|
| 240 |
|
---|
| 241 | qreal documentMargin() const;
|
---|
| 242 | void setDocumentMargin(qreal margin);
|
---|
| 243 |
|
---|
| 244 | void adjustSize();
|
---|
| 245 | QSizeF size() const;
|
---|
| 246 |
|
---|
| 247 | int blockCount() const;
|
---|
| 248 | int lineCount() const;
|
---|
| 249 | int characterCount() const;
|
---|
| 250 |
|
---|
| 251 | #ifndef QT_NO_CSSPARSER
|
---|
| 252 | void setDefaultStyleSheet(const QString &sheet);
|
---|
| 253 | QString defaultStyleSheet() const;
|
---|
| 254 | #endif
|
---|
| 255 |
|
---|
| 256 | void undo(QTextCursor *cursor);
|
---|
| 257 | void redo(QTextCursor *cursor);
|
---|
| 258 |
|
---|
| 259 | int maximumBlockCount() const;
|
---|
| 260 | void setMaximumBlockCount(int maximum);
|
---|
| 261 |
|
---|
| 262 | QTextOption defaultTextOption() const;
|
---|
| 263 | void setDefaultTextOption(const QTextOption &option);
|
---|
| 264 |
|
---|
| 265 | Q_SIGNALS:
|
---|
| 266 | void contentsChange(int from, int charsRemoves, int charsAdded);
|
---|
| 267 | void contentsChanged();
|
---|
| 268 | void undoAvailable(bool);
|
---|
| 269 | void redoAvailable(bool);
|
---|
| 270 | void undoCommandAdded();
|
---|
| 271 | void modificationChanged(bool m);
|
---|
| 272 | void cursorPositionChanged(const QTextCursor &cursor);
|
---|
| 273 | void blockCountChanged(int newBlockCount);
|
---|
| 274 |
|
---|
| 275 | void documentLayoutChanged();
|
---|
| 276 |
|
---|
| 277 | public Q_SLOTS:
|
---|
| 278 | void undo();
|
---|
| 279 | void redo();
|
---|
| 280 | void appendUndoItem(QAbstractUndoItem *);
|
---|
| 281 | void setModified(bool m = true);
|
---|
| 282 |
|
---|
| 283 | protected:
|
---|
| 284 | virtual QTextObject *createObject(const QTextFormat &f);
|
---|
| 285 | virtual QVariant loadResource(int type, const QUrl &name);
|
---|
| 286 |
|
---|
| 287 | QTextDocument(QTextDocumentPrivate &dd, QObject *parent);
|
---|
| 288 | public:
|
---|
| 289 | QTextDocumentPrivate *docHandle() const;
|
---|
| 290 | private:
|
---|
| 291 | Q_DISABLE_COPY(QTextDocument)
|
---|
| 292 | Q_DECLARE_PRIVATE(QTextDocument)
|
---|
| 293 | friend class QTextObjectPrivate;
|
---|
| 294 | };
|
---|
| 295 |
|
---|
| 296 | Q_DECLARE_OPERATORS_FOR_FLAGS(QTextDocument::FindFlags)
|
---|
| 297 |
|
---|
| 298 | QT_END_NAMESPACE
|
---|
| 299 |
|
---|
| 300 | QT_END_HEADER
|
---|
| 301 |
|
---|
| 302 | #endif // QTEXTDOCUMENT_H
|
---|