| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial Usage | 
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and Nokia. | 
|---|
| 14 | ** | 
|---|
| 15 | ** GNU Lesser General Public License Usage | 
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 19 | ** packaging of this file.  Please review the following information to | 
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 22 | ** | 
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
| 26 | ** package. | 
|---|
| 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 | ** | 
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please | 
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #ifndef QTEXTOBJECT_H | 
|---|
| 43 | #define QTEXTOBJECT_H | 
|---|
| 44 |  | 
|---|
| 45 | #include <QtCore/qobject.h> | 
|---|
| 46 | #include <QtGui/qtextformat.h> | 
|---|
| 47 |  | 
|---|
| 48 | QT_BEGIN_HEADER | 
|---|
| 49 |  | 
|---|
| 50 | QT_BEGIN_NAMESPACE | 
|---|
| 51 |  | 
|---|
| 52 | QT_MODULE(Gui) | 
|---|
| 53 |  | 
|---|
| 54 | class QTextObjectPrivate; | 
|---|
| 55 | class QTextDocument; | 
|---|
| 56 | class QTextDocumentPrivate; | 
|---|
| 57 | class QTextCursor; | 
|---|
| 58 | class QTextBlock; | 
|---|
| 59 | class QTextFragment; | 
|---|
| 60 | class QTextLayout; | 
|---|
| 61 | class QTextList; | 
|---|
| 62 |  | 
|---|
| 63 | class Q_GUI_EXPORT QTextObject : public QObject | 
|---|
| 64 | { | 
|---|
| 65 | Q_OBJECT | 
|---|
| 66 |  | 
|---|
| 67 | protected: | 
|---|
| 68 | explicit QTextObject(QTextDocument *doc); | 
|---|
| 69 | ~QTextObject(); | 
|---|
| 70 |  | 
|---|
| 71 | void setFormat(const QTextFormat &format); | 
|---|
| 72 |  | 
|---|
| 73 | public: | 
|---|
| 74 | QTextFormat format() const; | 
|---|
| 75 | int formatIndex() const; | 
|---|
| 76 |  | 
|---|
| 77 | QTextDocument *document() const; | 
|---|
| 78 |  | 
|---|
| 79 | int objectIndex() const; | 
|---|
| 80 |  | 
|---|
| 81 | QTextDocumentPrivate *docHandle() const; | 
|---|
| 82 |  | 
|---|
| 83 | protected: | 
|---|
| 84 | QTextObject(QTextObjectPrivate &p, QTextDocument *doc); | 
|---|
| 85 |  | 
|---|
| 86 | private: | 
|---|
| 87 | Q_DECLARE_PRIVATE(QTextObject) | 
|---|
| 88 | Q_DISABLE_COPY(QTextObject) | 
|---|
| 89 | friend class QTextDocumentPrivate; | 
|---|
| 90 | }; | 
|---|
| 91 |  | 
|---|
| 92 | class QTextBlockGroupPrivate; | 
|---|
| 93 | class Q_GUI_EXPORT QTextBlockGroup : public QTextObject | 
|---|
| 94 | { | 
|---|
| 95 | Q_OBJECT | 
|---|
| 96 |  | 
|---|
| 97 | protected: | 
|---|
| 98 | explicit QTextBlockGroup(QTextDocument *doc); | 
|---|
| 99 | ~QTextBlockGroup(); | 
|---|
| 100 |  | 
|---|
| 101 | virtual void blockInserted(const QTextBlock &block); | 
|---|
| 102 | virtual void blockRemoved(const QTextBlock &block); | 
|---|
| 103 | virtual void blockFormatChanged(const QTextBlock &block); | 
|---|
| 104 |  | 
|---|
| 105 | QList<QTextBlock> blockList() const; | 
|---|
| 106 |  | 
|---|
| 107 | protected: | 
|---|
| 108 | QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc); | 
|---|
| 109 | private: | 
|---|
| 110 | Q_DECLARE_PRIVATE(QTextBlockGroup) | 
|---|
| 111 | Q_DISABLE_COPY(QTextBlockGroup) | 
|---|
| 112 | friend class QTextDocumentPrivate; | 
|---|
| 113 | }; | 
|---|
| 114 |  | 
|---|
| 115 | class Q_GUI_EXPORT QTextFrameLayoutData { | 
|---|
| 116 | public: | 
|---|
| 117 | virtual ~QTextFrameLayoutData(); | 
|---|
| 118 | }; | 
|---|
| 119 |  | 
|---|
| 120 | class QTextFramePrivate; | 
|---|
| 121 | class Q_GUI_EXPORT QTextFrame : public QTextObject | 
|---|
| 122 | { | 
|---|
| 123 | Q_OBJECT | 
|---|
| 124 |  | 
|---|
| 125 | public: | 
|---|
| 126 | explicit QTextFrame(QTextDocument *doc); | 
|---|
| 127 | ~QTextFrame(); | 
|---|
| 128 |  | 
|---|
| 129 | inline void setFrameFormat(const QTextFrameFormat &format); | 
|---|
| 130 | QTextFrameFormat frameFormat() const { return QTextObject::format().toFrameFormat(); } | 
|---|
| 131 |  | 
|---|
| 132 | QTextCursor firstCursorPosition() const; | 
|---|
| 133 | QTextCursor lastCursorPosition() const; | 
|---|
| 134 | int firstPosition() const; | 
|---|
| 135 | int lastPosition() const; | 
|---|
| 136 |  | 
|---|
| 137 | QTextFrameLayoutData *layoutData() const; | 
|---|
| 138 | void setLayoutData(QTextFrameLayoutData *data); | 
|---|
| 139 |  | 
|---|
| 140 | QList<QTextFrame *> childFrames() const; | 
|---|
| 141 | QTextFrame *parentFrame() const; | 
|---|
| 142 |  | 
|---|
| 143 | class Q_GUI_EXPORT iterator { | 
|---|
| 144 | QTextFrame *f; | 
|---|
| 145 | int b; | 
|---|
| 146 | int e; | 
|---|
| 147 | QTextFrame *cf; | 
|---|
| 148 | int cb; | 
|---|
| 149 |  | 
|---|
| 150 | friend class QTextFrame; | 
|---|
| 151 | friend class QTextTableCell; | 
|---|
| 152 | friend class QTextDocumentLayoutPrivate; | 
|---|
| 153 | iterator(QTextFrame *frame, int block, int begin, int end); | 
|---|
| 154 | public: | 
|---|
| 155 | iterator(); | 
|---|
| 156 | iterator(const iterator &o); | 
|---|
| 157 | iterator &operator=(const iterator &o); | 
|---|
| 158 |  | 
|---|
| 159 | QTextFrame *parentFrame() const { return f; } | 
|---|
| 160 |  | 
|---|
| 161 | QTextFrame *currentFrame() const; | 
|---|
| 162 | QTextBlock currentBlock() const; | 
|---|
| 163 |  | 
|---|
| 164 | bool atEnd() const { return !cf && cb == e; } | 
|---|
| 165 |  | 
|---|
| 166 | inline bool operator==(const iterator &o) const { return f == o.f && cf == o.cf && cb == o.cb; } | 
|---|
| 167 | inline bool operator!=(const iterator &o) const { return f != o.f || cf != o.cf || cb != o.cb; } | 
|---|
| 168 | iterator &operator++(); | 
|---|
| 169 | inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; } | 
|---|
| 170 | iterator &operator--(); | 
|---|
| 171 | inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; } | 
|---|
| 172 | }; | 
|---|
| 173 |  | 
|---|
| 174 | friend class iterator; | 
|---|
| 175 | // more Qt | 
|---|
| 176 | typedef iterator Iterator; | 
|---|
| 177 |  | 
|---|
| 178 | iterator begin() const; | 
|---|
| 179 | iterator end() const; | 
|---|
| 180 |  | 
|---|
| 181 | protected: | 
|---|
| 182 | QTextFrame(QTextFramePrivate &p, QTextDocument *doc); | 
|---|
| 183 | private: | 
|---|
| 184 | friend class QTextDocumentPrivate; | 
|---|
| 185 | Q_DECLARE_PRIVATE(QTextFrame) | 
|---|
| 186 | Q_DISABLE_COPY(QTextFrame) | 
|---|
| 187 | }; | 
|---|
| 188 | Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE); | 
|---|
| 189 |  | 
|---|
| 190 | inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat) | 
|---|
| 191 | { QTextObject::setFormat(aformat); } | 
|---|
| 192 |  | 
|---|
| 193 | class Q_GUI_EXPORT QTextBlockUserData { | 
|---|
| 194 | public: | 
|---|
| 195 | virtual ~QTextBlockUserData(); | 
|---|
| 196 | }; | 
|---|
| 197 |  | 
|---|
| 198 | class Q_GUI_EXPORT QTextBlock | 
|---|
| 199 | { | 
|---|
| 200 | friend class QSyntaxHighlighter; | 
|---|
| 201 | public: | 
|---|
| 202 | inline QTextBlock(QTextDocumentPrivate *priv, int b) : p(priv), n(b) {} | 
|---|
| 203 | inline QTextBlock() : p(0), n(0) {} | 
|---|
| 204 | inline QTextBlock(const QTextBlock &o) : p(o.p), n(o.n) {} | 
|---|
| 205 | inline QTextBlock &operator=(const QTextBlock &o) { p = o.p; n = o.n; return *this; } | 
|---|
| 206 |  | 
|---|
| 207 | inline bool isValid() const { return p != 0 && n != 0; } | 
|---|
| 208 |  | 
|---|
| 209 | inline bool operator==(const QTextBlock &o) const { return p == o.p && n == o.n; } | 
|---|
| 210 | inline bool operator!=(const QTextBlock &o) const { return p != o.p || n != o.n; } | 
|---|
| 211 | inline bool operator<(const QTextBlock &o) const { return position() < o.position(); } | 
|---|
| 212 |  | 
|---|
| 213 | int position() const; | 
|---|
| 214 | int length() const; | 
|---|
| 215 | bool contains(int position) const; | 
|---|
| 216 |  | 
|---|
| 217 | QTextLayout *layout() const; | 
|---|
| 218 | void clearLayout(); | 
|---|
| 219 | QTextBlockFormat blockFormat() const; | 
|---|
| 220 | int blockFormatIndex() const; | 
|---|
| 221 | QTextCharFormat charFormat() const; | 
|---|
| 222 | int charFormatIndex() const; | 
|---|
| 223 |  | 
|---|
| 224 | QString text() const; | 
|---|
| 225 |  | 
|---|
| 226 | const QTextDocument *document() const; | 
|---|
| 227 |  | 
|---|
| 228 | QTextList *textList() const; | 
|---|
| 229 |  | 
|---|
| 230 | QTextBlockUserData *userData() const; | 
|---|
| 231 | void setUserData(QTextBlockUserData *data); | 
|---|
| 232 |  | 
|---|
| 233 | int userState() const; | 
|---|
| 234 | void setUserState(int state); | 
|---|
| 235 |  | 
|---|
| 236 | int revision() const; | 
|---|
| 237 | void setRevision(int rev); | 
|---|
| 238 |  | 
|---|
| 239 | bool isVisible() const; | 
|---|
| 240 | void setVisible(bool visible); | 
|---|
| 241 |  | 
|---|
| 242 | int blockNumber() const; | 
|---|
| 243 | int firstLineNumber() const; | 
|---|
| 244 |  | 
|---|
| 245 | void setLineCount(int count); | 
|---|
| 246 | int lineCount() const; | 
|---|
| 247 |  | 
|---|
| 248 | class Q_GUI_EXPORT iterator { | 
|---|
| 249 | const QTextDocumentPrivate *p; | 
|---|
| 250 | int b; | 
|---|
| 251 | int e; | 
|---|
| 252 | int n; | 
|---|
| 253 | friend class QTextBlock; | 
|---|
| 254 | iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {} | 
|---|
| 255 | public: | 
|---|
| 256 | iterator() : p(0), b(0), e(0), n(0) {} | 
|---|
| 257 | iterator(const iterator &o) : p(o.p), b(o.b), e(o.e), n(o.n) {} | 
|---|
| 258 |  | 
|---|
| 259 | QTextFragment fragment() const; | 
|---|
| 260 |  | 
|---|
| 261 | bool atEnd() const { return n == e; } | 
|---|
| 262 |  | 
|---|
| 263 | inline bool operator==(const iterator &o) const { return p == o.p && n == o.n; } | 
|---|
| 264 | inline bool operator!=(const iterator &o) const { return p != o.p || n != o.n; } | 
|---|
| 265 | iterator &operator++(); | 
|---|
| 266 | inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; } | 
|---|
| 267 | iterator &operator--(); | 
|---|
| 268 | inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; } | 
|---|
| 269 | }; | 
|---|
| 270 |  | 
|---|
| 271 | // more Qt | 
|---|
| 272 | typedef iterator Iterator; | 
|---|
| 273 |  | 
|---|
| 274 | iterator begin() const; | 
|---|
| 275 | iterator end() const; | 
|---|
| 276 |  | 
|---|
| 277 | QTextBlock next() const; | 
|---|
| 278 | QTextBlock previous() const; | 
|---|
| 279 |  | 
|---|
| 280 | inline QTextDocumentPrivate *docHandle() const { return p; } | 
|---|
| 281 | inline int fragmentIndex() const { return n; } | 
|---|
| 282 |  | 
|---|
| 283 | private: | 
|---|
| 284 | QTextDocumentPrivate *p; | 
|---|
| 285 | int n; | 
|---|
| 286 | friend class QTextDocumentPrivate; | 
|---|
| 287 | friend class QTextLayout; | 
|---|
| 288 | }; | 
|---|
| 289 |  | 
|---|
| 290 | Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE); | 
|---|
| 291 | Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE); | 
|---|
| 292 |  | 
|---|
| 293 |  | 
|---|
| 294 | class Q_GUI_EXPORT QTextFragment | 
|---|
| 295 | { | 
|---|
| 296 | public: | 
|---|
| 297 | inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {} | 
|---|
| 298 | inline QTextFragment() : p(0), n(0), ne(0) {} | 
|---|
| 299 | inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {} | 
|---|
| 300 | inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; } | 
|---|
| 301 |  | 
|---|
| 302 | inline bool isValid() const { return p && n; } | 
|---|
| 303 |  | 
|---|
| 304 | inline bool operator==(const QTextFragment &o) const { return p == o.p && n == o.n; } | 
|---|
| 305 | inline bool operator!=(const QTextFragment &o) const { return p != o.p || n != o.n; } | 
|---|
| 306 | inline bool operator<(const QTextFragment &o) const { return position() < o.position(); } | 
|---|
| 307 |  | 
|---|
| 308 | int position() const; | 
|---|
| 309 | int length() const; | 
|---|
| 310 | bool contains(int position) const; | 
|---|
| 311 |  | 
|---|
| 312 | QTextCharFormat charFormat() const; | 
|---|
| 313 | int charFormatIndex() const; | 
|---|
| 314 | QString text() const; | 
|---|
| 315 |  | 
|---|
| 316 | private: | 
|---|
| 317 | const QTextDocumentPrivate *p; | 
|---|
| 318 | int n; | 
|---|
| 319 | int ne; | 
|---|
| 320 | }; | 
|---|
| 321 |  | 
|---|
| 322 | Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE); | 
|---|
| 323 |  | 
|---|
| 324 | QT_END_NAMESPACE | 
|---|
| 325 |  | 
|---|
| 326 | QT_END_HEADER | 
|---|
| 327 |  | 
|---|
| 328 | #endif // QTEXTOBJECT_H | 
|---|