~oif-team/ubuntu/natty/qt4-x11/xi2.1

« back to all changes in this revision

Viewing changes to src/gui/text/qtextlayout.h

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-08-24 04:09:09 UTC
  • Revision ID: james.westby@ubuntu.com-20050824040909-xmxe9jfr4a0w5671
Tags: upstream-4.0.0
ImportĀ upstreamĀ versionĀ 4.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/****************************************************************************
 
2
**
 
3
** Copyright (C) 1992-2005 Trolltech AS. All rights reserved.
 
4
**
 
5
** This file is part of the text module of the Qt Toolkit.
 
6
**
 
7
** This file may be distributed under the terms of the Q Public License
 
8
** as defined by Trolltech AS of Norway and appearing in the file
 
9
** LICENSE.QPL included in the packaging of this file.
 
10
**
 
11
** This file may be distributed and/or modified under the terms of the
 
12
** GNU General Public License version 2 as published by the Free Software
 
13
** Foundation and appearing in the file LICENSE.GPL included in the
 
14
** packaging of this file.
 
15
**
 
16
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
 
17
**   information about Qt Commercial License Agreements.
 
18
** See http://www.trolltech.com/qpl/ for QPL licensing information.
 
19
** See http://www.trolltech.com/gpl/ for GPL licensing information.
 
20
**
 
21
** Contact info@trolltech.com if any conditions of this licensing are
 
22
** not clear to you.
 
23
**
 
24
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 
25
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
26
**
 
27
****************************************************************************/
 
28
#ifndef QTEXTLAYOUT_H
 
29
#define QTEXTLAYOUT_H
 
30
 
 
31
#include "QtCore/qstring.h"
 
32
#include "QtCore/qnamespace.h"
 
33
#include "QtCore/qrect.h"
 
34
#include "QtCore/qvector.h"
 
35
#include "QtGui/qcolor.h"
 
36
#include "QtCore/qobject.h"
 
37
#include "QtGui/qevent.h"
 
38
#include "QtGui/qtextformat.h"
 
39
 
 
40
class QTextEngine;
 
41
class QFont;
 
42
class QRect;
 
43
class QRegion;
 
44
class QTextFormat;
 
45
class QPalette;
 
46
class QPainter;
 
47
 
 
48
class Q_GUI_EXPORT QTextInlineObject
 
49
{
 
50
public:
 
51
    QTextInlineObject(int i, QTextEngine *e) : itm(i), eng(e) {}
 
52
    inline QTextInlineObject() : itm(0), eng(0) {}
 
53
    inline bool isValid() const { return eng; }
 
54
 
 
55
    QRectF rect() const;
 
56
    qreal width() const;
 
57
    qreal ascent() const;
 
58
    qreal descent() const;
 
59
    qreal height() const;
 
60
 
 
61
    Qt::LayoutDirection textDirection() const;
 
62
 
 
63
    void setWidth(qreal w);
 
64
    void setAscent(qreal a);
 
65
    void setDescent(qreal d);
 
66
 
 
67
    int textPosition() const;
 
68
 
 
69
    int formatIndex() const;
 
70
    QTextFormat format() const;
 
71
 
 
72
private:
 
73
    friend class QTextLayout;
 
74
    int itm;
 
75
    QTextEngine *eng;
 
76
};
 
77
 
 
78
class QPaintDevice;
 
79
class QTextFormat;
 
80
class QTextLine;
 
81
class QTextBlock;
 
82
class QTextOption;
 
83
 
 
84
class Q_GUI_EXPORT QTextLayout
 
85
{
 
86
public:
 
87
    // does itemization
 
88
    QTextLayout();
 
89
    QTextLayout(const QString& text);
 
90
    QTextLayout(const QString& text, const QFont &font, QPaintDevice *paintdevice = 0);
 
91
    QTextLayout(const QTextBlock &b);
 
92
    ~QTextLayout();
 
93
 
 
94
    void setFont(const QFont &f);
 
95
    QFont font() const;
 
96
 
 
97
    void setText(const QString& string);
 
98
    QString text() const;
 
99
 
 
100
    void setTextOption(const QTextOption &option);
 
101
    QTextOption textOption() const;
 
102
 
 
103
    void setPreeditArea(int position, const QString &text);
 
104
    int preeditAreaPosition() const;
 
105
    QString preeditAreaText() const;
 
106
 
 
107
    struct FormatRange {
 
108
        int start;
 
109
        int length;
 
110
        QTextCharFormat format;
 
111
    };
 
112
    void setAdditionalFormats(const QList<FormatRange> &overrides);
 
113
    QList<FormatRange> additionalFormats() const;
 
114
    void clearAdditionalFormats();
 
115
 
 
116
    void setCacheEnabled(bool enable);
 
117
    bool cacheEnabled() const;
 
118
 
 
119
    void beginLayout();
 
120
    void endLayout();
 
121
 
 
122
    QTextLine createLine();
 
123
 
 
124
    int lineCount() const;
 
125
    QTextLine lineAt(int i) const;
 
126
    QTextLine lineForTextPosition(int pos) const;
 
127
 
 
128
    enum CursorMode {
 
129
        SkipCharacters,
 
130
        SkipWords
 
131
    };
 
132
    bool isValidCursorPosition(int pos) const;
 
133
    int nextCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
 
134
    int previousCursorPosition(int oldPos, CursorMode mode = SkipCharacters) const;
 
135
 
 
136
    void draw(QPainter *p, const QPointF &pos, const QVector<FormatRange> &selections = QVector<FormatRange>(),
 
137
              const QRectF &clip = QRectF()) const;
 
138
    void drawCursor(QPainter *p, const QPointF &pos, int cursorPosition) const;
 
139
 
 
140
    QPointF position() const;
 
141
    void setPosition(const QPointF &p);
 
142
 
 
143
    QRectF boundingRect() const;
 
144
 
 
145
    qreal minimumWidth() const;
 
146
    qreal maximumWidth() const;
 
147
 
 
148
    QTextEngine *engine() const { return d; }
 
149
private:
 
150
    QTextLayout(QTextEngine *e) : d(e) {}
 
151
    Q_DISABLE_COPY(QTextLayout)
 
152
 
 
153
    friend class QPainter;
 
154
    friend class QPSPrinter;
 
155
    QTextEngine *d;
 
156
};
 
157
 
 
158
 
 
159
class Q_GUI_EXPORT QTextLine
 
160
{
 
161
public:
 
162
    inline QTextLine() : i(0), eng(0) {}
 
163
    inline bool isValid() const { return eng; }
 
164
 
 
165
    QRectF rect() const;
 
166
    qreal x() const;
 
167
    qreal y() const;
 
168
    qreal width() const;
 
169
    qreal ascent() const;
 
170
    qreal descent() const;
 
171
    qreal height() const;
 
172
 
 
173
    qreal naturalTextWidth() const;
 
174
    QRectF naturalTextRect() const;
 
175
 
 
176
    enum Edge {
 
177
        Leading,
 
178
        Trailing
 
179
    };
 
180
    enum CursorPosition {
 
181
        CursorBetweenCharacters,
 
182
        CursorOnCharacter
 
183
    };
 
184
 
 
185
    /* cursorPos gets set to the valid position */
 
186
    qreal cursorToX(int *cursorPos, Edge edge = Leading) const;
 
187
    inline qreal cursorToX(int cursorPos, Edge edge = Leading) const { return cursorToX(&cursorPos, edge); }
 
188
    int xToCursor(qreal x, CursorPosition = CursorBetweenCharacters) const;
 
189
 
 
190
    void setLineWidth(qreal width);
 
191
    void setNumColumns(int columns);
 
192
 
 
193
    void setPosition(const QPointF &pos);
 
194
 
 
195
    int textStart() const;
 
196
    int textLength() const;
 
197
 
 
198
    int lineNumber() const { return i; }
 
199
 
 
200
    void draw(QPainter *p, const QPointF &point, const QTextLayout::FormatRange *selection = 0) const;
 
201
 
 
202
private:
 
203
    QTextLine(int line, QTextEngine *e) : i(line), eng(e) {}
 
204
    void layout_helper(int numGlyphs);
 
205
    friend class QTextLayout;
 
206
    int i;
 
207
    QTextEngine *eng;
 
208
};
 
209
 
 
210
#endif // QTEXTLAYOUT_H