Diffstat (limited to 'noncore/apps/opie-write/qrichtext_p.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-write/qrichtext_p.h | 2158 |
1 files changed, 2158 insertions, 0 deletions
diff --git a/noncore/apps/opie-write/qrichtext_p.h b/noncore/apps/opie-write/qrichtext_p.h new file mode 100644 index 0000000..94ce913 --- a/dev/null +++ b/noncore/apps/opie-write/qrichtext_p.h | |||
@@ -0,0 +1,2158 @@ | |||
1 | /**************************************************************************** | ||
2 | ** $Id$ | ||
3 | ** | ||
4 | ** Definition of internal rich text classes | ||
5 | ** | ||
6 | ** Created : 990124 | ||
7 | ** | ||
8 | ** Copyright (C) 1999-2000 Trolltech AS. All rights reserved. | ||
9 | ** | ||
10 | ** This file is part of the kernel module of the Qt GUI Toolkit. | ||
11 | ** | ||
12 | ** This file may be distributed under the terms of the Q Public License | ||
13 | ** as defined by Trolltech AS of Norway and appearing in the file | ||
14 | ** LICENSE.QPL included in the packaging of this file. | ||
15 | ** | ||
16 | ** This file may be distributed and/or modified under the terms of the | ||
17 | ** GNU General Public License version 2 as published by the Free Software | ||
18 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
19 | ** packaging of this file. | ||
20 | ** | ||
21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition | ||
22 | ** licenses may use this file in accordance with the Qt Commercial License | ||
23 | ** Agreement provided with the Software. | ||
24 | ** | ||
25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
27 | ** | ||
28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for | ||
29 | ** information about Qt Commercial License Agreements. | ||
30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information. | ||
31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
32 | ** | ||
33 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
34 | ** not clear to you. | ||
35 | ** | ||
36 | **********************************************************************/ | ||
37 | |||
38 | #ifndef QRICHTEXT_P_H | ||
39 | #define QRICHTEXT_P_H | ||
40 | |||
41 | // | ||
42 | // W A R N I N G | ||
43 | // ------------- | ||
44 | // | ||
45 | // This file is not part of the Qt API. It exists for the convenience | ||
46 | // of a number of Qt sources files. This header file may change from | ||
47 | // version to version without notice, or even be removed. | ||
48 | // | ||
49 | // We mean it. | ||
50 | // | ||
51 | // | ||
52 | |||
53 | #ifndef QT_H | ||
54 | #include "qt3namespace.h" | ||
55 | #include "qstring.h" | ||
56 | #include "qlist.h" | ||
57 | #include "qrect.h" | ||
58 | #include "qfontmetrics.h" | ||
59 | #include "qintdict.h" | ||
60 | #include "qmap.h" | ||
61 | #include "qstringlist.h" | ||
62 | #include "qfont.h" | ||
63 | #include "qcolor.h" | ||
64 | #include "qsize.h" | ||
65 | #include "qvaluelist.h" | ||
66 | #include "qvaluestack.h" | ||
67 | #include "qobject.h" | ||
68 | #include "qdict.h" | ||
69 | #include "qtextstream.h" | ||
70 | #include "qpixmap.h" | ||
71 | #include "qstylesheet.h" | ||
72 | #include "qvector.h" | ||
73 | #include "qpainter.h" | ||
74 | #include "qlayout.h" | ||
75 | #include "qobject.h" | ||
76 | #include "qcomplextext_p.h" | ||
77 | #include "qapplication.h" | ||
78 | #include <limits.h> | ||
79 | #endif // QT_H | ||
80 | |||
81 | //#define DEBUG_COLLECTION | ||
82 | |||
83 | namespace Qt3 { | ||
84 | |||
85 | class QTextDocument; | ||
86 | class QTextString; | ||
87 | class QTextPreProcessor; | ||
88 | class QTextFormat; | ||
89 | class QTextCursor; | ||
90 | class QTextParag; | ||
91 | class QTextFormatter; | ||
92 | class QTextIndent; | ||
93 | class QTextFormatCollection; | ||
94 | class QStyleSheetItem; | ||
95 | class QTextCustomItem; | ||
96 | class QTextFlow; | ||
97 | struct QBidiContext; | ||
98 | |||
99 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
100 | |||
101 | class Q_EXPORT QTextStringChar | ||
102 | { | ||
103 | friend class QTextString; | ||
104 | |||
105 | public: | ||
106 | // this is never called, initialize variables in QTextString::insert()!!! | ||
107 | QTextStringChar() : lineStart( 0 ), type( Regular ), startOfRun( 0 ) {d.format=0;} | ||
108 | ~QTextStringChar(); | ||
109 | |||
110 | QChar c; | ||
111 | enum Type { Regular=0, Custom=1, Anchor=2, CustomAnchor=3 }; | ||
112 | uint lineStart : 1; | ||
113 | uint rightToLeft : 1; | ||
114 | uint hasCursor : 1; | ||
115 | uint canBreak : 1; | ||
116 | Type type : 2; | ||
117 | uint startOfRun : 1; | ||
118 | |||
119 | int x; | ||
120 | int height() const; | ||
121 | int ascent() const; | ||
122 | int descent() const; | ||
123 | bool isCustom() const { return (type & Custom) != 0; } | ||
124 | QTextFormat *format() const; | ||
125 | QTextCustomItem *customItem() const; | ||
126 | void setFormat( QTextFormat *f ); | ||
127 | void setCustomItem( QTextCustomItem *i ); | ||
128 | QTextStringChar *clone() const; | ||
129 | struct CustomData | ||
130 | { | ||
131 | QTextFormat *format; | ||
132 | QTextCustomItem *custom; | ||
133 | QString anchorName; | ||
134 | QString anchorHref; | ||
135 | }; | ||
136 | |||
137 | void loseCustomItem(); | ||
138 | |||
139 | union { | ||
140 | QTextFormat* format; | ||
141 | CustomData* custom; | ||
142 | } d; | ||
143 | |||
144 | bool isAnchor() const { return ( type & Anchor) != 0; } | ||
145 | QString anchorName() const; | ||
146 | QString anchorHref() const; | ||
147 | void setAnchor( const QString& name, const QString& href ); | ||
148 | |||
149 | private: | ||
150 | QTextStringChar &operator=( const QTextStringChar & ) { | ||
151 | //abort(); | ||
152 | return *this; | ||
153 | } | ||
154 | friend class QComplexText; | ||
155 | friend class QTextParag; | ||
156 | }; | ||
157 | |||
158 | #if defined(Q_TEMPLATEDLL) | ||
159 | // MOC_SKIP_BEGIN | ||
160 | template class Q_EXPORT QMemArray<QTextStringChar>; | ||
161 | // MOC_SKIP_END | ||
162 | #endif | ||
163 | |||
164 | class Q_EXPORT QTextString | ||
165 | { | ||
166 | public: | ||
167 | |||
168 | QTextString(); | ||
169 | QTextString( const QTextString &s ); | ||
170 | virtual ~QTextString(); | ||
171 | |||
172 | static QString toString( const QMemArray<QTextStringChar> &data ); | ||
173 | QString toString() const; | ||
174 | |||
175 | QTextStringChar &at( int i ) const; | ||
176 | int length() const; | ||
177 | |||
178 | int width( int idx ) const; | ||
179 | |||
180 | void insert( int index, const QString &s, QTextFormat *f ); | ||
181 | void insert( int index, QTextStringChar *c ); | ||
182 | void truncate( int index ); | ||
183 | void remove( int index, int len ); | ||
184 | void clear(); | ||
185 | |||
186 | void setFormat( int index, QTextFormat *f, bool useCollection ); | ||
187 | |||
188 | void setBidi( bool b ) { bidi = b; } | ||
189 | bool isBidi() const; | ||
190 | bool isRightToLeft() const; | ||
191 | QChar::Direction direction() const; | ||
192 | void setDirection( QChar::Direction d ) { dir = d; bidiDirty = TRUE; } | ||
193 | |||
194 | QMemArray<QTextStringChar> subString( int start = 0, int len = 0xFFFFFF ) const; | ||
195 | QMemArray<QTextStringChar> rawData() const { return data; } | ||
196 | |||
197 | void operator=( const QString &s ) { clear(); insert( 0, s, 0 ); } | ||
198 | void operator+=( const QString &s ); | ||
199 | void prepend( const QString &s ) { insert( 0, s, 0 ); } | ||
200 | |||
201 | private: | ||
202 | void checkBidi() const; | ||
203 | |||
204 | QMemArray<QTextStringChar> data; | ||
205 | uint bidiDirty : 1; | ||
206 | uint bidi : 1; // true when the paragraph has right to left characters | ||
207 | uint rightToLeft : 1; | ||
208 | uint dir : 5; | ||
209 | }; | ||
210 | |||
211 | inline bool QTextString::isBidi() const | ||
212 | { | ||
213 | if ( bidiDirty ) | ||
214 | checkBidi(); | ||
215 | return bidi; | ||
216 | } | ||
217 | |||
218 | inline bool QTextString::isRightToLeft() const | ||
219 | { | ||
220 | if ( bidiDirty ) | ||
221 | checkBidi(); | ||
222 | return rightToLeft; | ||
223 | } | ||
224 | |||
225 | inline QChar::Direction QTextString::direction() const | ||
226 | { | ||
227 | return (QChar::Direction) dir; | ||
228 | } | ||
229 | |||
230 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
231 | |||
232 | #if defined(Q_TEMPLATEDLL) | ||
233 | // MOC_SKIP_BEGIN | ||
234 | template class Q_EXPORT QValueStack<int>; | ||
235 | template class Q_EXPORT QValueStack<QTextParag*>; | ||
236 | template class Q_EXPORT QValueStack<bool>; | ||
237 | // MOC_SKIP_END | ||
238 | #endif | ||
239 | |||
240 | class Q_EXPORT QTextCursor | ||
241 | { | ||
242 | public: | ||
243 | QTextCursor( QTextDocument *d ); | ||
244 | QTextCursor(); | ||
245 | QTextCursor( const QTextCursor &c ); | ||
246 | QTextCursor &operator=( const QTextCursor &c ); | ||
247 | virtual ~QTextCursor() {} | ||
248 | |||
249 | bool operator==( const QTextCursor &c ) const; | ||
250 | bool operator!=( const QTextCursor &c ) const { return !(*this == c); } | ||
251 | |||
252 | QTextDocument *document() const { return doc; } | ||
253 | void setDocument( QTextDocument *d ); | ||
254 | |||
255 | QTextParag *parag() const; | ||
256 | int index() const; | ||
257 | void setParag( QTextParag *s, bool restore = TRUE ); | ||
258 | |||
259 | void gotoLeft(); | ||
260 | void gotoRight(); | ||
261 | void gotoNextLetter(); | ||
262 | void gotoPreviousLetter(); | ||
263 | void gotoUp(); | ||
264 | void gotoDown(); | ||
265 | void gotoLineEnd(); | ||
266 | void gotoLineStart(); | ||
267 | void gotoHome(); | ||
268 | void gotoEnd(); | ||
269 | void gotoPageUp( int visibleHeight ); | ||
270 | void gotoPageDown( int visibleHeight ); | ||
271 | void gotoNextWord(); | ||
272 | void gotoPreviousWord(); | ||
273 | void gotoWordLeft(); | ||
274 | void gotoWordRight(); | ||
275 | |||
276 | void insert( const QString &s, bool checkNewLine, QMemArray<QTextStringChar> *formatting = 0 ); | ||
277 | void splitAndInsertEmptyParag( bool ind = TRUE, bool updateIds = TRUE ); | ||
278 | bool remove(); | ||
279 | void killLine(); | ||
280 | void indent(); | ||
281 | |||
282 | bool atParagStart(); | ||
283 | bool atParagEnd(); | ||
284 | |||
285 | void setIndex( int i, bool restore = TRUE ); | ||
286 | |||
287 | void checkIndex(); | ||
288 | |||
289 | int offsetX() const { return ox; } | ||
290 | int offsetY() const { return oy; } | ||
291 | |||
292 | QTextParag *topParag() const { return parags.isEmpty() ? string : parags.first(); } | ||
293 | int totalOffsetX() const; | ||
294 | int totalOffsetY() const; | ||
295 | |||
296 | bool place( const QPoint &pos, QTextParag *s ) { return place( pos, s, FALSE ); } | ||
297 | bool place( const QPoint &pos, QTextParag *s, bool link ); | ||
298 | void restoreState(); | ||
299 | |||
300 | int x() const; | ||
301 | int y() const; | ||
302 | |||
303 | int nestedDepth() const { return (int)indices.count(); } //### size_t/int cast | ||
304 | void oneUp() { if ( !indices.isEmpty() ) pop(); } | ||
305 | void setValid( bool b ) { valid = b; } | ||
306 | bool isValid() const { return valid; } | ||
307 | |||
308 | private: | ||
309 | enum Operation { EnterBegin, EnterEnd, Next, Prev, Up, Down }; | ||
310 | |||
311 | void push(); | ||
312 | void pop(); | ||
313 | void processNesting( Operation op ); | ||
314 | void invalidateNested(); | ||
315 | void gotoIntoNested( const QPoint &globalPos ); | ||
316 | |||
317 | QTextParag *string; | ||
318 | QTextDocument *doc; | ||
319 | int idx, tmpIndex; | ||
320 | int ox, oy; | ||
321 | QValueStack<int> indices; | ||
322 | QValueStack<QTextParag*> parags; | ||
323 | QValueStack<int> xOffsets; | ||
324 | QValueStack<int> yOffsets; | ||
325 | QValueStack<bool> nestedStack; | ||
326 | uint nested : 1; | ||
327 | uint valid : 1; | ||
328 | |||
329 | }; | ||
330 | |||
331 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
332 | |||
333 | class Q_EXPORT QTextCommand | ||
334 | { | ||
335 | public: | ||
336 | enum Commands { Invalid, Insert, Delete, Format, Alignment, ParagType }; | ||
337 | |||
338 | QTextCommand( QTextDocument *d ) : doc( d ), cursor( d ) {} | ||
339 | virtual ~QTextCommand(); | ||
340 | |||
341 | virtual Commands type() const; | ||
342 | |||
343 | virtual QTextCursor *execute( QTextCursor *c ) = 0; | ||
344 | virtual QTextCursor *unexecute( QTextCursor *c ) = 0; | ||
345 | |||
346 | protected: | ||
347 | QTextDocument *doc; | ||
348 | QTextCursor cursor; | ||
349 | |||
350 | }; | ||
351 | |||
352 | #if defined(Q_TEMPLATEDLL) | ||
353 | // MOC_SKIP_BEGIN | ||
354 | template class Q_EXPORT QPtrList<QTextCommand>; | ||
355 | // MOC_SKIP_END | ||
356 | #endif | ||
357 | |||
358 | class Q_EXPORT QTextCommandHistory | ||
359 | { | ||
360 | public: | ||
361 | QTextCommandHistory( int s ) : current( -1 ), steps( s ) { history.setAutoDelete( TRUE ); } | ||
362 | virtual ~QTextCommandHistory(); | ||
363 | |||
364 | void clear() { history.clear(); current = -1; } | ||
365 | |||
366 | void addCommand( QTextCommand *cmd ); | ||
367 | QTextCursor *undo( QTextCursor *c ); | ||
368 | QTextCursor *redo( QTextCursor *c ); | ||
369 | |||
370 | bool isUndoAvailable(); | ||
371 | bool isRedoAvailable(); | ||
372 | |||
373 | void setUndoDepth( int d ) { steps = d; } | ||
374 | int undoDepth() const { return steps; } | ||
375 | |||
376 | int historySize() const { return history.count(); } | ||
377 | int currentPosition() const { return current; } | ||
378 | |||
379 | private: | ||
380 | QPtrList<QTextCommand> history; | ||
381 | int current, steps; | ||
382 | |||
383 | }; | ||
384 | |||
385 | inline QTextCommandHistory::~QTextCommandHistory() | ||
386 | { | ||
387 | clear(); | ||
388 | } | ||
389 | |||
390 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
391 | |||
392 | class Q_EXPORT QTextCustomItem | ||
393 | { | ||
394 | public: | ||
395 | QTextCustomItem( QTextDocument *p ) | ||
396 | : xpos(0), ypos(-1), width(-1), height(0), parent( p ) | ||
397 | {} | ||
398 | virtual ~QTextCustomItem(); | ||
399 | virtual void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ) = 0; | ||
400 | |||
401 | virtual void adjustToPainter( QPainter* ); | ||
402 | |||
403 | enum Placement { PlaceInline = 0, PlaceLeft, PlaceRight }; | ||
404 | virtual Placement placement() const; | ||
405 | bool placeInline() { return placement() == PlaceInline; } | ||
406 | |||
407 | virtual bool ownLine() const; | ||
408 | virtual void resize( int nwidth ); | ||
409 | virtual void invalidate(); | ||
410 | virtual int ascent() const { return height; } | ||
411 | |||
412 | virtual bool isNested() const; | ||
413 | virtual int minimumWidth() const; | ||
414 | |||
415 | virtual QString richText() const; | ||
416 | |||
417 | int xpos; // used for floating items | ||
418 | int ypos; // used for floating items | ||
419 | int width; | ||
420 | int height; | ||
421 | |||
422 | QRect geometry() const { return QRect( xpos, ypos, width, height ); } | ||
423 | |||
424 | virtual bool enter( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy, bool atEnd = FALSE ); | ||
425 | virtual bool enterAt( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy, const QPoint & ); | ||
426 | virtual bool next( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ); | ||
427 | virtual bool prev( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ); | ||
428 | virtual bool down( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ); | ||
429 | virtual bool up( QTextCursor *, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ); | ||
430 | |||
431 | void setParagraph( QTextParag *p ) { parag = p; } | ||
432 | QTextParag *paragrapth() const { return parag; } | ||
433 | |||
434 | QTextDocument *parent; | ||
435 | QTextParag *parag; | ||
436 | |||
437 | virtual void pageBreak( int y, QTextFlow* flow ); | ||
438 | }; | ||
439 | |||
440 | #if defined(Q_TEMPLATEDLL) | ||
441 | // MOC_SKIP_BEGIN | ||
442 | template class Q_EXPORT QMap<QString, QString>; | ||
443 | // MOC_SKIP_END | ||
444 | #endif | ||
445 | |||
446 | class Q_EXPORT QTextImage : public QTextCustomItem | ||
447 | { | ||
448 | public: | ||
449 | QTextImage( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, | ||
450 | QMimeSourceFactory &factory ); | ||
451 | virtual ~QTextImage(); | ||
452 | |||
453 | Placement placement() const { return place; } | ||
454 | void adjustToPainter( QPainter* ); | ||
455 | int minimumWidth() const { return width; } | ||
456 | |||
457 | QString richText() const; | ||
458 | |||
459 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); | ||
460 | |||
461 | private: | ||
462 | QRegion* reg; | ||
463 | QPixmap pm; | ||
464 | Placement place; | ||
465 | int tmpwidth, tmpheight; | ||
466 | QMap<QString, QString> attributes; | ||
467 | QString imgId; | ||
468 | |||
469 | }; | ||
470 | |||
471 | class Q_EXPORT QTextHorizontalLine : public QTextCustomItem | ||
472 | { | ||
473 | public: | ||
474 | QTextHorizontalLine( QTextDocument *p, const QMap<QString, QString> &attr, const QString& context, | ||
475 | QMimeSourceFactory &factory ); | ||
476 | virtual ~QTextHorizontalLine(); | ||
477 | |||
478 | void adjustToPainter( QPainter* ); | ||
479 | void draw(QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); | ||
480 | QString richText() const; | ||
481 | |||
482 | bool ownLine() const { return TRUE; } | ||
483 | |||
484 | private: | ||
485 | int tmpheight; | ||
486 | QColor color; | ||
487 | |||
488 | }; | ||
489 | |||
490 | #if defined(Q_TEMPLATEDLL) | ||
491 | // MOC_SKIP_BEGIN | ||
492 | template class Q_EXPORT QPtrList<QTextCustomItem>; | ||
493 | // MOC_SKIP_END | ||
494 | #endif | ||
495 | |||
496 | class Q_EXPORT QTextFlow | ||
497 | { | ||
498 | friend class QTextDocument; | ||
499 | friend class QTextTableCell; | ||
500 | |||
501 | public: | ||
502 | QTextFlow(); | ||
503 | virtual ~QTextFlow(); | ||
504 | |||
505 | virtual void setWidth( int width ); | ||
506 | int width() const; | ||
507 | |||
508 | virtual void setPageSize( int ps ); | ||
509 | int pageSize() const { return pagesize; } | ||
510 | |||
511 | virtual int adjustLMargin( int yp, int h, int margin, int space ); | ||
512 | virtual int adjustRMargin( int yp, int h, int margin, int space ); | ||
513 | |||
514 | virtual void registerFloatingItem( QTextCustomItem* item ); | ||
515 | virtual void unregisterFloatingItem( QTextCustomItem* item ); | ||
516 | virtual QRect boundingRect() const; | ||
517 | virtual void drawFloatingItems(QPainter* p, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); | ||
518 | |||
519 | virtual int adjustFlow( int y, int w, int h ); // adjusts y according to the defined pagesize. Returns the shift. | ||
520 | |||
521 | virtual bool isEmpty(); | ||
522 | |||
523 | void clear(); | ||
524 | |||
525 | private: | ||
526 | int w; | ||
527 | int pagesize; | ||
528 | |||
529 | QPtrList<QTextCustomItem> leftItems; | ||
530 | QPtrList<QTextCustomItem> rightItems; | ||
531 | |||
532 | }; | ||
533 | |||
534 | inline int QTextFlow::width() const { return w; } | ||
535 | |||
536 | class QTextTable; | ||
537 | |||
538 | class Q_EXPORT QTextTableCell : public QLayoutItem | ||
539 | { | ||
540 | friend class QTextTable; | ||
541 | |||
542 | public: | ||
543 | QTextTableCell( QTextTable* table, | ||
544 | int row, int column, | ||
545 | const QMap<QString, QString> &attr, | ||
546 | const QStyleSheetItem* style, | ||
547 | const QTextFormat& fmt, const QString& context, | ||
548 | QMimeSourceFactory &factory, QStyleSheet *sheet, const QString& doc ); | ||
549 | QTextTableCell( QTextTable* table, int row, int column ); | ||
550 | virtual ~QTextTableCell(); | ||
551 | |||
552 | QSize sizeHint() const ; | ||
553 | QSize minimumSize() const ; | ||
554 | QSize maximumSize() const ; | ||
555 | QSizePolicy::ExpandData expanding() const; | ||
556 | bool isEmpty() const; | ||
557 | void setGeometry( const QRect& ) ; | ||
558 | QRect geometry() const; | ||
559 | |||
560 | bool hasHeightForWidth() const; | ||
561 | int heightForWidth( int ) const; | ||
562 | |||
563 | void adjustToPainter( QPainter* ); | ||
564 | |||
565 | int row() const { return row_; } | ||
566 | int column() const { return col_; } | ||
567 | int rowspan() const { return rowspan_; } | ||
568 | int colspan() const { return colspan_; } | ||
569 | int stretch() const { return stretch_; } | ||
570 | |||
571 | QTextDocument* richText() const { return richtext; } | ||
572 | QTextTable* table() const { return parent; } | ||
573 | |||
574 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, const QColorGroup& cg, bool selected ); | ||
575 | |||
576 | QBrush *backGround() const { return background; } | ||
577 | virtual void invalidate(); | ||
578 | |||
579 | int verticalAlignmentOffset() const; | ||
580 | int horizontalAlignmentOffset() const; | ||
581 | |||
582 | private: | ||
583 | QRect geom; | ||
584 | QTextTable* parent; | ||
585 | QTextDocument* richtext; | ||
586 | int row_; | ||
587 | int col_; | ||
588 | int rowspan_; | ||
589 | int colspan_; | ||
590 | int stretch_; | ||
591 | int maxw; | ||
592 | int minw; | ||
593 | bool hasFixedWidth; | ||
594 | QBrush *background; | ||
595 | int cached_width; | ||
596 | int cached_sizehint; | ||
597 | QMap<QString, QString> attributes; | ||
598 | int align; | ||
599 | }; | ||
600 | |||
601 | #if defined(Q_TEMPLATEDLL) | ||
602 | // MOC_SKIP_BEGIN | ||
603 | template class Q_EXPORT QPtrList<QTextTableCell>; | ||
604 | template class Q_EXPORT QMap<QTextCursor*, int>; | ||
605 | // MOC_SKIP_END | ||
606 | #endif | ||
607 | |||
608 | class Q_EXPORT QTextTable: public QTextCustomItem | ||
609 | { | ||
610 | friend class QTextTableCell; | ||
611 | |||
612 | public: | ||
613 | QTextTable( QTextDocument *p, const QMap<QString, QString> &attr ); | ||
614 | virtual ~QTextTable(); | ||
615 | |||
616 | void adjustToPainter( QPainter *p ); | ||
617 | void pageBreak( int y, QTextFlow* flow ); | ||
618 | void draw( QPainter* p, int x, int y, int cx, int cy, int cw, int ch, | ||
619 | const QColorGroup& cg, bool selected ); | ||
620 | |||
621 | bool noErase() const { return TRUE; } | ||
622 | bool ownLine() const { return TRUE; } | ||
623 | Placement placement() const { return place; } | ||
624 | bool isNested() const { return TRUE; } | ||
625 | void resize( int nwidth ); | ||
626 | virtual void invalidate(); | ||
627 | |||
628 | virtual bool enter( QTextCursor *c, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy, bool atEnd = FALSE ); | ||
629 | virtual bool enterAt( QTextCursor *c, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy, const QPoint &pos ); | ||
630 | virtual bool next( QTextCursor *c, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ); | ||
631 | virtual bool prev( QTextCursor *c, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ); | ||
632 | virtual bool down( QTextCursor *c, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ); | ||
633 | virtual bool up( QTextCursor *c, QTextDocument *&doc, QTextParag *¶g, int &idx, int &ox, int &oy ); | ||
634 | |||
635 | QString richText() const; | ||
636 | |||
637 | int minimumWidth() const; | ||
638 | |||
639 | QPtrList<QTextTableCell> tableCells() const { return cells; } | ||
640 | |||
641 | bool isStretching() const { return stretch; } | ||
642 | |||
643 | private: | ||
644 | void format( int w ); | ||
645 | void addCell( QTextTableCell* cell ); | ||
646 | |||
647 | private: | ||
648 | QGridLayout* layout; | ||
649 | QPtrList<QTextTableCell> cells; | ||
650 | int cachewidth; | ||
651 | int fixwidth; | ||
652 | int cellpadding; | ||
653 | int cellspacing; | ||
654 | int border; | ||
655 | int outerborder; | ||
656 | int stretch; | ||
657 | int innerborder; | ||
658 | int us_cp, us_ib, us_b, us_ob, us_cs; | ||
659 | QMap<QString, QString> attributes; | ||
660 | QMap<QTextCursor*, int> currCell; | ||
661 | Placement place; | ||
662 | void adjustCells( int y , int shift ); | ||
663 | int pageBreakFor; | ||
664 | }; | ||
665 | |||
666 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
667 | |||
668 | class QTextTableCell; | ||
669 | class QTextParag; | ||
670 | |||
671 | struct Q_EXPORT QTextDocumentSelection | ||
672 | { | ||
673 | QTextCursor startCursor, endCursor; | ||
674 | bool swapped; | ||
675 | }; | ||
676 | |||
677 | #if defined(Q_TEMPLATEDLL) | ||
678 | // MOC_SKIP_BEGIN | ||
679 | template class Q_EXPORT QMap<int, QColor>; | ||
680 | template class Q_EXPORT QMap<int, bool>; | ||
681 | template class Q_EXPORT QMap<int, QTextDocumentSelection>; | ||
682 | template class Q_EXPORT QPtrList<QTextDocument>; | ||
683 | // MOC_SKIP_END | ||
684 | #endif | ||
685 | |||
686 | class Q_EXPORT QTextDocument : public QObject | ||
687 | { | ||
688 | Q_OBJECT | ||
689 | |||
690 | friend class QTextTableCell; | ||
691 | friend class QTextCursor; | ||
692 | friend class QTextEdit; | ||
693 | friend class QTextParag; | ||
694 | |||
695 | public: | ||
696 | enum SelectionIds { | ||
697 | Standard = 0, | ||
698 | Temp = 32000 // This selection must not be drawn, it's used e.g. by undo/redo to | ||
699 | // remove multiple lines with removeSelectedText() | ||
700 | }; | ||
701 | |||
702 | QTextDocument( QTextDocument *p ); | ||
703 | QTextDocument( QTextDocument *d, QTextFormatCollection *f ); | ||
704 | virtual ~QTextDocument(); | ||
705 | |||
706 | QTextDocument *parent() const { return par; } | ||
707 | QTextParag *parentParag() const { return parParag; } | ||
708 | |||
709 | void setText( const QString &text, const QString &context ); | ||
710 | QMap<QString, QString> attributes() const { return attribs; } | ||
711 | void setAttributes( const QMap<QString, QString> &attr ) { attribs = attr; } | ||
712 | |||
713 | QString text() const; | ||
714 | QString text( int parag ) const; | ||
715 | QString originalText() const; | ||
716 | |||
717 | int x() const; | ||
718 | int y() const; | ||
719 | int width() const; | ||
720 | int widthUsed() const; | ||
721 | int visibleWidth() const; | ||
722 | int height() const; | ||
723 | void setWidth( int w ); | ||
724 | int minimumWidth() const; | ||
725 | bool setMinimumWidth( int needed, int used = -1, QTextParag *parag = 0 ); | ||
726 | |||
727 | void setY( int y ); | ||
728 | int leftMargin() const; | ||
729 | void setLeftMargin( int lm ); | ||
730 | int rightMargin() const; | ||
731 | void setRightMargin( int rm ); | ||
732 | |||
733 | QTextParag *firstParag() const; | ||
734 | QTextParag *lastParag() const; | ||
735 | void setFirstParag( QTextParag *p ); | ||
736 | void setLastParag( QTextParag *p ); | ||
737 | |||
738 | void invalidate(); | ||
739 | |||
740 | void setPreProcessor( QTextPreProcessor *sh ); | ||
741 | QTextPreProcessor *preProcessor() const; | ||
742 | |||
743 | void setFormatter( QTextFormatter *f ); | ||
744 | QTextFormatter *formatter() const; | ||
745 | |||
746 | void setIndent( QTextIndent *i ); | ||
747 | QTextIndent *indent() const; | ||
748 | |||
749 | QColor selectionColor( int id ) const; | ||
750 | bool invertSelectionText( int id ) const; | ||
751 | void setSelectionColor( int id, const QColor &c ); | ||
752 | void setInvertSelectionText( int id, bool b ); | ||
753 | bool hasSelection( int id, bool visible = FALSE ) const; | ||
754 | void setSelectionStart( int id, QTextCursor *cursor ); | ||
755 | bool setSelectionEnd( int id, QTextCursor *cursor ); | ||
756 | void selectAll( int id ); | ||
757 | bool removeSelection( int id ); | ||
758 | void selectionStart( int id, int ¶gId, int &index ); | ||
759 | QTextCursor selectionStartCursor( int id ); | ||
760 | QTextCursor selectionEndCursor( int id ); | ||
761 | void selectionEnd( int id, int ¶gId, int &index ); | ||
762 | void setFormat( int id, QTextFormat *f, int flags ); | ||
763 | QTextParag *selectionStart( int id ); | ||
764 | QTextParag *selectionEnd( int id ); | ||
765 | int numSelections() const { return nSelections; } | ||
766 | void addSelection( int id ); | ||
767 | |||
768 | QString selectedText( int id, bool withCustom = TRUE ) const; | ||
769 | void copySelectedText( int id ); | ||
770 | void removeSelectedText( int id, QTextCursor *cursor ); | ||
771 | void indentSelection( int id ); | ||
772 | |||
773 | QTextParag *paragAt( int i ) const; | ||
774 | |||
775 | void addCommand( QTextCommand *cmd ); | ||
776 | QTextCursor *undo( QTextCursor *c = 0 ); | ||
777 | QTextCursor *redo( QTextCursor *c = 0 ); | ||
778 | QTextCommandHistory *commands() const { return commandHistory; } | ||
779 | |||
780 | QTextFormatCollection *formatCollection() const; | ||
781 | |||
782 | bool find( const QString &expr, bool cs, bool wo, bool forward, int *parag, int *index, QTextCursor *cursor ); | ||
783 | |||
784 | void setTextFormat( Qt::TextFormat f ); | ||
785 | Qt::TextFormat textFormat() const; | ||
786 | |||
787 | bool inSelection( int selId, const QPoint &pos ) const; | ||
788 | |||
789 | QStyleSheet *styleSheet() const { return sheet_; } | ||
790 | QMimeSourceFactory *mimeSourceFactory() const { return factory_; } | ||
791 | QString context() const { return contxt; } | ||
792 | |||
793 | void setStyleSheet( QStyleSheet *s ); | ||
794 | void updateStyles(); | ||
795 | void updateFontSizes( int base, bool usePixels ); | ||
796 | void updateFontAttributes( const QFont &f, const QFont &old ); | ||
797 | void setMimeSourceFactory( QMimeSourceFactory *f ) { if ( f ) factory_ = f; } | ||
798 | void setContext( const QString &c ) { if ( !c.isEmpty() ) contxt = c; } | ||
799 | |||
800 | void setUnderlineLinks( bool b ) { underlLinks = b; } | ||
801 | bool underlineLinks() const { return underlLinks; } | ||
802 | |||
803 | void setPaper( QBrush *brush ) { if ( backBrush ) delete backBrush; backBrush = brush; } | ||
804 | QBrush *paper() const { return backBrush; } | ||
805 | |||
806 | void doLayout( QPainter *p, int w ); | ||
807 | void draw( QPainter *p, const QRect& rect, const QColorGroup &cg, const QBrush *paper = 0 ); | ||
808 | void drawParag( QPainter *p, QTextParag *parag, int cx, int cy, int cw, int ch, | ||
809 | QPixmap *&doubleBuffer, const QColorGroup &cg, | ||
810 | bool drawCursor, QTextCursor *cursor, bool resetChanged = TRUE ); | ||
811 | QTextParag *draw( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg, | ||
812 | bool onlyChanged = FALSE, bool drawCursor = FALSE, QTextCursor *cursor = 0, | ||
813 | bool resetChanged = TRUE ); | ||
814 | |||
815 | void setDefaultFont( const QFont &f ); | ||
816 | |||
817 | void registerCustomItem( QTextCustomItem *i, QTextParag *p ); | ||
818 | void unregisterCustomItem( QTextCustomItem *i, QTextParag *p ); | ||
819 | |||
820 | void setFlow( QTextFlow *f ); | ||
821 | void takeFlow(); | ||
822 | QTextFlow *flow() const { return flow_; } | ||
823 | bool isPageBreakEnabled() const { return pages; } | ||
824 | void setPageBreakEnabled( bool b ) { pages = b; } | ||
825 | |||
826 | void setUseFormatCollection( bool b ) { useFC = b; } | ||
827 | bool useFormatCollection() const { return useFC; } | ||
828 | |||
829 | QTextTableCell *tableCell() const { return tc; } | ||
830 | void setTableCell( QTextTableCell *c ) { tc = c; } | ||
831 | |||
832 | void setPlainText( const QString &text ); | ||
833 | void setRichText( const QString &text, const QString &context ); | ||
834 | QString richText( QTextParag *p = 0 ) const; | ||
835 | QString plainText( QTextParag *p = 0 ) const; | ||
836 | |||
837 | bool focusNextPrevChild( bool next ); | ||
838 | |||
839 | int alignment() const; | ||
840 | void setAlignment( int a ); | ||
841 | |||
842 | int *tabArray() const; | ||
843 | int tabStopWidth() const; | ||
844 | void setTabArray( int *a ); | ||
845 | void setTabStops( int tw ); | ||
846 | |||
847 | void setUndoDepth( int d ) { commandHistory->setUndoDepth( d ); } | ||
848 | int undoDepth() const { return commandHistory->undoDepth(); } | ||
849 | |||
850 | int length() const; | ||
851 | void clear( bool createEmptyParag = FALSE ); | ||
852 | |||
853 | virtual QTextParag *createParag( QTextDocument *d, QTextParag *pr = 0, QTextParag *nx = 0, bool updateIds = TRUE ); | ||
854 | void insertChild( QObject *o ) { QObject::insertChild( o ); } | ||
855 | void removeChild( QObject *o ) { QObject::removeChild( o ); } | ||
856 | void insertChild( QTextDocument *d ) { childList.append( d ); } | ||
857 | void removeChild( QTextDocument *d ) { childList.removeRef( d ); } | ||
858 | QPtrList<QTextDocument> children() const { return childList; } | ||
859 | |||
860 | void setAddMargins( bool b ) { addMargs = b; } | ||
861 | int addMargins() const { return addMargs; } | ||
862 | |||
863 | bool hasFocusParagraph() const; | ||
864 | QString focusHref() const; | ||
865 | |||
866 | void invalidateOriginalText() { oTextValid = FALSE; oText = ""; } | ||
867 | |||
868 | signals: | ||
869 | void minimumWidthChanged( int ); | ||
870 | |||
871 | private: | ||
872 | void init(); | ||
873 | QPixmap *bufferPixmap( const QSize &s ); | ||
874 | // HTML parser | ||
875 | bool hasPrefix(const QChar* doc, int length, int pos, QChar c); | ||
876 | bool hasPrefix(const QChar* doc, int length, int pos, const QString& s); | ||
877 | QTextCustomItem* parseTable( const QMap<QString, QString> &attr, const QTextFormat &fmt, | ||
878 | const QChar* doc, int length, int& pos, QTextParag *curpar ); | ||
879 | bool eatSpace(const QChar* doc, int length, int& pos, bool includeNbsp = FALSE ); | ||
880 | bool eat(const QChar* doc, int length, int& pos, QChar c); | ||
881 | QString parseOpenTag(const QChar* doc, int length, int& pos, QMap<QString, QString> &attr, bool& emptyTag); | ||
882 | QString parseCloseTag( const QChar* doc, int length, int& pos ); | ||
883 | QChar parseHTMLSpecialChar(const QChar* doc, int length, int& pos); | ||
884 | QString parseWord(const QChar* doc, int length, int& pos, bool lower = TRUE); | ||
885 | QChar parseChar(const QChar* doc, int length, int& pos, QStyleSheetItem::WhiteSpaceMode wsm ); | ||
886 | void setRichTextInternal( const QString &text ); | ||
887 | |||
888 | private: | ||
889 | struct Q_EXPORT Focus { | ||
890 | QTextParag *parag; | ||
891 | int start, len; | ||
892 | QString href; | ||
893 | }; | ||
894 | |||
895 | int cx, cy, cw, vw; | ||
896 | QTextParag *fParag, *lParag; | ||
897 | QTextPreProcessor *pProcessor; | ||
898 | QMap<int, QColor> selectionColors; | ||
899 | QMap<int, QTextDocumentSelection> selections; | ||
900 | QMap<int, bool> selectionText; | ||
901 | QTextCommandHistory *commandHistory; | ||
902 | QTextFormatter *pFormatter; | ||
903 | QTextIndent *indenter; | ||
904 | QTextFormatCollection *fCollection; | ||
905 | Qt::TextFormat txtFormat; | ||
906 | uint preferRichText : 1; | ||
907 | uint pages : 1; | ||
908 | uint useFC : 1; | ||
909 | uint withoutDoubleBuffer : 1; | ||
910 | uint underlLinks : 1; | ||
911 | uint nextDoubleBuffered : 1; | ||
912 | uint addMargs : 1; | ||
913 | uint oTextValid : 1; | ||
914 | uint mightHaveCustomItems : 1; | ||
915 | int align; | ||
916 | int nSelections; | ||
917 | QTextFlow *flow_; | ||
918 | QTextDocument *par; | ||
919 | QTextParag *parParag; | ||
920 | QTextTableCell *tc; | ||
921 | QTextCursor *tmpCursor; | ||
922 | QBrush *backBrush; | ||
923 | QPixmap *buf_pixmap; | ||
924 | Focus focusIndicator; | ||
925 | int minw; | ||
926 | int wused; | ||
927 | int leftmargin; | ||
928 | int rightmargin; | ||
929 | QTextParag *minwParag, *curParag; | ||
930 | QStyleSheet* sheet_; | ||
931 | QMimeSourceFactory* factory_; | ||
932 | QString contxt; | ||
933 | QMap<QString, QString> attribs; | ||
934 | int *tArray; | ||
935 | int tStopWidth; | ||
936 | int uDepth; | ||
937 | QString oText; | ||
938 | QPtrList<QTextDocument> childList; | ||
939 | QColor linkColor; | ||
940 | |||
941 | }; | ||
942 | |||
943 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
944 | |||
945 | |||
946 | class Q_EXPORT QTextDeleteCommand : public QTextCommand | ||
947 | { | ||
948 | public: | ||
949 | QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, | ||
950 | const QValueList< QPtrVector<QStyleSheetItem> > &os, | ||
951 | const QValueList<QStyleSheetItem::ListStyle> &ols, | ||
952 | const QMemArray<int> &oas ); | ||
953 | QTextDeleteCommand( QTextParag *p, int idx, const QMemArray<QTextStringChar> &str ); | ||
954 | virtual ~QTextDeleteCommand(); | ||
955 | |||
956 | Commands type() const { return Delete; } | ||
957 | QTextCursor *execute( QTextCursor *c ); | ||
958 | QTextCursor *unexecute( QTextCursor *c ); | ||
959 | |||
960 | protected: | ||
961 | int id, index; | ||
962 | QTextParag *parag; | ||
963 | QMemArray<QTextStringChar> text; | ||
964 | QValueList< QPtrVector<QStyleSheetItem> > oldStyles; | ||
965 | QValueList<QStyleSheetItem::ListStyle> oldListStyles; | ||
966 | QMemArray<int> oldAligns; | ||
967 | |||
968 | }; | ||
969 | |||
970 | class Q_EXPORT QTextInsertCommand : public QTextDeleteCommand | ||
971 | { | ||
972 | public: | ||
973 | QTextInsertCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, | ||
974 | const QValueList< QPtrVector<QStyleSheetItem> > &os, | ||
975 | const QValueList<QStyleSheetItem::ListStyle> &ols, | ||
976 | const QMemArray<int> &oas ) | ||
977 | : QTextDeleteCommand( d, i, idx, str, os, ols, oas ) {} | ||
978 | QTextInsertCommand( QTextParag *p, int idx, const QMemArray<QTextStringChar> &str ) | ||
979 | : QTextDeleteCommand( p, idx, str ) {} | ||
980 | virtual ~QTextInsertCommand() {} | ||
981 | |||
982 | Commands type() const { return Insert; } | ||
983 | QTextCursor *execute( QTextCursor *c ) { return QTextDeleteCommand::unexecute( c ); } | ||
984 | QTextCursor *unexecute( QTextCursor *c ) { return QTextDeleteCommand::execute( c ); } | ||
985 | |||
986 | }; | ||
987 | |||
988 | class Q_EXPORT QTextFormatCommand : public QTextCommand | ||
989 | { | ||
990 | public: | ||
991 | QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ); | ||
992 | virtual ~QTextFormatCommand(); | ||
993 | |||
994 | Commands type() const { return Format; } | ||
995 | QTextCursor *execute( QTextCursor *c ); | ||
996 | QTextCursor *unexecute( QTextCursor *c ); | ||
997 | |||
998 | protected: | ||
999 | int startId, startIndex, endId, endIndex; | ||
1000 | QTextFormat *format; | ||
1001 | QMemArray<QTextStringChar> oldFormats; | ||
1002 | int flags; | ||
1003 | |||
1004 | }; | ||
1005 | |||
1006 | class Q_EXPORT QTextAlignmentCommand : public QTextCommand | ||
1007 | { | ||
1008 | public: | ||
1009 | QTextAlignmentCommand( QTextDocument *d, int fParag, int lParag, int na, const QMemArray<int> &oa ); | ||
1010 | virtual ~QTextAlignmentCommand() {} | ||
1011 | |||
1012 | Commands type() const { return Alignment; } | ||
1013 | QTextCursor *execute( QTextCursor *c ); | ||
1014 | QTextCursor *unexecute( QTextCursor *c ); | ||
1015 | |||
1016 | private: | ||
1017 | int firstParag, lastParag; | ||
1018 | int newAlign; | ||
1019 | QMemArray<int> oldAligns; | ||
1020 | |||
1021 | }; | ||
1022 | |||
1023 | class Q_EXPORT QTextParagTypeCommand : public QTextCommand | ||
1024 | { | ||
1025 | public: | ||
1026 | QTextParagTypeCommand( QTextDocument *d, int fParag, int lParag, bool l, | ||
1027 | QStyleSheetItem::ListStyle s, const QValueList< QPtrVector<QStyleSheetItem> > &os, | ||
1028 | const QValueList<QStyleSheetItem::ListStyle> &ols ); | ||
1029 | virtual ~QTextParagTypeCommand() {} | ||
1030 | |||
1031 | Commands type() const { return ParagType; } | ||
1032 | QTextCursor *execute( QTextCursor *c ); | ||
1033 | QTextCursor *unexecute( QTextCursor *c ); | ||
1034 | |||
1035 | private: | ||
1036 | int firstParag, lastParag; | ||
1037 | bool list; | ||
1038 | QStyleSheetItem::ListStyle listStyle; | ||
1039 | QValueList< QPtrVector<QStyleSheetItem> > oldStyles; | ||
1040 | QValueList<QStyleSheetItem::ListStyle> oldListStyles; | ||
1041 | |||
1042 | }; | ||
1043 | |||
1044 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1045 | |||
1046 | struct Q_EXPORT QTextParagSelection | ||
1047 | { | ||
1048 | int start, end; | ||
1049 | }; | ||
1050 | |||
1051 | struct Q_EXPORT QTextParagLineStart | ||
1052 | { | ||
1053 | QTextParagLineStart() : y( 0 ), baseLine( 0 ), h( 0 ) | ||
1054 | #ifndef QT_NO_COMPLEXTEXT | ||
1055 | , bidicontext( 0 ) | ||
1056 | #endif | ||
1057 | { } | ||
1058 | QTextParagLineStart( ushort y_, ushort bl, ushort h_ ) : y( y_ ), baseLine( bl ), h( h_ ), | ||
1059 | w( 0 ) | ||
1060 | #ifndef QT_NO_COMPLEXTEXT | ||
1061 | , bidicontext( 0 ) | ||
1062 | #endif | ||
1063 | { } | ||
1064 | #ifndef QT_NO_COMPLEXTEXT | ||
1065 | QTextParagLineStart( QBidiContext *c, QBidiStatus s ) : y(0), baseLine(0), h(0), | ||
1066 | status( s ), bidicontext( c ) { if ( bidicontext ) bidicontext->ref(); } | ||
1067 | #endif | ||
1068 | |||
1069 | virtual ~QTextParagLineStart() | ||
1070 | { | ||
1071 | #ifndef QT_NO_COMPLEXTEXT | ||
1072 | if ( bidicontext && bidicontext->deref() ) | ||
1073 | delete bidicontext; | ||
1074 | #endif | ||
1075 | } | ||
1076 | |||
1077 | #ifndef QT_NO_COMPLEXTEXT | ||
1078 | void setContext( QBidiContext *c ) { | ||
1079 | if ( c == bidicontext ) | ||
1080 | return; | ||
1081 | if ( bidicontext && bidicontext->deref() ) | ||
1082 | delete bidicontext; | ||
1083 | bidicontext = c; | ||
1084 | if ( bidicontext ) | ||
1085 | bidicontext->ref(); | ||
1086 | } | ||
1087 | QBidiContext *context() const { return bidicontext; } | ||
1088 | #endif | ||
1089 | |||
1090 | public: | ||
1091 | ushort y, baseLine, h; | ||
1092 | #ifndef QT_NO_COMPLEXTEXT | ||
1093 | QBidiStatus status; | ||
1094 | #endif | ||
1095 | int w; | ||
1096 | |||
1097 | private: | ||
1098 | #ifndef QT_NO_COMPLEXTEXT | ||
1099 | QBidiContext *bidicontext; | ||
1100 | #endif | ||
1101 | }; | ||
1102 | |||
1103 | #if defined(Q_TEMPLATEDLL) | ||
1104 | // MOC_SKIP_BEGIN | ||
1105 | template class Q_EXPORT QMap<int, QTextParagSelection>; | ||
1106 | template class Q_EXPORT QMap<int, QTextParagLineStart*>; | ||
1107 | // MOC_SKIP_END | ||
1108 | #endif | ||
1109 | |||
1110 | class Q_EXPORT QTextParagData | ||
1111 | { | ||
1112 | public: | ||
1113 | QTextParagData() {} | ||
1114 | virtual ~QTextParagData(); | ||
1115 | virtual void join( QTextParagData * ); | ||
1116 | }; | ||
1117 | |||
1118 | class Q_EXPORT QTextParagPseudoDocument | ||
1119 | { | ||
1120 | public: | ||
1121 | QTextParagPseudoDocument(); | ||
1122 | ~QTextParagPseudoDocument(); | ||
1123 | QRect docRect; | ||
1124 | QTextFormatter *pFormatter; | ||
1125 | QTextCommandHistory *commandHistory; | ||
1126 | int minw; | ||
1127 | int wused; | ||
1128 | }; | ||
1129 | |||
1130 | //nase | ||
1131 | class Q_EXPORT QTextParag | ||
1132 | { | ||
1133 | friend class QTextDocument; | ||
1134 | friend class QTextCursor; | ||
1135 | |||
1136 | public: | ||
1137 | QTextParag( QTextDocument *d, QTextParag *pr = 0, QTextParag *nx = 0, bool updateIds = TRUE ); | ||
1138 | virtual ~QTextParag(); | ||
1139 | |||
1140 | QTextString *string() const; | ||
1141 | QTextStringChar *at( int i ) const; // maybe remove later | ||
1142 | int leftGap() const; | ||
1143 | int length() const; // maybe remove later | ||
1144 | |||
1145 | void setListStyle( QStyleSheetItem::ListStyle ls ); | ||
1146 | QStyleSheetItem::ListStyle listStyle() const; | ||
1147 | void setListValue( int v ) { list_val = v; } | ||
1148 | int listValue() const { return list_val; } | ||
1149 | |||
1150 | void setList( bool b, int listStyle ); | ||
1151 | void incDepth(); | ||
1152 | void decDepth(); | ||
1153 | int listDepth() const; | ||
1154 | |||
1155 | void setFormat( QTextFormat *fm ); | ||
1156 | QTextFormat *paragFormat() const; | ||
1157 | |||
1158 | QTextDocument *document() const; | ||
1159 | QTextParagPseudoDocument *pseudoDocument() const; | ||
1160 | |||
1161 | QRect rect() const; | ||
1162 | void setHeight( int h ) { r.setHeight( h ); } | ||
1163 | void show(); | ||
1164 | void hide(); | ||
1165 | bool isVisible() const { return visible; } | ||
1166 | |||
1167 | QTextParag *prev() const; | ||
1168 | QTextParag *next() const; | ||
1169 | void setPrev( QTextParag *s ); | ||
1170 | void setNext( QTextParag *s ); | ||
1171 | |||
1172 | void insert( int index, const QString &s ); | ||
1173 | void append( const QString &s, bool reallyAtEnd = FALSE ); | ||
1174 | void truncate( int index ); | ||
1175 | void remove( int index, int len ); | ||
1176 | void join( QTextParag *s ); | ||
1177 | |||
1178 | void invalidate( int chr ); | ||
1179 | |||
1180 | void move( int &dy ); | ||
1181 | void format( int start = -1, bool doMove = TRUE ); | ||
1182 | |||
1183 | bool isValid() const; | ||
1184 | bool hasChanged() const; | ||
1185 | void setChanged( bool b, bool recursive = FALSE ); | ||
1186 | |||
1187 | int lineHeightOfChar( int i, int *bl = 0, int *y = 0 ) const; | ||
1188 | QTextStringChar *lineStartOfChar( int i, int *index = 0, int *line = 0 ) const; | ||
1189 | int lines() const; | ||
1190 | QTextStringChar *lineStartOfLine( int line, int *index = 0 ) const; | ||
1191 | int lineY( int l ) const; | ||
1192 | int lineBaseLine( int l ) const; | ||
1193 | int lineHeight( int l ) const; | ||
1194 | void lineInfo( int l, int &y, int &h, int &bl ) const; | ||
1195 | |||
1196 | void setSelection( int id, int start, int end ); | ||
1197 | void removeSelection( int id ); | ||
1198 | int selectionStart( int id ) const; | ||
1199 | int selectionEnd( int id ) const; | ||
1200 | bool hasSelection( int id ) const; | ||
1201 | bool hasAnySelection() const; | ||
1202 | bool fullSelected( int id ) const; | ||
1203 | |||
1204 | void setEndState( int s ); | ||
1205 | int endState() const; | ||
1206 | |||
1207 | void setParagId( int i ); | ||
1208 | int paragId() const; | ||
1209 | |||
1210 | bool firstPreProcess() const; | ||
1211 | void setFirstPreProcess( bool b ); | ||
1212 | |||
1213 | void indent( int *oldIndent = 0, int *newIndent = 0 ); | ||
1214 | |||
1215 | void setExtraData( QTextParagData *data ); | ||
1216 | QTextParagData *extraData() const; | ||
1217 | |||
1218 | QMap<int, QTextParagLineStart*> &lineStartList(); | ||
1219 | |||
1220 | void setFormat( int index, int len, QTextFormat *f, bool useCollection = TRUE, int flags = -1 ); | ||
1221 | |||
1222 | void setAlignment( int a ); | ||
1223 | int alignment() const; | ||
1224 | |||
1225 | virtual void paint( QPainter &painter, const QColorGroup &cg, QTextCursor *cursor = 0, bool drawSelections = FALSE, | ||
1226 | int clipx = -1, int clipy = -1, int clipw = -1, int cliph = -1 ); | ||
1227 | |||
1228 | void setStyleSheetItems( const QPtrVector<QStyleSheetItem> &vec ); | ||
1229 | QPtrVector<QStyleSheetItem> styleSheetItems() const; | ||
1230 | QStyleSheetItem *style() const; | ||
1231 | |||
1232 | virtual int topMargin() const; | ||
1233 | virtual int bottomMargin() const; | ||
1234 | virtual int leftMargin() const; | ||
1235 | virtual int firstLineMargin() const; | ||
1236 | virtual int rightMargin() const; | ||
1237 | virtual int lineSpacing() const; | ||
1238 | |||
1239 | int numberOfSubParagraph() const; | ||
1240 | void registerFloatingItem( QTextCustomItem *i ); | ||
1241 | void unregisterFloatingItem( QTextCustomItem *i ); | ||
1242 | |||
1243 | void setFullWidth( bool b ) { fullWidth = b; } | ||
1244 | bool isFullWidth() const { return fullWidth; } | ||
1245 | |||
1246 | QTextTableCell *tableCell() const; | ||
1247 | |||
1248 | QBrush *background() const; | ||
1249 | |||
1250 | int documentWidth() const; | ||
1251 | int documentVisibleWidth() const; | ||
1252 | int documentX() const; | ||
1253 | int documentY() const; | ||
1254 | QTextFormatCollection *formatCollection() const; | ||
1255 | QTextFormatter *formatter() const; | ||
1256 | |||
1257 | virtual int nextTab( int i, int x ); | ||
1258 | int *tabArray() const; | ||
1259 | void setTabArray( int *a ); | ||
1260 | void setTabStops( int tw ); | ||
1261 | |||
1262 | void adjustToPainter( QPainter *p ); | ||
1263 | |||
1264 | void setNewLinesAllowed( bool b ); | ||
1265 | bool isNewLinesAllowed() const; | ||
1266 | |||
1267 | QString richText() const; | ||
1268 | |||
1269 | void addCommand( QTextCommand *cmd ); | ||
1270 | QTextCursor *undo( QTextCursor *c = 0 ); | ||
1271 | QTextCursor *redo( QTextCursor *c = 0 ); | ||
1272 | QTextCommandHistory *commands() const; | ||
1273 | virtual void copyParagData( QTextParag *parag ); | ||
1274 | |||
1275 | void setBreakable( bool b ) { breakable = b; } | ||
1276 | bool isBreakable() const { return breakable; } | ||
1277 | |||
1278 | void setBackgroundColor( const QColor &c ); | ||
1279 | QColor *backgroundColor() const { return bgcol; } | ||
1280 | void clearBackgroundColor(); | ||
1281 | |||
1282 | bool isLineBreak() const { return isBr; } | ||
1283 | |||
1284 | void setMovedDown( bool b ) { movedDown = b; } | ||
1285 | bool wasMovedDown() const { return movedDown; } | ||
1286 | |||
1287 | void setDirection( QChar::Direction d ); | ||
1288 | QChar::Direction direction() const; | ||
1289 | |||
1290 | protected: | ||
1291 | virtual void drawLabel( QPainter* p, int x, int y, int w, int h, int base, const QColorGroup& cg ); | ||
1292 | virtual void drawParagString( QPainter &painter, const QString &str, int start, int len, int startX, | ||
1293 | int lastY, int baseLine, int bw, int h, bool drawSelections, | ||
1294 | QTextStringChar *formatChar, int i, const QMemArray<int> &selectionStarts, | ||
1295 | const QMemArray<int> &selectionEnds, const QColorGroup &cg, bool rightToLeft ); | ||
1296 | |||
1297 | private: | ||
1298 | QMap<int, QTextParagSelection> &selections() const; | ||
1299 | QPtrVector<QStyleSheetItem> &styleSheetItemsVec() const; | ||
1300 | QPtrList<QTextCustomItem> &floatingItems() const; | ||
1301 | |||
1302 | QMap<int, QTextParagLineStart*> lineStarts; | ||
1303 | int invalid; | ||
1304 | QRect r; | ||
1305 | QTextParag *p, *n; | ||
1306 | void *docOrPseudo; | ||
1307 | uint changed : 1; | ||
1308 | uint firstFormat : 1; | ||
1309 | uint firstPProcess : 1; | ||
1310 | uint needPreProcess : 1; | ||
1311 | uint fullWidth : 1; | ||
1312 | uint newLinesAllowed : 1; | ||
1313 | uint lastInFrame : 1; | ||
1314 | uint visible : 1; | ||
1315 | uint breakable : 1; | ||
1316 | uint isBr : 1; | ||
1317 | uint movedDown : 1; | ||
1318 | uint mightHaveCustomItems : 1; | ||
1319 | uint hasdoc : 1; | ||
1320 | int align : 4; | ||
1321 | int state, id; | ||
1322 | QTextString *str; | ||
1323 | QMap<int, QTextParagSelection> *mSelections; | ||
1324 | QPtrVector<QStyleSheetItem> *mStyleSheetItemsVec; | ||
1325 | QPtrList<QTextCustomItem> *mFloatingItems; | ||
1326 | QStyleSheetItem::ListStyle listS; | ||
1327 | int numSubParag; | ||
1328 | int tm, bm, lm, rm, flm; | ||
1329 | QTextFormat *defFormat; | ||
1330 | int *tArray; | ||
1331 | int tabStopWidth; | ||
1332 | QTextParagData *eData; | ||
1333 | int list_val; | ||
1334 | QColor *bgcol; | ||
1335 | |||
1336 | }; | ||
1337 | |||
1338 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1339 | |||
1340 | class Q_EXPORT QTextFormatter | ||
1341 | { | ||
1342 | public: | ||
1343 | QTextFormatter(); | ||
1344 | virtual ~QTextFormatter(); | ||
1345 | |||
1346 | virtual int format( QTextDocument *doc, QTextParag *parag, int start, const QMap<int, QTextParagLineStart*> &oldLineStarts ) = 0; | ||
1347 | virtual int formatVertically( QTextDocument* doc, QTextParag* parag ); | ||
1348 | |||
1349 | bool isWrapEnabled( QTextParag *p ) const { if ( !wrapEnabled ) return FALSE; if ( p && !p->isBreakable() ) return FALSE; return TRUE;} | ||
1350 | int wrapAtColumn() const { return wrapColumn;} | ||
1351 | virtual void setWrapEnabled( bool b ); | ||
1352 | virtual void setWrapAtColumn( int c ); | ||
1353 | virtual void setAllowBreakInWords( bool b ) { biw = b; } | ||
1354 | bool allowBreakInWords() const { return biw; } | ||
1355 | |||
1356 | int minimumWidth() const { return thisminw; } | ||
1357 | int widthUsed() const { return thiswused; } | ||
1358 | |||
1359 | protected: | ||
1360 | virtual QTextParagLineStart *formatLine( QTextParag *parag, QTextString *string, QTextParagLineStart *line, QTextStringChar *start, | ||
1361 | QTextStringChar *last, int align = Qt3::AlignAuto, int space = 0 ); | ||
1362 | #ifndef QT_NO_COMPLEXTEXT | ||
1363 | virtual QTextParagLineStart *bidiReorderLine( QTextParag *parag, QTextString *string, QTextParagLineStart *line, QTextStringChar *start, | ||
1364 | QTextStringChar *last, int align, int space ); | ||
1365 | #endif | ||
1366 | virtual bool isBreakable( QTextString *string, int pos ) const; | ||
1367 | void insertLineStart( QTextParag *parag, int index, QTextParagLineStart *ls ); | ||
1368 | |||
1369 | int thisminw; | ||
1370 | int thiswused; | ||
1371 | |||
1372 | private: | ||
1373 | bool wrapEnabled; | ||
1374 | int wrapColumn; | ||
1375 | bool biw; | ||
1376 | |||
1377 | #ifdef HAVE_THAI_BREAKS | ||
1378 | static QCString *thaiCache; | ||
1379 | static QTextString *cachedString; | ||
1380 | static ThBreakIterator *thaiIt; | ||
1381 | #endif | ||
1382 | }; | ||
1383 | |||
1384 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1385 | |||
1386 | class Q_EXPORT QTextFormatterBreakInWords : public QTextFormatter | ||
1387 | { | ||
1388 | public: | ||
1389 | QTextFormatterBreakInWords(); | ||
1390 | virtual ~QTextFormatterBreakInWords() {} | ||
1391 | |||
1392 | int format( QTextDocument *doc, QTextParag *parag, int start, const QMap<int, QTextParagLineStart*> &oldLineStarts ); | ||
1393 | |||
1394 | }; | ||
1395 | |||
1396 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1397 | |||
1398 | class Q_EXPORT QTextFormatterBreakWords : public QTextFormatter | ||
1399 | { | ||
1400 | public: | ||
1401 | QTextFormatterBreakWords(); | ||
1402 | virtual ~QTextFormatterBreakWords() {} | ||
1403 | |||
1404 | int format( QTextDocument *doc, QTextParag *parag, int start, const QMap<int, QTextParagLineStart*> &oldLineStarts ); | ||
1405 | |||
1406 | }; | ||
1407 | |||
1408 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1409 | |||
1410 | class Q_EXPORT QTextIndent | ||
1411 | { | ||
1412 | public: | ||
1413 | QTextIndent(); | ||
1414 | virtual ~QTextIndent() {} | ||
1415 | |||
1416 | virtual void indent( QTextDocument *doc, QTextParag *parag, int *oldIndent = 0, int *newIndent = 0 ) = 0; | ||
1417 | |||
1418 | }; | ||
1419 | |||
1420 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1421 | |||
1422 | class Q_EXPORT QTextPreProcessor | ||
1423 | { | ||
1424 | public: | ||
1425 | enum Ids { | ||
1426 | Standard = 0 | ||
1427 | }; | ||
1428 | |||
1429 | QTextPreProcessor(); | ||
1430 | virtual ~QTextPreProcessor() {} | ||
1431 | |||
1432 | virtual void process( QTextDocument *doc, QTextParag *, int, bool = TRUE ) = 0; | ||
1433 | virtual QTextFormat *format( int id ) = 0; | ||
1434 | |||
1435 | }; | ||
1436 | |||
1437 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1438 | |||
1439 | class Q_EXPORT QTextFormat | ||
1440 | { | ||
1441 | friend class QTextFormatCollection; | ||
1442 | friend class QTextDocument; | ||
1443 | |||
1444 | public: | ||
1445 | enum Flags { | ||
1446 | NoFlags, | ||
1447 | Bold = 1, | ||
1448 | Italic = 2, | ||
1449 | Underline = 4, | ||
1450 | Family = 8, | ||
1451 | Size = 16, | ||
1452 | Color = 32, | ||
1453 | Misspelled = 64, | ||
1454 | VAlign = 128, | ||
1455 | Font = Bold | Italic | Underline | Family | Size, | ||
1456 | Format = Font | Color | Misspelled | VAlign | ||
1457 | }; | ||
1458 | |||
1459 | enum VerticalAlignment { AlignNormal, AlignSuperScript, AlignSubScript }; | ||
1460 | |||
1461 | QTextFormat(); | ||
1462 | virtual ~QTextFormat(); | ||
1463 | |||
1464 | QTextFormat( const QStyleSheetItem *s ); | ||
1465 | QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent = 0 ); | ||
1466 | QTextFormat( const QTextFormat &fm ); | ||
1467 | QTextFormat makeTextFormat( const QStyleSheetItem *style, const QMap<QString,QString>& attr ) const; | ||
1468 | QTextFormat& operator=( const QTextFormat &fm ); | ||
1469 | QColor color() const; | ||
1470 | QFont font() const; | ||
1471 | bool isMisspelled() const; | ||
1472 | VerticalAlignment vAlign() const; | ||
1473 | int minLeftBearing() const; | ||
1474 | int minRightBearing() const; | ||
1475 | int width( const QChar &c ) const; | ||
1476 | int width( const QString &str, int pos ) const; | ||
1477 | int height() const; | ||
1478 | int ascent() const; | ||
1479 | int descent() const; | ||
1480 | int leading() const; | ||
1481 | bool useLinkColor() const; | ||
1482 | |||
1483 | void setBold( bool b ); | ||
1484 | void setItalic( bool b ); | ||
1485 | void setUnderline( bool b ); | ||
1486 | void setFamily( const QString &f ); | ||
1487 | void setPointSize( int s ); | ||
1488 | void setFont( const QFont &f ); | ||
1489 | void setColor( const QColor &c ); | ||
1490 | void setMisspelled( bool b ); | ||
1491 | void setVAlign( VerticalAlignment a ); | ||
1492 | |||
1493 | bool operator==( const QTextFormat &f ) const; | ||
1494 | QTextFormatCollection *parent() const; | ||
1495 | QString key() const; | ||
1496 | |||
1497 | static QString getKey( const QFont &f, const QColor &c, bool misspelled, VerticalAlignment vAlign ); | ||
1498 | |||
1499 | void addRef(); | ||
1500 | void removeRef(); | ||
1501 | |||
1502 | QString makeFormatChangeTags( QTextFormat *f, const QString& oldAnchorHref, const QString& anchorHref ) const; | ||
1503 | QString makeFormatEndTags( const QString& anchorHref ) const; | ||
1504 | |||
1505 | static void setPainter( QPainter *p ); | ||
1506 | static QPainter* painter(); | ||
1507 | void updateStyle(); | ||
1508 | void updateStyleFlags(); | ||
1509 | void setStyle( const QString &s ); | ||
1510 | QString styleName() const { return style; } | ||
1511 | |||
1512 | int changed() const { return different; } | ||
1513 | bool fontSizesInPixels() { return usePixelSizes; } | ||
1514 | |||
1515 | protected: | ||
1516 | virtual void generateKey(); | ||
1517 | |||
1518 | private: | ||
1519 | void update(); | ||
1520 | |||
1521 | private: | ||
1522 | QFont fn; | ||
1523 | QColor col; | ||
1524 | QFontMetrics fm; | ||
1525 | uint missp : 1; | ||
1526 | uint linkColor : 1; | ||
1527 | uint usePixelSizes : 1; | ||
1528 | int leftBearing, rightBearing; | ||
1529 | VerticalAlignment ha; | ||
1530 | uchar widths[ 256 ]; | ||
1531 | int hei, asc, dsc; | ||
1532 | QTextFormatCollection *collection; | ||
1533 | int ref; | ||
1534 | QString k; | ||
1535 | int logicalFontSize; | ||
1536 | int stdSize; | ||
1537 | static QPainter *pntr; | ||
1538 | QString style; | ||
1539 | int different; | ||
1540 | |||
1541 | }; | ||
1542 | |||
1543 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1544 | |||
1545 | #if defined(Q_TEMPLATEDLL) | ||
1546 | // MOC_SKIP_BEGIN | ||
1547 | template class Q_EXPORT QDict<QTextFormat>; | ||
1548 | // MOC_SKIP_END | ||
1549 | #endif | ||
1550 | |||
1551 | class Q_EXPORT QTextFormatCollection | ||
1552 | { | ||
1553 | friend class QTextDocument; | ||
1554 | friend class QTextFormat; | ||
1555 | |||
1556 | public: | ||
1557 | QTextFormatCollection(); | ||
1558 | virtual ~QTextFormatCollection(); | ||
1559 | |||
1560 | void setDefaultFormat( QTextFormat *f ); | ||
1561 | QTextFormat *defaultFormat() const; | ||
1562 | virtual QTextFormat *format( QTextFormat *f ); | ||
1563 | virtual QTextFormat *format( QTextFormat *of, QTextFormat *nf, int flags ); | ||
1564 | virtual QTextFormat *format( const QFont &f, const QColor &c ); | ||
1565 | virtual void remove( QTextFormat *f ); | ||
1566 | virtual QTextFormat *createFormat( const QTextFormat &f ) { return new QTextFormat( f ); } | ||
1567 | virtual QTextFormat *createFormat( const QFont &f, const QColor &c ) { return new QTextFormat( f, c, this ); } | ||
1568 | void debug(); | ||
1569 | |||
1570 | QStyleSheet *styleSheet() const { return sheet; } | ||
1571 | void setStyleSheet( QStyleSheet *s ) { sheet = s; } | ||
1572 | void updateStyles(); | ||
1573 | void updateFontSizes( int base, bool usePixels ); | ||
1574 | void updateFontAttributes( const QFont &f, const QFont &old ); | ||
1575 | QDict<QTextFormat> dict() const { return cKey; } | ||
1576 | |||
1577 | private: | ||
1578 | void updateKeys(); | ||
1579 | |||
1580 | private: | ||
1581 | QTextFormat *defFormat, *lastFormat, *cachedFormat; | ||
1582 | QDict<QTextFormat> cKey; | ||
1583 | QTextFormat *cres; | ||
1584 | QFont cfont; | ||
1585 | QColor ccol; | ||
1586 | QString kof, knf; | ||
1587 | int cflags; | ||
1588 | QStyleSheet *sheet; | ||
1589 | |||
1590 | }; | ||
1591 | |||
1592 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1593 | |||
1594 | inline int QTextString::length() const | ||
1595 | { | ||
1596 | return data.size(); | ||
1597 | } | ||
1598 | |||
1599 | inline void QTextString::operator+=( const QString &s ) | ||
1600 | { | ||
1601 | insert( length(), s, 0 ); | ||
1602 | } | ||
1603 | |||
1604 | inline int QTextParag::length() const | ||
1605 | { | ||
1606 | return str->length(); | ||
1607 | } | ||
1608 | |||
1609 | inline QRect QTextParag::rect() const | ||
1610 | { | ||
1611 | return r; | ||
1612 | } | ||
1613 | |||
1614 | inline QTextParag *QTextCursor::parag() const | ||
1615 | { | ||
1616 | return string; | ||
1617 | } | ||
1618 | |||
1619 | inline int QTextCursor::index() const | ||
1620 | { | ||
1621 | return idx; | ||
1622 | } | ||
1623 | |||
1624 | inline void QTextCursor::setIndex( int i, bool restore ) | ||
1625 | { | ||
1626 | if ( restore ) | ||
1627 | restoreState(); | ||
1628 | if ( i < 0 || i >= string->length() ) { | ||
1629 | #if defined(QT_CHECK_RANGE) | ||
1630 | qWarning( "QTextCursor::setIndex: %d out of range", i ); | ||
1631 | #endif | ||
1632 | i = i < 0 ? 0 : string->length() - 1; | ||
1633 | } | ||
1634 | |||
1635 | tmpIndex = -1; | ||
1636 | idx = i; | ||
1637 | } | ||
1638 | |||
1639 | inline void QTextCursor::setParag( QTextParag *s, bool restore ) | ||
1640 | { | ||
1641 | if ( restore ) | ||
1642 | restoreState(); | ||
1643 | idx = 0; | ||
1644 | string = s; | ||
1645 | tmpIndex = -1; | ||
1646 | } | ||
1647 | |||
1648 | inline void QTextCursor::checkIndex() | ||
1649 | { | ||
1650 | if ( idx >= string->length() ) | ||
1651 | idx = string->length() - 1; | ||
1652 | } | ||
1653 | |||
1654 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1655 | |||
1656 | inline int QTextDocument::x() const | ||
1657 | { | ||
1658 | return cx; | ||
1659 | } | ||
1660 | |||
1661 | inline int QTextDocument::y() const | ||
1662 | { | ||
1663 | return cy; | ||
1664 | } | ||
1665 | |||
1666 | inline int QTextDocument::width() const | ||
1667 | { | ||
1668 | return QMAX( cw, flow_->width() ); | ||
1669 | } | ||
1670 | |||
1671 | inline int QTextDocument::visibleWidth() const | ||
1672 | { | ||
1673 | return vw; | ||
1674 | } | ||
1675 | |||
1676 | inline QTextParag *QTextDocument::firstParag() const | ||
1677 | { | ||
1678 | return fParag; | ||
1679 | } | ||
1680 | |||
1681 | inline QTextParag *QTextDocument::lastParag() const | ||
1682 | { | ||
1683 | return lParag; | ||
1684 | } | ||
1685 | |||
1686 | inline void QTextDocument::setFirstParag( QTextParag *p ) | ||
1687 | { | ||
1688 | fParag = p; | ||
1689 | } | ||
1690 | |||
1691 | inline void QTextDocument::setLastParag( QTextParag *p ) | ||
1692 | { | ||
1693 | lParag = p; | ||
1694 | } | ||
1695 | |||
1696 | inline void QTextDocument::setWidth( int w ) | ||
1697 | { | ||
1698 | cw = QMAX( w, minw ); | ||
1699 | flow_->setWidth( cw ); | ||
1700 | vw = w; | ||
1701 | } | ||
1702 | |||
1703 | inline int QTextDocument::minimumWidth() const | ||
1704 | { | ||
1705 | return minw; | ||
1706 | } | ||
1707 | |||
1708 | inline void QTextDocument::setY( int y ) | ||
1709 | { | ||
1710 | cy = y; | ||
1711 | } | ||
1712 | |||
1713 | inline int QTextDocument::leftMargin() const | ||
1714 | { | ||
1715 | return leftmargin; | ||
1716 | } | ||
1717 | |||
1718 | inline void QTextDocument::setLeftMargin( int lm ) | ||
1719 | { | ||
1720 | leftmargin = lm; | ||
1721 | } | ||
1722 | |||
1723 | inline int QTextDocument::rightMargin() const | ||
1724 | { | ||
1725 | return rightmargin; | ||
1726 | } | ||
1727 | |||
1728 | inline void QTextDocument::setRightMargin( int rm ) | ||
1729 | { | ||
1730 | rightmargin = rm; | ||
1731 | } | ||
1732 | |||
1733 | inline QTextPreProcessor *QTextDocument::preProcessor() const | ||
1734 | { | ||
1735 | return pProcessor; | ||
1736 | } | ||
1737 | |||
1738 | inline void QTextDocument::setPreProcessor( QTextPreProcessor * sh ) | ||
1739 | { | ||
1740 | pProcessor = sh; | ||
1741 | } | ||
1742 | |||
1743 | inline void QTextDocument::setFormatter( QTextFormatter *f ) | ||
1744 | { | ||
1745 | delete pFormatter; | ||
1746 | pFormatter = f; | ||
1747 | } | ||
1748 | |||
1749 | inline QTextFormatter *QTextDocument::formatter() const | ||
1750 | { | ||
1751 | return pFormatter; | ||
1752 | } | ||
1753 | |||
1754 | inline void QTextDocument::setIndent( QTextIndent *i ) | ||
1755 | { | ||
1756 | indenter = i; | ||
1757 | } | ||
1758 | |||
1759 | inline QTextIndent *QTextDocument::indent() const | ||
1760 | { | ||
1761 | return indenter; | ||
1762 | } | ||
1763 | |||
1764 | inline QColor QTextDocument::selectionColor( int id ) const | ||
1765 | { | ||
1766 | return selectionColors[ id ]; | ||
1767 | } | ||
1768 | |||
1769 | inline bool QTextDocument::invertSelectionText( int id ) const | ||
1770 | { | ||
1771 | return selectionText[ id ]; | ||
1772 | } | ||
1773 | |||
1774 | inline void QTextDocument::setSelectionColor( int id, const QColor &c ) | ||
1775 | { | ||
1776 | selectionColors[ id ] = c; | ||
1777 | } | ||
1778 | |||
1779 | inline void QTextDocument::setInvertSelectionText( int id, bool b ) | ||
1780 | { | ||
1781 | selectionText[ id ] = b; | ||
1782 | } | ||
1783 | |||
1784 | inline QTextFormatCollection *QTextDocument::formatCollection() const | ||
1785 | { | ||
1786 | return fCollection; | ||
1787 | } | ||
1788 | |||
1789 | inline int QTextDocument::alignment() const | ||
1790 | { | ||
1791 | return align; | ||
1792 | } | ||
1793 | |||
1794 | inline void QTextDocument::setAlignment( int a ) | ||
1795 | { | ||
1796 | align = a; | ||
1797 | } | ||
1798 | |||
1799 | inline int *QTextDocument::tabArray() const | ||
1800 | { | ||
1801 | return tArray; | ||
1802 | } | ||
1803 | |||
1804 | inline int QTextDocument::tabStopWidth() const | ||
1805 | { | ||
1806 | return tStopWidth; | ||
1807 | } | ||
1808 | |||
1809 | inline void QTextDocument::setTabArray( int *a ) | ||
1810 | { | ||
1811 | tArray = a; | ||
1812 | } | ||
1813 | |||
1814 | inline void QTextDocument::setTabStops( int tw ) | ||
1815 | { | ||
1816 | tStopWidth = tw; | ||
1817 | } | ||
1818 | |||
1819 | inline QString QTextDocument::originalText() const | ||
1820 | { | ||
1821 | if ( oTextValid ) | ||
1822 | return oText; | ||
1823 | return text(); | ||
1824 | } | ||
1825 | |||
1826 | inline void QTextDocument::setFlow( QTextFlow *f ) | ||
1827 | { | ||
1828 | if ( flow_ ) | ||
1829 | delete flow_; | ||
1830 | flow_ = f; | ||
1831 | } | ||
1832 | |||
1833 | inline void QTextDocument::takeFlow() | ||
1834 | { | ||
1835 | flow_ = 0; | ||
1836 | } | ||
1837 | |||
1838 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1839 | |||
1840 | inline QColor QTextFormat::color() const | ||
1841 | { | ||
1842 | return col; | ||
1843 | } | ||
1844 | |||
1845 | inline QFont QTextFormat::font() const | ||
1846 | { | ||
1847 | return fn; | ||
1848 | } | ||
1849 | |||
1850 | inline bool QTextFormat::isMisspelled() const | ||
1851 | { | ||
1852 | return missp; | ||
1853 | } | ||
1854 | |||
1855 | inline QTextFormat::VerticalAlignment QTextFormat::vAlign() const | ||
1856 | { | ||
1857 | return ha; | ||
1858 | } | ||
1859 | |||
1860 | inline bool QTextFormat::operator==( const QTextFormat &f ) const | ||
1861 | { | ||
1862 | return k == f.k; | ||
1863 | } | ||
1864 | |||
1865 | inline QTextFormatCollection *QTextFormat::parent() const | ||
1866 | { | ||
1867 | return collection; | ||
1868 | } | ||
1869 | |||
1870 | inline void QTextFormat::addRef() | ||
1871 | { | ||
1872 | ref++; | ||
1873 | #ifdef DEBUG_COLLECTION | ||
1874 | qDebug( "add ref of '%s' to %d (%p)", k.latin1(), ref, this ); | ||
1875 | #endif | ||
1876 | } | ||
1877 | |||
1878 | inline void QTextFormat::removeRef() | ||
1879 | { | ||
1880 | ref--; | ||
1881 | if ( !collection ) | ||
1882 | return; | ||
1883 | if ( this == collection->defFormat ) | ||
1884 | return; | ||
1885 | #ifdef DEBUG_COLLECTION | ||
1886 | qDebug( "remove ref of '%s' to %d (%p)", k.latin1(), ref, this ); | ||
1887 | #endif | ||
1888 | if ( ref == 0 ) | ||
1889 | collection->remove( this ); | ||
1890 | } | ||
1891 | |||
1892 | inline QString QTextFormat::key() const | ||
1893 | { | ||
1894 | return k; | ||
1895 | } | ||
1896 | |||
1897 | inline bool QTextFormat::useLinkColor() const | ||
1898 | { | ||
1899 | return linkColor; | ||
1900 | } | ||
1901 | |||
1902 | inline void QTextFormat::setStyle( const QString &s ) | ||
1903 | { | ||
1904 | style = s; | ||
1905 | updateStyleFlags(); | ||
1906 | } | ||
1907 | |||
1908 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1909 | |||
1910 | inline QTextStringChar &QTextString::at( int i ) const | ||
1911 | { | ||
1912 | return data[ i ]; | ||
1913 | } | ||
1914 | |||
1915 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
1916 | |||
1917 | inline QTextStringChar *QTextParag::at( int i ) const | ||
1918 | { | ||
1919 | return &str->at( i ); | ||
1920 | } | ||
1921 | |||
1922 | inline bool QTextParag::isValid() const | ||
1923 | { | ||
1924 | return invalid == -1; | ||
1925 | } | ||
1926 | |||
1927 | inline bool QTextParag::hasChanged() const | ||
1928 | { | ||
1929 | return changed; | ||
1930 | } | ||
1931 | |||
1932 | inline void QTextParag::setBackgroundColor( const QColor & c ) | ||
1933 | { | ||
1934 | delete bgcol; | ||
1935 | bgcol = new QColor( c ); | ||
1936 | setChanged( TRUE ); | ||
1937 | } | ||
1938 | |||
1939 | inline void QTextParag::clearBackgroundColor() | ||
1940 | { | ||
1941 | delete bgcol; bgcol = 0; setChanged( TRUE ); | ||
1942 | } | ||
1943 | |||
1944 | inline void QTextParag::append( const QString &s, bool reallyAtEnd ) | ||
1945 | { | ||
1946 | if ( reallyAtEnd ) | ||
1947 | insert( str->length(), s ); | ||
1948 | else | ||
1949 | insert( QMAX( str->length() - 1, 0 ), s ); | ||
1950 | } | ||
1951 | |||
1952 | inline QTextParag *QTextParag::prev() const | ||
1953 | { | ||
1954 | return p; | ||
1955 | } | ||
1956 | |||
1957 | inline QTextParag *QTextParag::next() const | ||
1958 | { | ||
1959 | return n; | ||
1960 | } | ||
1961 | |||
1962 | inline bool QTextParag::hasAnySelection() const | ||
1963 | { | ||
1964 | return mSelections ? !selections().isEmpty() : FALSE; | ||
1965 | } | ||
1966 | |||
1967 | inline void QTextParag::setEndState( int s ) | ||
1968 | { | ||
1969 | if ( s == state ) | ||
1970 | return; | ||
1971 | state = s; | ||
1972 | } | ||
1973 | |||
1974 | inline int QTextParag::endState() const | ||
1975 | { | ||
1976 | return state; | ||
1977 | } | ||
1978 | |||
1979 | inline void QTextParag::setParagId( int i ) | ||
1980 | { | ||
1981 | id = i; | ||
1982 | } | ||
1983 | |||
1984 | inline int QTextParag::paragId() const | ||
1985 | { | ||
1986 | if ( id == -1 ) | ||
1987 | qWarning( "invalid parag id!!!!!!!! (%p)", (void*)this ); | ||
1988 | return id; | ||
1989 | } | ||
1990 | |||
1991 | inline bool QTextParag::firstPreProcess() const | ||
1992 | { | ||
1993 | return firstPProcess; | ||
1994 | } | ||
1995 | |||
1996 | inline void QTextParag::setFirstPreProcess( bool b ) | ||
1997 | { | ||
1998 | firstPProcess = b; | ||
1999 | } | ||
2000 | |||
2001 | inline QMap<int, QTextParagLineStart*> &QTextParag::lineStartList() | ||
2002 | { | ||
2003 | return lineStarts; | ||
2004 | } | ||
2005 | |||
2006 | inline QTextString *QTextParag::string() const | ||
2007 | { | ||
2008 | return str; | ||
2009 | } | ||
2010 | |||
2011 | inline QTextDocument *QTextParag::document() const | ||
2012 | { | ||
2013 | if ( hasdoc ) | ||
2014 | return (QTextDocument*) docOrPseudo; | ||
2015 | return 0; | ||
2016 | } | ||
2017 | |||
2018 | inline QTextParagPseudoDocument *QTextParag::pseudoDocument() const | ||
2019 | { | ||
2020 | if ( hasdoc ) | ||
2021 | return 0; | ||
2022 | return (QTextParagPseudoDocument*) docOrPseudo; | ||
2023 | } | ||
2024 | |||
2025 | |||
2026 | inline QTextTableCell *QTextParag::tableCell() const | ||
2027 | { | ||
2028 | return hasdoc ? document()->tableCell () : 0; | ||
2029 | } | ||
2030 | |||
2031 | inline QTextCommandHistory *QTextParag::commands() const | ||
2032 | { | ||
2033 | return hasdoc ? document()->commands() : pseudoDocument()->commandHistory; | ||
2034 | } | ||
2035 | |||
2036 | |||
2037 | inline void QTextParag::setAlignment( int a ) | ||
2038 | { | ||
2039 | if ( a == (int)align ) | ||
2040 | return; | ||
2041 | align = a; | ||
2042 | invalidate( 0 ); | ||
2043 | } | ||
2044 | |||
2045 | inline void QTextParag::setListStyle( QStyleSheetItem::ListStyle ls ) | ||
2046 | { | ||
2047 | listS = ls; | ||
2048 | invalidate( 0 ); | ||
2049 | } | ||
2050 | |||
2051 | inline QStyleSheetItem::ListStyle QTextParag::listStyle() const | ||
2052 | { | ||
2053 | return listS; | ||
2054 | } | ||
2055 | |||
2056 | inline QTextFormat *QTextParag::paragFormat() const | ||
2057 | { | ||
2058 | return defFormat; | ||
2059 | } | ||
2060 | |||
2061 | inline void QTextParag::registerFloatingItem( QTextCustomItem *i ) | ||
2062 | { | ||
2063 | floatingItems().append( i ); | ||
2064 | } | ||
2065 | |||
2066 | inline void QTextParag::unregisterFloatingItem( QTextCustomItem *i ) | ||
2067 | { | ||
2068 | floatingItems().removeRef( i ); | ||
2069 | } | ||
2070 | |||
2071 | inline QBrush *QTextParag::background() const | ||
2072 | { | ||
2073 | return tableCell() ? tableCell()->backGround() : 0; | ||
2074 | } | ||
2075 | |||
2076 | inline int QTextParag::documentWidth() const | ||
2077 | { | ||
2078 | return hasdoc ? document()->width() : pseudoDocument()->docRect.width(); | ||
2079 | } | ||
2080 | |||
2081 | inline int QTextParag::documentVisibleWidth() const | ||
2082 | { | ||
2083 | return hasdoc ? document()->visibleWidth() : pseudoDocument()->docRect.width(); | ||
2084 | } | ||
2085 | |||
2086 | inline int QTextParag::documentX() const | ||
2087 | { | ||
2088 | return hasdoc ? document()->x() : pseudoDocument()->docRect.x(); | ||
2089 | } | ||
2090 | |||
2091 | inline int QTextParag::documentY() const | ||
2092 | { | ||
2093 | return hasdoc ? document()->y() : pseudoDocument()->docRect.y(); | ||
2094 | } | ||
2095 | |||
2096 | inline void QTextParag::setExtraData( QTextParagData *data ) | ||
2097 | { | ||
2098 | eData = data; | ||
2099 | } | ||
2100 | |||
2101 | inline QTextParagData *QTextParag::extraData() const | ||
2102 | { | ||
2103 | return eData; | ||
2104 | } | ||
2105 | |||
2106 | inline void QTextParag::setNewLinesAllowed( bool b ) | ||
2107 | { | ||
2108 | newLinesAllowed = b; | ||
2109 | } | ||
2110 | |||
2111 | inline bool QTextParag::isNewLinesAllowed() const | ||
2112 | { | ||
2113 | return newLinesAllowed; | ||
2114 | } | ||
2115 | |||
2116 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
2117 | |||
2118 | inline void QTextFormatCollection::setDefaultFormat( QTextFormat *f ) | ||
2119 | { | ||
2120 | defFormat = f; | ||
2121 | } | ||
2122 | |||
2123 | inline QTextFormat *QTextFormatCollection::defaultFormat() const | ||
2124 | { | ||
2125 | return defFormat; | ||
2126 | } | ||
2127 | |||
2128 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
2129 | |||
2130 | inline QTextFormat *QTextStringChar::format() const | ||
2131 | { | ||
2132 | return (type == Regular) ? d.format : d.custom->format; | ||
2133 | } | ||
2134 | |||
2135 | |||
2136 | inline QTextCustomItem *QTextStringChar::customItem() const | ||
2137 | { | ||
2138 | return isCustom() ? d.custom->custom : 0; | ||
2139 | } | ||
2140 | |||
2141 | inline int QTextStringChar::height() const | ||
2142 | { | ||
2143 | return !isCustom() ? format()->height() : ( customItem()->placement() == QTextCustomItem::PlaceInline ? customItem()->height : 0 ); | ||
2144 | } | ||
2145 | |||
2146 | inline int QTextStringChar::ascent() const | ||
2147 | { | ||
2148 | return !isCustom() ? format()->ascent() : ( customItem()->placement() == QTextCustomItem::PlaceInline ? customItem()->ascent() : 0 ); | ||
2149 | } | ||
2150 | |||
2151 | inline int QTextStringChar::descent() const | ||
2152 | { | ||
2153 | return !isCustom() ? format()->descent() : 0; | ||
2154 | } | ||
2155 | |||
2156 | } // namespace Qt3 | ||
2157 | |||
2158 | #endif | ||