1 | /* |
---|
2 | |
---|
3 | Copyright 2012-2015 Adam Reichold |
---|
4 | |
---|
5 | This file is part of qpdfview. |
---|
6 | |
---|
7 | qpdfview is free software: you can redistribute it and/or modify |
---|
8 | it under the terms of the GNU General Public License as published by |
---|
9 | the Free Software Foundation, either version 2 of the License, or |
---|
10 | (at your option) any later version. |
---|
11 | |
---|
12 | qpdfview is distributed in the hope that it will be useful, |
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | GNU General Public License for more details. |
---|
16 | |
---|
17 | You should have received a copy of the GNU General Public License |
---|
18 | along with qpdfview. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | |
---|
20 | */ |
---|
21 | |
---|
22 | #include "searchtask.h" |
---|
23 | |
---|
24 | #include "model.h" |
---|
25 | |
---|
26 | namespace qpdfview |
---|
27 | { |
---|
28 | |
---|
29 | SearchTask::SearchTask(QObject* parent) : QThread(parent), |
---|
30 | m_wasCanceled(NotCanceled), |
---|
31 | m_progress(0), |
---|
32 | m_pages(), |
---|
33 | m_text(), |
---|
34 | m_matchCase(false), |
---|
35 | m_wholeWords(false), |
---|
36 | m_beginAtPage(1) |
---|
37 | { |
---|
38 | } |
---|
39 | |
---|
40 | void SearchTask::run() |
---|
41 | { |
---|
42 | for(int index = m_beginAtPage - 1; index < m_pages.count() + m_beginAtPage - 1; ++index) |
---|
43 | { |
---|
44 | if(testCancellation()) |
---|
45 | { |
---|
46 | break; |
---|
47 | } |
---|
48 | |
---|
49 | const QList< QRectF > results = m_pages.at(index % m_pages.count())->search(m_text, m_matchCase, m_wholeWords); |
---|
50 | |
---|
51 | emit resultsReady(index % m_pages.count(), results); |
---|
52 | |
---|
53 | releaseProgress(100 * (index + 1 - m_beginAtPage + 1) / m_pages.count()); |
---|
54 | |
---|
55 | emit progressChanged(loadProgress()); |
---|
56 | } |
---|
57 | |
---|
58 | releaseProgress(0); |
---|
59 | } |
---|
60 | |
---|
61 | void SearchTask::start(const QVector< Model::Page* >& pages, |
---|
62 | const QString& text, bool matchCase, bool wholeWords, int beginAtPage) |
---|
63 | { |
---|
64 | m_pages = pages; |
---|
65 | |
---|
66 | m_text = text; |
---|
67 | m_matchCase = matchCase; |
---|
68 | m_wholeWords = wholeWords; |
---|
69 | m_beginAtPage = beginAtPage; |
---|
70 | |
---|
71 | resetCancellation(); |
---|
72 | releaseProgress(0); |
---|
73 | |
---|
74 | QThread::start(); |
---|
75 | } |
---|
76 | |
---|
77 | } // qpdfview |
---|