| 1880 | } |
| 1881 | |
| 1882 | void DocumentPrivate::doContinueGooglesDocumentSearch(QSet<int> *pagesToNotify, QHash<Page *, QList<MatchColor>> *pageMatches, int currentPage, int searchID, const QStringList &words) |
| 1883 | { |
| 1884 | RunningSearch *search = m_searches.value(searchID); |
| 1885 | |
| 1886 | if (m_searchCancelled || !search) { |
| 1887 | using Matches = QList<MatchColor>; |
| 1888 | |
| 1889 | QApplication::restoreOverrideCursor(); |
| 1890 | |
| 1891 | if (search) { |
| 1892 | search->isCurrentlySearching = false; |
| 1893 | } |
| 1894 | |
| 1895 | Q_EMIT m_parent->searchFinished(searchID, Document::SearchCancelled); |
| 1896 | |
| 1897 | for (Matches &mv : *pageMatches) { |
| 1898 | for (auto &[area, color] : mv) { |
| 1899 | delete area; |
| 1900 | area = nullptr; |
| 1901 | } |
| 1902 | } |
| 1903 | delete pageMatches; |
| 1904 | delete pagesToNotify; |
| 1905 | return; |
| 1906 | } |
| 1907 | |
| 1908 | const int wordCount = words.count(); |
| 1909 | const int hueStep = (wordCount > 1) ? (60 / (wordCount - 1)) : 60; |
| 1910 | int baseHue, baseSat, baseVal; |
| 1911 | search->cachedColor.getHsv(&baseHue, &baseSat, &baseVal); |
| 1912 | |
| 1913 | if (currentPage < m_pagesVector.count()) { |
| 1914 | // get page (from the first to the last) |
| 1915 | Page *page = m_pagesVector.at(currentPage); |
| 1916 | |
| 1917 | // request search page if needed |
| 1918 | if (!page->hasTextPage()) { |
| 1919 | int pageNumber = page->number(); // redundant? is it == currentPage ? |
| 1920 | m_parent->requestTextPage(pageNumber); |
| 1921 | } |
| 1922 | |
| 1923 | // loop on a page adding highlights for all found items |
| 1924 | bool allMatched = wordCount > 0, anyMatched = false; |
| 1925 | for (int w = 0; w < wordCount; w++) { |
| 1926 | const QString &word = words[w]; |
| 1927 | int newHue = baseHue - w * hueStep; |
| 1928 | if (newHue < 0) { |
| 1929 | newHue += 360; |
| 1930 | } |
| 1931 | QColor wordColor = QColor::fromHsv(newHue, baseSat, baseVal); |
| 1932 | RegularAreaRect *lastMatch = nullptr; |
| 1933 | // add all highlights for current word |
| 1934 | bool wordMatched = false; |
| 1935 | while (true) { |
| 1936 | if (lastMatch) { |
| 1937 | lastMatch = page->findText(searchID, word, NextResult, search->cachedCaseSensitivity, lastMatch); |
| 1938 | } else { |
| 1939 | lastMatch = page->findText(searchID, word, FromTop, search->cachedCaseSensitivity); |
no test coverage detected