summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-write/qrichtext_p.cpp
authorleseb <leseb>2002-07-15 23:22:50 (UTC)
committer leseb <leseb>2002-07-15 23:22:50 (UTC)
commit72eb74051ed8f1b7696041e241ab99df3af5b08d (patch) (unidiff)
treebf9beee9469bc4384cb8178fbd6565cf161b4708 /noncore/apps/opie-write/qrichtext_p.cpp
parentdcea0e50a00ed9efb988ded5abf5d39de1bea393 (diff)
downloadopie-72eb74051ed8f1b7696041e241ab99df3af5b08d.zip
opie-72eb74051ed8f1b7696041e241ab99df3af5b08d.tar.gz
opie-72eb74051ed8f1b7696041e241ab99df3af5b08d.tar.bz2
Sync with Qt 3.0.5
Diffstat (limited to 'noncore/apps/opie-write/qrichtext_p.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-write/qrichtext_p.cpp303
1 files changed, 100 insertions, 203 deletions
diff --git a/noncore/apps/opie-write/qrichtext_p.cpp b/noncore/apps/opie-write/qrichtext_p.cpp
index fb20730..6783e0b 100644
--- a/noncore/apps/opie-write/qrichtext_p.cpp
+++ b/noncore/apps/opie-write/qrichtext_p.cpp
@@ -56,30 +56,29 @@ int QTextCustomItem::minimumWidth() const { return 0; }
56 56
57QString QTextCustomItem::richText() const { return QString::null; } 57QString QTextCustomItem::richText() const { return QString::null; }
58 58
59bool QTextCustomItem::enter( QTextCursor *, QTextDocument *&doc, QTextParag *&parag, int &idx, int &ox, int &oy, bool atEnd ) 59bool QTextCustomItem::enter( QTextCursor *, QTextDocument*&, QTextParagraph *&, int &, int &, int &, bool )
60{ 60{
61 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; Q_UNUSED( atEnd ) return TRUE; 61 return TRUE;
62
63} 62}
64bool QTextCustomItem::enterAt( QTextCursor *, QTextDocument *&doc, QTextParag *&parag, int &idx, int &ox, int &oy, const QPoint & ) 63bool QTextCustomItem::enterAt( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int &, const QPoint & )
65{ 64{
66 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; 65 return TRUE;
67} 66}
68bool QTextCustomItem::next( QTextCursor *, QTextDocument *&doc, QTextParag *&parag, int &idx, int &ox, int &oy ) 67bool QTextCustomItem::next( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & )
69{ 68{
70 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; 69 return TRUE;
71} 70}
72bool QTextCustomItem::prev( QTextCursor *, QTextDocument *&doc, QTextParag *&parag, int &idx, int &ox, int &oy ) 71bool QTextCustomItem::prev( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & )
73{ 72{
74 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; 73 return TRUE;
75} 74}
76bool QTextCustomItem::down( QTextCursor *, QTextDocument *&doc, QTextParag *&parag, int &idx, int &ox, int &oy ) 75bool QTextCustomItem::down( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & )
77{ 76{
78 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; 77 return TRUE;
79} 78}
80bool QTextCustomItem::up( QTextCursor *, QTextDocument *&doc, QTextParag *&parag, int &idx, int &ox, int &oy ) 79bool QTextCustomItem::up( QTextCursor *, QTextDocument *&, QTextParagraph *&, int &, int &, int & )
81{ 80{
82 doc = doc; parag = parag; idx = idx; ox = ox; oy = oy; return TRUE; 81 return TRUE;
83} 82}
84 83
85void QTextFlow::setPageSize( int ps ) { pagesize = ps; } 84void QTextFlow::setPageSize( int ps ) { pagesize = ps; }
@@ -89,8 +88,8 @@ void QTextTableCell::invalidate() { cached_width = -1; cached_sizehint = -1; }
89 88
90void QTextTable::invalidate() { cachewidth = -1; } 89void QTextTable::invalidate() { cachewidth = -1; }
91 90
92QTextParagData::~QTextParagData() {} 91QTextParagraphData::~QTextParagraphData() {}
93void QTextParagData::join( QTextParagData * ) {} 92void QTextParagraphData::join( QTextParagraphData * ) {}
94 93
95QTextFormatter::~QTextFormatter() {} 94QTextFormatter::~QTextFormatter() {}
96void QTextFormatter::setWrapEnabled( bool b ) { wrapEnabled = b; } 95void QTextFormatter::setWrapEnabled( bool b ) { wrapEnabled = b; }
@@ -100,23 +99,51 @@ void QTextFormatter::setWrapAtColumn( int c ) { wrapColumn = c; }
100 99
101int QTextCursor::x() const 100int QTextCursor::x() const
102{ 101{
103 QTextStringChar *c = string->at( idx ); 102 QTextStringChar *c = para->at( idx );
104 int curx = c->x; 103 int curx = c->x;
105 if ( !c->rightToLeft && 104 if ( !c->rightToLeft &&
106 c->c.isSpace() && 105 c->c.isSpace() &&
107 idx > 0 && 106 idx > 0 &&
108 ( string->alignment() & Qt3::AlignJustify ) == Qt3::AlignJustify ) 107 !c->lineStart &&
109 curx = string->at( idx - 1 )->x + string->string()->width( idx - 1 ); 108 ( para->alignment() & Qt3::AlignJustify ) == Qt3::AlignJustify )
109 curx = para->at( idx - 1 )->x + para->string()->width( idx - 1 );
110 if ( c->rightToLeft ) 110 if ( c->rightToLeft )
111 curx += string->string()->width( idx ); 111 curx += para->string()->width( idx );
112 return curx; 112 return curx;
113} 113}
114 114
115int QTextCursor::y() const 115int QTextCursor::y() const
116{ 116{
117 int dummy, line; 117 int dummy, line;
118 string->lineStartOfChar( idx, &dummy, &line ); 118 para->lineStartOfChar( idx, &dummy, &line );
119 return string->lineY( line ); 119 return para->lineY( line );
120}
121
122int QTextCursor::globalX() const { return totalOffsetX() + para->rect().x() + x(); }
123int QTextCursor::globalY() const { return totalOffsetY() + para->rect().y() + y(); }
124
125QTextDocument *QTextCursor::document() const
126{
127 return para ? para->document() : 0;
128}
129
130void QTextCursor::gotoPosition( QTextParagraph* p, int index )
131{
132 if ( para && p != para ) {
133 while ( para->document() != p->document() && !indices.isEmpty() )
134 pop();
135 Q_ASSERT( indices.isEmpty() || para->document() == p->document() );
136 }
137 para = p;
138 if ( index < 0 || index >= para->length() ) {
139#if defined(QT_CHECK_RANGE)
140 qWarning( "QTextCursor::gotoParagraph Index: %d out of range", index );
141#endif
142 index = index < 0 ? 0 : para->length() - 1;
143 }
144
145 tmpIndex = -1;
146 idx = index;
120} 147}
121 148
122bool QTextDocument::hasSelection( int id, bool visible ) const 149bool QTextDocument::hasSelection( int id, bool visible ) const
@@ -127,18 +154,18 @@ bool QTextDocument::hasSelection( int id, bool visible ) const
127 ( (QTextDocument*)this )->selectionEndCursor( id ) ) ); 154 ( (QTextDocument*)this )->selectionEndCursor( id ) ) );
128} 155}
129 156
130void QTextDocument::setSelectionStart( int id, QTextCursor *cursor ) 157void QTextDocument::setSelectionStart( int id, const QTextCursor &cursor )
131{ 158{
132 QTextDocumentSelection sel; 159 QTextDocumentSelection sel;
133 sel.startCursor = *cursor; 160 sel.startCursor = cursor;
134 sel.endCursor = *cursor; 161 sel.endCursor = cursor;
135 sel.swapped = FALSE; 162 sel.swapped = FALSE;
136 selections[ id ] = sel; 163 selections[ id ] = sel;
137} 164}
138 165
139QTextParag *QTextDocument::paragAt( int i ) const 166QTextParagraph *QTextDocument::paragAt( int i ) const
140{ 167{
141 QTextParag* p = curParag; 168 QTextParagraph* p = curParag;
142 if ( !p || p->paragId() > i ) 169 if ( !p || p->paragId() > i )
143 p = fParag; 170 p = fParag;
144 while ( p && p->paragId() != i ) 171 while ( p && p->paragId() != i )
@@ -153,8 +180,7 @@ QTextFormat::~QTextFormat()
153} 180}
154 181
155QTextFormat::QTextFormat() 182QTextFormat::QTextFormat()
156 : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ), 183 : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() )
157 different( NoFlags )
158{ 184{
159 ref = 0; 185 ref = 0;
160 186
@@ -163,15 +189,14 @@ QTextFormat::QTextFormat()
163 stdSize = qApp->font().pixelSize(); 189 stdSize = qApp->font().pixelSize();
164 usePixelSizes = TRUE; 190 usePixelSizes = TRUE;
165 } 191 }
166 192
167 missp = FALSE; 193 missp = FALSE;
168 ha = AlignNormal; 194 ha = AlignNormal;
169 collection = 0; 195 collection = 0;
170} 196}
171 197
172QTextFormat::QTextFormat( const QStyleSheetItem *style ) 198QTextFormat::QTextFormat( const QStyleSheetItem *style )
173 : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() ), 199 : fm( QFontMetrics( fn ) ), linkColor( TRUE ), logicalFontSize( 3 ), stdSize( qApp->font().pointSize() )
174 different( NoFlags )
175{ 200{
176 ref = 0; 201 ref = 0;
177 202
@@ -181,7 +206,6 @@ QTextFormat::QTextFormat( const QStyleSheetItem *style )
181 usePixelSizes = TRUE; 206 usePixelSizes = TRUE;
182 } 207 }
183 208
184 this->style = style->name();
185 missp = FALSE; 209 missp = FALSE;
186 ha = AlignNormal; 210 ha = AlignNormal;
187 collection = 0; 211 collection = 0;
@@ -190,6 +214,7 @@ QTextFormat::QTextFormat( const QStyleSheetItem *style )
190 style->fontWeight(), 214 style->fontWeight(),
191 style->fontItalic() ); 215 style->fontItalic() );
192 fn.setUnderline( style->fontUnderline() ); 216 fn.setUnderline( style->fontUnderline() );
217 fn.setStrikeOut( style->fontStrikeOut() );
193 col = style->color(); 218 col = style->color();
194 fm = QFontMetrics( fn ); 219 fm = QFontMetrics( fn );
195 leftBearing = fm.minLeftBearing(); 220 leftBearing = fm.minLeftBearing();
@@ -202,12 +227,11 @@ QTextFormat::QTextFormat( const QStyleSheetItem *style )
202 memset( widths, 0, 256 ); 227 memset( widths, 0, 256 );
203 generateKey(); 228 generateKey();
204 addRef(); 229 addRef();
205 updateStyleFlags();
206} 230}
207 231
208QTextFormat::QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent ) 232QTextFormat::QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection *parent )
209 : fn( f ), col( c ), fm( QFontMetrics( f ) ), linkColor( TRUE ), 233 : fn( f ), col( c ), fm( QFontMetrics( f ) ), linkColor( TRUE ),
210 logicalFontSize( 3 ), stdSize( f.pointSize() ), different( NoFlags ) 234 logicalFontSize( 3 ), stdSize( f.pointSize() )
211{ 235{
212 ref = 0; 236 ref = 0;
213 usePixelSizes = FALSE; 237 usePixelSizes = FALSE;
@@ -226,7 +250,6 @@ QTextFormat::QTextFormat( const QFont &f, const QColor &c, QTextFormatCollection
226 memset( widths, 0, 256 ); 250 memset( widths, 0, 256 );
227 generateKey(); 251 generateKey();
228 addRef(); 252 addRef();
229 updateStyleFlags();
230} 253}
231 254
232QTextFormat::QTextFormat( const QTextFormat &f ) 255QTextFormat::QTextFormat( const QTextFormat &f )
@@ -249,8 +272,6 @@ QTextFormat::QTextFormat( const QTextFormat &f )
249 ha = f.ha; 272 ha = f.ha;
250 k = f.k; 273 k = f.k;
251 linkColor = f.linkColor; 274 linkColor = f.linkColor;
252 style = f.style;
253 different = f.different;
254 addRef(); 275 addRef();
255} 276}
256 277
@@ -274,8 +295,6 @@ QTextFormat& QTextFormat::operator=( const QTextFormat &f )
274 ha = f.ha; 295 ha = f.ha;
275 k = f.k; 296 k = f.k;
276 linkColor = f.linkColor; 297 linkColor = f.linkColor;
277 style = f.style;
278 different = f.different;
279 addRef(); 298 addRef();
280 return *this; 299 return *this;
281} 300}
@@ -290,7 +309,6 @@ void QTextFormat::update()
290 dsc = fm.descent(); 309 dsc = fm.descent();
291 memset( widths, 0, 256 ); 310 memset( widths, 0, 256 );
292 generateKey(); 311 generateKey();
293 updateStyleFlags();
294} 312}
295 313
296 314
@@ -372,52 +390,6 @@ QString QTextFormat::getKey( const QFont &fn, const QColor &col, bool misspelled
372 return k; 390 return k;
373} 391}
374 392
375void QTextFormat::updateStyle()
376{
377 if ( !collection || !collection->styleSheet() )
378 return;
379 QStyleSheetItem *item = collection->styleSheet()->item( style );
380 if ( !item )
381 return;
382 if ( !( different & Color ) && item->color().isValid() )
383 col = item->color();
384 if ( !( different & Size ) && item->fontSize() != -1 )
385 fn.setPointSize( item->fontSize() );
386 if ( !( different & Family ) && !item->fontFamily().isEmpty() )
387 fn.setFamily( item->fontFamily() );
388 if ( !( different & Bold ) && item->fontWeight() != -1 )
389 fn.setWeight( item->fontWeight() );
390 if ( !( different & Italic ) && item->definesFontItalic() )
391 fn.setItalic( item->fontItalic() );
392 if ( !( different & Underline ) && item->definesFontUnderline() )
393 fn.setUnderline( item->fontUnderline() );
394 generateKey();
395 update();
396
397}
398
399void QTextFormat::updateStyleFlags()
400{
401 different = NoFlags;
402 if ( !collection || !collection->styleSheet() )
403 return;
404 QStyleSheetItem *item = collection->styleSheet()->item( style );
405 if ( !item )
406 return;
407 if ( item->color() != col )
408 different |= Color;
409 if ( item->fontSize() != fn.pointSize() )
410 different |= Size;
411 if ( item->fontFamily() != fn.family() )
412 different |= Family;
413 if ( item->fontItalic() != fn.italic() )
414 different |= Italic;
415 if ( item->fontUnderline() != fn.underline() )
416 different |= Underline;
417 if ( item->fontWeight() != fn.weight() )
418 different |= Bold;
419}
420
421QString QTextString::toString( const QMemArray<QTextStringChar> &data ) 393QString QTextString::toString( const QMemArray<QTextStringChar> &data )
422{ 394{
423 QString s; 395 QString s;
@@ -443,22 +415,22 @@ QString QTextString::toString() const
443 return toString( data ); 415 return toString( data );
444} 416}
445 417
446void QTextParag::setSelection( int id, int start, int end ) 418void QTextParagraph::setSelection( int id, int start, int end )
447{ 419{
448 QMap<int, QTextParagSelection>::ConstIterator it = selections().find( id ); 420 QMap<int, QTextParagraphSelection>::ConstIterator it = selections().find( id );
449 if ( it != mSelections->end() ) { 421 if ( it != mSelections->end() ) {
450 if ( start == ( *it ).start && end == ( *it ).end ) 422 if ( start == ( *it ).start && end == ( *it ).end )
451 return; 423 return;
452 } 424 }
453 425
454 QTextParagSelection sel; 426 QTextParagraphSelection sel;
455 sel.start = start; 427 sel.start = start;
456 sel.end = end; 428 sel.end = end;
457 (*mSelections)[ id ] = sel; 429 (*mSelections)[ id ] = sel;
458 setChanged( TRUE, TRUE ); 430 setChanged( TRUE, TRUE );
459} 431}
460 432
461void QTextParag::removeSelection( int id ) 433void QTextParagraph::removeSelection( int id )
462{ 434{
463 if ( !hasSelection( id ) ) 435 if ( !hasSelection( id ) )
464 return; 436 return;
@@ -467,98 +439,93 @@ void QTextParag::removeSelection( int id )
467 setChanged( TRUE, TRUE ); 439 setChanged( TRUE, TRUE );
468} 440}
469 441
470int QTextParag::selectionStart( int id ) const 442int QTextParagraph::selectionStart( int id ) const
471{ 443{
472 if ( !mSelections ) 444 if ( !mSelections )
473 return -1; 445 return -1;
474 QMap<int, QTextParagSelection>::ConstIterator it = mSelections->find( id ); 446 QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id );
475 if ( it == mSelections->end() ) 447 if ( it == mSelections->end() )
476 return -1; 448 return -1;
477 return ( *it ).start; 449 return ( *it ).start;
478} 450}
479 451
480int QTextParag::selectionEnd( int id ) const 452int QTextParagraph::selectionEnd( int id ) const
481{ 453{
482 if ( !mSelections ) 454 if ( !mSelections )
483 return -1; 455 return -1;
484 QMap<int, QTextParagSelection>::ConstIterator it = mSelections->find( id ); 456 QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id );
485 if ( it == mSelections->end() ) 457 if ( it == mSelections->end() )
486 return -1; 458 return -1;
487 return ( *it ).end; 459 return ( *it ).end;
488} 460}
489 461
490bool QTextParag::hasSelection( int id ) const 462bool QTextParagraph::hasSelection( int id ) const
491{ 463{
492 if ( !mSelections ) 464 return mSelections ? mSelections->contains( id ) : FALSE;
493 return FALSE;
494 QMap<int, QTextParagSelection>::ConstIterator it = mSelections->find( id );
495 if ( it == mSelections->end() )
496 return FALSE;
497 return ( *it ).start != ( *it ).end || length() == 1;
498} 465}
499 466
500bool QTextParag::fullSelected( int id ) const 467bool QTextParagraph::fullSelected( int id ) const
501{ 468{
502 if ( !mSelections ) 469 if ( !mSelections )
503 return FALSE; 470 return FALSE;
504 QMap<int, QTextParagSelection>::ConstIterator it = mSelections->find( id ); 471 QMap<int, QTextParagraphSelection>::ConstIterator it = mSelections->find( id );
505 if ( it == mSelections->end() ) 472 if ( it == mSelections->end() )
506 return FALSE; 473 return FALSE;
507 return ( *it ).start == 0 && ( *it ).end == str->length() - 1; 474 return ( *it ).start == 0 && ( *it ).end == str->length() - 1;
508} 475}
509 476
510int QTextParag::lineY( int l ) const 477int QTextParagraph::lineY( int l ) const
511{ 478{
512 if ( l > (int)lineStarts.count() - 1 ) { 479 if ( l > (int)lineStarts.count() - 1 ) {
513 qWarning( "QTextParag::lineY: line %d out of range!", l ); 480 qWarning( "QTextParagraph::lineY: line %d out of range!", l );
514 return 0; 481 return 0;
515 } 482 }
516 483
517 if ( !isValid() ) 484 if ( !isValid() )
518 ( (QTextParag*)this )->format(); 485 ( (QTextParagraph*)this )->format();
519 486
520 QMap<int, QTextParagLineStart*>::ConstIterator it = lineStarts.begin(); 487 QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
521 while ( l-- > 0 ) 488 while ( l-- > 0 )
522 ++it; 489 ++it;
523 return ( *it )->y; 490 return ( *it )->y;
524} 491}
525 492
526int QTextParag::lineBaseLine( int l ) const 493int QTextParagraph::lineBaseLine( int l ) const
527{ 494{
528 if ( l > (int)lineStarts.count() - 1 ) { 495 if ( l > (int)lineStarts.count() - 1 ) {
529 qWarning( "QTextParag::lineBaseLine: line %d out of range!", l ); 496 qWarning( "QTextParagraph::lineBaseLine: line %d out of range!", l );
530 return 10; 497 return 10;
531 } 498 }
532 499
533 if ( !isValid() ) 500 if ( !isValid() )
534 ( (QTextParag*)this )->format(); 501 ( (QTextParagraph*)this )->format();
535 502
536 QMap<int, QTextParagLineStart*>::ConstIterator it = lineStarts.begin(); 503 QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
537 while ( l-- > 0 ) 504 while ( l-- > 0 )
538 ++it; 505 ++it;
539 return ( *it )->baseLine; 506 return ( *it )->baseLine;
540} 507}
541 508
542int QTextParag::lineHeight( int l ) const 509int QTextParagraph::lineHeight( int l ) const
543{ 510{
544 if ( l > (int)lineStarts.count() - 1 ) { 511 if ( l > (int)lineStarts.count() - 1 ) {
545 qWarning( "QTextParag::lineHeight: line %d out of range!", l ); 512 qWarning( "QTextParagraph::lineHeight: line %d out of range!", l );
546 return 15; 513 return 15;
547 } 514 }
548 515
549 if ( !isValid() ) 516 if ( !isValid() )
550 ( (QTextParag*)this )->format(); 517 ( (QTextParagraph*)this )->format();
551 518
552 QMap<int, QTextParagLineStart*>::ConstIterator it = lineStarts.begin(); 519 QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
553 while ( l-- > 0 ) 520 while ( l-- > 0 )
554 ++it; 521 ++it;
555 return ( *it )->h; 522 return ( *it )->h;
556} 523}
557 524
558void QTextParag::lineInfo( int l, int &y, int &h, int &bl ) const 525void QTextParagraph::lineInfo( int l, int &y, int &h, int &bl ) const
559{ 526{
560 if ( l > (int)lineStarts.count() - 1 ) { 527 if ( l > (int)lineStarts.count() - 1 ) {
561 qWarning( "QTextParag::lineInfo: line %d out of range!", l ); 528 qWarning( "QTextParagraph::lineInfo: line %d out of range!", l );
562 qDebug( "%d %d", (int)lineStarts.count() - 1, l ); 529 qDebug( "%d %d", (int)lineStarts.count() - 1, l );
563 y = 0; 530 y = 0;
564 h = 15; 531 h = 15;
@@ -567,9 +534,9 @@ void QTextParag::lineInfo( int l, int &y, int &h, int &bl ) const
567 } 534 }
568 535
569 if ( !isValid() ) 536 if ( !isValid() )
570 ( (QTextParag*)this )->format(); 537 ( (QTextParagraph*)this )->format();
571 538
572 QMap<int, QTextParagLineStart*>::ConstIterator it = lineStarts.begin(); 539 QMap<int, QTextLineStart*>::ConstIterator it = lineStarts.begin();
573 while ( l-- > 0 ) 540 while ( l-- > 0 )
574 ++it; 541 ++it;
575 y = ( *it )->y; 542 y = ( *it )->y;
@@ -577,95 +544,31 @@ void QTextParag::lineInfo( int l, int &y, int &h, int &bl ) const
577 bl = ( *it )->baseLine; 544 bl = ( *it )->baseLine;
578} 545}
579 546
580int QTextParag::alignment() const
581{
582 if ( align != -1 )
583 return align;
584 QStyleSheetItem *item = style();
585 if ( !item )
586 return Qt3::AlignAuto;
587 if ( mStyleSheetItemsVec ) {
588 for ( int i = 0; i < (int)mStyleSheetItemsVec->size(); ++i ) {
589 item = (*mStyleSheetItemsVec)[ i ];
590 if ( item->alignment() != QStyleSheetItem::Undefined )
591 return item->alignment();
592 }
593 }
594 return Qt3::AlignAuto;
595}
596 547
597QPtrVector<QStyleSheetItem> QTextParag::styleSheetItems() const 548void QTextParagraph::setAlignment( int a )
598{ 549{
599 QPtrVector<QStyleSheetItem> vec; 550 if ( a == (int)align )
600 if ( mStyleSheetItemsVec ) {
601 vec.resize( mStyleSheetItemsVec->size() );
602 for ( int i = 0; i < (int)vec.size(); ++i )
603 vec.insert( i, (*mStyleSheetItemsVec)[ i ] );
604 }
605 return vec;
606}
607
608QStyleSheetItem *QTextParag::style() const
609{
610 if ( !mStyleSheetItemsVec || mStyleSheetItemsVec->size() == 0 )
611 return 0;
612 return (*mStyleSheetItemsVec)[ mStyleSheetItemsVec->size() - 1 ];
613}
614
615int QTextParag::numberOfSubParagraph() const
616{
617 if ( list_val != -1 )
618 return list_val;
619 if ( numSubParag != -1 )
620 return numSubParag;
621 int n = 0;
622 QTextParag *p = (QTextParag*)this;
623 while ( p && ( styleSheetItemsVec().size() >= p->styleSheetItemsVec().size() &&
624 styleSheetItemsVec()[ (int)p->styleSheetItemsVec().size() - 1 ] == p->style() ||
625 p->styleSheetItemsVec().size() >= styleSheetItemsVec().size() &&
626 p->styleSheetItemsVec()[ (int)styleSheetItemsVec().size() - 1 ] == style() ) ) {
627 if ( p->style() == style() && listStyle() != p->listStyle()
628 && p->styleSheetItemsVec().size() == styleSheetItemsVec().size() )
629 break;
630 if ( p->style()->displayMode() == QStyleSheetItem::DisplayListItem
631 && p->style() != style() || styleSheetItemsVec().size() == p->styleSheetItemsVec().size() )
632 ++n;
633 p = p->prev();
634 }
635 ( (QTextParag*)this )->numSubParag = n;
636 return n;
637}
638
639void QTextParag::setFormat( QTextFormat *fm )
640{
641 bool doUpdate = FALSE;
642 if (defFormat && (defFormat != formatCollection()->defaultFormat()))
643 doUpdate = TRUE;
644 defFormat = formatCollection()->format( fm );
645 if ( !doUpdate )
646 return; 551 return;
647 for ( int i = 0; i < length(); ++i ) { 552 align = a;
648 if ( at( i )->format()->styleName() == defFormat->styleName() ) 553 invalidate( 0 );
649 at( i )->format()->updateStyle();
650 }
651} 554}
652 555
653QTextFormatter *QTextParag::formatter() const 556QTextFormatter *QTextParagraph::formatter() const
654{ 557{
655 if ( hasdoc ) 558 if ( hasdoc )
656 return document()->formatter(); 559 return document()->formatter();
657 if ( pseudoDocument()->pFormatter ) 560 if ( pseudoDocument()->pFormatter )
658 return pseudoDocument()->pFormatter; 561 return pseudoDocument()->pFormatter;
659 return ( ( (QTextParag*)this )->pseudoDocument()->pFormatter = new QTextFormatterBreakWords ); 562 return ( ( (QTextParagraph*)this )->pseudoDocument()->pFormatter = new QTextFormatterBreakWords );
660} 563}
661 564
662void QTextParag::setTabArray( int *a ) 565void QTextParagraph::setTabArray( int *a )
663{ 566{
664 delete [] tArray; 567 delete [] tArray;
665 tArray = a; 568 tArray = a;
666} 569}
667 570
668void QTextParag::setTabStops( int tw ) 571void QTextParagraph::setTabStops( int tw )
669{ 572{
670 if ( hasdoc ) 573 if ( hasdoc )
671 document()->setTabStops( tw ); 574 document()->setTabStops( tw );
@@ -673,24 +576,18 @@ void QTextParag::setTabStops( int tw )
673 tabStopWidth = tw; 576 tabStopWidth = tw;
674} 577}
675 578
676QMap<int, QTextParagSelection> &QTextParag::selections() const 579QMap<int, QTextParagraphSelection> &QTextParagraph::selections() const
677{ 580{
678 if ( !mSelections ) 581 if ( !mSelections )
679 ((QTextParag *)this)->mSelections = new QMap<int, QTextParagSelection>; 582 ((QTextParagraph *)this)->mSelections = new QMap<int, QTextParagraphSelection>;
680 return *mSelections; 583 return *mSelections;
681} 584}
682 585
683QPtrVector<QStyleSheetItem> &QTextParag::styleSheetItemsVec() const
684{
685 if ( !mStyleSheetItemsVec )
686 ((QTextParag *)this)->mStyleSheetItemsVec = new QPtrVector<QStyleSheetItem>;
687 return *mStyleSheetItemsVec;
688}
689 586
690QPtrList<QTextCustomItem> &QTextParag::floatingItems() const 587QPtrList<QTextCustomItem> &QTextParagraph::floatingItems() const
691{ 588{
692 if ( !mFloatingItems ) 589 if ( !mFloatingItems )
693 ((QTextParag *)this)->mFloatingItems = new QPtrList<QTextCustomItem>; 590 ((QTextParagraph *)this)->mFloatingItems = new QPtrList<QTextCustomItem>;
694 return *mFloatingItems; 591 return *mFloatingItems;
695} 592}
696 593
@@ -702,5 +599,5 @@ QTextStringChar::~QTextStringChar()
702 delete d.custom; 599 delete d.custom;
703} 600}
704 601
705QTextParagPseudoDocument::QTextParagPseudoDocument():pFormatter(0),commandHistory(0), minw(0),wused(0){} 602QTextParagraphPseudoDocument::QTextParagraphPseudoDocument():pFormatter(0),commandHistory(0), minw(0),wused(0){}
706QTextParagPseudoDocument::~QTextParagPseudoDocument(){ delete pFormatter; delete commandHistory; } 603QTextParagraphPseudoDocument::~QTextParagraphPseudoDocument(){ delete pFormatter; delete commandHistory; }