Switch to unified view

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.5 2006-11-09 19:04:28 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.6 2006-11-17 10:09:07 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
...
...
169
169
170
// Perform text search. If next is true, we look for the next match of the
170
// Perform text search. If next is true, we look for the next match of the
171
// current search, trying to advance and possibly wrapping around. If next is
171
// current search, trying to advance and possibly wrapping around. If next is
172
// false, the search string has been modified, we search for the new string, 
172
// false, the search string has been modified, we search for the new string, 
173
// starting from the current position
173
// starting from the current position
174
void Preview::doSearch(const QString &text, bool next, bool reverse)
174
void Preview::doSearch(const QString &text, bool next, bool reverse, 
175
             bool wo)
175
{
176
{
176
    LOGDEB1(("Preview::doSearch: next %d rev %d\n", int(next), int(reverse)));
177
    LOGDEB1(("Preview::doSearch: next %d rev %d\n", int(next), int(reverse)));
177
    QTextEdit *edit = getCurrentEditor();
178
    QTextEdit *edit = getCurrentEditor();
178
    if (edit == 0) {
179
    if (edit == 0) {
179
    // ??
180
    // ??
...
...
201
        msindex = meindex;
202
        msindex = meindex;
202
        LOGDEB1(("New para: %d index %d\n", mspara, msindex));
203
        LOGDEB1(("New para: %d index %d\n", mspara, msindex));
203
    }
204
    }
204
    }
205
    }
205
206
206
    bool found = edit->find(text, matchCase, false, 
207
    bool found = edit->find(text, matchCase, wo, 
207
                  !reverse, &mspara, &msindex);
208
                  !reverse, &mspara, &msindex);
208
    LOGDEB(("Found at para: %d index %d\n", mspara, msindex));
209
    LOGDEB(("Found at para: %d index %d\n", mspara, msindex));
209
210
210
    if (!found && next && true) { // need a 'canwrap' test here
211
    if (!found && next && true) { // need a 'canwrap' test here
211
    if (reverse) {
212
    if (reverse) {
...
...
446
};
447
};
447
448
448
/* A thread to convert to rich text (mark search terms) */
449
/* A thread to convert to rich text (mark search terms) */
449
class ToRichThread : public QThread {
450
class ToRichThread : public QThread {
450
    string ∈
451
    string ∈
451
    list<string> &terms;
452
    RefCntr<Rcl::SearchData> m_searchData;
452
    string& firstTerm;
453
    string& firstTerm;
453
    QString &out;
454
    QString &out;
454
    int loglevel;
455
    int loglevel;
455
 public:
456
 public:
456
    ToRichThread(string &i, list<string> &trms, 
457
    ToRichThread(string &i, RefCntr<Rcl::SearchData> searchData,
457
         string& ft, QString &o) 
458
         string& ft, QString &o) 
458
    : in(i), terms(trms), firstTerm(ft), out(o)
459
    : in(i), m_searchData(searchData), firstTerm(ft), out(o)
459
    {
460
    {
460
        loglevel = DebugLog::getdbl()->getlevel();
461
        loglevel = DebugLog::getdbl()->getlevel();
461
    }
462
    }
462
    virtual void run()
463
    virtual void run()
463
    {
464
    {
464
    DebugLog::getdbl()->setloglevel(loglevel);
465
    DebugLog::getdbl()->setloglevel(loglevel);
465
    string rich;
466
    string rich;
466
    try {
467
    try {
467
        plaintorich(in, rich, terms, &firstTerm);
468
        plaintorich(in, rich, m_searchData, &firstTerm);
468
    } catch (CancelExcept) {
469
    } catch (CancelExcept) {
469
    }
470
    }
470
    out = QString::fromUtf8(rich.c_str(), rich.length());
471
    out = QString::fromUtf8(rich.c_str(), rich.length());
471
    }
472
    }
472
};
473
};
...
...
544
545
545
    // Create preview text: highlight search terms (if not too big):
546
    // Create preview text: highlight search terms (if not too big):
546
    QString richTxt;
547
    QString richTxt;
547
    bool highlightTerms = fdoc.text.length() < 1000 *1024;
548
    bool highlightTerms = fdoc.text.length() < 1000 *1024;
548
    string firstTerm;
549
    string firstTerm;
549
    list<string> terms;
550
    rcldb->getMatchTerms(idoc, terms);
551
    if (highlightTerms) {
550
    if (highlightTerms) {
552
    progress.setLabelText(tr("Creating preview text"));
551
    progress.setLabelText(tr("Creating preview text"));
553
    ToRichThread rthr(fdoc.text, terms, firstTerm, richTxt);
552
    ToRichThread rthr(fdoc.text, m_searchData, firstTerm, richTxt);
554
    rthr.start();
553
    rthr.start();
555
554
556
    for (;;prog++) {
555
    for (;;prog++) {
557
        waiter.start(); waiter.wait();
556
        waiter.start(); waiter.wait();
558
        if (rthr.finished())
557
        if (rthr.finished())
...
...
628
    doSearch(searchTextLine->text(), true, false);
627
    doSearch(searchTextLine->text(), true, false);
629
    } else {
628
    } else {
630
    if (!firstTerm.empty()) {
629
    if (!firstTerm.empty()) {
631
        bool wasC = matchCheck->isChecked();
630
        bool wasC = matchCheck->isChecked();
632
        matchCheck->setChecked(false);
631
        matchCheck->setChecked(false);
633
        doSearch(QString::fromUtf8(terms.begin()->c_str()), true, false);
632
        doSearch(QString::fromUtf8(firstTerm.c_str()), true, false, true);
634
        matchCheck->setChecked(wasC);
633
        matchCheck->setChecked(wasC);
635
    }
634
    }
636
    }
635
    }
637
    emit(previewExposed(m_searchId, docnum));
636
    emit(previewExposed(m_searchId, docnum));
638
    return true;
637
    return true;
639
}
638
}
640