| 453 | } |
| 454 | |
| 455 | bool QLiteHtmlWidget::findText(const QString &text, |
| 456 | QTextDocument::FindFlags flags, |
| 457 | bool incremental, |
| 458 | bool *wrapped) |
| 459 | { |
| 460 | bool success = false; |
| 461 | QVector<QRect> oldSelection; |
| 462 | QVector<QRect> newSelection; |
| 463 | d->documentContainer |
| 464 | .findText(text, flags, incremental, wrapped, &success, &oldSelection, &newSelection); |
| 465 | // scroll to search result position and/or redraw as necessary |
| 466 | QRect newSelectionCombined; |
| 467 | for (const QRect &r : newSelection) |
| 468 | newSelectionCombined = newSelectionCombined.united(r); |
| 469 | QScrollBar *vBar = verticalScrollBar(); |
| 470 | const int top = newSelectionCombined.top(); |
| 471 | const int bottom = newSelectionCombined.bottom() - toVirtual(viewport()->size()).height(); |
| 472 | if (success && top < vBar->value() && vBar->minimum() <= top) { |
| 473 | vBar->setValue(top); |
| 474 | } else if (success && vBar->value() < bottom && bottom <= vBar->maximum()) { |
| 475 | vBar->setValue(bottom); |
| 476 | } else { |
| 477 | viewport()->update(fromVirtual(newSelectionCombined.translated(-scrollPosition()))); |
| 478 | for (const QRect &r : oldSelection) |
| 479 | viewport()->update(fromVirtual(r.translated(-scrollPosition()))); |
| 480 | } |
| 481 | return success; |
| 482 | } |
| 483 | |
| 484 | void QLiteHtmlWidget::setDefaultFont(const QFont &font) |
| 485 | { |