#include <q3richtext_p.h>
Inheritance diagram for Q3TextFormatter:

Definition at line 1320 of file q3richtext_p.h.
Public Member Functions | |
| Q3TextFormatter () | |
| virtual | ~Q3TextFormatter () |
| virtual int | format (Q3TextDocument *doc, Q3TextParagraph *parag, int start, const QMap< int, QTextLineStart * > &oldLineStarts)=0 |
| virtual int | formatVertically (Q3TextDocument *doc, Q3TextParagraph *parag) |
| bool | isWrapEnabled (Q3TextParagraph *p) const |
| int | wrapAtColumn () const |
| virtual void | setWrapEnabled (bool b) |
| virtual void | setWrapAtColumn (int c) |
| virtual void | setAllowBreakInWords (bool b) |
| bool | allowBreakInWords () const |
| int | minimumWidth () const |
| int | widthUsed () const |
Protected Member Functions | |
| virtual QTextLineStart * | formatLine (Q3TextParagraph *parag, Q3TextString *string, QTextLineStart *line, Q3TextStringChar *start, Q3TextStringChar *last, int align=Qt::AlignAuto, int space=0) |
| virtual QTextLineStart * | bidiReorderLine (Q3TextParagraph *parag, Q3TextString *string, QTextLineStart *line, Q3TextStringChar *start, Q3TextStringChar *last, int align, int space) |
| void | insertLineStart (Q3TextParagraph *parag, int index, QTextLineStart *ls) |
Protected Attributes | |
| int | thisminw |
| int | thiswused |
Private Attributes | |
| bool | wrapEnabled |
| int | wrapColumn |
| bool | biw |
| Q3TextFormatter::Q3TextFormatter | ( | ) |
Definition at line 5322 of file q3richtext.cpp.
05323 : thisminw(0), thiswused(0), wrapEnabled(true), wrapColumn(-1), biw(false) 05324 { 05325 }
| Q3TextFormatter::~Q3TextFormatter | ( | ) | [virtual] |
| virtual int Q3TextFormatter::format | ( | Q3TextDocument * | doc, | |
| Q3TextParagraph * | parag, | |||
| int | start, | |||
| const QMap< int, QTextLineStart * > & | oldLineStarts | |||
| ) | [pure virtual] |
Referenced by Q3TextParagraph::format().
| int Q3TextFormatter::formatVertically | ( | Q3TextDocument * | doc, | |
| Q3TextParagraph * | parag | |||
| ) | [virtual] |
Definition at line 5540 of file q3richtext.cpp.
References Q3TextFlow::adjustFlow(), Q3TextString::at(), QMap< Key, T >::begin(), Q3TextParagraph::bottomMargin(), c, QMap< Key, T >::end(), Q3TextDocument::flow(), h, QRect::height(), QMap< Key, T >::key(), Q3TextParagraph::lineStartList(), m, Q3TextParagraph::next(), Q3TextParagraph::prev(), qMax(), Q3TextParagraph::rect(), Q3TextParagraph::setHeight(), Q3TextParagraph::setMovedDown(), shift(), Q3TextParagraph::string(), Q3TextParagraph::topMargin(), QMap< Key, T >::value(), QTextLineStart::y, and QRect::y().
Referenced by Q3TextParagraph::format().
05541 { 05542 int oldHeight = parag->rect().height(); 05543 QMap<int, QTextLineStart*>& lineStarts = parag->lineStartList(); 05544 QMap<int, QTextLineStart*>::Iterator it = lineStarts.begin(); 05545 int h = parag->prev() ? qMax(parag->prev()->bottomMargin(),parag->topMargin()) / 2: 0; 05546 for (; it != lineStarts.end() ; ++it ) { 05547 QTextLineStart * ls = it.value(); 05548 ls->y = h; 05549 Q3TextStringChar *c = ¶g->string()->at(it.key()); 05550 #ifndef QT_NO_TEXTCUSTOMITEM 05551 if (c && c->customItem() && c->customItem()->ownLine()) { 05552 int h = c->customItem()->height; 05553 c->customItem()->pageBreak(parag->rect().y() + ls->y + ls->baseLine - h, doc->flow()); 05554 int delta = c->customItem()->height - h; 05555 ls->h += delta; 05556 if (delta) 05557 parag->setMovedDown(true); 05558 } else 05559 #endif 05560 { 05561 05562 int shift = doc->flow()->adjustFlow(parag->rect().y() + ls->y, ls->w, ls->h); 05563 ls->y += shift; 05564 if (shift) 05565 parag->setMovedDown(true); 05566 } 05567 h = ls->y + ls->h; 05568 } 05569 int m = parag->bottomMargin(); 05570 if (!parag->next()) 05571 m = 0; 05572 else 05573 m = qMax(m, parag->next()->topMargin()) / 2; 05574 h += m; 05575 parag->setHeight(h); 05576 return h - oldHeight; 05577 }
Here is the call graph for this function:

| bool Q3TextFormatter::isWrapEnabled | ( | Q3TextParagraph * | p | ) | const [inline] |
Definition at line 1329 of file q3richtext_p.h.
References p.
Referenced by Q3TextFormatterBreakInWords::format(), and Q3TextFormatterBreakWords::format().
01329 { if (!wrapEnabled) return false; if (p && !p->isBreakable()) return false; return true;}
| int Q3TextFormatter::wrapAtColumn | ( | ) | const [inline] |
Definition at line 1330 of file q3richtext_p.h.
Referenced by Q3TextFormatterBreakInWords::format(), and Q3TextFormatterBreakWords::format().
01330 { return wrapColumn;}
| void Q3TextFormatter::setWrapEnabled | ( | bool | b | ) | [virtual] |
Definition at line 89 of file q3richtext_p.cpp.
References wrapEnabled.
Referenced by Q3TextEdit::optimDrawContents(), Q3TextEdit::setWordWrap(), and Q3TextEdit::setWrapPolicy().
00089 { wrapEnabled = b; }
| void Q3TextFormatter::setWrapAtColumn | ( | int | c | ) | [virtual] |
Definition at line 90 of file q3richtext_p.cpp.
References wrapColumn.
Referenced by Q3TextEdit::setWordWrap(), Q3TextEdit::setWrapColumnOrWidth(), and Q3TextEdit::setWrapPolicy().
00090 { wrapColumn = c; }
| virtual void Q3TextFormatter::setAllowBreakInWords | ( | bool | b | ) | [inline, virtual] |
Definition at line 1333 of file q3richtext_p.h.
Referenced by Q3IconViewItemLineEdit::Q3IconViewItemLineEdit(), Q3SimpleRichText::setWidth(), and Q3TextEdit::setWrapPolicy().
| bool Q3TextFormatter::allowBreakInWords | ( | ) | const [inline] |
Definition at line 1334 of file q3richtext_p.h.
Referenced by Q3TextFormatterBreakWords::format().
01334 { return biw; }
| int Q3TextFormatter::minimumWidth | ( | ) | const [inline] |
Definition at line 1336 of file q3richtext_p.h.
Referenced by Q3TextParagraph::format().
01336 { return thisminw; }
| int Q3TextFormatter::widthUsed | ( | ) | const [inline] |
Definition at line 1337 of file q3richtext_p.h.
Referenced by Q3TextParagraph::format().
01337 { return thiswused; }
| QTextLineStart * Q3TextFormatter::formatLine | ( | Q3TextParagraph * | parag, | |
| Q3TextString * | string, | |||
| QTextLineStart * | line, | |||
| Q3TextStringChar * | start, | |||
| Q3TextStringChar * | last, | |||
| int | align = Qt::AlignAuto, |
|||
| int | space = 0 | |||
| ) | [protected, virtual] |
Definition at line 5327 of file q3richtext.cpp.
References Qt::AlignHCenter, Qt::AlignJustify, Qt::AlignRight, Q3TextString::at(), bidiReorderLine(), Q3TextStringChar::c, Q3TextStringChar::format, Q3TextString::isBidi(), j, length, s, start, QTextLineStart::w, Q3TextStringChar::whiteSpace, Q3TextFormat::width(), Q3TextString::width(), and Q3TextStringChar::x.
Referenced by Q3TextFormatterBreakInWords::format(), and Q3TextFormatterBreakWords::format().
05329 { 05330 if (lastChar < startChar) 05331 return new QTextLineStart; 05332 #ifndef QT_NO_COMPLEXTEXT 05333 if(string->isBidi()) 05334 return bidiReorderLine(parag, string, line, startChar, lastChar, align, space); 05335 #endif 05336 int start = (startChar - &string->at(0)); 05337 int last = (lastChar - &string->at(0)); 05338 05339 // ignore white space at the end of the line. 05340 Q3TextStringChar *ch = lastChar; 05341 while (ch > startChar && ch->whiteSpace) { 05342 space += ch->format()->width(' '); 05343 --ch; 05344 } 05345 05346 if (space < 0) 05347 space = 0; 05348 05349 // do alignment Auto == Left in this case 05350 if (align & Qt::AlignHCenter || align & Qt::AlignRight) { 05351 if (align & Qt::AlignHCenter) 05352 space /= 2; 05353 for (int j = start; j <= last; ++j) 05354 string->at(j).x += space; 05355 } else if (align & Qt::AlignJustify) { 05356 int numSpaces = 0; 05357 // End at "last-1", the last space ends up with a width of 0 05358 for (int j = last-1; j >= start; --j) { 05359 // Start at last tab, if any. 05360 Q3TextStringChar &ch = string->at(j); 05361 if (ch.c == '\t') { 05362 start = j+1; 05363 break; 05364 } 05365 if(ch.whiteSpace) 05366 numSpaces++; 05367 } 05368 int toAdd = 0; 05369 for (int k = start + 1; k <= last; ++k) { 05370 Q3TextStringChar &ch = string->at(k); 05371 if(numSpaces && ch.whiteSpace) { 05372 int s = space / numSpaces; 05373 toAdd += s; 05374 space -= s; 05375 numSpaces--; 05376 } 05377 string->at(k).x += toAdd; 05378 } 05379 } 05380 05381 if (last >= 0 && last < string->length()) 05382 line->w = string->at(last).x + string->width(last); 05383 else 05384 line->w = 0; 05385 05386 return new QTextLineStart; 05387 }
Here is the call graph for this function:

| QTextLineStart * Q3TextFormatter::bidiReorderLine | ( | Q3TextParagraph * | parag, | |
| Q3TextString * | string, | |||
| QTextLineStart * | line, | |||
| Q3TextStringChar * | start, | |||
| Q3TextStringChar * | last, | |||
| int | align, | |||
| int | space | |||
| ) | [protected, virtual] |
Definition at line 5396 of file q3richtext.cpp.
References Qt::AlignHCenter, Qt::AlignJustify, Qt::AlignRight, Q3TextString::at(), Q3TextStringChar::bidiLevel, QTextEngine::bidiReorder(), Q3TextStringChar::c, Q3TextFormat::font(), Q3TextFormat::fontMetrics(), Q3TextStringChar::format, i, Q3TextStringChar::isCustom(), Q3TextString::isRightToLeft(), QChar::isSpace(), QFont::italic(), j, l, Qt::LeftToRight, length, levels, QFontMetrics::rightBearing(), Qt::RightToLeft, Q3TextStringChar::rightToLeft, s, start, QChar::unicode(), QStyle::visualAlignment(), Q3TextStringChar::whiteSpace, Q3TextFormat::width(), Q3TextString::width(), Q3TextStringChar::x, and x.
Referenced by formatLine().
05398 { 05399 // ignore white space at the end of the line. 05400 int endSpaces = 0; 05401 while (lastChar > startChar && lastChar->whiteSpace) { 05402 space += lastChar->format()->width(' '); 05403 --lastChar; 05404 ++endSpaces; 05405 } 05406 05407 int start = (startChar - &text->at(0)); 05408 int last = (lastChar - &text->at(0)); 05409 05410 int length = lastChar - startChar + 1; 05411 05412 05413 int x = startChar->x; 05414 05415 unsigned char _levels[256]; 05416 int _visual[256]; 05417 05418 unsigned char *levels = _levels; 05419 int *visual = _visual; 05420 05421 if (length > 255) { 05422 levels = (unsigned char *)malloc(length*sizeof(unsigned char)); 05423 visual = (int *)malloc(length*sizeof(int)); 05424 } 05425 05426 //qDebug("bidiReorderLine: length=%d (%d-%d)", length, start, last); 05427 05428 Q3TextStringChar *ch = startChar; 05429 unsigned char *l = levels; 05430 while (ch <= lastChar) { 05431 //qDebug(" level: %d", ch->bidiLevel); 05432 *(l++) = (ch++)->bidiLevel; 05433 } 05434 05435 QTextEngine::bidiReorder(length, levels, visual); 05436 05437 // now construct the reordered string out of the runs... 05438 05439 int numSpaces = 0; 05440 align = QStyle::visualAlignment(text->isRightToLeft() ? Qt::RightToLeft : Qt::LeftToRight, QFlag(align)); 05441 05442 // This is not really correct, but as we can't make the scrollbar move to the left of the origin, 05443 // this ensures all text can be scrolled to and read. 05444 if (space < 0) 05445 space = 0; 05446 05447 if (align & Qt::AlignHCenter) 05448 x += space/2; 05449 else if (align & Qt::AlignRight) 05450 x += space; 05451 else if (align & Qt::AlignJustify) { 05452 // End at "last-1", the last space ends up with a width of 0 05453 for (int j = last-1; j >= start; --j) { 05454 // Start at last tab, if any. 05455 Q3TextStringChar &ch = text->at(j); 05456 if (ch.c == '\t') { 05457 start = j+1; 05458 break; 05459 } 05460 if(ch.whiteSpace) 05461 numSpaces++; 05462 } 05463 } 05464 05465 int toAdd = 0; 05466 int xorig = x; 05467 Q3TextStringChar *lc = startChar + visual[0]; 05468 for (int i = 0; i < length; i++) { 05469 Q3TextStringChar *ch = startChar + visual[i]; 05470 if (numSpaces && ch->whiteSpace) { 05471 int s = space / numSpaces; 05472 toAdd += s; 05473 space -= s; 05474 numSpaces--; 05475 } 05476 05477 if (lc->format() != ch->format() && !ch->c.isSpace() 05478 && lc->format()->font().italic() && !ch->format()->font().italic()) { 05479 int rb = lc->format()->fontMetrics().rightBearing(lc->c); 05480 if (rb < 0) 05481 x -= rb; 05482 } 05483 05484 ch->x = x + toAdd; 05485 ch->rightToLeft = ch->bidiLevel % 2; 05486 //qDebug("visual: %d (%p) placed at %d rightToLeft=%d", visual[i], ch, x +toAdd, ch->rightToLeft ); 05487 int ww = 0; 05488 if (ch->c.unicode() >= 32 || ch->c == '\t' || ch->c == '\n' || ch->isCustom()) { 05489 ww = text->width(start+visual[i]); 05490 } else { 05491 ww = ch->format()->width(' '); 05492 } 05493 x += ww; 05494 lc = ch; 05495 } 05496 x += toAdd; 05497 05498 while (endSpaces--) { 05499 ++lastChar; 05500 int sw = lastChar->format()->width(' '); 05501 if (text->isRightToLeft()) { 05502 xorig -= sw; 05503 lastChar->x = xorig; 05504 ch->rightToLeft = true; 05505 } else { 05506 lastChar->x = x; 05507 x += sw; 05508 ch->rightToLeft = false; 05509 } 05510 } 05511 05512 line->w = x; 05513 05514 if (length > 255) { 05515 free(levels); 05516 free(visual); 05517 } 05518 05519 return new QTextLineStart; 05520 }
Here is the call graph for this function:

| void Q3TextFormatter::insertLineStart | ( | Q3TextParagraph * | parag, | |
| int | index, | |||
| QTextLineStart * | ls | |||
| ) | [protected] |
Definition at line 5524 of file q3richtext.cpp.
References QMap< Key, T >::end(), QMap< Key, T >::erase(), QMap< Key, T >::find(), QMap< Key, T >::insert(), and Q3TextParagraph::lineStartList().
Referenced by Q3TextFormatterBreakInWords::format(), and Q3TextFormatterBreakWords::format().
05525 { 05526 QMap<int, QTextLineStart*>::Iterator it; 05527 if ((it = parag->lineStartList().find(index)) == parag->lineStartList().end()) { 05528 parag->lineStartList().insert(index, ls); 05529 } else { 05530 delete *it; 05531 parag->lineStartList().erase(it); 05532 parag->lineStartList().insert(index, ls); 05533 } 05534 }
Here is the call graph for this function:

int Q3TextFormatter::thisminw [protected] |
Definition at line 1348 of file q3richtext_p.h.
Referenced by Q3TextFormatterBreakInWords::format(), and Q3TextFormatterBreakWords::format().
int Q3TextFormatter::thiswused [protected] |
Definition at line 1349 of file q3richtext_p.h.
Referenced by Q3TextFormatterBreakInWords::format(), and Q3TextFormatterBreakWords::format().
bool Q3TextFormatter::wrapEnabled [private] |
Definition at line 1352 of file q3richtext_p.h.
Referenced by Q3TextFormatterBreakInWords::format(), Q3TextFormatterBreakWords::format(), and setWrapEnabled().
int Q3TextFormatter::wrapColumn [private] |
bool Q3TextFormatter::biw [private] |
Definition at line 1354 of file q3richtext_p.h.
1.5.1