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.26 2007-07-20 14:43:21 dockes Exp $ (C) 2005 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: preview_w.cpp,v 1.27 2007-09-08 17:25:49 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
...
...
703
    // Reset config just in case.
703
    // Reset config just in case.
704
    rclconfig->setKeyDir("");
704
    rclconfig->setKeyDir("");
705
705
706
    // Create preview text: highlight search terms (if not too big):
706
    // Create preview text: highlight search terms (if not too big):
707
    QString richTxt;
707
    QString richTxt;
708
    bool highlightTerms = fdoc.text.length() < 2000 * 1024;
708
709
    // We don't do the highlighting for very big texts: too long. We
710
    // should at least do special char escaping, in case a '&' or '<'
711
    // somehow slipped through previous processing.
712
    bool highlightTerms = fdoc.text.length() < (unsigned long)prefs.maxhltextmbs * 1024 * 1024;
713
    int beaconPos = -1;
709
    if (highlightTerms) {
714
    if (highlightTerms) {
710
    progress.setLabelText(tr("Creating preview text"));
715
    progress.setLabelText(tr("Creating preview text"));
716
  qApp->processEvents();
711
    ToRichThread rthr(fdoc.text, m_hData, richTxt);
717
    ToRichThread rthr(fdoc.text, m_hData, richTxt);
712
    rthr.start();
718
    rthr.start();
713
719
714
    for (;;prog++) {
720
    for (;;prog++) {
715
        waiter.start(); waiter.wait();
721
        waiter.start(); waiter.wait();
...
...
738
        return false;
744
        return false;
739
        } else {
745
        } else {
740
        richTxt += "<b>Cancelled !</b>";
746
        richTxt += "<b>Cancelled !</b>";
741
        }
747
        }
742
    }
748
    }
749
  beaconPos = richTxt.find(QString::fromUtf8(firstTermBeacon));
743
    } else {
750
    } else {
751
  // Note that in the case were we don't call plaintorich, the
752
  // text will no be identified as richtxt/html (no <html> or
753
  // <qt> etc. at the beginning), and there is no need to escape
754
  // special characters
744
    richTxt = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
755
    richTxt = QString::fromUtf8(fdoc.text.c_str(), fdoc.text.length());
745
    }
756
    }
746
757
747
    int pos = richTxt.find(QString::fromUtf8(firstTermBeacon));
748
    m_haveAnchors = (pos != -1);
758
    m_haveAnchors = (beaconPos != -1);
749
    LOGDEB(("LoadFileInCurrentTab: rich: cancel %d txtln %d, hasAnchors %d "
759
    LOGDEB(("LoadFileInCurrentTab: rich: cancel %d txtln %d, hasAnchors %d "
750
        "(pos %d)\n", 
760
        "(beaconPos %d)\n", 
751
        CancelCheck::instance().cancelState(), richTxt.length(), 
761
        CancelCheck::instance().cancelState(), richTxt.length(), 
752
        m_haveAnchors, pos));
762
        m_haveAnchors, beaconPos));
753
763
754
    // Load into editor
764
    // Load into editor
755
    // Do it in several chunks 
765
    // Do it in several chunks 
756
    QTextEdit *editor = getCurrentEditor();
766
    QTextEdit *editor = getCurrentEditor();
757
    editor->setText("");
767
    editor->setText("");
...
...
794
    }
804
    }
795
    }
805
    }
796
    progress.close();
806
    progress.close();
797
807
798
    if (searchTextLine->text().length() != 0) {
808
    if (searchTextLine->text().length() != 0) {
809
  // If there is a current search string, perform the search
799
    m_canBeep = true;
810
    m_canBeep = true;
800
    doSearch(searchTextLine->text(), true, false);
811
    doSearch(searchTextLine->text(), true, false);
801
    } else {
812
    } else {
813
  // Position to the first query term
802
    if (m_haveAnchors) {
814
    if (m_haveAnchors) {
803
        QString aname = QString::fromUtf8(termAnchorName(1).c_str());
815
        QString aname = QString::fromUtf8(termAnchorName(1).c_str());
804
        LOGDEB2(("Call scrolltoanchor(%s)\n", (const char *)aname.utf8()));
816
        LOGDEB2(("Call scrolltoanchor(%s)\n", (const char *)aname.utf8()));
805
        editor->scrollToAnchor(aname);
817
        editor->scrollToAnchor(aname);
806
      // The q3textedit version of find is slow to the point of being
818
807
      // unusable (plus it does not always work)
808
#if (QT_VERSION < 0x040000)
819
#if (QT_VERSION < 0x040000)
820
      // The q3textedit version of te::find() is slow to the point of
821
      // being unusable (plus it does not always work). So we
822
      // don't position to the first term automatically, the
823
      // user can still use the search function in the preview
824
      // window to do it
809
#ifdef QT_SCROLL_TO_ANCHOR_BUG
825
#ifdef QT_SCROLL_TO_ANCHOR_BUG
810
        bool ocanbeep = m_canBeep;
826
        bool ocanbeep = m_canBeep;
811
        m_canBeep = false;
827
        m_canBeep = false;
812
        QString empty;
828
        QString empty;
829
      // Calling doSearch() with an empty string will look for
830
      // the first occurrence of a search term`
813
        // doSearch(_text, next, reverse, wordOnly)
831
        // doSearch(_text, next, reverse, wordOnly)
814
        doSearch(empty, true, false, false);
832
        doSearch(empty, true, false, false);
815
        m_canBeep = ocanbeep;
833
        m_canBeep = ocanbeep;
816
#endif
834
#endif
817
#endif // (QT_VERSION < 0x040000)
835
#endif // (QT_VERSION < 0x040000)
818
    }
836
    }
819
    }
837
    }
838
820
    // Enter document in document history
839
    // Enter document in document history
821
    g_dynconf->enterDoc(fn, doc.ipath);
840
    g_dynconf->enterDoc(fn, doc.ipath);
822
841
823
    editor->setFocus();
842
    editor->setFocus();
824
    emit(previewExposed(this, m_searchId, docnum));
843
    emit(previewExposed(this, m_searchId, docnum));