qtextobject.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QTEXTOBJECT_H
00043 #define QTEXTOBJECT_H
00044 
00045 #include <QtCore/qobject.h>
00046 #include <QtGui/qtextformat.h>
00047 
00048 QT_BEGIN_HEADER
00049 
00050 QT_BEGIN_NAMESPACE
00051 
00052 QT_MODULE(Gui)
00053 
00054 class QTextObjectPrivate;
00055 class QTextDocument;
00056 class QTextDocumentPrivate;
00057 class QTextCursor;
00058 class QTextBlock;
00059 class QTextFragment;
00060 class QTextLayout;
00061 class QTextList;
00062 
00063 class Q_GUI_EXPORT QTextObject : public QObject
00064 {
00065     Q_OBJECT
00066 
00067 protected:
00068     explicit QTextObject(QTextDocument *doc);
00069     ~QTextObject();
00070 
00071     void setFormat(const QTextFormat &format);
00072 
00073 public:
00074     QTextFormat format() const;
00075     int formatIndex() const;
00076 
00077     QTextDocument *document() const;
00078 
00079     int objectIndex() const;
00080 
00081     QTextDocumentPrivate *docHandle() const;
00082 
00083 protected:
00084     QTextObject(QTextObjectPrivate &p, QTextDocument *doc);
00085 
00086 private:
00087     Q_DECLARE_PRIVATE(QTextObject)
00088     Q_DISABLE_COPY(QTextObject)
00089     friend class QTextDocumentPrivate;
00090 };
00091 
00092 class QTextBlockGroupPrivate;
00093 class Q_GUI_EXPORT QTextBlockGroup : public QTextObject
00094 {
00095     Q_OBJECT
00096 
00097 protected:
00098     explicit QTextBlockGroup(QTextDocument *doc);
00099     ~QTextBlockGroup();
00100 
00101     virtual void blockInserted(const QTextBlock &block);
00102     virtual void blockRemoved(const QTextBlock &block);
00103     virtual void blockFormatChanged(const QTextBlock &block);
00104 
00105     QList<QTextBlock> blockList() const;
00106 
00107 protected:
00108     QTextBlockGroup(QTextBlockGroupPrivate &p, QTextDocument *doc);
00109 private:
00110     Q_DECLARE_PRIVATE(QTextBlockGroup)
00111     Q_DISABLE_COPY(QTextBlockGroup)
00112     friend class QTextDocumentPrivate;
00113 };
00114 
00115 class Q_GUI_EXPORT QTextFrameLayoutData {
00116 public:
00117     virtual ~QTextFrameLayoutData();
00118 };
00119 
00120 class QTextFramePrivate;
00121 class Q_GUI_EXPORT QTextFrame : public QTextObject
00122 {
00123     Q_OBJECT
00124 
00125 public:
00126     explicit QTextFrame(QTextDocument *doc);
00127     ~QTextFrame();
00128 
00129     inline void setFrameFormat(const QTextFrameFormat &format);
00130     QTextFrameFormat frameFormat() const { return QTextObject::format().toFrameFormat(); }
00131 
00132     QTextCursor firstCursorPosition() const;
00133     QTextCursor lastCursorPosition() const;
00134     int firstPosition() const;
00135     int lastPosition() const;
00136 
00137     QTextFrameLayoutData *layoutData() const;
00138     void setLayoutData(QTextFrameLayoutData *data);
00139 
00140     QList<QTextFrame *> childFrames() const;
00141     QTextFrame *parentFrame() const;
00142 
00143     class Q_GUI_EXPORT iterator {
00144         QTextFrame *f;
00145         int b;
00146         int e;
00147         QTextFrame *cf;
00148         int cb;
00149 
00150         friend class QTextFrame;
00151         friend class QTextTableCell;
00152         friend class QTextDocumentLayoutPrivate;
00153         iterator(QTextFrame *frame, int block, int begin, int end);
00154     public:
00155         iterator();
00156         iterator(const iterator &o);
00157         iterator &operator=(const iterator &o);
00158 
00159         QTextFrame *parentFrame() const { return f; }
00160 
00161         QTextFrame *currentFrame() const;
00162         QTextBlock currentBlock() const;
00163 
00164         bool atEnd() const { return !cf && cb == e; }
00165 
00166         inline bool operator==(const iterator &o) const { return f == o.f && cf == o.cf && cb == o.cb; }
00167         inline bool operator!=(const iterator &o) const { return f != o.f || cf != o.cf || cb != o.cb; }
00168         iterator &operator++();
00169         inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
00170         iterator &operator--();
00171         inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
00172     };
00173 
00174     friend class iterator;
00175     // more Qt
00176     typedef iterator Iterator;
00177 
00178     iterator begin() const;
00179     iterator end() const;
00180 
00181 protected:
00182     QTextFrame(QTextFramePrivate &p, QTextDocument *doc);
00183 private:
00184     friend class QTextDocumentPrivate;
00185     Q_DECLARE_PRIVATE(QTextFrame)
00186     Q_DISABLE_COPY(QTextFrame)
00187 };
00188 Q_DECLARE_TYPEINFO(QTextFrame::iterator, Q_MOVABLE_TYPE);
00189 
00190 inline void QTextFrame::setFrameFormat(const QTextFrameFormat &aformat)
00191 { QTextObject::setFormat(aformat); }
00192 
00193 class Q_GUI_EXPORT QTextBlockUserData {
00194 public:
00195     virtual ~QTextBlockUserData();
00196 };
00197 
00198 class Q_GUI_EXPORT QTextBlock
00199 {
00200     friend class QSyntaxHighlighter;
00201 public:
00202     inline QTextBlock(QTextDocumentPrivate *priv, int b) : p(priv), n(b) {}
00203     inline QTextBlock() : p(0), n(0) {}
00204     inline QTextBlock(const QTextBlock &o) : p(o.p), n(o.n) {}
00205     inline QTextBlock &operator=(const QTextBlock &o) { p = o.p; n = o.n; return *this; }
00206 
00207     inline bool isValid() const { return p != 0 && n != 0; }
00208 
00209     inline bool operator==(const QTextBlock &o) const { return p == o.p && n == o.n; }
00210     inline bool operator!=(const QTextBlock &o) const { return p != o.p || n != o.n; }
00211     inline bool operator<(const QTextBlock &o) const { return position() < o.position(); }
00212 
00213     int position() const;
00214     int length() const;
00215     bool contains(int position) const;
00216 
00217     QTextLayout *layout() const;
00218     void clearLayout();
00219     QTextBlockFormat blockFormat() const;
00220     int blockFormatIndex() const;
00221     QTextCharFormat charFormat() const;
00222     int charFormatIndex() const;
00223 
00224     Qt::LayoutDirection textDirection() const;
00225 
00226     QString text() const;
00227 
00228     const QTextDocument *document() const;
00229 
00230     QTextList *textList() const;
00231 
00232     QTextBlockUserData *userData() const;
00233     void setUserData(QTextBlockUserData *data);
00234 
00235     int userState() const;
00236     void setUserState(int state);
00237 
00238     int revision() const;
00239     void setRevision(int rev);
00240 
00241     bool isVisible() const;
00242     void setVisible(bool visible);
00243 
00244     int blockNumber() const;
00245     int firstLineNumber() const;
00246 
00247     void setLineCount(int count);
00248     int lineCount() const;
00249 
00250     class Q_GUI_EXPORT iterator {
00251         const QTextDocumentPrivate *p;
00252         int b;
00253         int e;
00254         int n;
00255         friend class QTextBlock;
00256         iterator(const QTextDocumentPrivate *priv, int begin, int end, int f) : p(priv), b(begin), e(end), n(f) {}
00257     public:
00258         iterator() : p(0), b(0), e(0), n(0) {}
00259         iterator(const iterator &o) : p(o.p), b(o.b), e(o.e), n(o.n) {}
00260 
00261         QTextFragment fragment() const;
00262 
00263         bool atEnd() const { return n == e; }
00264 
00265         inline bool operator==(const iterator &o) const { return p == o.p && n == o.n; }
00266         inline bool operator!=(const iterator &o) const { return p != o.p || n != o.n; }
00267         iterator &operator++();
00268         inline iterator operator++(int) { iterator tmp = *this; operator++(); return tmp; }
00269         iterator &operator--();
00270         inline iterator operator--(int) { iterator tmp = *this; operator--(); return tmp; }
00271     };
00272 
00273     // more Qt
00274     typedef iterator Iterator;
00275 
00276     iterator begin() const;
00277     iterator end() const;
00278 
00279     QTextBlock next() const;
00280     QTextBlock previous() const;
00281 
00282     inline QTextDocumentPrivate *docHandle() const { return p; }
00283     inline int fragmentIndex() const { return n; }
00284 
00285 private:
00286     QTextDocumentPrivate *p;
00287     int n;
00288     friend class QTextDocumentPrivate;
00289     friend class QTextLayout;
00290 };
00291 
00292 Q_DECLARE_TYPEINFO(QTextBlock, Q_MOVABLE_TYPE);
00293 Q_DECLARE_TYPEINFO(QTextBlock::iterator, Q_MOVABLE_TYPE);
00294 
00295 
00296 class Q_GUI_EXPORT QTextFragment
00297 {
00298 public:
00299     inline QTextFragment(const QTextDocumentPrivate *priv, int f, int fe) : p(priv), n(f), ne(fe) {}
00300     inline QTextFragment() : p(0), n(0), ne(0) {}
00301     inline QTextFragment(const QTextFragment &o) : p(o.p), n(o.n), ne(o.ne) {}
00302     inline QTextFragment &operator=(const QTextFragment &o) { p = o.p; n = o.n; ne = o.ne; return *this; }
00303 
00304     inline bool isValid() const { return p && n; }
00305 
00306     inline bool operator==(const QTextFragment &o) const { return p == o.p && n == o.n; }
00307     inline bool operator!=(const QTextFragment &o) const { return p != o.p || n != o.n; }
00308     inline bool operator<(const QTextFragment &o) const { return position() < o.position(); }
00309 
00310     int position() const;
00311     int length() const;
00312     bool contains(int position) const;
00313 
00314     QTextCharFormat charFormat() const;
00315     int charFormatIndex() const;
00316     QString text() const;
00317 
00318 private:
00319     const QTextDocumentPrivate *p;
00320     int n;
00321     int ne;
00322 };
00323 
00324 Q_DECLARE_TYPEINFO(QTextFragment, Q_MOVABLE_TYPE);
00325 
00326 QT_END_NAMESPACE
00327 
00328 QT_END_HEADER
00329 
00330 #endif // QTEXTOBJECT_H