[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation (qt-info@nokia.com)
|
---|
[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 qt-info@nokia.com.
|
---|
[2] | 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 |
|
---|
[846] | 224 | Qt::LayoutDirection textDirection() const;
|
---|
| 225 |
|
---|
[2] | 226 | QString text() const;
|
---|
| 227 |
|
---|
| 228 | const QTextDocument *document() const;
|
---|
| 229 |
|
---|
| 230 | QTextList *textList() const;
|
---|
| 231 |
|
---|
| 232 | QTextBlockUserData *userData() const;
|
---|
| 233 | void setUserData(QTextBlockUserData *data);
|
---|
| 234 |
|
---|
| 235 | int userState() const;
|
---|
| 236 | void setUserState(int state);
|
---|
| 237 |
|
---|
| 238 | int revision() const;
|
---|
| 239 | void setRevision(int rev);
|
---|
| 240 |
|
---|
| 241 | bool isVisible() const;
|
---|
| 242 | void setVisible(bool visible);
|
---|
| 243 |
|
---|
| 244 | int blockNumber() const;
|
---|
| 245 | int firstLineNumber() const;
|
---|
| 246 |
|
---|
| 247 | void setLineCount(int count);
|
---|
| 248 | int lineCount() const;
|
---|
| 249 |
|
---|
| 250 | class Q_GUI_EXPORT iterator {
|
---|
| 251 | const QTextDocumentPrivate *p;
|
---|
| 252 | int b;
|
---|
| 253 | int e;
|
---|
| 254 | int n;
|
---|
| 255 | friend class QTextBlock;
|
---|
| 256 | iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {}
|
---|
| 257 | public:
|
---|
| 258 | iterator() : p(0), b(0), e(0), n(0) {}
|
---|
| 259 | iterator(const iterator &o) : p(o.p), b(o.b), e(o.e), n(o.n) {}
|
---|
| 260 |
|
---|
| 261 | QTextFragment fragment() const;
|
---|
| 262 |
|
---|
| 263 | bool atEnd() const { return n == e; }
|
---|
| 264 |
|
---|
| 265 | inline bool operator==(const iterator &o) const { return p == o.p && n == o.n; }
|
---|
| 266 | inline bool operator!=(const iterator &o) const { return p != o.p || n != o.n; }
|
---|
| 267 | iterator &operator++();
|
---|
| 268 | inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
|
---|
| 269 | iterator &operator--();
|
---|
| 270 | inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
|
---|
| 271 | };
|
---|
| 272 |
|
---|
| 273 | // more Qt
|
---|
| 274 | typedef iterator Iterator;
|
---|
| 275 |
|
---|
| 276 | iterator begin() const;
|
---|
| 277 | iterator end() const;
|
---|
| 278 |
|
---|
| 279 | QTextBlock next() const;
|
---|
| 280 | QTextBlock previous() const;
|
---|
| 281 |
|
---|
| 282 | inline QTextDocumentPrivate *docHandle() const { return p; }
|
---|
| 283 | inline int fragmentIndex() const { return n; }
|
---|
| 284 |
|
---|
| 285 | private:
|
---|
| 286 | QTextDocumentPrivate *p;
|
---|
| 287 | int n;
|
---|
| 288 | friend class QTextDocumentPrivate;
|
---|
| 289 | friend class QTextLayout;
|
---|
| 290 | };
|
---|
| 291 |
|
---|
| 292 | Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
|
---|
| 293 | Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE);
|
---|
| 294 |
|
---|
| 295 |
|
---|
| 296 | class Q_GUI_EXPORT QTextFragment
|
---|
| 297 | {
|
---|
| 298 | public:
|
---|
| 299 | inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {}
|
---|
| 300 | inline QTextFragment() : p(0), n(0), ne(0) {}
|
---|
| 301 | inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {}
|
---|
| 302 | inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; }
|
---|
| 303 |
|
---|
| 304 | inline bool isValid() const { return p && n; }
|
---|
| 305 |
|
---|
| 306 | inline bool operator==(const QTextFragment &o) const { return p == o.p && n == o.n; }
|
---|
| 307 | inline bool operator!=(const QTextFragment &o) const { return p != o.p || n != o.n; }
|
---|
| 308 | inline bool operator<(const QTextFragment &o) const { return position() < o.position(); }
|
---|
| 309 |
|
---|
| 310 | int position() const;
|
---|
| 311 | int length() const;
|
---|
| 312 | bool contains(int position) const;
|
---|
| 313 |
|
---|
| 314 | QTextCharFormat charFormat() const;
|
---|
| 315 | int charFormatIndex() const;
|
---|
| 316 | QString text() const;
|
---|
| 317 |
|
---|
| 318 | private:
|
---|
| 319 | const QTextDocumentPrivate *p;
|
---|
| 320 | int n;
|
---|
| 321 | int ne;
|
---|
| 322 | };
|
---|
| 323 |
|
---|
| 324 | Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE);
|
---|
| 325 |
|
---|
| 326 | QT_END_NAMESPACE
|
---|
| 327 |
|
---|
| 328 | QT_END_HEADER
|
---|
| 329 |
|
---|
| 330 | #endif // QTEXTOBJECT_H
|
---|