|
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.22 2007-06-20 13:15:57 dockes Exp $ (C) 2005 J.F.Dockes";
|
2 |
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.23 2007-07-13 06:31:30 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
|
|
... |
|
... |
98 |
}
|
98 |
}
|
99 |
m_loading = false;
|
99 |
m_loading = false;
|
100 |
currentChanged(pvTab->currentPage());
|
100 |
currentChanged(pvTab->currentPage());
|
101 |
}
|
101 |
}
|
102 |
|
102 |
|
103 |
void Preview::destroy()
|
|
|
104 |
{
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
void Preview::closeEvent(QCloseEvent *e)
|
103 |
void Preview::closeEvent(QCloseEvent *e)
|
108 |
{
|
104 |
{
|
|
|
105 |
LOGDEB(("Preview::closeEvent. m_loading %d\n", m_loading));
|
|
|
106 |
if (m_loading) {
|
|
|
107 |
CancelCheck::instance().setCancel();
|
|
|
108 |
e->ignore();
|
|
|
109 |
return;
|
|
|
110 |
}
|
109 |
prefs.pvwidth = width();
|
111 |
prefs.pvwidth = width();
|
110 |
prefs.pvheight = height();
|
112 |
prefs.pvheight = height();
|
111 |
emit previewExposed(m_searchId, -1);
|
113 |
emit previewExposed(m_searchId, -1);
|
112 |
emit previewClosed((QWidget *)this);
|
114 |
emit previewClosed((QWidget *)this);
|
113 |
QWidget::closeEvent(e);
|
115 |
QWidget::closeEvent(e);
|
|
... |
|
... |
215 |
// false, the search string has been modified, we search for the new string,
|
217 |
// false, the search string has been modified, we search for the new string,
|
216 |
// starting from the current position
|
218 |
// starting from the current position
|
217 |
void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
219 |
void Preview::doSearch(const QString &_text, bool next, bool reverse,
|
218 |
bool wordOnly)
|
220 |
bool wordOnly)
|
219 |
{
|
221 |
{
|
220 |
LOGDEB(("Preview::doSearch: [%s] next %d rev %d\n",
|
222 |
LOGDEB(("Preview::doSearch: text [%s] txtlen %d next %d rev %d word %d\n",
|
221 |
(const char *)_text.utf8(), int(next), int(reverse)));
|
223 |
(const char *)_text.utf8(), _text.length(), int(next),
|
|
|
224 |
int(reverse), int(wordOnly)));
|
222 |
QString text = _text;
|
225 |
QString text = _text;
|
223 |
if (text.isEmpty()) {
|
226 |
|
224 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
227 |
bool matchCase = matchCheck->isChecked();
|
225 |
text = QString::fromUtf8(firstTermBeacon);
|
|
|
226 |
#endif
|
|
|
227 |
}
|
|
|
228 |
QTextEdit *edit = getCurrentEditor();
|
228 |
QTextEdit *edit = getCurrentEditor();
|
229 |
if (edit == 0) {
|
229 |
if (edit == 0) {
|
230 |
// ??
|
230 |
// ??
|
231 |
return;
|
231 |
return;
|
232 |
}
|
232 |
}
|
233 |
|
233 |
|
234 |
bool matchCase = matchCheck->isChecked();
|
234 |
if (text.isEmpty()) {
|
|
|
235 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
|
|
236 |
text = QString::fromUtf8(firstTermBeacon);
|
|
|
237 |
matchCase = false;
|
|
|
238 |
#else
|
|
|
239 |
#error "Cycling without beacons needs coding"
|
|
|
240 |
#endif
|
|
|
241 |
}
|
235 |
|
242 |
|
236 |
LOGDEB(("Preview::doSearch: find: case %d word %d fw %d\n",
|
243 |
// If next is false, the user added characters to the current
|
237 |
matchCase, wordOnly, !reverse));
|
|
|
238 |
|
|
|
239 |
// If the search text changed we need to reset the cursor position
|
244 |
// search string. We need to reset the cursor position to the
|
240 |
// to the start of the previous match, else incremental search is
|
245 |
// start of the previous match, else incremental search is going
|
241 |
// going to look for the next occurrence instead of trying to
|
246 |
// to look for the next occurrence instead of trying to lenghten
|
242 |
// lenghten the current match
|
247 |
// the current match
|
243 |
if (!next) {
|
248 |
if (!next) {
|
244 |
int ps, is, pe, ie;
|
249 |
int ps, is, pe, ie;
|
245 |
edit->getSelection(&ps, &is, &pe, &ie);
|
250 |
edit->getSelection(&ps, &is, &pe, &ie);
|
246 |
if (is > 0)
|
251 |
if (is > 0)
|
247 |
is--;
|
252 |
is--;
|
248 |
else if (ps > 0)
|
253 |
else if (ps > 0)
|
249 |
ps--;
|
254 |
ps--;
|
250 |
LOGDEB(("Setting cursor to %d %d\n", ps, is));
|
255 |
LOGDEB(("Preview::doSearch: setting cursor to %d %d\n", ps, is));
|
251 |
edit->setCursorPosition(ps, is);
|
256 |
edit->setCursorPosition(ps, is);
|
252 |
}
|
257 |
}
|
253 |
|
258 |
|
|
|
259 |
LOGDEB(("Preview::doSearch: first find call\n"));
|
254 |
bool found = edit->find(text, matchCase, wordOnly, !reverse, 0, 0);
|
260 |
bool found = edit->find(text, matchCase, wordOnly, !reverse, 0, 0);
|
|
|
261 |
LOGDEB(("Preview::doSearch: first find call return\n"));
|
255 |
// If not found, try to wrap around.
|
262 |
// If not found, try to wrap around.
|
256 |
if (!found && next) {
|
263 |
if (!found && next) {
|
257 |
LOGDEB(("Preview::doSearch: wrapping around\n"));
|
264 |
LOGDEB(("Preview::doSearch: wrapping around\n"));
|
258 |
int mspara, msindex;
|
265 |
int mspara, msindex;
|
259 |
if (reverse) {
|
266 |
if (reverse) {
|
260 |
mspara = edit->paragraphs();
|
267 |
mspara = edit->paragraphs();
|
261 |
msindex = edit->paragraphLength(mspara);
|
268 |
msindex = edit->paragraphLength(mspara);
|
262 |
} else {
|
269 |
} else {
|
263 |
mspara = msindex = 0;
|
270 |
mspara = msindex = 0;
|
264 |
}
|
271 |
}
|
|
|
272 |
LOGDEB(("Preview::doSearch: 2nd find call\n"));
|
265 |
found = edit->find(text,matchCase, false, !reverse, &mspara, &msindex);
|
273 |
found = edit->find(text,matchCase, false, !reverse, &mspara, &msindex);
|
|
|
274 |
LOGDEB(("Preview::doSearch: 2nd find call return\n"));
|
266 |
}
|
275 |
}
|
267 |
|
276 |
|
268 |
if (found) {
|
277 |
if (found) {
|
269 |
canBeep = true;
|
278 |
canBeep = true;
|
270 |
} else {
|
279 |
} else {
|
271 |
if (canBeep)
|
280 |
if (canBeep)
|
272 |
QApplication::beep();
|
281 |
QApplication::beep();
|
273 |
canBeep = false;
|
282 |
canBeep = false;
|
274 |
}
|
283 |
}
|
|
|
284 |
LOGDEB(("Preview::doSearch: return\n"));
|
275 |
}
|
285 |
}
|
276 |
|
|
|
277 |
|
286 |
|
278 |
void Preview::nextPressed()
|
287 |
void Preview::nextPressed()
|
279 |
{
|
288 |
{
|
280 |
doSearch(searchTextLine->text(), true, false);
|
289 |
doSearch(searchTextLine->text(), true, false);
|
281 |
}
|
290 |
}
|
282 |
|
|
|
283 |
|
291 |
|
284 |
void Preview::prevPressed()
|
292 |
void Preview::prevPressed()
|
285 |
{
|
293 |
{
|
286 |
doSearch(searchTextLine->text(), true, true);
|
294 |
doSearch(searchTextLine->text(), true, true);
|
287 |
}
|
295 |
}
|
|
... |
|
... |
360 |
emit(wordSelect(edit->selectedText()));
|
368 |
emit(wordSelect(edit->selectedText()));
|
361 |
}
|
369 |
}
|
362 |
|
370 |
|
363 |
void Preview::closeCurrentTab()
|
371 |
void Preview::closeCurrentTab()
|
364 |
{
|
372 |
{
|
|
|
373 |
LOGDEB(("Preview::closeCurrentTab: m_loading %d\n", m_loading));
|
365 |
if (m_loading)
|
374 |
if (m_loading) {
|
|
|
375 |
CancelCheck::instance().setCancel();
|
366 |
return;
|
376 |
return;
|
|
|
377 |
}
|
367 |
if (pvTab->count() > 1) {
|
378 |
if (pvTab->count() > 1) {
|
368 |
QWidget *tw = pvTab->currentPage();
|
379 |
QWidget *tw = pvTab->currentPage();
|
369 |
if (!tw)
|
380 |
if (!tw)
|
370 |
return;
|
381 |
return;
|
371 |
pvTab->removePage(tw);
|
382 |
pvTab->removePage(tw);
|
|
... |
|
... |
593 |
#endif
|
604 |
#endif
|
594 |
class LoadGuard {
|
605 |
class LoadGuard {
|
595 |
bool *m_bp;
|
606 |
bool *m_bp;
|
596 |
public:
|
607 |
public:
|
597 |
LoadGuard(bool *bp) {m_bp = bp ; *m_bp = true;}
|
608 |
LoadGuard(bool *bp) {m_bp = bp ; *m_bp = true;}
|
598 |
~LoadGuard() {*m_bp = false;}
|
609 |
~LoadGuard() {*m_bp = false; CancelCheck::instance().setCancel(false);}
|
599 |
};
|
610 |
};
|
600 |
|
611 |
|
601 |
bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
612 |
bool Preview::loadFileInCurrentTab(string fn, size_t sz, const Rcl::Doc &idoc,
|
602 |
int docnum)
|
613 |
int docnum)
|
603 |
{
|
614 |
{
|
|
... |
|
... |
605 |
LOGERR(("ALready loading\n"));
|
616 |
LOGERR(("ALready loading\n"));
|
606 |
return false;
|
617 |
return false;
|
607 |
}
|
618 |
}
|
608 |
|
619 |
|
609 |
LoadGuard guard(&m_loading);
|
620 |
LoadGuard guard(&m_loading);
|
|
|
621 |
CancelCheck::instance().setCancel(false);
|
610 |
|
622 |
|
611 |
Rcl::Doc doc = idoc;
|
623 |
Rcl::Doc doc = idoc;
|
612 |
bool cancel = false;
|
|
|
613 |
|
624 |
|
614 |
if (doc.meta["title"].empty())
|
625 |
if (doc.meta["title"].empty())
|
615 |
doc.meta["title"] = path_getsimple(doc.url);
|
626 |
doc.meta["title"] = path_getsimple(doc.url);
|
616 |
|
627 |
|
617 |
setCurTabProps(fn, doc, docnum);
|
628 |
setCurTabProps(fn, doc, docnum);
|
|
... |
|
... |
648 |
#endif
|
659 |
#endif
|
649 |
progress.setProgress(prog , prog <= nsteps-1 ? nsteps : prog+1);
|
660 |
progress.setProgress(prog , prog <= nsteps-1 ? nsteps : prog+1);
|
650 |
qApp->processEvents();
|
661 |
qApp->processEvents();
|
651 |
if (progress.wasCanceled()) {
|
662 |
if (progress.wasCanceled()) {
|
652 |
CancelCheck::instance().setCancel();
|
663 |
CancelCheck::instance().setCancel();
|
653 |
cancel = true;
|
|
|
654 |
}
|
664 |
}
|
655 |
if (prog >= 5)
|
665 |
if (prog >= 5)
|
656 |
sleep(1);
|
666 |
sleep(1);
|
657 |
}
|
667 |
}
|
658 |
if (cancel)
|
668 |
|
|
|
669 |
LOGDEB(("LoadFileInCurrentTab: after file load: cancel %d status %d"
|
|
|
670 |
" text length %d\n",
|
|
|
671 |
CancelCheck::instance().cancelState(), status, fdoc.text.length()));
|
|
|
672 |
|
|
|
673 |
if (CancelCheck::instance().cancelState())
|
659 |
return false;
|
674 |
return false;
|
660 |
if (status != 0) {
|
675 |
if (status != 0) {
|
661 |
QString explain;
|
676 |
QString explain;
|
662 |
if (!lthr.missing.empty()) {
|
677 |
if (!lthr.missing.empty()) {
|
663 |
explain = QString::fromAscii("<br>") +
|
678 |
explain = QString::fromAscii("<br>") +
|
|
... |
|
... |
692 |
#endif
|
707 |
#endif
|
693 |
progress.setProgress(prog , prog <= nsteps-1 ? nsteps : prog+1);
|
708 |
progress.setProgress(prog , prog <= nsteps-1 ? nsteps : prog+1);
|
694 |
qApp->processEvents();
|
709 |
qApp->processEvents();
|
695 |
if (progress.wasCanceled()) {
|
710 |
if (progress.wasCanceled()) {
|
696 |
CancelCheck::instance().setCancel();
|
711 |
CancelCheck::instance().setCancel();
|
697 |
cancel = true;
|
|
|
698 |
}
|
712 |
}
|
699 |
if (prog >= 5)
|
713 |
if (prog >= 5)
|
700 |
sleep(1);
|
714 |
sleep(1);
|
701 |
}
|
715 |
}
|
702 |
if (cancel) {
|
716 |
|
|
|
717 |
// Conversion to rich text done
|
|
|
718 |
if (CancelCheck::instance().cancelState()) {
|
703 |
if (richTxt.length() == 0) {
|
719 |
if (richTxt.length() == 0) {
|
704 |
// We cant call closeCurrentTab here as it might delete
|
720 |
// We cant call closeCurrentTab here as it might delete
|
705 |
// the object which would be a nasty surprise to our
|
721 |
// the object which would be a nasty surprise to our
|
706 |
// caller.
|
722 |
// caller.
|
707 |
return false;
|
723 |
return false;
|
|
... |
|
... |
710 |
}
|
726 |
}
|
711 |
}
|
727 |
}
|
712 |
} else {
|
728 |
} else {
|
713 |
richTxt = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
|
729 |
richTxt = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
|
714 |
}
|
730 |
}
|
|
|
731 |
|
|
|
732 |
int pos = richTxt.find(QString::fromUtf8(firstTermBeacon));
|
|
|
733 |
bool hasAnchors = (pos != -1);
|
|
|
734 |
LOGDEB(("LoadFileInCurrentTab: rich: cancel %d txtln %d, hasAnchors %d (pos %d)\n",
|
|
|
735 |
CancelCheck::instance().cancelState(), richTxt.length(), hasAnchors, pos));
|
715 |
|
736 |
|
716 |
// Load into editor
|
737 |
// Load into editor
|
717 |
// Do it in several chunks
|
738 |
// Do it in several chunks
|
718 |
QTextEdit *editor = getCurrentEditor();
|
739 |
QTextEdit *editor = getCurrentEditor();
|
719 |
editor->setText("");
|
740 |
editor->setText("");
|
|
... |
|
... |
748 |
editor->setCursorPosition(0,0);
|
769 |
editor->setCursorPosition(0,0);
|
749 |
editor->ensureCursorVisible();
|
770 |
editor->ensureCursorVisible();
|
750 |
}
|
771 |
}
|
751 |
|
772 |
|
752 |
if (progress.wasCanceled()) {
|
773 |
if (progress.wasCanceled()) {
|
753 |
cancel = true;
|
|
|
754 |
editor->append("<b>Cancelled !</b>");
|
774 |
editor->append("<b>Cancelled !</b>");
|
755 |
LOGDEB(("Cancelled\n"));
|
775 |
LOGDEB(("LoadFileInCurrentTab: cancelled in editor load\n"));
|
756 |
break;
|
776 |
break;
|
757 |
}
|
777 |
}
|
758 |
}
|
778 |
}
|
|
|
779 |
progress.close();
|
759 |
|
780 |
|
760 |
if (searchTextLine->text().length() != 0) {
|
781 |
if (searchTextLine->text().length() != 0) {
|
761 |
canBeep = true;
|
782 |
canBeep = true;
|
762 |
doSearch(searchTextLine->text(), true, false);
|
783 |
doSearch(searchTextLine->text(), true, false);
|
763 |
} else {
|
784 |
} else {
|
|
|
785 |
if (hasAnchors) {
|
764 |
QString aname = QString::fromUtf8(termAnchorName(1).c_str());
|
786 |
QString aname = QString::fromUtf8(termAnchorName(1).c_str());
|
765 |
LOGDEB2(("Calling scrolltoanchor [%s]\n", (const char *)aname.utf8()));
|
787 |
LOGDEB2(("Call scrolltoanchor(%s)\n", (const char *)aname.utf8()));
|
766 |
editor->scrollToAnchor(aname);
|
788 |
editor->scrollToAnchor(aname);
|
|
|
789 |
// The q3textedit version of find is slow to the point of being
|
|
|
790 |
// unusable (plus it does not always work)
|
|
|
791 |
#if (QT_VERSION < 0x040000)
|
767 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
792 |
#ifdef QT_SCROLL_TO_ANCHOR_BUG
|
768 |
bool ocanbeep = canBeep;
|
793 |
bool ocanbeep = canBeep;
|
769 |
canBeep = false;
|
794 |
canBeep = false;
|
770 |
QString empty;
|
795 |
QString empty;
|
|
|
796 |
// doSearch(_text, next, reverse, wordOnly)
|
771 |
doSearch(empty, 0, false, false);
|
797 |
doSearch(empty, true, false, false);
|
772 |
canBeep = ocanbeep;
|
798 |
canBeep = ocanbeep;
|
773 |
#endif
|
799 |
#endif
|
|
|
800 |
#endif // (QT_VERSION < 0x040000)
|
|
|
801 |
}
|
774 |
}
|
802 |
}
|
775 |
// Enter document in document history
|
803 |
// Enter document in document history
|
776 |
g_dynconf->enterDoc(fn, doc.ipath);
|
804 |
g_dynconf->enterDoc(fn, doc.ipath);
|
777 |
|
805 |
|
778 |
editor->setFocus();
|
806 |
editor->setFocus();
|
779 |
emit(previewExposed(m_searchId, docnum));
|
807 |
emit(previewExposed(m_searchId, docnum));
|
|
|
808 |
LOGDEB(("LoadFileInCurrentTab: returning true\n"));
|
780 |
return true;
|
809 |
return true;
|
781 |
}
|
810 |
}
|