QRegExp TextFindReplacePanel::regexp() { QRegExp expr(findString()); expr.setPatternSyntax(asRegExp() ? QRegExp::RegExp : QRegExp::FixedString); expr.setCaseSensitivity(matchCase() ? Qt::CaseSensitive : Qt::CaseInsensitive); return expr; }
void FindBar::findNext() { Q_ASSERT(m_associatedWebView); if (isHidden()) { QPoint previous_position = m_associatedWebView->page()->currentFrame()->scrollPosition(); m_associatedWebView->page()->focusNextPrevChild(true); m_associatedWebView->page()->currentFrame()->setScrollPosition(previous_position); return; } QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; if (matchCase()) options |= QWebPage::FindCaseSensitively; // FIXME: there's a problem with scrolling. Because we're using the QWebView inside a QScrollArea container, the attempts // to scroll the QWebView itself have no effect. // The WebKit sources themselves contain a nice comment about MacOS's Mail application which embeds a web view into // a scrollable container (now *this* looks familiar, doesn't it) and provides a special function, the scrollRectIntoView. // Sadly, the Qt wrapper doesn't implement it :(. bool found = m_associatedWebView->page()->findText(_lastStringSearched, options); notifyMatch(found); if (!found) { QPoint previous_position = m_associatedWebView->page()->currentFrame()->scrollPosition(); m_associatedWebView->page()->focusNextPrevChild(true); m_associatedWebView->page()->currentFrame()->setScrollPosition(previous_position); } }
void FindBar::findPrevious() { Q_ASSERT(m_associatedWebView); QWebPage::FindFlags options = QWebPage::FindBackward | QWebPage::FindWrapsAroundDocument; if (matchCase()) options |= QWebPage::FindCaseSensitively; bool found = m_associatedWebView->page()->findText(_lastStringSearched, options); notifyMatch(found); }
void FindBar::findPrevious() { // parent webwindow WebWindow *w = qobject_cast<WebWindow *>(parent()); QWebPage::FindFlags options = QWebPage::FindBackward | QWebPage::FindWrapsAroundDocument; if (matchCase()) options |= QWebPage::FindCaseSensitively; bool found = w->page()->findText(_lastStringSearched, options); notifyMatch(found); }
void FindBar::updateHighlight() { Q_ASSERT(m_associatedWebView); QWebPage::FindFlags options = QWebPage::HighlightAllOccurrences; m_associatedWebView->page()->findText(QString(), options); //Clear an existing highlight if (!isHidden() && highlightAllState()) { if (matchCase()) options |= QWebPage::FindCaseSensitively; m_associatedWebView->page()->findText(_lastStringSearched, options); } }
void FindBar::updateHighlight() { // parent webwindow WebWindow *w = qobject_cast<WebWindow *>(parent()); QWebPage::FindFlags options = QWebPage::HighlightAllOccurrences; w->page()->findText(QL1S(""), options); //Clear an existing highlight if (!isHidden() && highlightAllState()) { if (matchCase()) options |= QWebPage::FindCaseSensitively; w->page()->findText(_lastStringSearched, options); } }
void FindBar::findNext() { // parent webwindow WebWindow *w = qobject_cast<WebWindow *>(parent()); if (w->page()->isOnRekonqPage()) { // trigger part find action KParts::ReadOnlyPart *p = w->tabView()->part(); if (p) { connect(this, SIGNAL(triggerPartFind()), p, SLOT(slotFind())); emit triggerPartFind(); return; } } if (isHidden()) { QPoint previous_position = w->page()->currentFrame()->scrollPosition(); w->page()->focusNextPrevChild(true); w->page()->currentFrame()->setScrollPosition(previous_position); return; } QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; if (matchCase()) options |= QWebPage::FindCaseSensitively; bool found = w->page()->findText(_lastStringSearched, options); notifyMatch(found); if (!found) { QPoint previous_position = w->page()->currentFrame()->scrollPosition(); w->page()->focusNextPrevChild(true); w->page()->currentFrame()->setScrollPosition(previous_position); } }
void FindBar::find(FindBar::FindDirection dir) { Q_ASSERT(m_associatedWebView); if (isHidden()) { QPoint previous_position = m_associatedWebView->page()->currentFrame()->scrollPosition(); m_associatedWebView->page()->focusNextPrevChild(true); m_associatedWebView->page()->currentFrame()->setScrollPosition(previous_position); return; } QWebPage::FindFlags options = QWebPage::FindWrapsAroundDocument; if (dir == Backward) options |= QWebPage::FindBackward; if (matchCase()) options |= QWebPage::FindCaseSensitively; // HACK Because we're using the QWebView inside a QScrollArea container, the attempts // to scroll the QWebView itself have no direct effect. // Therefore we temporarily shrink the page viewport to the message viewport (ie. the size it // can cover at max), then perform the search, store the scrollPosition, restore the page viewport // and finally scroll the messageview to the gathered scrollPosition, mapped to the message (ie. // usually offset by the mail header) auto emb = qobject_cast<EmbeddedWebView *>(m_associatedWebView); QAbstractScrollArea *container = emb ? static_cast<QAbstractScrollArea*>(emb->scrollParent()) : nullptr; const QSize oldVpS = m_associatedWebView->page()->viewportSize(); const bool useResizeTrick = container ? !!container->verticalScrollBar() : false; // first shrink the page viewport if (useResizeTrick) { m_associatedWebView->setUpdatesEnabled(false); // don't let the user see the flicker we might produce QSize newVpS = oldVpS.boundedTo(container->size()); m_associatedWebView->page()->setViewportSize(newVpS); } // now perform the search (pot. in the shrinked viewport) bool found = m_associatedWebView->page()->findText(_lastStringSearched, options); notifyMatch(found); // scroll and reset the page viewport if necessary if (useResizeTrick) { Q_ASSERT(container->verticalScrollBar()); // the page has now a usable scroll position ... int scrollPosition = m_associatedWebView->page()->currentFrame()->scrollPosition().y(); // ... which needs to be extended by the pages offset (usually the header widget) // NOTICE: QWidget::mapTo() fails as the viewport child position can be negative, so we run ourself QWidget *runner = m_associatedWebView; while (runner->parentWidget() != container->viewport()) { scrollPosition += runner->y(); runner = runner->parentWidget(); } // reset viewport to original size ... m_associatedWebView->page()->setViewportSize(oldVpS); // ... let the user see the change ... m_associatedWebView->setUpdatesEnabled(true); // ... and finally scroll to the desired position if (found) container->verticalScrollBar()->setValue(scrollPosition); } if (!found) { QPoint previous_position = m_associatedWebView->page()->currentFrame()->scrollPosition(); m_associatedWebView->page()->focusNextPrevChild(true); m_associatedWebView->page()->currentFrame()->setScrollPosition(previous_position); } }