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