This commit is contained in:
dockes 2005-10-10 12:29:43 +00:00
parent 39338b4b4b
commit 75628a18bc
7 changed files with 396 additions and 406 deletions

View File

@ -13,8 +13,65 @@
</rect> </rect>
</property> </property>
<property name="caption"> <property name="caption">
<string>Form1</string> <string>Advanced search</string>
</property> </property>
<property name="sizeGripEnabled">
<bool>true</bool>
</property>
<widget class="QLabel">
<property name="name">
<cstring>textLabel1_3</cstring>
</property>
<property name="geometry">
<rect>
<x>120</x>
<y>20</y>
<width>110</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Complex search</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>searchPB</cstring>
</property>
<property name="geometry">
<rect>
<x>380</x>
<y>20</y>
<width>90</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Search</string>
</property>
</widget>
<widget class="Line">
<property name="name">
<cstring>line1</cstring>
</property>
<property name="geometry">
<rect>
<x>22</x>
<y>58</y>
<width>550</width>
<height>16</height>
</rect>
</property>
<property name="frameShape">
<enum>HLine</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
</widget>
<widget class="QLayoutWidget"> <widget class="QLayoutWidget">
<property name="name"> <property name="name">
<cstring>layout6</cstring> <cstring>layout6</cstring>
@ -147,28 +204,6 @@
<string>Search For</string> <string>Search For</string>
</property> </property>
</widget> </widget>
<widget class="Line">
<property name="name">
<cstring>line1</cstring>
</property>
<property name="geometry">
<rect>
<x>22</x>
<y>58</y>
<width>550</width>
<height>16</height>
</rect>
</property>
<property name="frameShape">
<enum>HLine</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
</widget>
<widget class="Line"> <widget class="Line">
<property name="name"> <property name="name">
<cstring>line2</cstring> <cstring>line2</cstring>
@ -224,6 +259,9 @@
<property name="name"> <property name="name">
<cstring>noFiltypsLB</cstring> <cstring>noFiltypsLB</cstring>
</property> </property>
<property name="enabled">
<bool>false</bool>
</property>
</widget> </widget>
</vbox> </vbox>
</widget> </widget>
@ -260,72 +298,51 @@
<property name="name"> <property name="name">
<cstring>yesFiltypsLB</cstring> <cstring>yesFiltypsLB</cstring>
</property> </property>
<property name="enabled">
<bool>false</bool>
</property>
</widget> </widget>
</vbox> </vbox>
</widget> </widget>
<widget class="QLabel"> <widget class="QLayoutWidget">
<property name="name"> <property name="name">
<cstring>textLabel1_3</cstring> <cstring>layout11</cstring>
</property>
<property name="geometry">
<rect>
<x>120</x>
<y>20</y>
<width>110</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>Complex search</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>delFiltypPB</cstring>
</property> </property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>270</x> <x>270</x>
<y>300</y> <y>300</y>
<width>86</width> <width>82</width>
<height>30</height> <height>68</height>
</rect> </rect>
</property> </property>
<property name="text"> <vbox>
<string>--------&gt;</string> <property name="name">
</property> <cstring>unnamed</cstring>
</widget> </property>
<widget class="QPushButton"> <widget class="QPushButton">
<property name="name"> <property name="name">
<cstring>addFiltypPB</cstring> <cstring>delFiltypPB</cstring>
</property> </property>
<property name="geometry"> <property name="enabled">
<rect> <bool>false</bool>
<x>270</x> </property>
<y>360</y> <property name="text">
<width>86</width> <string>--------&gt;</string>
<height>30</height> </property>
</rect> </widget>
</property> <widget class="QPushButton">
<property name="text"> <property name="name">
<string>&lt;---------</string> <cstring>addFiltypPB</cstring>
</property> </property>
</widget> <property name="enabled">
<widget class="QPushButton"> <bool>false</bool>
<property name="name"> </property>
<cstring>searchPB</cstring> <property name="text">
</property> <string>&lt;---------</string>
<property name="geometry"> </property>
<rect> </widget>
<x>380</x> </vbox>
<y>20</y>
<width>90</width>
<height>30</height>
</rect>
</property>
<property name="text">
<string>Search</string>
</property>
</widget> </widget>
</widget> </widget>
<connections> <connections>

View File

@ -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 <unistd.h> #include <unistd.h>

View File

@ -1,21 +1,21 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1"> <!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>Preview</class> <class>Preview</class>
<widget class="QDialog"> <widget class="QWidget">
<property name="name"> <property name="name">
<cstring>Preview</cstring> <cstring>Preview</cstring>
</property> </property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>159</x> <x>0</x>
<y>362</y> <y>0</y>
<width>469</width> <width>751</width>
<height>174</height> <height>727</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy>
<hsizetype>0</hsizetype> <hsizetype>5</hsizetype>
<vsizetype>0</vsizetype> <vsizetype>5</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
@ -35,26 +35,44 @@
</property> </property>
<widget class="QLayoutWidget"> <widget class="QLayoutWidget">
<property name="name"> <property name="name">
<cstring>layout5</cstring> <cstring>layout9</cstring>
</property> </property>
<vbox> <vbox>
<property name="name"> <property name="name">
<cstring>unnamed</cstring> <cstring>unnamed</cstring>
</property> </property>
<widget class="QTextEdit"> <widget class="QTabWidget">
<property name="name"> <property name="name">
<cstring>pvEdit</cstring> <cstring>pvTab</cstring>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property> </property>
<widget class="QWidget">
<property name="name">
<cstring>unnamed</cstring>
</property>
<attribute name="title">
<string>Preview 1</string>
</attribute>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QTextEdit">
<property name="name">
<cstring>pvEdit</cstring>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
</widget>
</vbox>
</widget>
</widget> </widget>
<widget class="QLayoutWidget"> <widget class="QLayoutWidget">
<property name="name"> <property name="name">
<cstring>layout4</cstring> <cstring>layout7</cstring>
</property> </property>
<hbox> <hbox>
<property name="name"> <property name="name">
@ -156,6 +174,7 @@
<slot>doSearch( bool next, bool reverse )</slot> <slot>doSearch( bool next, bool reverse )</slot>
<slot>nextPressed()</slot> <slot>nextPressed()</slot>
<slot>prevPressed()</slot> <slot>prevPressed()</slot>
<slot>currentChanged( QWidget * tw )</slot>
</slots> </slots>
<functions> <functions>
<function access="private" specifier="non virtual">init()</function> <function access="private" specifier="non virtual">init()</function>

View File

@ -12,20 +12,19 @@
void Preview::init() void Preview::init()
{ {
pvEdit->installEventFilter(this); connect(pvTab, SIGNAL(currentChanged(QWidget *)),
this, SLOT(currentChanged(QWidget *)));
searchTextLine->installEventFilter(this); searchTextLine->installEventFilter(this);
dynSearchActive = false; dynSearchActive = false;
canBeep = true; canBeep = true;
matchPara = 0;
matchIndex = 0;
} }
bool Preview::eventFilter(QObject *target, QEvent *event) bool Preview::eventFilter(QObject *target, QEvent *event)
{ {
if (event->type() != QEvent::KeyPress) if (event->type() != QEvent::KeyPress)
return QWidget::eventFilter(target, event); return QWidget::eventFilter(target, event);
fprintf(stderr, "Preview::eventFilter: keyEvent\n");
QKeyEvent *keyEvent = (QKeyEvent *)event; QKeyEvent *keyEvent = (QKeyEvent *)event;
if (dynSearchActive) { if (dynSearchActive) {
if (keyEvent->key() == Key_F3) { if (keyEvent->key() == Key_F3) {
@ -35,7 +34,12 @@ bool Preview::eventFilter(QObject *target, QEvent *event)
if (target != searchTextLine) if (target != searchTextLine)
return QApplication::sendEvent(searchTextLine, event); return QApplication::sendEvent(searchTextLine, event);
} else { } 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; dynSearchActive = true;
return true; return true;
} }
@ -46,7 +50,7 @@ bool Preview::eventFilter(QObject *target, QEvent *event)
void Preview::searchTextLine_textChanged(const QString & text) 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()) { if (text.isEmpty()) {
dynSearchActive = false; dynSearchActive = false;
} else { } else {
@ -62,41 +66,53 @@ void Preview::searchTextLine_textChanged(const QString & text)
// starting from the current position // starting from the current position
void Preview::doSearch(bool next, bool reverse) void Preview::doSearch(bool next, bool reverse)
{ {
//fprintf(stderr, "Preview::doSearch: next %d rev %d para %d index %d\n", //fprintf(stderr, "Preview::doSearch: next %d rev %d\n",
// int(next), int(reverse), matchPara, matchIndex); // 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(); 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) { if (next) {
// We search again, starting from the current match // We search again, starting from the current match
if (reverse) { if (reverse) {
// when searching backwards, have to move back one char // when searching backwards, have to move back one char
if (matchIndex > 0) if (msindex > 0)
matchIndex --; msindex --;
else if (matchPara > 0) { else if (mspara > 0) {
matchPara --; mspara --;
matchIndex = pvEdit->paragraphLength(matchPara); msindex = edit->paragraphLength(mspara);
} }
} else { } else {
// Forward search: start from end of selection // Forward search: start from end of selection
int bogus; int bogus;
pvEdit->getSelection(&bogus, &bogus, &matchPara, &matchIndex); mspara = mepara;
//fprintf(stderr, "New para: %d index %d\n",matchPara, matchIndex); msindex = meindex;
//fprintf(stderr, "New para: %d index %d\n", mspara, msindex);
} }
} }
bool found = pvEdit->find(searchTextLine->text(), matchCase, false, bool found = edit->find(searchTextLine->text(), matchCase, false,
!reverse, &matchPara, &matchIndex); !reverse, &mspara, &msindex);
if (!found && next && true) { // need a 'canwrap' test here if (!found && next && true) { // need a 'canwrap' test here
if (reverse) { if (reverse) {
matchPara = pvEdit->paragraphs(); mspara = edit->paragraphs();
matchIndex = pvEdit->paragraphLength(matchPara); msindex = edit->paragraphLength(mspara);
} else { } else {
matchPara = matchIndex = 0; mspara = msindex = 0;
} }
found = pvEdit->find(searchTextLine->text(), matchCase, false, found = edit->find(searchTextLine->text(), matchCase, false,
!reverse, &matchPara, &matchIndex); !reverse, &mspara, &msindex);
} }
if (found) { if (found) {
@ -119,3 +135,18 @@ void Preview::prevPressed()
{ {
doSearch(true, true); 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);
}
}

View File

@ -1,5 +1,5 @@
#ifndef lint #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 #endif
#include <stdio.h> #include <stdio.h>
@ -14,6 +14,8 @@ using std::pair;
#include <qapplication.h> #include <qapplication.h>
#include <qobject.h> #include <qobject.h>
#include <qtextedit.h> #include <qtextedit.h>
#include <qtabwidget.h>
#include <qlayout.h>
#include "preview.h" #include "preview.h"
#include "../plaintorich.h" #include "../plaintorich.h"
@ -25,7 +27,6 @@ int main( int argc, char ** argv )
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
Preview w; Preview w;
w.show();
string text; string text;
if (!file_to_string(filename, 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()); QString str = QString::fromUtf8(rich.c_str(), rich.length());
w.pvEdit->setText(str); 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(); return a.exec();
} }

View File

@ -8,18 +8,24 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>782</width> <width>160</width>
<height>622</height> <height>750</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy>
<hsizetype>7</hsizetype> <hsizetype>5</hsizetype>
<vsizetype>7</vsizetype> <vsizetype>5</vsizetype>
<horstretch>0</horstretch> <horstretch>0</horstretch>
<verstretch>0</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="caption"> <property name="caption">
<string>recoll</string> <string>recoll</string>
</property> </property>
@ -29,131 +35,117 @@
</property> </property>
<widget class="QLayoutWidget"> <widget class="QLayoutWidget">
<property name="name"> <property name="name">
<cstring>layout3</cstring> <cstring>layout8</cstring>
</property> </property>
<hbox> <vbox>
<property name="name"> <property name="name">
<cstring>unnamed</cstring> <cstring>unnamed</cstring>
</property> </property>
<widget class="QLineEdit"> <widget class="QLayoutWidget">
<property name="name"> <property name="name">
<cstring>queryText</cstring> <cstring>layout9</cstring>
</property>
<property name="frameShape">
<enum>LineEditPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property> </property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLineEdit">
<property name="name">
<cstring>queryText</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>8</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>155</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>LineEditPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>Search</cstring>
</property>
<property name="text">
<string>Search</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>clearqPB</cstring>
</property>
<property name="text">
<string>Clear</string>
</property>
<property name="accel">
<string>Ctrl+S</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>listPrevPb</cstring>
</property>
<property name="text">
<string>Previous page</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>listNextPB</cstring>
</property>
<property name="text">
<string>Next page</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>advSearchPB</cstring>
</property>
<property name="text">
<string>Adv. search</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer1</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>346</width>
<height>20</height>
</size>
</property>
</spacer>
</hbox>
</widget> </widget>
<widget class="QPushButton">
<property name="name">
<cstring>Search</cstring>
</property>
<property name="text">
<string>Search</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>clearqPB</cstring>
</property>
<property name="text">
<string>Clear</string>
</property>
<property name="accel">
<string>Ctrl+S</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>listPrevPb</cstring>
</property>
<property name="text">
<string>Previous page</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>listNextPB</cstring>
</property>
<property name="text">
<string>Next page</string>
</property>
</widget>
<spacer>
<property name="name">
<cstring>spacer1</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<property name="sizeType">
<enum>Expanding</enum>
</property>
<property name="sizeHint">
<size>
<width>346</width>
<height>20</height>
</size>
</property>
</spacer>
</hbox>
</widget>
<widget class="QSplitter">
<property name="name">
<cstring>splitter6</cstring>
</property>
<property name="orientation">
<enum>Horizontal</enum>
</property>
<widget class="QTextEdit">
<property name="name">
<cstring>reslistTE</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>2</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="textFormat">
<enum>RichText</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="undoRedoEnabled">
<bool>false</bool>
</property>
</widget>
<widget class="QSplitter">
<property name="name">
<cstring>splitter5</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>5</hsizetype>
<vsizetype>5</vsizetype>
<horstretch>5</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="orientation">
<enum>Vertical</enum>
</property>
<widget class="QTextEdit"> <widget class="QTextEdit">
<property name="name"> <property name="name">
<cstring>previewTextEdit</cstring> <cstring>reslistTE</cstring>
</property> </property>
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy> <sizepolicy>
<hsizetype>7</hsizetype> <hsizetype>5</hsizetype>
<vsizetype>7</vsizetype> <vsizetype>5</vsizetype>
<horstretch>0</horstretch> <horstretch>2</horstretch>
<verstretch>4</verstretch> <verstretch>0</verstretch>
</sizepolicy> </sizepolicy>
</property> </property>
<property name="textFormat"> <property name="textFormat">
@ -166,26 +158,7 @@
<bool>false</bool> <bool>false</bool>
</property> </property>
</widget> </widget>
<widget class="QTextEdit"> </vbox>
<property name="name">
<cstring>metaTextEdit</cstring>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>7</hsizetype>
<vsizetype>7</vsizetype>
<horstretch>0</horstretch>
<verstretch>1</verstretch>
</sizepolicy>
</property>
<property name="textFormat">
<enum>RichText</enum>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</widget>
</widget> </widget>
</vbox> </vbox>
</widget> </widget>
@ -253,10 +226,16 @@
<slot>fileExit()</slot> <slot>fileExit()</slot>
</connection> </connection>
<connection> <connection>
<sender>queryText</sender> <sender>fileStart_IndexingAction</sender>
<signal>returnPressed()</signal> <signal>activated()</signal>
<receiver>RecollMain</receiver> <receiver>RecollMain</receiver>
<slot>queryText_returnPressed()</slot> <slot>fileStart_IndexingAction_activated()</slot>
</connection>
<connection>
<sender>helpQuick_startAction</sender>
<signal>activated()</signal>
<receiver>RecollMain</receiver>
<slot>helpQuick_startAction_activated()</slot>
</connection> </connection>
<connection> <connection>
<sender>Search</sender> <sender>Search</sender>
@ -264,6 +243,12 @@
<receiver>RecollMain</receiver> <receiver>RecollMain</receiver>
<slot>Search_clicked()</slot> <slot>Search_clicked()</slot>
</connection> </connection>
<connection>
<sender>queryText</sender>
<signal>returnPressed()</signal>
<receiver>RecollMain</receiver>
<slot>queryText_returnPressed()</slot>
</connection>
<connection> <connection>
<sender>listPrevPb</sender> <sender>listPrevPb</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
@ -288,33 +273,23 @@
<receiver>RecollMain</receiver> <receiver>RecollMain</receiver>
<slot>reslistTE_clicked(int,int)</slot> <slot>reslistTE_clicked(int,int)</slot>
</connection> </connection>
<connection>
<sender>fileStart_IndexingAction</sender>
<signal>activated()</signal>
<receiver>RecollMain</receiver>
<slot>fileStart_IndexingAction_activated()</slot>
</connection>
<connection> <connection>
<sender>clearqPB</sender> <sender>clearqPB</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
<receiver>RecollMain</receiver> <receiver>RecollMain</receiver>
<slot>clearqPB_clicked()</slot> <slot>clearqPB_clicked()</slot>
</connection> </connection>
<connection>
<sender>helpQuick_startAction</sender>
<signal>activated()</signal>
<receiver>RecollMain</receiver>
<slot>helpQuick_startAction_activated()</slot>
</connection>
</connections> </connections>
<includes> <includes>
<include location="local" impldecl="in declaration">preview/.ui/preview.h</include>
<include location="local" impldecl="in implementation">recollmain.ui.h</include> <include location="local" impldecl="in implementation">recollmain.ui.h</include>
</includes> </includes>
<variables> <variables>
<variable>std::string stemlang;</variable>
<variable>bool dostem;</variable>
<variable>int reslist_current;</variable>
<variable>int reslist_winfirst;</variable> <variable>int reslist_winfirst;</variable>
<variable>int reslist_current;</variable>
<variable>bool dostem;</variable>
<variable>std::string stemlang;</variable>
<variable>Preview *curPreview;</variable>
</variables> </variables>
<slots> <slots>
<slot>fileExit()</slot> <slot>fileExit()</slot>
@ -328,7 +303,11 @@
<slot>listPrevPB_clicked()</slot> <slot>listPrevPB_clicked()</slot>
<slot>listNextPB_clicked()</slot> <slot>listNextPB_clicked()</slot>
<slot>helpQuick_startAction_activated()</slot> <slot>helpQuick_startAction_activated()</slot>
<slot>advSearchPB_clicked()</slot>
</slots> </slots>
<functions>
<function access="private">init()</function>
</functions>
<pixmapinproject/> <pixmapinproject/>
<layoutdefaults spacing="6" margin="11"/> <layoutdefaults spacing="6" margin="11"/>
</UI> </UI>

View File

@ -20,7 +20,7 @@ using std::pair;
#include <qmessagebox.h> #include <qmessagebox.h>
#include <qcstring.h> #include <qcstring.h>
#include <qtabwidget.h>
#include "rcldb.h" #include "rcldb.h"
#include "rclconfig.h" #include "rclconfig.h"
@ -29,16 +29,24 @@ using std::pair;
#include "pathut.h" #include "pathut.h"
#include "recoll.h" #include "recoll.h"
#include "internfile.h" #include "internfile.h"
#include "textsplit.h"
#include "smallut.h" #include "smallut.h"
#include "utf8iter.h" #include "plaintorich.h"
#include "transcode.h"
#include "unacpp.h" #include "unacpp.h"
#ifndef MIN #ifndef MIN
#define MIN(A,B) ((A) < (B) ? (A) : (B)) #define MIN(A,B) ((A) < (B) ? (A) : (B))
#endif #endif
static const int respagesize = 8;
void RecollMain::init()
{
curPreview = 0;
}
void RecollMain::fileExit() void RecollMain::fileExit()
{ {
LOGDEB1(("RecollMain: fileExit\n")); LOGDEB1(("RecollMain: fileExit\n"));
@ -65,112 +73,6 @@ void RecollMain::fileStart_IndexingAction_activated()
startindexing = 1; 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<string> *terms; // in: query terms
list<pair<int, int> > tboffs; // out: begin and end positions of
// query terms in text
myTextSplitCB(const list<string>& 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<string>::const_iterator it = terms->begin();
it != terms->end(); it++) {
if (!stringlowercmp(*it, dumb)) {
tboffs.push_back(pair<int, int>(bts, bte));
break;
}
}
return true;
}
};
// Fix result text for display inside the gui text window
static string plaintorich(const string &in, const list<string>& terms,
list<pair<int, int> >&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<pair<int, int> >::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 = "<qt><head><title></title></head><body><p>";
// 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<pair<int, int> >::iterator it = cb.tboffs.begin();
// Storage for the current term position in output.
pair<int, int> 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 += "<termtag>";
opos.first = outbytepos;
} else if (ibyteidx == (unsigned int)it->second) {
if (it != cb.tboffs.end())
it++;
opos.second = outbytepos;
termoffsets.push_back(opos);
out += "</termtag>";
}
}
switch(in[ibyteidx]) {
case '\n':
if (ateol < 2)
out += "<br>\n";
ateol++;
outbytepos++;
break;
case '\r': break;
case '<':
ateol = 0;
out += "&lt;";
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) static string urltolocalpath(string url)
{ {
@ -180,7 +82,8 @@ static string urltolocalpath(string url)
// Use external viewer to display file // Use external viewer to display file
void RecollMain::reslistTE_doubleClicked(int par, int) void RecollMain::reslistTE_doubleClicked(int par, int)
{ {
// restlistTE_clicked(par, car); LOGDEB(("RecollMain::reslistTE_doubleClicked: par %d\n", par));
Rcl::Doc doc; Rcl::Doc doc;
int reldocnum = par - 1; int reldocnum = par - 1;
if (!rcldb->getDoc(reslist_winfirst + reldocnum, doc, 0)) if (!rcldb->getDoc(reslist_winfirst + reldocnum, doc, 0))
@ -239,8 +142,10 @@ void RecollMain::reslistTE_clicked(int par, int car)
reslistTE->setParagraphBackgroundColor(par, color); reslistTE->setParagraphBackgroundColor(par, color);
int reldocnum = par - 1; int reldocnum = par - 1;
if (reslist_current == reldocnum)
return;
reslist_current = reldocnum; reslist_current = reldocnum;
previewTextEdit->clear();
if (!rcldb->getDoc(reslist_winfirst + reldocnum, doc, 0)) { if (!rcldb->getDoc(reslist_winfirst + reldocnum, doc, 0)) {
QMessageBox::warning(0, "Recoll", QMessageBox::warning(0, "Recoll",
@ -264,33 +169,52 @@ void RecollMain::reslistTE_clicked(int par, int car)
list<pair<int, int> > termoffsets; list<pair<int, int> > termoffsets;
string rich = plaintorich(fdoc.text, terms, 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 = QStyleSheetItem *item =
new QStyleSheetItem( previewTextEdit->styleSheet(), "termtag" ); new QStyleSheetItem(editor->styleSheet(),
"termtag" );
item->setColor("blue"); item->setColor("blue");
item->setFontWeight(QFont::Bold); item->setFontWeight(QFont::Bold);
QString str = QString::fromUtf8(rich.c_str(), rich.length()); QString str = QString::fromUtf8(rich.c_str(), rich.length());
previewTextEdit->setText(str); editor->setText(str);
int para = 0, index = 1; int para = 0, index = 1;
if (!termoffsets.empty()) { if (!termoffsets.empty()) {
index = (termoffsets.begin())->first; 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", LOGDEB(("Set cursor position: para %d, character index %d\n",
para,index)); para,index));
previewTextEdit->setCursorPosition(0, index); editor->setCursorPosition(0, index);
} }
previewTextEdit->ensureCursorVisible(); editor->ensureCursorVisible();
previewTextEdit->getCursorPosition(&para, &index); editor->getCursorPosition(&para, &index);
LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n", LOGDEB(("PREVIEW len %d paragraphs: %d. Cpos: %d %d\n",
previewTextEdit->length(), previewTextEdit->paragraphs(), editor->length(), editor->paragraphs(), para, index));
para, index));
} }
@ -333,7 +257,7 @@ void RecollMain::queryText_returnPressed()
if (!rcldb->setQuery(string((const char *)u8), dostem ? if (!rcldb->setQuery(string((const char *)u8), dostem ?
Rcl::Db::QO_STEM : Rcl::Db::QO_NONE, stemlang)) Rcl::Db::QO_STEM : Rcl::Db::QO_NONE, stemlang))
return; return;
list<string> terms; curPreview = 0;
listNextPB_clicked(); listNextPB_clicked();
} }
@ -348,7 +272,6 @@ void RecollMain::clearqPB_clicked()
queryText->clear(); queryText->clear();
} }
static const int respagesize = 10;
void RecollMain::listPrevPB_clicked() void RecollMain::listPrevPB_clicked()
{ {
if (reslist_winfirst <= 0) if (reslist_winfirst <= 0)
@ -361,12 +284,14 @@ void RecollMain::listPrevPB_clicked()
// Fill up result list window with next screen of hits // Fill up result list window with next screen of hits
void RecollMain::listNextPB_clicked() void RecollMain::listNextPB_clicked()
{ {
fprintf(stderr, "listNextPB_clicked\n");
if (!rcldb) if (!rcldb)
return; return;
int percent; int percent;
Rcl::Doc doc; Rcl::Doc doc;
rcldb->getDoc(0, doc, &percent); rcldb->getDoc(0, doc, &percent);
int resCnt = rcldb->getResCnt(); int resCnt = rcldb->getResCnt();
fprintf(stderr, "listNextPB_clicked rescnt\n");
LOGDEB(("listNextPB_clicked: rescnt %d, winfirst %d\n", resCnt, LOGDEB(("listNextPB_clicked: rescnt %d, winfirst %d\n", resCnt,
reslist_winfirst)); reslist_winfirst));
@ -381,7 +306,7 @@ void RecollMain::listNextPB_clicked()
bool gotone = false; bool gotone = false;
reslistTE->clear(); reslistTE->clear();
previewTextEdit->clear();
int last = MIN(resCnt-reslist_winfirst, respagesize); int last = MIN(resCnt-reslist_winfirst, respagesize);
// Insert results if any in result list window // Insert results if any in result list window
@ -438,7 +363,7 @@ void RecollMain::listNextPB_clicked()
reslistTE->setCursorPosition(0,0); reslistTE->setCursorPosition(0,0);
reslistTE->ensureCursorVisible(); reslistTE->ensureCursorVisible();
// Display preview for 1st doc in list // Display preview for 1st doc in list
reslistTE_clicked(1, 0); // reslistTE_clicked(1, 0);
} else { } else {
// Restore first in win parameter that we shouln't have incremented // Restore first in win parameter that we shouln't have incremented
reslist_winfirst -= respagesize; reslist_winfirst -= respagesize;
@ -473,3 +398,5 @@ void RecollMain::advSearchPB_clicked()
asearchform->show(); asearchform->show();
} }
} }