|
a/src/qtgui/preview_w.cpp |
|
b/src/qtgui/preview_w.cpp |
1 |
#ifndef lint
|
1 |
#ifndef lint
|
2 |
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.17 2007-02-19 18:15:14 dockes Exp $ (C) 2005 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.18 2007-05-23 09:19:48 dockes Exp $ (C) 2005 J.F.Dockes";
|
3 |
#endif
|
3 |
#endif
|
4 |
/*
|
4 |
/*
|
5 |
* This program is free software; you can redistribute it and/or modify
|
5 |
* This program is free software; you can redistribute it and/or modify
|
6 |
* it under the terms of the GNU General Public License as published by
|
6 |
* it under the terms of the GNU General Public License as published by
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
7 |
* the Free Software Foundation; either version 2 of the License, or
|
|
... |
|
... |
157 |
QWidget *tw = pvTab->currentPage();
|
157 |
QWidget *tw = pvTab->currentPage();
|
158 |
QWidget *e = 0;
|
158 |
QWidget *e = 0;
|
159 |
if (tw)
|
159 |
if (tw)
|
160 |
e = (QWidget *)tw->child("pvEdit");
|
160 |
e = (QWidget *)tw->child("pvEdit");
|
161 |
LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
|
161 |
LOGDEB1(("Widget: %p, edit %p, target %p\n", tw, e, target));
|
162 |
if (e && target == tw && keyEvent->key() == Qt::Key_Slash) {
|
162 |
if (e && target == e && keyEvent->key() == Qt::Key_Slash) {
|
163 |
searchTextLine->setFocus();
|
163 |
searchTextLine->setFocus();
|
164 |
dynSearchActive = true;
|
164 |
dynSearchActive = true;
|
165 |
return true;
|
165 |
return true;
|
166 |
}
|
166 |
}
|
167 |
}
|
167 |
}
|
|
... |
|
... |
172 |
void Preview::searchTextLine_textChanged(const QString & text)
|
172 |
void Preview::searchTextLine_textChanged(const QString & text)
|
173 |
{
|
173 |
{
|
174 |
LOGDEB1(("search line text changed. text: '%s'\n", text.ascii()));
|
174 |
LOGDEB1(("search line text changed. text: '%s'\n", text.ascii()));
|
175 |
if (text.isEmpty()) {
|
175 |
if (text.isEmpty()) {
|
176 |
dynSearchActive = false;
|
176 |
dynSearchActive = false;
|
177 |
nextButton->setEnabled(false);
|
177 |
// nextButton->setEnabled(false);
|
178 |
prevButton->setEnabled(false);
|
178 |
// prevButton->setEnabled(false);
|
179 |
clearPB->setEnabled(false);
|
179 |
clearPB->setEnabled(false);
|
180 |
} else {
|
180 |
} else {
|
181 |
dynSearchActive = true;
|
181 |
dynSearchActive = true;
|
182 |
nextButton->setEnabled(true);
|
182 |
// nextButton->setEnabled(true);
|
183 |
prevButton->setEnabled(true);
|
183 |
// prevButton->setEnabled(true);
|
184 |
clearPB->setEnabled(true);
|
184 |
clearPB->setEnabled(true);
|
185 |
doSearch(text, false, false);
|
185 |
doSearch(text, false, false);
|
186 |
}
|
186 |
}
|
187 |
}
|
187 |
}
|
188 |
|
188 |
|
|
... |
|
... |
204 |
|
204 |
|
205 |
// Perform text search. If next is true, we look for the next match of the
|
205 |
// Perform text search. If next is true, we look for the next match of the
|
206 |
// current search, trying to advance and possibly wrapping around. If next is
|
206 |
// current search, trying to advance and possibly wrapping around. If next is
|
207 |
// false, the search string has been modified, we search for the new string,
|
207 |
// false, the search string has been modified, we search for the new string,
|
208 |
// starting from the current position
|
208 |
// starting from the current position
|
209 |
void Preview::doSearch(const QString &text, bool next, bool reverse,
|
209 |
void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
210 |
bool wordOnly)
|
210 |
bool wordOnly)
|
211 |
{
|
211 |
{
|
212 |
LOGDEB1(("Preview::doSearch: [%s] next %d rev %d\n",
|
212 |
LOGDEB(("Preview::doSearch: [%s] next %d rev %d\n",
|
213 |
(const char *)text.utf8(), int(next), int(reverse)));
|
213 |
(const char *)_text.utf8(), int(next), int(reverse)));
|
|
|
214 |
QString text = _text;
|
214 |
if (text.isEmpty())
|
215 |
if (text.isEmpty()) {
|
215 |
return;
|
216 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
|
|
217 |
text = QString::fromUtf8(firstTermBeacon);
|
|
|
218 |
#endif
|
|
|
219 |
}
|
216 |
QTextEdit *edit = getCurrentEditor();
|
220 |
QTextEdit *edit = getCurrentEditor();
|
217 |
if (edit == 0) {
|
221 |
if (edit == 0) {
|
218 |
// ??
|
222 |
// ??
|
219 |
return;
|
223 |
return;
|
220 |
}
|
224 |
}
|
|
|
225 |
|
221 |
bool matchCase = matchCheck->isChecked();
|
226 |
bool matchCase = matchCheck->isChecked();
|
222 |
int mspara, msindex, mepara, meindex;
|
|
|
223 |
edit->getSelection(&mspara, &msindex, &mepara, &meindex);
|
|
|
224 |
if (mspara == -1)
|
|
|
225 |
mspara = msindex = mepara = meindex = 0;
|
|
|
226 |
|
227 |
|
|
|
228 |
LOGDEB(("Preview::doSearch: find: case %d word %d fw %d\n",
|
|
|
229 |
matchCase, wordOnly, !reverse));
|
|
|
230 |
|
|
|
231 |
// If the search text changed we need to reset the cursor position
|
|
|
232 |
// to the start of the previous match, else incremental search is
|
|
|
233 |
// going to look for the next occurrence instead of trying to
|
|
|
234 |
// lenghten the current match
|
227 |
if (next) {
|
235 |
if (!next) {
|
228 |
// We search again, starting from the current match
|
236 |
int ps, is, pe, ie;
|
229 |
if (reverse) {
|
237 |
edit->getSelection(&ps, &is, &pe, &ie);
|
230 |
// when searching backwards, have to move back one char
|
238 |
if (is > 0)
|
231 |
if (msindex > 0)
|
239 |
is--;
|
232 |
msindex --;
|
240 |
else if (ps > 0)
|
233 |
else if (mspara > 0) {
|
241 |
ps--;
|
234 |
mspara --;
|
242 |
LOGDEB(("Setting cursor to %d %d\n", ps, is));
|
235 |
msindex = edit->paragraphLength(mspara);
|
243 |
edit->setCursorPosition(ps, is);
|
236 |
}
|
244 |
}
|
237 |
} else {
|
|
|
238 |
// Forward search: start from end of selection
|
|
|
239 |
mspara = mepara;
|
|
|
240 |
msindex = meindex;
|
|
|
241 |
LOGDEB1(("New para: %d index %d\n", mspara, msindex));
|
|
|
242 |
}
|
|
|
243 |
}
|
|
|
244 |
|
245 |
|
245 |
bool found = edit->find(text, matchCase, wordOnly,
|
246 |
bool found = edit->find(text, matchCase, wordOnly, !reverse, 0, 0);
|
246 |
!reverse, &mspara, &msindex);
|
247 |
// If not found, try to wrap around.
|
247 |
LOGDEB(("Found at para: %d index %d\n", mspara, msindex));
|
248 |
if (!found && next) {
|
248 |
|
249 |
LOGDEB(("Preview::doSearch: wrapping around\n"));
|
249 |
if (!found && next && true) { // need a 'canwrap' test here
|
250 |
int mspara, msindex;
|
250 |
if (reverse) {
|
251 |
if (reverse) {
|
251 |
mspara = edit->paragraphs();
|
252 |
mspara = edit->paragraphs();
|
252 |
msindex = edit->paragraphLength(mspara);
|
253 |
msindex = edit->paragraphLength(mspara);
|
253 |
} else {
|
254 |
} else {
|
254 |
mspara = msindex = 0;
|
255 |
mspara = msindex = 0;
|
255 |
}
|
256 |
}
|
256 |
found = edit->find(text, matchCase, false, !reverse, &mspara, &msindex);
|
257 |
found = edit->find(text,matchCase, false, !reverse, &mspara, &msindex);
|
257 |
}
|
258 |
}
|
258 |
|
259 |
|
259 |
if (found) {
|
260 |
if (found) {
|
260 |
canBeep = true;
|
261 |
canBeep = true;
|
261 |
} else {
|
262 |
} else {
|
|
... |
|
... |
620 |
// Reset config just in case.
|
621 |
// Reset config just in case.
|
621 |
rclconfig->setKeyDir("");
|
622 |
rclconfig->setKeyDir("");
|
622 |
|
623 |
|
623 |
// Create preview text: highlight search terms (if not too big):
|
624 |
// Create preview text: highlight search terms (if not too big):
|
624 |
QString richTxt;
|
625 |
QString richTxt;
|
625 |
bool highlightTerms = fdoc.text.length() < 1000 *1024;
|
626 |
bool highlightTerms = fdoc.text.length() < 2000 * 1024;
|
626 |
if (highlightTerms) {
|
627 |
if (highlightTerms) {
|
627 |
progress.setLabelText(tr("Creating preview text"));
|
628 |
progress.setLabelText(tr("Creating preview text"));
|
628 |
ToRichThread rthr(fdoc.text, m_hData, richTxt);
|
629 |
ToRichThread rthr(fdoc.text, m_hData, richTxt);
|
629 |
rthr.start();
|
630 |
rthr.start();
|
630 |
|
631 |
|
|
... |
|
... |
655 |
} else {
|
656 |
} else {
|
656 |
richTxt += "<b>Cancelled !</b>";
|
657 |
richTxt += "<b>Cancelled !</b>";
|
657 |
}
|
658 |
}
|
658 |
}
|
659 |
}
|
659 |
} else {
|
660 |
} else {
|
660 |
richTxt = fdoc.text.c_str();
|
661 |
richTxt = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
|
661 |
}
|
662 |
}
|
662 |
|
663 |
|
663 |
// Load into editor
|
664 |
// Load into editor
|
664 |
// Do it in several chunks
|
665 |
// Do it in several chunks
|
665 |
QTextEdit *editor = getCurrentEditor();
|
666 |
QTextEdit *editor = getCurrentEditor();
|
|
... |
|
... |
706 |
|
707 |
|
707 |
if (searchTextLine->text().length() != 0) {
|
708 |
if (searchTextLine->text().length() != 0) {
|
708 |
canBeep = true;
|
709 |
canBeep = true;
|
709 |
doSearch(searchTextLine->text(), true, false);
|
710 |
doSearch(searchTextLine->text(), true, false);
|
710 |
} else {
|
711 |
} else {
|
711 |
QString aname = QString::fromUtf8(firstTermAnchorName);
|
712 |
QString aname = QString::fromUtf8(termAnchorName(1).c_str());
|
712 |
LOGDEB2(("Calling scrolltoanchor [%s]\n", (const char *)aname.utf8()));
|
713 |
LOGDEB2(("Calling scrolltoanchor [%s]\n", (const char *)aname.utf8()));
|
713 |
editor->scrollToAnchor(aname);
|
714 |
editor->scrollToAnchor(aname);
|
714 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
715 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
715 |
bool wasC = matchCheck->isChecked();
|
|
|
716 |
matchCheck->setChecked(false);
|
|
|
717 |
bool ocanbeep = canBeep;
|
716 |
bool ocanbeep = canBeep;
|
718 |
canBeep = false;
|
717 |
canBeep = false;
|
719 |
doSearch(QString::fromUtf8(firstTermBeacon), 0, false, false);
|
718 |
QString empty;
|
|
|
719 |
doSearch(empty, 0, false, false);
|
720 |
canBeep = ocanbeep;
|
720 |
canBeep = ocanbeep;
|
721 |
editor->del();
|
|
|
722 |
matchCheck->setChecked(wasC);
|
|
|
723 |
#endif
|
721 |
#endif
|
724 |
}
|
722 |
}
|
|
|
723 |
editor->setFocus();
|
725 |
emit(previewExposed(m_searchId, docnum));
|
724 |
emit(previewExposed(m_searchId, docnum));
|
726 |
return true;
|
725 |
return true;
|
727 |
}
|
726 |
}
|