-rw-r--r-- | noncore/apps/opie-write/qrichtext.cpp | 72 |
1 files changed, 23 insertions, 49 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 | |||
@@ -184,22 +184,19 @@ QTextDeleteCommand::~QTextDeleteCommand() | |||
184 | text[ i ].format()->removeRef(); | 184 | text[ i ].format()->removeRef(); |
185 | } | 185 | } |
186 | text.resize( 0 ); | 186 | text.resize( 0 ); |
187 | } | 187 | } |
188 | 188 | ||
189 | QTextCursor *QTextDeleteCommand::execute( QTextCursor *c ) | 189 | QTextCursor *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 ) { |
@@ -215,38 +212,32 @@ QTextCursor *QTextDeleteCommand::execute( QTextCursor *c ) | |||
215 | } | 212 | } |
216 | 213 | ||
217 | return c; | 214 | return c; |
218 | } | 215 | } |
219 | 216 | ||
220 | QTextCursor *QTextDeleteCommand::unexecute( QTextCursor *c ) | 217 | QTextCursor *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 ) { |
@@ -1396,45 +1387,34 @@ struct Q_EXPORT QTextDocumentTag { | |||
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) { \ | 1396 | if ( !textEditMode && curpar && curpar->length()>1 && curpar->at( curpar->length()-2)->c == QChar_linesep ) \ |
1406 | if ( !curpar ) { \ | 1397 | curpar->remove( curpar->length()-2, 1 ); \ |
1407 | owarn << "no current paragraph" << oendl; \ | 1398 | curpar = createParagraph( this, curpar, curpar->next() ); styles.append( vec ); vec = 0;} \ |
1408 | return; \ | 1399 | hasNewPar = TRUE; \ |
1409 | } \ | 1400 | curpar->rtext = TRUE; \ |
1410 | if ( !textEditMode && curpar && curpar->length()>1 && curpar->at( curpar->length()-2)->c == QChar_linesep ) \ | 1401 | curpar->align = curtag.alignment; \ |
1411 | curpar->remove( curpar->length()-2, 1 ); \ | 1402 | curpar->lstyle = curtag.liststyle; \ |
1412 | curpar = createParagraph( this, curpar, curpar->next() ); styles.append( vec ); \ | 1403 | curpar->litem = ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ); \ |
1413 | if ( !curpar ) { \ | 1404 | curpar->str->setDirection( (QChar::Direction)curtag.direction ); \ |
1414 | owarn << "failed in creating a new paragraph" << oendl; \ | 1405 | space = TRUE; \ |
1415 | return; \ | 1406 | delete vec; vec = new QPtrVector<QStyleSheetItem>( (uint)tags.count() + 1); \ |
1416 | } \ | 1407 | int i = 0; \ |
1417 | vec = 0; \ | 1408 | for ( QValueStack<QTextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it ) \ |
1418 | } \ | 1409 | vec->insert( i++, (*it).style ); \ |
1419 | hasNewPar = TRUE; \ | 1410 | vec->insert( i, curtag.style ); \ |
1420 | curpar->rtext = TRUE; \ | 1411 | }while(FALSE) |
1421 | curpar->align = curtag.alignment; \ | 1412 | |
1422 | curpar->lstyle = curtag.liststyle; \ | ||
1423 | curpar->litem = ( curtag.style->displayMode() == QStyleSheetItem::DisplayListItem ); \ | ||
1424 | curpar->str->setDirection( (QChar::Direction)curtag.direction ); \ | ||
1425 | space = TRUE; \ | ||
1426 | delete vec; \ | ||
1427 | vec = new QPtrVector<QStyleSheetItem>( (uint)tags.count() + 1); \ | ||
1428 | int i = 0; \ | ||
1429 | for ( QValueStack<QTextDocumentTag>::Iterator it = tags.begin(); it != tags.end(); ++it ) \ | ||
1430 | vec->insert( i++, (*it).style ); \ | ||
1431 | vec->insert( i, curtag.style ); \ | ||
1432 | } while ( FALSE ) | ||
1433 | 1413 | ||
1434 | void QTextDocument::setRichText( const QString &text, const QString &context ) | 1414 | void 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; |
@@ -1910,21 +1890,18 @@ void QTextDocument::setRichTextMarginsInternal( QPtrList< QPtrVector<QStyleSheet | |||
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; |
@@ -3065,25 +3042,22 @@ QTextParagraph *QTextDocument::draw( QPainter *p, int cx, int cy, int cw, int ch | |||
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 ); |
@@ -5359,17 +5333,17 @@ int QTextFormatterBreakWords::format( QTextDocument *doc, QTextParagraph *parag, | |||
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; |