summaryrefslogtreecommitdiff
authorerik <erik>2007-02-08 01:46:35 (UTC)
committer erik <erik>2007-02-08 01:46:35 (UTC)
commit41dce553a418765d5075fc249c636104a2a82329 (patch) (unidiff)
treeca9b39611b17355cf2cb1c890d68f3a008e38866
parent2e497f7cae45184184e2416114887095735958f5 (diff)
downloadopie-41dce553a418765d5075fc249c636104a2a82329.zip
opie-41dce553a418765d5075fc249c636104a2a82329.tar.gz
opie-41dce553a418765d5075fc249c636104a2a82329.tar.bz2
Removal of useless code based on a conditional that is never set to anything
but false.
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-write/qrichtext.cpp44
1 files changed, 9 insertions, 35 deletions
diff --git a/noncore/apps/opie-write/qrichtext.cpp b/noncore/apps/opie-write/qrichtext.cpp
index 768da44..b457cd6 100644
--- a/noncore/apps/opie-write/qrichtext.cpp
+++ b/noncore/apps/opie-write/qrichtext.cpp
@@ -144,149 +144,140 @@ QTextCursor *QTextCommandHistory::redo( QTextCursor *c )
144 } 144 }
145 } 145 }
146 return 0; 146 return 0;
147} 147}
148 148
149bool QTextCommandHistory::isUndoAvailable() 149bool QTextCommandHistory::isUndoAvailable()
150{ 150{
151 return current > -1; 151 return current > -1;
152} 152}
153 153
154bool QTextCommandHistory::isRedoAvailable() 154bool QTextCommandHistory::isRedoAvailable()
155{ 155{
156 return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0; 156 return current > -1 && current < (int)history.count() - 1 || current == -1 && history.count() > 0;
157} 157}
158 158
159// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 159// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
160 160
161QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str, 161QTextDeleteCommand::QTextDeleteCommand( QTextDocument *d, int i, int idx, const QMemArray<QTextStringChar> &str,
162 const QByteArray& oldStyleInfo ) 162 const QByteArray& oldStyleInfo )
163 : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo ) 163 : QTextCommand( d ), id( i ), index( idx ), parag( 0 ), text( str ), styleInformation( oldStyleInfo )
164{ 164{
165 for ( int j = 0; j < (int)text.size(); ++j ) { 165 for ( int j = 0; j < (int)text.size(); ++j ) {
166 if ( text[ j ].format() ) 166 if ( text[ j ].format() )
167 text[ j ].format()->addRef(); 167 text[ j ].format()->addRef();
168 } 168 }
169} 169}
170 170
171QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str ) 171QTextDeleteCommand::QTextDeleteCommand( QTextParagraph *p, int idx, const QMemArray<QTextStringChar> &str )
172 : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str ) 172 : QTextCommand( 0 ), id( -1 ), index( idx ), parag( p ), text( str )
173{ 173{
174 for ( int i = 0; i < (int)text.size(); ++i ) { 174 for ( int i = 0; i < (int)text.size(); ++i ) {
175 if ( text[ i ].format() ) 175 if ( text[ i ].format() )
176 text[ i ].format()->addRef(); 176 text[ i ].format()->addRef();
177 } 177 }
178} 178}
179 179
180QTextDeleteCommand::~QTextDeleteCommand() 180QTextDeleteCommand::~QTextDeleteCommand()
181{ 181{
182 for ( int i = 0; i < (int)text.size(); ++i ) { 182 for ( int i = 0; i < (int)text.size(); ++i ) {
183 if ( text[ i ].format() ) 183 if ( text[ i ].format() )
184 text[ i ].format()->removeRef(); 184 text[ i ].format()->removeRef();
185 } 185 }
186 text.resize( 0 ); 186 text.resize( 0 );
187} 187}
188 188
189QTextCursor *QTextDeleteCommand::execute( QTextCursor *c ) 189QTextCursor *QTextDeleteCommand::execute( QTextCursor *c )
190{ 190{
191 QTextParagraph *s = doc ? doc->paragAt( id ) : parag; 191 QTextParagraph *s = doc ? doc->paragAt( id ) : parag;
192 if ( !s && doc ) { 192 if ( !s ) {
193 owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl; 193 owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl;
194 return 0; 194 return 0;
195 } else if ( !doc ) {
196 owarn << "No valid doc" << oendl;
197 return 0;
198 } 195 }
199 196
200 cursor.setParagraph( s ); 197 cursor.setParagraph( s );
201 cursor.setIndex( index ); 198 cursor.setIndex( index );
202 int len = text.size(); 199 int len = text.size();
203 if ( c ) 200 if ( c )
204 *c = cursor; 201 *c = cursor;
205 if ( doc ) { 202 if ( doc ) {
206 doc->setSelectionStart( QTextDocument::Temp, cursor ); 203 doc->setSelectionStart( QTextDocument::Temp, cursor );
207 for ( int i = 0; i < len; ++i ) 204 for ( int i = 0; i < len; ++i )
208 cursor.gotoNextLetter(); 205 cursor.gotoNextLetter();
209 doc->setSelectionEnd( QTextDocument::Temp, cursor ); 206 doc->setSelectionEnd( QTextDocument::Temp, cursor );
210 doc->removeSelectedText( QTextDocument::Temp, &cursor ); 207 doc->removeSelectedText( QTextDocument::Temp, &cursor );
211 if ( c ) 208 if ( c )
212 *c = cursor; 209 *c = cursor;
213 } else { 210 } else {
214 s->remove( index, len ); 211 s->remove( index, len );
215 } 212 }
216 213
217 return c; 214 return c;
218} 215}
219 216
220QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c ) 217QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c )
221{ 218{
222 QTextParagraph *s = doc ? doc->paragAt( id ) : parag; 219 QTextParagraph *s = doc ? doc->paragAt( id ) : parag;
223 if ( !s && doc ) { 220 if ( !s ) {
224 owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl; 221 owarn << "can't locate parag at " << id << ", last parag: " << doc->lastParagraph()->paragId() << "" << oendl;
225 return 0; 222 return 0;
226 } else if ( !doc ) {
227 owarn << "No valid doc" << oendl;
228 return 0;
229 } 223 }
230 224
231 cursor.setParagraph( s ); 225 cursor.setParagraph( s );
232 cursor.setIndex( index ); 226 cursor.setIndex( index );
233 QString str = QTextString::toString( text ); 227 QString str = QTextString::toString( text );
234 cursor.insert( str, TRUE, &text ); 228 cursor.insert( str, TRUE, &text );
235 cursor.setParagraph( s ); 229 cursor.setParagraph( s );
236 cursor.setIndex( index ); 230 cursor.setIndex( index );
237 if ( c ) { 231 if ( c ) {
238 c->setParagraph( s ); 232 c->setParagraph( s );
239 c->setIndex( index ); 233 c->setIndex( index );
240 for ( int i = 0; i < (int)text.size(); ++i ) 234 for ( int i = 0; i < (int)text.size(); ++i )
241 c->gotoNextLetter(); 235 c->gotoNextLetter();
242 } else {
243 owarn << "No valid cursor" << oendl;
244 return 0;
245 } 236 }
246 237
247 if ( !styleInformation.isEmpty() ) { 238 if ( !styleInformation.isEmpty() ) {
248 QDataStream styleStream( styleInformation, IO_ReadOnly ); 239 QDataStream styleStream( styleInformation, IO_ReadOnly );
249 int num; 240 int num;
250 styleStream >> num; 241 styleStream >> num;
251 QTextParagraph *p = s; 242 QTextParagraph *p = s;
252 while ( num-- && p ) { 243 while ( num-- && p ) {
253 p->readStyleInformation( styleStream ); 244 p->readStyleInformation( styleStream );
254 p = p->next(); 245 p = p->next();
255 } 246 }
256 } 247 }
257 s = cursor.paragraph(); 248 s = cursor.paragraph();
258 while ( s ) { 249 while ( s ) {
259 s->format(); 250 s->format();
260 s->setChanged( TRUE ); 251 s->setChanged( TRUE );
261 if ( s == c->paragraph() ) 252 if ( s == c->paragraph() )
262 break; 253 break;
263 s = s->next(); 254 s = s->next();
264 } 255 }
265 256
266 return &cursor; 257 return &cursor;
267} 258}
268 259
269QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx, 260QTextFormatCommand::QTextFormatCommand( QTextDocument *d, int sid, int sidx, int eid, int eidx,
270 const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl ) 261 const QMemArray<QTextStringChar> &old, QTextFormat *f, int fl )
271 : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl ) 262 : QTextCommand( d ), startId( sid ), startIndex( sidx ), endId( eid ), endIndex( eidx ), format( f ), oldFormats( old ), flags( fl )
272{ 263{
273 format = d->formatCollection()->format( f ); 264 format = d->formatCollection()->format( f );
274 for ( int j = 0; j < (int)oldFormats.size(); ++j ) { 265 for ( int j = 0; j < (int)oldFormats.size(); ++j ) {
275 if ( oldFormats[ j ].format() ) 266 if ( oldFormats[ j ].format() )
276 oldFormats[ j ].format()->addRef(); 267 oldFormats[ j ].format()->addRef();
277 } 268 }
278} 269}
279 270
280QTextFormatCommand::~QTextFormatCommand() 271QTextFormatCommand::~QTextFormatCommand()
281{ 272{
282 format->removeRef(); 273 format->removeRef();
283 for ( int j = 0; j < (int)oldFormats.size(); ++j ) { 274 for ( int j = 0; j < (int)oldFormats.size(); ++j ) {
284 if ( oldFormats[ j ].format() ) 275 if ( oldFormats[ j ].format() )
285 oldFormats[ j ].format()->removeRef(); 276 oldFormats[ j ].format()->removeRef();
286 } 277 }
287} 278}
288 279
289QTextCursor *QTextFormatCommand::execute( QTextCursor *c ) 280QTextCursor *QTextFormatCommand::execute( QTextCursor *c )
290{ 281{
291 QTextParagraph *sp = doc->paragAt( startId ); 282 QTextParagraph *sp = doc->paragAt( startId );
292 QTextParagraph *ep = doc->paragAt( endId ); 283 QTextParagraph *ep = doc->paragAt( endId );
@@ -1356,126 +1347,115 @@ void QTextDocument::setPlainText( const QString &text )
1356 } 1347 }
1357 if ( !lParag ) 1348 if ( !lParag )
1358 lParag = fParag = createParagraph( this, 0, 0 ); 1349 lParag = fParag = createParagraph( this, 0, 0 );
1359} 1350}
1360 1351
1361struct Q_EXPORT QTextDocumentTag { 1352struct Q_EXPORT QTextDocumentTag {
1362 QTextDocumentTag(){} 1353 QTextDocumentTag(){}
1363 QTextDocumentTag( const QString&n, const QStyleSheetItem* s, const QTextFormat& f ) 1354 QTextDocumentTag( const QString&n, const QStyleSheetItem* s, const QTextFormat& f )
1364 :name(n),style(s), format(f), alignment(Qt3::AlignAuto), direction(QChar::DirON),liststyle(QStyleSheetItem::ListDisc) { 1355 :name(n),style(s), format(f), alignment(Qt3::AlignAuto), direction(QChar::DirON),liststyle(QStyleSheetItem::ListDisc) {
1365 wsm = QStyleSheetItem::WhiteSpaceNormal; 1356 wsm = QStyleSheetItem::WhiteSpaceNormal;
1366 } 1357 }
1367 QString name; 1358 QString name;
1368 const QStyleSheetItem* style; 1359 const QStyleSheetItem* style;
1369 QString anchorHref; 1360 QString anchorHref;
1370 QStyleSheetItem::WhiteSpaceMode wsm; 1361 QStyleSheetItem::WhiteSpaceMode wsm;
1371 QTextFormat format; 1362 QTextFormat format;
1372 int alignment : 16; 1363 int alignment : 16;
1373 int direction : 5; 1364 int direction : 5;
1374 QStyleSheetItem::ListStyle liststyle; 1365 QStyleSheetItem::ListStyle liststyle;
1375 1366
1376 QTextDocumentTag( const QTextDocumentTag& t ) { 1367 QTextDocumentTag( const QTextDocumentTag& t ) {
1377 name = t.name; 1368 name = t.name;
1378 style = t.style; 1369 style = t.style;
1379 anchorHref = t.anchorHref; 1370 anchorHref = t.anchorHref;
1380 wsm = t.wsm; 1371 wsm = t.wsm;
1381 format = t.format; 1372 format = t.format;
1382 alignment = t.alignment; 1373 alignment = t.alignment;
1383 direction = t.direction; 1374 direction = t.direction;
1384 liststyle = t.liststyle; 1375 liststyle = t.liststyle;
1385 } 1376 }
1386 QTextDocumentTag& operator=(const QTextDocumentTag& t) { 1377 QTextDocumentTag& operator=(const QTextDocumentTag& t) {
1387 name = t.name; 1378 name = t.name;
1388 style = t.style; 1379 style = t.style;
1389 anchorHref = t.anchorHref; 1380 anchorHref = t.anchorHref;
1390 wsm = t.wsm; 1381 wsm = t.wsm;
1391 format = t.format; 1382 format = t.format;
1392 alignment = t.alignment; 1383 alignment = t.alignment;
1393 direction = t.direction; 1384 direction = t.direction;
1394 liststyle = t.liststyle; 1385 liststyle = t.liststyle;
1395 return *this; 1386 return *this;
1396 } 1387 }
1397 1388
1398#if defined(Q_FULL_TEMPLATE_INSTANTIATION) 1389#if defined(Q_FULL_TEMPLATE_INSTANTIATION)
1399 bool operator==( const QTextDocumentTag& ) const { return FALSE; } 1390 bool operator==( const QTextDocumentTag& ) const { return FALSE; }
1400#endif 1391#endif
1401}; 1392};
1402 1393
1403 1394
1404#define NEWPAR do { \ 1395#define NEWPAR do{ if ( !hasNewPar) { \
1405 if ( !hasNewPar) { \
1406 if ( !curpar ) { \
1407 owarn << "no current paragraph" << oendl; \
1408 return; \
1409 } \
1410 if ( !textEditMode && curpar && curpar->length()>1 && curpar->at( curpar->length()-2)->c == QChar_linesep ) \ 1396 if ( !textEditMode && curpar && curpar->length()>1 && curpar->at( curpar->length()-2)->c == QChar_linesep ) \
1411 curpar->remove( curpar->length()-2, 1 ); \ 1397 curpar->remove( curpar->length()-2, 1 ); \
1412 curpar = createParagraph( this, curpar, curpar->next() ); styles.append( vec ); \ 1398 curpar = createParagraph( this, curpar, curpar->next() ); styles.append( vec ); vec = 0;} \
1413 if ( !curpar ) { \
1414 owarn << "failed in creating a new paragraph" << oendl; \
1415 return; \
1416 } \
1417 vec = 0; \
1418 } \
1419 hasNewPar = TRUE; \ 1399 hasNewPar = TRUE; \
1420 curpar->rtext = TRUE; \ 1400 curpar->rtext = TRUE; \
1421 curpar->align = curtag.alignment; \ 1401 curpar->align = curtag.alignment; \
1422 curpar->lstyle = curtag.liststyle; \ 1402 curpar->lstyle = curtag.liststyle; \
1423 curpar->litem = ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ); \ 1403 curpar->litem = ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ); \
1424 curpar->str->setDirection( (QChar::Direction)curtag.direction ); \ 1404 curpar->str->setDirection( (QChar::Direction)curtag.direction ); \
1425 space = TRUE; \ 1405 space = TRUE; \
1426 delete vec; \ 1406 delete vec; vec = new QPtrVector<QStyleSheetItem>( (uint)tags.count() + 1); \
1427 vec = new QPtrVector<QStyleSheetItem>( (uint)tags.count() + 1); \
1428 int i = 0; \ 1407 int i = 0; \
1429 for ( QValueStack<QTextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it ) \ 1408 for ( QValueStack<QTextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it ) \
1430 vec->insert( i++, (*it).style ); \ 1409 vec->insert( i++, (*it).style ); \
1431 vec->insert( i, curtag.style ); \ 1410 vec->insert( i, curtag.style ); \
1432 } while ( FALSE ) 1411 } while ( FALSE )
1433 1412
1413
1434void QTextDocument::setRichText( const QString &text, const QString &context ) 1414void QTextDocument::setRichText( const QString &text, const QString &context )
1435{ 1415{
1436 if ( !context.isEmpty() ) 1416 if ( !context.isEmpty() )
1437 setContext( context ); 1417 setContext( context );
1438 clear(); 1418 clear();
1439 fParag = lParag = createParagraph( this ); 1419 fParag = lParag = createParagraph( this );
1440 oTextValid = TRUE; 1420 oTextValid = TRUE;
1441 oText = text; 1421 oText = text;
1442 setRichTextInternal( text ); 1422 setRichTextInternal( text );
1443 fParag->rtext = TRUE; 1423 fParag->rtext = TRUE;
1444} 1424}
1445 1425
1446void QTextDocument::setRichTextInternal( const QString &text, QTextCursor* cursor ) 1426void QTextDocument::setRichTextInternal( const QString &text, QTextCursor* cursor )
1447{ 1427{
1448 QTextParagraph* curpar = lParag; 1428 QTextParagraph* curpar = lParag;
1449 int pos = 0; 1429 int pos = 0;
1450 QValueStack<QTextDocumentTag> tags; 1430 QValueStack<QTextDocumentTag> tags;
1451 QTextDocumentTag initag( "", sheet_->item(""), *formatCollection()->defaultFormat() ); 1431 QTextDocumentTag initag( "", sheet_->item(""), *formatCollection()->defaultFormat() );
1452 QTextDocumentTag curtag = initag; 1432 QTextDocumentTag curtag = initag;
1453 bool space = TRUE; 1433 bool space = TRUE;
1454 bool canMergeLi = FALSE; 1434 bool canMergeLi = FALSE;
1455 1435
1456 bool textEditMode = FALSE; 1436 bool textEditMode = FALSE;
1457 1437
1458 const QChar* doc = text.unicode(); 1438 const QChar* doc = text.unicode();
1459 int length = text.length(); 1439 int length = text.length();
1460 bool hasNewPar = curpar->length() <= 1; 1440 bool hasNewPar = curpar->length() <= 1;
1461 QString anchorName; 1441 QString anchorName;
1462 1442
1463 // style sheet handling for margin and line spacing calculation below 1443 // style sheet handling for margin and line spacing calculation below
1464 QTextParagraph* stylesPar = curpar; 1444 QTextParagraph* stylesPar = curpar;
1465 QPtrVector<QStyleSheetItem>* vec = 0; 1445 QPtrVector<QStyleSheetItem>* vec = 0;
1466 QPtrList< QPtrVector<QStyleSheetItem> > styles; 1446 QPtrList< QPtrVector<QStyleSheetItem> > styles;
1467 styles.setAutoDelete( TRUE ); 1447 styles.setAutoDelete( TRUE );
1468 1448
1469 if ( cursor ) { 1449 if ( cursor ) {
1470 cursor->splitAndInsertEmptyParagraph(); 1450 cursor->splitAndInsertEmptyParagraph();
1471 QTextCursor tmp = *cursor; 1451 QTextCursor tmp = *cursor;
1472 tmp.gotoPreviousLetter(); 1452 tmp.gotoPreviousLetter();
1473 stylesPar = curpar = tmp.paragraph(); 1453 stylesPar = curpar = tmp.paragraph();
1474 hasNewPar = TRUE; 1454 hasNewPar = TRUE;
1475 textEditMode = TRUE; 1455 textEditMode = TRUE;
1476 } else { 1456 } else {
1477 NEWPAR; 1457 NEWPAR;
1478 } 1458 }
1479 1459
1480 // set rtext spacing to FALSE for the initial paragraph. 1460 // set rtext spacing to FALSE for the initial paragraph.
1481 curpar->rtext = FALSE; 1461 curpar->rtext = FALSE;
@@ -1870,101 +1850,98 @@ void QTextDocument::setRichTextInternal( const QString &text, QTextCursor* curso
1870 f->ref += s.length() -1; // that what friends are for... 1850 f->ref += s.length() -1; // that what friends are for...
1871 if ( !curtag.anchorHref.isEmpty() ) { 1851 if ( !curtag.anchorHref.isEmpty() ) {
1872 for ( int i = 0; i < int(s.length()); i++ ) 1852 for ( int i = 0; i < int(s.length()); i++ )
1873 curpar->at(index + i)->setAnchor( QString::null, curtag.anchorHref ); 1853 curpar->at(index + i)->setAnchor( QString::null, curtag.anchorHref );
1874 } 1854 }
1875 if ( !anchorName.isEmpty() ) { 1855 if ( !anchorName.isEmpty() ) {
1876 curpar->at(index)->setAnchor( anchorName, curpar->at(index)->anchorHref() ); 1856 curpar->at(index)->setAnchor( anchorName, curpar->at(index)->anchorHref() );
1877 anchorName = QString::null; 1857 anchorName = QString::null;
1878 } 1858 }
1879 } 1859 }
1880 } 1860 }
1881 } 1861 }
1882 if ( hasNewPar && curpar != fParag && !cursor ) { 1862 if ( hasNewPar && curpar != fParag && !cursor ) {
1883 // cleanup unused last paragraphs 1863 // cleanup unused last paragraphs
1884 curpar = curpar->p; 1864 curpar = curpar->p;
1885 delete curpar->n; 1865 delete curpar->n;
1886 } 1866 }
1887 if ( !anchorName.isEmpty() ) { 1867 if ( !anchorName.isEmpty() ) {
1888 curpar->at(curpar->length() - 1)->setAnchor( anchorName, curpar->at( curpar->length() - 1 )->anchorHref() ); 1868 curpar->at(curpar->length() - 1)->setAnchor( anchorName, curpar->at( curpar->length() - 1 )->anchorHref() );
1889 anchorName = QString::null; 1869 anchorName = QString::null;
1890 } 1870 }
1891 1871
1892 1872
1893 setRichTextMarginsInternal( styles, stylesPar ); 1873 setRichTextMarginsInternal( styles, stylesPar );
1894 1874
1895 if ( cursor ) { 1875 if ( cursor ) {
1896 cursor->gotoPreviousLetter(); 1876 cursor->gotoPreviousLetter();
1897 cursor->remove(); 1877 cursor->remove();
1898 } 1878 }
1899 1879
1900} 1880}
1901 1881
1902void QTextDocument::setRichTextMarginsInternal( QPtrList< QPtrVector<QStyleSheetItem> >& styles, QTextParagraph* stylesPar ) 1882void QTextDocument::setRichTextMarginsInternal( QPtrList< QPtrVector<QStyleSheetItem> >& styles, QTextParagraph* stylesPar )
1903{ 1883{
1904 // margin and line spacing calculation 1884 // margin and line spacing calculation
1905 QPtrVector<QStyleSheetItem>* prevStyle = 0; 1885 QPtrVector<QStyleSheetItem>* prevStyle = 0;
1906 QPtrVector<QStyleSheetItem>* curStyle = styles.first(); 1886 QPtrVector<QStyleSheetItem>* curStyle = styles.first();
1907 QPtrVector<QStyleSheetItem>* nextStyle = styles.next(); 1887 QPtrVector<QStyleSheetItem>* nextStyle = styles.next();
1908 while ( stylesPar ) { 1888 while ( stylesPar ) {
1909 if ( !curStyle ) { 1889 if ( !curStyle ) {
1910 stylesPar = stylesPar->next(); 1890 stylesPar = stylesPar->next();
1911 prevStyle = curStyle; 1891 prevStyle = curStyle;
1912 curStyle = nextStyle; 1892 curStyle = nextStyle;
1913 nextStyle = styles.next(); 1893 nextStyle = styles.next();
1914 continue; 1894 continue;
1915 } 1895 }
1916 1896
1917 int i, mar; 1897 int i, mar;
1918 QStyleSheetItem* mainStyle = (*curStyle)[curStyle->size()-1]; 1898 QStyleSheetItem* mainStyle = curStyle->size() ? (*curStyle)[curStyle->size()-1] : 0;
1919 if ( !mainStyle ) 1899 if ( mainStyle && mainStyle->displayMode() == QStyleSheetItem::DisplayListItem )
1920 return;
1921
1922 if ( mainStyle->displayMode() == QStyleSheetItem::DisplayListItem )
1923 stylesPar->setListItem( TRUE ); 1900 stylesPar->setListItem( TRUE );
1924 int numLists = 0; 1901 int numLists = 0;
1925 for ( i = 0; i < (int)curStyle->size(); ++i ) { 1902 for ( i = 0; i < (int)curStyle->size(); ++i ) {
1926 if ( (*curStyle)[ i ]->displayMode() == QStyleSheetItem::DisplayBlock 1903 if ( (*curStyle)[ i ]->displayMode() == QStyleSheetItem::DisplayBlock
1927 && int((*curStyle)[ i ]->listStyle()) != QStyleSheetItem::Undefined ) 1904 && int((*curStyle)[ i ]->listStyle()) != QStyleSheetItem::Undefined )
1928 numLists++; 1905 numLists++;
1929 } 1906 }
1930 stylesPar->ldepth = numLists; 1907 stylesPar->ldepth = numLists;
1931 if ( stylesPar->next() && nextStyle ) { 1908 if ( stylesPar->next() && nextStyle ) {
1932 // also set the depth of the next paragraph, required for the margin calculation 1909 // also set the depth of the next paragraph, required for the margin calculation
1933 numLists = 0; 1910 numLists = 0;
1934 for ( i = 0; i < (int)nextStyle->size(); ++i ) { 1911 for ( i = 0; i < (int)nextStyle->size(); ++i ) {
1935 if ( (*nextStyle)[ i ]->displayMode() == QStyleSheetItem::DisplayBlock 1912 if ( (*nextStyle)[ i ]->displayMode() == QStyleSheetItem::DisplayBlock
1936 && int((*nextStyle)[ i ]->listStyle()) != QStyleSheetItem::Undefined ) 1913 && int((*nextStyle)[ i ]->listStyle()) != QStyleSheetItem::Undefined )
1937 numLists++; 1914 numLists++;
1938 } 1915 }
1939 stylesPar->next()->ldepth = numLists; 1916 stylesPar->next()->ldepth = numLists;
1940 } 1917 }
1941 1918
1942 // do the top margin 1919 // do the top margin
1943 QStyleSheetItem* item = mainStyle; 1920 QStyleSheetItem* item = mainStyle;
1944 int m; 1921 int m;
1945 if (stylesPar->utm > 0 ) { 1922 if (stylesPar->utm > 0 ) {
1946 m = stylesPar->utm-1; 1923 m = stylesPar->utm-1;
1947 stylesPar->utm = 0; 1924 stylesPar->utm = 0;
1948 } else { 1925 } else {
1949 m = QMAX(0, item->margin( QStyleSheetItem::MarginTop ) ); 1926 m = QMAX(0, item->margin( QStyleSheetItem::MarginTop ) );
1950 if ( item->displayMode() == QStyleSheetItem::DisplayListItem 1927 if ( item->displayMode() == QStyleSheetItem::DisplayListItem
1951 && stylesPar->ldepth ) 1928 && stylesPar->ldepth )
1952 m /= stylesPar->ldepth; 1929 m /= stylesPar->ldepth;
1953 } 1930 }
1954 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) { 1931 for ( i = (int)curStyle->size() - 2 ; i >= 0; --i ) {
1955 item = (*curStyle)[ i ]; 1932 item = (*curStyle)[ i ];
1956 if ( prevStyle && i < (int) prevStyle->size() && 1933 if ( prevStyle && i < (int) prevStyle->size() &&
1957 ( item->displayMode() == QStyleSheetItem::DisplayBlock && 1934 ( item->displayMode() == QStyleSheetItem::DisplayBlock &&
1958 (*prevStyle)[ i ] == item ) ) 1935 (*prevStyle)[ i ] == item ) )
1959 break; 1936 break;
1960 // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags 1937 // emulate CSS2' standard 0 vertical margin for multiple ul or ol tags
1961 if ( int(item->listStyle()) != QStyleSheetItem::Undefined && 1938 if ( int(item->listStyle()) != QStyleSheetItem::Undefined &&
1962 ( ( i> 0 && (*curStyle)[ i-1 ] == item ) || (*curStyle)[i+1] == item ) ) 1939 ( ( i> 0 && (*curStyle)[ i-1 ] == item ) || (*curStyle)[i+1] == item ) )
1963 continue; 1940 continue;
1964 mar = QMAX( 0, item->margin( QStyleSheetItem::MarginTop ) ); 1941 mar = QMAX( 0, item->margin( QStyleSheetItem::MarginTop ) );
1965 m = QMAX( m, mar ); 1942 m = QMAX( m, mar );
1966 } 1943 }
1967 stylesPar->utm = m - stylesPar->topMargin(); 1944 stylesPar->utm = m - stylesPar->topMargin();
1968 1945
1969 // do the bottom margin 1946 // do the bottom margin
1970 item = mainStyle; 1947 item = mainStyle;
@@ -3025,105 +3002,102 @@ void QTextDocument::drawParagraph( QPainter *p, QTextParagraph *parag, int cx, i
3025 3002
3026 if ( useDoubleBuffer ) { 3003 if ( useDoubleBuffer ) {
3027 delete painter; 3004 delete painter;
3028 painter = 0; 3005 painter = 0;
3029 p->drawPixmap( ir.topLeft(), *doubleBuffer, QRect( QPoint( 0, 0 ), ir.size() ) ); 3006 p->drawPixmap( ir.topLeft(), *doubleBuffer, QRect( QPoint( 0, 0 ), ir.size() ) );
3030 } else { 3007 } else {
3031 painter->translate( -ir.x(), -ir.y() ); 3008 painter->translate( -ir.x(), -ir.y() );
3032 } 3009 }
3033 3010
3034 if ( useDoubleBuffer ) { 3011 if ( useDoubleBuffer ) {
3035 if ( parag->rect().x() + parag->rect().width() < parag->document()->x() + parag->document()->width() ) { 3012 if ( parag->rect().x() + parag->rect().width() < parag->document()->x() + parag->document()->width() ) {
3036 p->fillRect( parag->rect().x() + parag->rect().width(), parag->rect().y(), 3013 p->fillRect( parag->rect().x() + parag->rect().width(), parag->rect().y(),
3037 ( parag->document()->x() + parag->document()->width() ) - 3014 ( parag->document()->x() + parag->document()->width() ) -
3038 ( parag->rect().x() + parag->rect().width() ), 3015 ( parag->rect().x() + parag->rect().width() ),
3039 parag->rect().height(), cg.brush( QColorGroup::Base ) ); 3016 parag->rect().height(), cg.brush( QColorGroup::Base ) );
3040 } 3017 }
3041 } 3018 }
3042 3019
3043 parag->document()->nextDoubleBuffered = FALSE; 3020 parag->document()->nextDoubleBuffered = FALSE;
3044} 3021}
3045 3022
3046QTextParagraph *QTextDocument::draw( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg, 3023QTextParagraph *QTextDocument::draw( QPainter *p, int cx, int cy, int cw, int ch, const QColorGroup &cg,
3047 bool onlyChanged, bool drawCursor, QTextCursor *cursor, bool resetChanged ) 3024 bool onlyChanged, bool drawCursor, QTextCursor *cursor, bool resetChanged )
3048{ 3025{
3049 if ( withoutDoubleBuffer || par && par->withoutDoubleBuffer ) { 3026 if ( withoutDoubleBuffer || par && par->withoutDoubleBuffer ) {
3050 withoutDoubleBuffer = TRUE; 3027 withoutDoubleBuffer = TRUE;
3051 QRect r; 3028 QRect r;
3052 draw( p, r, cg ); 3029 draw( p, r, cg );
3053 return 0; 3030 return 0;
3054 } 3031 }
3055 withoutDoubleBuffer = FALSE; 3032 withoutDoubleBuffer = FALSE;
3056 3033
3057 if ( !firstParagraph() ) 3034 if ( !firstParagraph() )
3058 return 0; 3035 return 0;
3059 3036
3060 if ( cx < 0 && cy < 0 ) { 3037 if ( cx < 0 && cy < 0 ) {
3061 cx = 0; 3038 cx = 0;
3062 cy = 0; 3039 cy = 0;
3063 cw = width(); 3040 cw = width();
3064 ch = height(); 3041 ch = height();
3065 } 3042 }
3066 3043
3067 QTextParagraph *lastFormatted = 0; 3044 QTextParagraph *lastFormatted = 0;
3068 QTextParagraph *parag = firstParagraph(); 3045 QTextParagraph *parag = firstParagraph();
3069 3046
3070 QPixmap *doubleBuffer = 0; 3047 QPixmap *doubleBuffer = 0;
3071 QPainter painter; 3048 QPainter painter;
3072 3049
3073 bool fullWidthSelection = FALSE;
3074 while ( parag ) { 3050 while ( parag ) {
3075 lastFormatted = parag; 3051 lastFormatted = parag;
3076 if ( !parag->isValid() ) 3052 if ( !parag->isValid() )
3077 parag->format(); 3053 parag->format();
3078 3054
3079 QRect pr = parag->rect(); 3055 QRect pr = parag->rect();
3080 if ( fullWidthSelection )
3081 pr.setWidth( parag->document()->width() );
3082 if ( pr.y() > cy + ch ) 3056 if ( pr.y() > cy + ch )
3083 goto floating; 3057 goto floating;
3084 if ( !pr.intersects( QRect( cx, cy, cw, ch ) ) || ( onlyChanged && !parag->hasChanged() ) ) { 3058 if ( !pr.intersects( QRect( cx, cy, cw, ch ) ) || ( onlyChanged && !parag->hasChanged() ) ) {
3085 parag = parag->next(); 3059 parag = parag->next();
3086 continue; 3060 continue;
3087 } 3061 }
3088 3062
3089 drawParagraph( p, parag, cx, cy, cw, ch, doubleBuffer, cg, drawCursor, cursor, resetChanged ); 3063 drawParagraph( p, parag, cx, cy, cw, ch, doubleBuffer, cg, drawCursor, cursor, resetChanged );
3090 parag = parag->next(); 3064 parag = parag->next();
3091 } 3065 }
3092 3066
3093 parag = lastParagraph(); 3067 parag = lastParagraph();
3094 3068
3095 floating: 3069 floating:
3096 if ( parag->rect().y() + parag->rect().height() < parag->document()->height() ) { 3070 if ( parag->rect().y() + parag->rect().height() < parag->document()->height() ) {
3097 if ( !parag->document()->parent() ) { 3071 if ( !parag->document()->parent() ) {
3098 p->fillRect( 0, parag->rect().y() + parag->rect().height(), parag->document()->width(), 3072 p->fillRect( 0, parag->rect().y() + parag->rect().height(), parag->document()->width(),
3099 parag->document()->height() - ( parag->rect().y() + parag->rect().height() ), 3073 parag->document()->height() - ( parag->rect().y() + parag->rect().height() ),
3100 cg.brush( QColorGroup::Base ) ); 3074 cg.brush( QColorGroup::Base ) );
3101 } 3075 }
3102 if ( !flow()->isEmpty() ) { 3076 if ( !flow()->isEmpty() ) {
3103 QRect cr( cx, cy, cw, ch ); 3077 QRect cr( cx, cy, cw, ch );
3104 flow()->drawFloatingItems( p, cr.x(), cr.y(), cr.width(), cr.height(), cg, FALSE ); 3078 flow()->drawFloatingItems( p, cr.x(), cr.y(), cr.width(), cr.height(), cg, FALSE );
3105 } 3079 }
3106 } 3080 }
3107 3081
3108 if ( buf_pixmap && buf_pixmap->height() > 300 ) { 3082 if ( buf_pixmap && buf_pixmap->height() > 300 ) {
3109 delete buf_pixmap; 3083 delete buf_pixmap;
3110 buf_pixmap = 0; 3084 buf_pixmap = 0;
3111 } 3085 }
3112 3086
3113 return lastFormatted; 3087 return lastFormatted;
3114} 3088}
3115 3089
3116/* 3090/*
3117 #### this function only sets the default font size in the format collection 3091 #### this function only sets the default font size in the format collection
3118 */ 3092 */
3119void QTextDocument::setDefaultFormat( const QFont &font, const QColor &color ) 3093void QTextDocument::setDefaultFormat( const QFont &font, const QColor &color )
3120{ 3094{
3121 bool reformat = font != fCollection->defaultFormat()->font(); 3095 bool reformat = font != fCollection->defaultFormat()->font();
3122 for ( QTextDocument *d = childList.first(); d; d = childList.next() ) 3096 for ( QTextDocument *d = childList.first(); d; d = childList.next() )
3123 d->setDefaultFormat( font, color ); 3097 d->setDefaultFormat( font, color );
3124 fCollection->updateDefaultFormat( font, color, sheet_ ); 3098 fCollection->updateDefaultFormat( font, color, sheet_ );
3125 3099
3126 if ( !reformat ) 3100 if ( !reformat )
3127 return; 3101 return;
3128 tStopWidth = formatCollection()->defaultFormat()->width( 'x' ) * 8; 3102 tStopWidth = formatCollection()->defaultFormat()->width( 'x' ) * 8;
3129 3103
@@ -5319,97 +5293,97 @@ int QTextFormatterBreakWords::format( QTextDocument *doc, QTextParagraph *parag,
5319 QTextStringChar *firstChar = 0; 5293 QTextStringChar *firstChar = 0;
5320 QTextString *string = parag->string(); 5294 QTextString *string = parag->string();
5321 int left = doc ? parag->leftMargin() + doc->leftMargin() : 0; 5295 int left = doc ? parag->leftMargin() + doc->leftMargin() : 0;
5322 int x = left + ( doc ? parag->firstLineMargin() : 0 ); 5296 int x = left + ( doc ? parag->firstLineMargin() : 0 );
5323 int y = parag->prev() ? QMAX(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0; 5297 int y = parag->prev() ? QMAX(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0;
5324 int h = y; 5298 int h = y;
5325 int len = parag->length(); 5299 int len = parag->length();
5326 if ( doc ) 5300 if ( doc )
5327 x = doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), x, 0 ); 5301 x = doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), x, 0 );
5328 int dw = parag->documentVisibleWidth() - ( doc ? ( left != x ? 0 : doc->rightMargin() ) : 0 ); 5302 int dw = parag->documentVisibleWidth() - ( doc ? ( left != x ? 0 : doc->rightMargin() ) : 0 );
5329 5303
5330 int curLeft = x; 5304 int curLeft = x;
5331 int rm = parag->rightMargin(); 5305 int rm = parag->rightMargin();
5332 int rdiff = doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 0 ) : 0; 5306 int rdiff = doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 0 ) : 0;
5333 int w = dw - rdiff; 5307 int w = dw - rdiff;
5334 bool fullWidth = TRUE; 5308 bool fullWidth = TRUE;
5335 int marg = left + rdiff; 5309 int marg = left + rdiff;
5336 int minw = 0; 5310 int minw = 0;
5337 int wused = 0; 5311 int wused = 0;
5338 int tminw = marg; 5312 int tminw = marg;
5339 int linespacing = doc ? parag->lineSpacing() : 0; 5313 int linespacing = doc ? parag->lineSpacing() : 0;
5340 bool wrapEnabled = isWrapEnabled( parag ); 5314 bool wrapEnabled = isWrapEnabled( parag );
5341 5315
5342 start = 0; 5316 start = 0;
5343 if ( start == 0 ) 5317 if ( start == 0 )
5344 c = &parag->string()->at( 0 ); 5318 c = &parag->string()->at( 0 );
5345 5319
5346 int i = start; 5320 int i = start;
5347 QTextLineStart *lineStart = new QTextLineStart( y, y, 0 ); 5321 QTextLineStart *lineStart = new QTextLineStart( y, y, 0 );
5348 insertLineStart( parag, 0, lineStart ); 5322 insertLineStart( parag, 0, lineStart );
5349 int lastBreak = -1; 5323 int lastBreak = -1;
5350 int tmpBaseLine = 0, tmph = 0; 5324 int tmpBaseLine = 0, tmph = 0;
5351 bool lastWasNonInlineCustom = FALSE; 5325 bool lastWasNonInlineCustom = FALSE;
5352 5326
5353 int align = parag->alignment(); 5327 int align = parag->alignment();
5354 if ( align == Qt3::AlignAuto && doc && doc->alignment() != Qt3::AlignAuto ) 5328 if ( align == Qt3::AlignAuto && doc && doc->alignment() != Qt3::AlignAuto )
5355 align = doc->alignment(); 5329 align = doc->alignment();
5356 5330
5357 align &= Qt3::AlignHorizontal_Mask; 5331 align &= Qt3::AlignHorizontal_Mask;
5358 5332
5359 QPainter *painter = QTextFormat::painter(); 5333 QPainter *painter = QTextFormat::painter();
5360 int col = 0; 5334 int col = 0;
5361 int ww = 0; 5335 int ww = 0;
5362 QChar lastChr; 5336 QChar lastChr;
5363 for ( ; i < len; ++i, ++col ) { 5337 for ( ; i < len; ++i, ++col ) {
5364 if ( c ) 5338 if ( c )
5365 lastChr = c->c; 5339 lastChr = c->c;
5366 // ### next line should not be needed 5340 // ### next line should not be needed
5367 if ( c && painter ) 5341 if ( painter )
5368 c->format()->setPainter( painter ); 5342 c->format()->setPainter( painter );
5369 c = &string->at( i ); 5343 c = &string->at( i );
5370 c->rightToLeft = FALSE; 5344 c->rightToLeft = FALSE;
5371 if ( i > 0 && (x > curLeft || ww == 0) || lastWasNonInlineCustom ) { 5345 if ( i > 0 && (x > curLeft || ww == 0) || lastWasNonInlineCustom ) {
5372 c->lineStart = 0; 5346 c->lineStart = 0;
5373 } else { 5347 } else {
5374 c->lineStart = 1; 5348 c->lineStart = 1;
5375 firstChar = c; 5349 firstChar = c;
5376 } 5350 }
5377 5351
5378 if ( c->isCustom() && c->customItem()->placement() != QTextCustomItem::PlaceInline ) 5352 if ( c->isCustom() && c->customItem()->placement() != QTextCustomItem::PlaceInline )
5379 lastWasNonInlineCustom = TRUE; 5353 lastWasNonInlineCustom = TRUE;
5380 else 5354 else
5381 lastWasNonInlineCustom = FALSE; 5355 lastWasNonInlineCustom = FALSE;
5382 5356
5383 if ( c->c.unicode() >= 32 || c->isCustom() ) { 5357 if ( c->c.unicode() >= 32 || c->isCustom() ) {
5384 ww = string->width( i ); 5358 ww = string->width( i );
5385 } else if ( c->c == '\t' ) { 5359 } else if ( c->c == '\t' ) {
5386 int nx = parag->nextTab( i, x - left ) + left; 5360 int nx = parag->nextTab( i, x - left ) + left;
5387 if ( nx < x ) 5361 if ( nx < x )
5388 ww = w - x; 5362 ww = w - x;
5389 else 5363 else
5390 ww = nx - x; 5364 ww = nx - x;
5391 } else { 5365 } else {
5392 ww = c->format()->width( ' ' ); 5366 ww = c->format()->width( ' ' );
5393 } 5367 }
5394 5368
5395 // last character ("invisible" space) has no width 5369 // last character ("invisible" space) has no width
5396 if ( i == len - 1 ) 5370 if ( i == len - 1 )
5397 ww = 0; 5371 ww = 0;
5398 5372
5399 QTextCustomItem* ci = c->customItem(); 5373 QTextCustomItem* ci = c->customItem();
5400 if ( c->isCustom() && ci->ownLine() ) { 5374 if ( c->isCustom() && ci->ownLine() ) {
5401 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left; 5375 x = doc ? doc->flow()->adjustLMargin( y + parag->rect().y(), parag->rect().height(), left, 4 ) : left;
5402 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 ); 5376 w = dw - ( doc ? doc->flow()->adjustRMargin( y + parag->rect().y(), parag->rect().height(), rm, 4 ) : 0 );
5403 QTextLineStart *lineStart2 = formatLine( parag, string, lineStart, firstChar, c-1, align, SPACE(w - x) ); 5377 QTextLineStart *lineStart2 = formatLine( parag, string, lineStart, firstChar, c-1, align, SPACE(w - x) );
5404 ci->resize( w - x); 5378 ci->resize( w - x);
5405 if ( ci->width < w - x ) { 5379 if ( ci->width < w - x ) {
5406 if ( align & Qt::AlignHCenter ) 5380 if ( align & Qt::AlignHCenter )
5407 x = ( w - ci->width ) / 2; 5381 x = ( w - ci->width ) / 2;
5408 else if ( align & Qt::AlignRight ) { 5382 else if ( align & Qt::AlignRight ) {
5409 x = w - ci->width; 5383 x = w - ci->width;
5410 } 5384 }
5411 } 5385 }
5412 c->x = x; 5386 c->x = x;
5413 curLeft = x; 5387 curLeft = x;
5414 if ( i == 0 || !isBreakable( string, i - 1 ) || string->at( i - 1 ).lineStart == 0 ) { 5388 if ( i == 0 || !isBreakable( string, i - 1 ) || string->at( i - 1 ).lineStart == 0 ) {
5415 y += QMAX( h, QMAX( tmph, linespacing ) ); 5389 y += QMAX( h, QMAX( tmph, linespacing ) );