From 75628a18bc06d2d8f6017d91446e380fef05c2dc Mon Sep 17 00:00:00 2001 From: dockes Date: Mon, 10 Oct 2005 12:29:43 +0000 Subject: [PATCH] ckpt --- src/qtgui/advsearch.ui | 173 +++++++++++--------- src/qtgui/main.cpp | 3 + src/qtgui/preview/preview.ui | 53 ++++-- src/qtgui/preview/preview.ui.h | 77 ++++++--- src/qtgui/preview/pvmain.cpp | 18 +- src/qtgui/recollmain.ui | 289 +++++++++++++++------------------ src/qtgui/recollmain.ui.h | 189 +++++++-------------- 7 files changed, 396 insertions(+), 406 deletions(-) diff --git a/src/qtgui/advsearch.ui b/src/qtgui/advsearch.ui index 009f5370..f748aac6 100644 --- a/src/qtgui/advsearch.ui +++ b/src/qtgui/advsearch.ui @@ -13,8 +13,65 @@ - Form1 + Advanced search + + true + + + + textLabel1_3 + + + + 120 + 20 + 110 + 20 + + + + Complex search + + + + + searchPB + + + + 380 + 20 + 90 + 30 + + + + Search + + + + + line1 + + + + 22 + 58 + 550 + 16 + + + + HLine + + + Sunken + + + Horizontal + + layout6 @@ -147,28 +204,6 @@ Search For - - - line1 - - - - 22 - 58 - 550 - 16 - - - - HLine - - - Sunken - - - Horizontal - - line2 @@ -224,6 +259,9 @@ noFiltypsLB + + false + @@ -260,72 +298,51 @@ yesFiltypsLB + + false + - + - textLabel1_3 - - - - 120 - 20 - 110 - 20 - - - - Complex search - - - - - delFiltypPB + layout11 270 300 - 86 - 30 + 82 + 68 - - --------> - - - - - addFiltypPB - - - - 270 - 360 - 86 - 30 - - - - <--------- - - - - - searchPB - - - - 380 - 20 - 90 - 30 - - - - Search - + + + unnamed + + + + delFiltypPB + + + false + + + --------> + + + + + addFiltypPB + + + false + + + <--------- + + + diff --git a/src/qtgui/main.cpp b/src/qtgui/main.cpp index 0c609c0d..14384a14 100644 --- a/src/qtgui/main.cpp +++ b/src/qtgui/main.cpp @@ -1,3 +1,6 @@ +#ifndef lint +static char rcsid[] = "@(#$Id: main.cpp,v 1.9 2005-10-10 12:29:42 dockes Exp $ (C) 2005 J.F.Dockes"; +#endif #include diff --git a/src/qtgui/preview/preview.ui b/src/qtgui/preview/preview.ui index c8078ab6..c5d0f079 100644 --- a/src/qtgui/preview/preview.ui +++ b/src/qtgui/preview/preview.ui @@ -1,21 +1,21 @@ Preview - + Preview - 159 - 362 - 469 - 174 + 0 + 0 + 751 + 727 - 0 - 0 + 5 + 5 0 0 @@ -35,26 +35,44 @@ - layout5 + layout9 unnamed - + - pvEdit - - - true - - - false + pvTab + + + unnamed + + + Preview 1 + + + + unnamed + + + + pvEdit + + + true + + + false + + + + - layout4 + layout7 @@ -156,6 +174,7 @@ doSearch( bool next, bool reverse ) nextPressed() prevPressed() + currentChanged( QWidget * tw ) init() diff --git a/src/qtgui/preview/preview.ui.h b/src/qtgui/preview/preview.ui.h index 13109415..142b11b3 100644 --- a/src/qtgui/preview/preview.ui.h +++ b/src/qtgui/preview/preview.ui.h @@ -12,20 +12,19 @@ void Preview::init() { - pvEdit->installEventFilter(this); + connect(pvTab, SIGNAL(currentChanged(QWidget *)), + this, SLOT(currentChanged(QWidget *))); searchTextLine->installEventFilter(this); dynSearchActive = false; canBeep = true; - matchPara = 0; - matchIndex = 0; } bool Preview::eventFilter(QObject *target, QEvent *event) { - if (event->type() != QEvent::KeyPress) return QWidget::eventFilter(target, event); + fprintf(stderr, "Preview::eventFilter: keyEvent\n"); QKeyEvent *keyEvent = (QKeyEvent *)event; if (dynSearchActive) { if (keyEvent->key() == Key_F3) { @@ -35,7 +34,12 @@ bool Preview::eventFilter(QObject *target, QEvent *event) if (target != searchTextLine) return QApplication::sendEvent(searchTextLine, event); } else { - if (keyEvent->key() == Key_Slash && target == pvEdit) { + QWidget *tw = pvTab->currentPage(); + QWidget *e = 0; + if (tw) + e = (QTextEdit *)tw->child("pvEdit"); + fprintf(stderr, "Widget: %p, edit %p, target %p\n", tw, e, target); + if (e && target == tw && keyEvent->key() == Key_Slash) { dynSearchActive = true; return true; } @@ -46,7 +50,7 @@ bool Preview::eventFilter(QObject *target, QEvent *event) void Preview::searchTextLine_textChanged(const QString & text) { - //fprintf(stderr, "search line text changed. text: '%s'\n", text.ascii()); + fprintf(stderr, "search line text changed. text: '%s'\n", text.ascii()); if (text.isEmpty()) { dynSearchActive = false; } else { @@ -62,41 +66,53 @@ void Preview::searchTextLine_textChanged(const QString & text) // starting from the current position void Preview::doSearch(bool next, bool reverse) { - //fprintf(stderr, "Preview::doSearch: next %d rev %d para %d index %d\n", - // int(next), int(reverse), matchPara, matchIndex); - + //fprintf(stderr, "Preview::doSearch: next %d rev %d\n", + // int(next), int(reverse)); + QWidget *tw = pvTab->currentPage(); + QTextEdit *edit = 0; + if (tw) { + if ((edit = (QTextEdit*)tw->child("pvEdit")) == 0) { + // ?? + return; + } + } bool matchCase = matchCheck->isChecked(); + int mspara, msindex, mepara, meindex; + edit->getSelection(&mspara, &msindex, &mepara, &meindex); + if (mspara == -1) + mspara = msindex = mepara = meindex = 0; if (next) { // We search again, starting from the current match if (reverse) { // when searching backwards, have to move back one char - if (matchIndex > 0) - matchIndex --; - else if (matchPara > 0) { - matchPara --; - matchIndex = pvEdit->paragraphLength(matchPara); + if (msindex > 0) + msindex --; + else if (mspara > 0) { + mspara --; + msindex = edit->paragraphLength(mspara); } } else { // Forward search: start from end of selection int bogus; - pvEdit->getSelection(&bogus, &bogus, &matchPara, &matchIndex); - //fprintf(stderr, "New para: %d index %d\n",matchPara, matchIndex); + mspara = mepara; + msindex = meindex; + //fprintf(stderr, "New para: %d index %d\n", mspara, msindex); } } - bool found = pvEdit->find(searchTextLine->text(), matchCase, false, - !reverse, &matchPara, &matchIndex); + bool found = edit->find(searchTextLine->text(), matchCase, false, + !reverse, &mspara, &msindex); if (!found && next && true) { // need a 'canwrap' test here if (reverse) { - matchPara = pvEdit->paragraphs(); - matchIndex = pvEdit->paragraphLength(matchPara); + mspara = edit->paragraphs(); + msindex = edit->paragraphLength(mspara); } else { - matchPara = matchIndex = 0; + mspara = msindex = 0; } - found = pvEdit->find(searchTextLine->text(), matchCase, false, - !reverse, &matchPara, &matchIndex); + found = edit->find(searchTextLine->text(), matchCase, false, + !reverse, &mspara, &msindex); } if (found) { @@ -119,3 +135,18 @@ void Preview::prevPressed() { doSearch(true, true); } + + +void Preview::currentChanged(QWidget * tw) +{ + QObject *o; + o = tw->child("pvEdit"); + fprintf(stderr, "Preview::currentChanged(). Edit %p\n", o); + + if (o == 0) { + fprintf(stderr, "Editor child not found\n"); + } else { + tw->installEventFilter(this); + o->installEventFilter(this); + } +} diff --git a/src/qtgui/preview/pvmain.cpp b/src/qtgui/preview/pvmain.cpp index 0aefb98f..9cf7f5b5 100644 --- a/src/qtgui/preview/pvmain.cpp +++ b/src/qtgui/preview/pvmain.cpp @@ -1,5 +1,5 @@ #ifndef lint -static char rcsid[] = "@(#$Id: pvmain.cpp,v 1.1 2005-09-27 06:20:16 dockes Exp $ (C) 2005 J.F.Dockes"; +static char rcsid[] = "@(#$Id: pvmain.cpp,v 1.2 2005-10-10 12:29:43 dockes Exp $ (C) 2005 J.F.Dockes"; #endif #include @@ -14,6 +14,8 @@ using std::pair; #include #include #include +#include +#include #include "preview.h" #include "../plaintorich.h" @@ -25,7 +27,6 @@ int main( int argc, char ** argv ) { QApplication a(argc, argv); Preview w; - w.show(); string text; if (!file_to_string(filename, text)) { @@ -38,5 +39,18 @@ int main( int argc, char ** argv ) QString str = QString::fromUtf8(rich.c_str(), rich.length()); w.pvEdit->setText(str); + // QVBoxLayout *unnamedLayout = + // new QVBoxLayout(0, 11, 6, "unnamedLayout"); + QWidget *anon = new QWidget(w.pvTab); + QVBoxLayout *anonLayout = new QVBoxLayout(anon, 11, 6, "unnamedLayout"); + QTextEdit *newEd = new QTextEdit(anon, "pvEdit"); + anonLayout->addWidget(newEd); + fprintf(stderr, "pvEdit %p newEd: %p\n", w.pvEdit, newEd); + newEd->setReadOnly( TRUE ); + newEd->setUndoRedoEnabled( FALSE ); + newEd->setText(str); + + w.pvTab->addTab(anon, "Tab 2"); + w.show(); return a.exec(); } diff --git a/src/qtgui/recollmain.ui b/src/qtgui/recollmain.ui index b8f644b4..f4a80ed0 100644 --- a/src/qtgui/recollmain.ui +++ b/src/qtgui/recollmain.ui @@ -8,18 +8,24 @@ 0 0 - 782 - 622 + 160 + 750 - 7 - 7 + 5 + 5 0 0 + + + 0 + 0 + + recoll @@ -29,131 +35,117 @@ - layout3 + layout8 - + unnamed - + - queryText - - - LineEditPanel - - - Sunken + layout9 + + + unnamed + + + + queryText + + + + 7 + 0 + 8 + 0 + + + + + 155 + 0 + + + + LineEditPanel + + + Sunken + + + + + Search + + + Search + + + + + clearqPB + + + Clear + + + Ctrl+S + + + + + listPrevPb + + + Previous page + + + + + listNextPB + + + Next page + + + + + advSearchPB + + + Adv. search + + + + + spacer1 + + + Horizontal + + + Expanding + + + + 346 + 20 + + + + - - - Search - - - Search - - - - - clearqPB - - - Clear - - - Ctrl+S - - - - - listPrevPb - - - Previous page - - - - - listNextPB - - - Next page - - - - - spacer1 - - - Horizontal - - - Expanding - - - - 346 - 20 - - - - - - - - splitter6 - - - Horizontal - - - - reslistTE - - - - 5 - 5 - 2 - 0 - - - - RichText - - - true - - - false - - - - - splitter5 - - - - 5 - 5 - 5 - 0 - - - - Vertical - - previewTextEdit + reslistTE - 7 - 7 - 0 - 4 + 5 + 5 + 2 + 0 @@ -166,26 +158,7 @@ false - - - metaTextEdit - - - - 7 - 7 - 0 - 1 - - - - RichText - - - true - - - + @@ -253,10 +226,16 @@ fileExit() - queryText - returnPressed() + fileStart_IndexingAction + activated() RecollMain - queryText_returnPressed() + fileStart_IndexingAction_activated() + + + helpQuick_startAction + activated() + RecollMain + helpQuick_startAction_activated() Search @@ -264,6 +243,12 @@ RecollMain Search_clicked() + + queryText + returnPressed() + RecollMain + queryText_returnPressed() + listPrevPb clicked() @@ -288,33 +273,23 @@ RecollMain reslistTE_clicked(int,int) - - fileStart_IndexingAction - activated() - RecollMain - fileStart_IndexingAction_activated() - clearqPB clicked() RecollMain clearqPB_clicked() - - helpQuick_startAction - activated() - RecollMain - helpQuick_startAction_activated() - + preview/.ui/preview.h recollmain.ui.h - std::string stemlang; - bool dostem; - int reslist_current; int reslist_winfirst; + int reslist_current; + bool dostem; + std::string stemlang; + Preview *curPreview; fileExit() @@ -328,7 +303,11 @@ listPrevPB_clicked() listNextPB_clicked() helpQuick_startAction_activated() + advSearchPB_clicked() + + init() + diff --git a/src/qtgui/recollmain.ui.h b/src/qtgui/recollmain.ui.h index 44d2db14..c227664a 100644 --- a/src/qtgui/recollmain.ui.h +++ b/src/qtgui/recollmain.ui.h @@ -20,7 +20,7 @@ using std::pair; #include #include - +#include #include "rcldb.h" #include "rclconfig.h" @@ -29,16 +29,24 @@ using std::pair; #include "pathut.h" #include "recoll.h" #include "internfile.h" -#include "textsplit.h" #include "smallut.h" -#include "utf8iter.h" -#include "transcode.h" +#include "plaintorich.h" + #include "unacpp.h" + #ifndef MIN #define MIN(A,B) ((A) < (B) ? (A) : (B)) #endif +static const int respagesize = 8; + + +void RecollMain::init() +{ + curPreview = 0; +} + void RecollMain::fileExit() { LOGDEB1(("RecollMain: fileExit\n")); @@ -65,112 +73,6 @@ void RecollMain::fileStart_IndexingAction_activated() startindexing = 1; } -// Text splitter callback used to take note of the position of query terms -// inside the result text. This is then used to post highlight tags. -class myTextSplitCB : public TextSplitCB { - public: - const list *terms; // in: query terms - list > tboffs; // out: begin and end positions of - // query terms in text - - myTextSplitCB(const list& terms) - : terms(&terms) { - } - - // Callback called by the text-to-words breaker for each word - virtual bool takeword(const std::string& term, int pos, int bts, int bte) { - string dumb; - Rcl::dumb_string(term, dumb); - //LOGDEB(("Input dumbbed term: '%s' %d %d %d\n", dumb.c_str(), - // pos, bts, bte)); - for (list::const_iterator it = terms->begin(); - it != terms->end(); it++) { - if (!stringlowercmp(*it, dumb)) { - tboffs.push_back(pair(bts, bte)); - break; - } - } - - return true; - } -}; - -// Fix result text for display inside the gui text window -static string plaintorich(const string &in, const list& terms, - list >&termoffsets) -{ - LOGDEB(("plaintorich: terms: %s\n", - stringlistdisp(terms).c_str())); - - termoffsets.erase(termoffsets.begin(), termoffsets.end()); - - myTextSplitCB cb(terms); - TextSplit splitter(&cb, true); - splitter.text_to_words(in); - - for (list >::iterator li = cb.tboffs.begin(); - li != cb.tboffs.end(); li++) { - } - - // State variable used to limitate the number of consecutive empty lines - int ateol = 0; - - // Rich text output - string out = "

"; - - // Iterator for the list of input term positions. We use it to - // output highlight tags and to compute term positions in the - // output text - list >::iterator it = cb.tboffs.begin(); - - // Storage for the current term position in output. - pair opos; - int outbytepos; // This is the current position in output, excluding tags - for (unsigned int ibyteidx = 0; ibyteidx < in.length(); ibyteidx++) { - if (it != cb.tboffs.end()) { - if (ibyteidx == (unsigned int)it->first) { - out += ""; - opos.first = outbytepos; - } else if (ibyteidx == (unsigned int)it->second) { - if (it != cb.tboffs.end()) - it++; - opos.second = outbytepos; - termoffsets.push_back(opos); - out += ""; - } - } - switch(in[ibyteidx]) { - case '\n': - if (ateol < 2) - out += "
\n"; - ateol++; - outbytepos++; - break; - case '\r': break; - case '<': - ateol = 0; - out += "<"; - outbytepos++; - break; - default: - ateol = 0; - out += in[ibyteidx]; - outbytepos++; - } - } - - { - FILE *fp = fopen("/tmp/termsdeb", "w"); - string unaced, ascii; - fprintf(fp, "plaintorich: text:\n%s\n", out.c_str()); - unac_cpp(out, unaced); - fprintf(fp, "plaintorich: text:\n%s\n", unaced.c_str()); - transcode(unaced, ascii, "UTF-8", "ASCII"); - fprintf(fp, "plaintorich: text:\n%s\n", ascii.c_str()); - fclose(fp); - } - return out; -} static string urltolocalpath(string url) { @@ -180,7 +82,8 @@ static string urltolocalpath(string url) // Use external viewer to display file void RecollMain::reslistTE_doubleClicked(int par, int) { - // restlistTE_clicked(par, car); + LOGDEB(("RecollMain::reslistTE_doubleClicked: par %d\n", par)); + Rcl::Doc doc; int reldocnum = par - 1; if (!rcldb->getDoc(reslist_winfirst + reldocnum, doc, 0)) @@ -239,8 +142,10 @@ void RecollMain::reslistTE_clicked(int par, int car) reslistTE->setParagraphBackgroundColor(par, color); int reldocnum = par - 1; + if (reslist_current == reldocnum) + return; + reslist_current = reldocnum; - previewTextEdit->clear(); if (!rcldb->getDoc(reslist_winfirst + reldocnum, doc, 0)) { QMessageBox::warning(0, "Recoll", @@ -264,33 +169,52 @@ void RecollMain::reslistTE_clicked(int par, int car) list > termoffsets; string rich = plaintorich(fdoc.text, terms, termoffsets); + QTextEdit *editor; + if (curPreview == 0) { + curPreview = new Preview(0, "Preview"); + curPreview->setCaption(queryText->text()); + if (curPreview == 0) { + QMessageBox::warning(0, "Warning", + "Can't create preview window", + QMessageBox::Ok, + QMessageBox::NoButton); + return; + } + curPreview->show(); + editor = curPreview->pvEdit; + } else { + QWidget *anon = new QWidget((QWidget *)curPreview->pvTab); + QVBoxLayout *anonLayout = new QVBoxLayout(anon, 1, 1, "anonLayout"); + editor = new QTextEdit(anon, "pvEdit"); + editor->setReadOnly( TRUE ); + editor->setUndoRedoEnabled( FALSE ); + anonLayout->addWidget(editor); + curPreview->pvTab->addTab(anon, "Tab"); + curPreview->pvTab->showPage(anon); + } + curPreview->pvTab->changeTab(curPreview->pvTab->currentPage(), + QString::fromUtf8(doc.title.c_str(), + doc.title.length())); + QStyleSheetItem *item = - new QStyleSheetItem( previewTextEdit->styleSheet(), "termtag" ); + new QStyleSheetItem(editor->styleSheet(), + "termtag" ); item->setColor("blue"); item->setFontWeight(QFont::Bold); QString str = QString::fromUtf8(rich.c_str(), rich.length()); - previewTextEdit->setText(str); + editor->setText(str); int para = 0, index = 1; if (!termoffsets.empty()) { index = (termoffsets.begin())->first; - LOGDEB(("Preview: Byte index for first term: %d\n", index)); - // Translate byte to character offset - string::size_type pos = 0; - Utf8Iter it(rich); - for (; pos != string::npos && (int)pos < index; it++) { - pos = it.getBpos(); - } - index = pos == string::npos ? 0 : it.getCpos(); LOGDEB(("Set cursor position: para %d, character index %d\n", para,index)); - previewTextEdit->setCursorPosition(0, index); + editor->setCursorPosition(0, index); } - previewTextEdit->ensureCursorVisible(); - previewTextEdit->getCursorPosition(¶, &index); + editor->ensureCursorVisible(); + editor->getCursorPosition(¶, &index); LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n", - previewTextEdit->length(), previewTextEdit->paragraphs(), - para, index)); + editor->length(), editor->paragraphs(), para, index)); } @@ -333,7 +257,7 @@ void RecollMain::queryText_returnPressed() if (!rcldb->setQuery(string((const char *)u8), dostem ? Rcl::Db::QO_STEM : Rcl::Db::QO_NONE, stemlang)) return; - list terms; + curPreview = 0; listNextPB_clicked(); } @@ -348,7 +272,6 @@ void RecollMain::clearqPB_clicked() queryText->clear(); } -static const int respagesize = 10; void RecollMain::listPrevPB_clicked() { if (reslist_winfirst <= 0) @@ -361,12 +284,14 @@ void RecollMain::listPrevPB_clicked() // Fill up result list window with next screen of hits void RecollMain::listNextPB_clicked() { + fprintf(stderr, "listNextPB_clicked\n"); if (!rcldb) return; int percent; Rcl::Doc doc; rcldb->getDoc(0, doc, &percent); int resCnt = rcldb->getResCnt(); + fprintf(stderr, "listNextPB_clicked rescnt\n"); LOGDEB(("listNextPB_clicked: rescnt %d, winfirst %d\n", resCnt, reslist_winfirst)); @@ -381,7 +306,7 @@ void RecollMain::listNextPB_clicked() bool gotone = false; reslistTE->clear(); - previewTextEdit->clear(); + int last = MIN(resCnt-reslist_winfirst, respagesize); // Insert results if any in result list window @@ -438,7 +363,7 @@ void RecollMain::listNextPB_clicked() reslistTE->setCursorPosition(0,0); reslistTE->ensureCursorVisible(); // Display preview for 1st doc in list - reslistTE_clicked(1, 0); + // reslistTE_clicked(1, 0); } else { // Restore first in win parameter that we shouln't have incremented reslist_winfirst -= respagesize; @@ -473,3 +398,5 @@ void RecollMain::advSearchPB_clicked() asearchform->show(); } } + +