source: trunk/src/kernel/qtextlayout_p.h@ 10

Last change on this file since 10 was 2, checked in by dmik, 20 years ago

Imported xplatform parts of the official release 3.3.1 from Trolltech

  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1/****************************************************************************
2** $Id: qtextlayout_p.h 2 2005-11-16 15:49:26Z dmik $
3**
4** ???
5**
6** Copyright (C) 1992-2003 Trolltech AS. All rights reserved.
7**
8** This file is part of the kernel module of the Qt GUI Toolkit.
9**
10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file.
14**
15** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
16** licenses for Qt/Embedded may use this file in accordance with the
17** Qt Embedded Commercial License Agreement provided with the Software.
18**
19** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21**
22** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
23** information about Qt Commercial License Agreements.
24** See http://www.trolltech.com/gpl/ for GPL licensing information.
25**
26** Contact info@trolltech.com if any conditions of this licensing are
27** not clear to you.
28**
29**********************************************************************/
30
31#ifndef QTEXTLAYOUT_P_H
32#define QTEXTLAYOUT_P_H
33
34#ifndef QT_H
35#include "qstring.h"
36#include "qnamespace.h"
37#include "qrect.h"
38#endif // QT_H
39
40class QTextEngine;
41class QFont;
42
43class Q_EXPORT QTextItem
44{
45public:
46 inline QTextItem() : item(0), engine(0) {}
47 inline bool isValid() const { return (bool)engine; }
48
49 QRect rect() const;
50 int x() const;
51 int y() const;
52 int width() const;
53 int ascent() const;
54 int descent() const;
55
56 enum Edge {
57 Leading,
58 Trailing
59 };
60 enum CursorPosition {
61 BetweenCharacters,
62 OnCharacters
63 };
64
65 /* cPos gets set to the valid position */
66 int cursorToX( int *cPos, Edge edge = Leading ) const;
67 inline int cursorToX( int cPos, Edge edge = Leading ) const { return cursorToX( &cPos, edge ); }
68 int xToCursor( int x, CursorPosition = BetweenCharacters ) const;
69
70 bool isRightToLeft() const;
71 bool isObject() const;
72 bool isSpace() const;
73 bool isTab() const;
74
75 void setWidth( int w );
76 void setAscent( int a );
77 void setDescent( int d );
78
79 int from() const;
80 int length() const;
81
82private:
83 friend class QTextLayout;
84 friend class QPainter;
85 friend class QPSPrinter;
86 QTextItem( int i, QTextEngine *e ) : item( i ), engine( e ) {}
87 int item;
88 QTextEngine *engine;
89};
90
91
92class QPainter;
93
94class Q_EXPORT QTextLayout
95{
96public:
97 // does itemization
98 QTextLayout();
99 QTextLayout( const QString& string, QPainter * = 0 );
100 QTextLayout( const QString& string, const QFont& fnt );
101 ~QTextLayout();
102
103 void setText( const QString& string, const QFont& fnt );
104
105 enum LineBreakStrategy {
106 AtWordBoundaries,
107 AtCharBoundaries
108 };
109
110 /* add an additional item boundary eg. for style change */
111 void setBoundary( int strPos );
112
113 int numItems() const;
114 QTextItem itemAt( int i ) const;
115 QTextItem findItem( int strPos ) const;
116
117 enum LayoutMode {
118 NoBidi,
119 SingleLine,
120 MultiLine
121 };
122 void beginLayout( LayoutMode m = MultiLine );
123 void beginLine( int width );
124
125 bool atEnd() const;
126 QTextItem nextItem();
127 QTextItem currentItem();
128 /* ## maybe also currentItem() */
129 void setLineWidth( int newWidth );
130 int lineWidth() const;
131 int widthUsed() const;
132 int availableWidth() const;
133
134 enum Result {
135 Ok,
136 LineFull,
137 LineEmpty,
138 Error
139 };
140 /* returns true if completely added */
141 Result addCurrentItem();
142
143 /* Note: if ascent and descent are used they must be initialized to the minimum ascent/descent
144 acceptable for the line. QFontMetrics::ascent/descent() is usually the right choice */
145 Result endLine( int x = 0, int y = 0, int alignment = Qt::AlignLeft,
146 int *ascent = 0, int *descent = 0, int *left = 0, int *right = 0 );
147 void endLayout();
148
149 enum CursorMode {
150 SkipCharacters,
151 SkipWords
152 };
153 bool validCursorPosition( int pos ) const;
154 int nextCursorPosition( int oldPos, CursorMode mode = SkipCharacters ) const;
155 int previousCursorPosition( int oldPos, CursorMode mode = SkipCharacters ) const;
156
157private:
158 QTextLayout( QTextEngine *e ) : d( e ) {}
159 /* disable copy and assignment */
160 QTextLayout( const QTextLayout & ) {}
161 void operator = ( const QTextLayout & ) {}
162
163 friend class QTextItem;
164 friend class QPainter;
165 friend class QPSPrinter;
166 QTextEngine *d;
167};
168
169
170/*
171 class QPainter {
172 .....
173 void drawTextItem( int x, int y, QTextItem *item );
174 };
175*/
176
177#endif
Note: See TracBrowser for help on using the repository browser.