*** empty log message ***

This commit is contained in:
dockes 2005-09-27 06:20:16 +00:00
parent b12d438154
commit 39338b4b4b
4 changed files with 351 additions and 0 deletions

View File

@ -0,0 +1,23 @@
TEMPLATE = app
LANGUAGE = C++
CONFIG += qt warn_on release
unix:LIBS += ../../lib/librcl.a ../../bincimapmime/libmime.a -L/usr/local/lib -lxapian -liconv -lfontconfig -lfreetype -lexpat -lz
unix:INCLUDEPATH += ../ ../../common ../../index ../../query ../../unac ../../utils
SOURCES += pvmain.cpp \
../plaintorich.cpp
FORMS = preview.ui
#
unix {
UI_DIR = .ui
MOC_DIR = .moc
OBJECTS_DIR = .obj
}

View File

@ -0,0 +1,165 @@
<!DOCTYPE UI><UI version="3.3" stdsetdef="1">
<class>Preview</class>
<widget class="QDialog">
<property name="name">
<cstring>Preview</cstring>
</property>
<property name="geometry">
<rect>
<x>159</x>
<y>362</y>
<width>469</width>
<height>174</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>0</hsizetype>
<vsizetype>0</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>30</height>
</size>
</property>
<property name="caption">
<string>Preview</string>
</property>
<vbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout5</cstring>
</property>
<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>
<widget class="QLayoutWidget">
<property name="name">
<cstring>layout4</cstring>
</property>
<hbox>
<property name="name">
<cstring>unnamed</cstring>
</property>
<widget class="QLabel">
<property name="name">
<cstring>searchLabel</cstring>
</property>
<property name="text">
<string>&amp;Search for:</string>
</property>
<property name="buddy" stdset="0">
<cstring>searchTextLine</cstring>
</property>
</widget>
<widget class="QLineEdit">
<property name="name">
<cstring>searchTextLine</cstring>
</property>
<property name="frameShape">
<enum>LineEditPanel</enum>
</property>
<property name="frameShadow">
<enum>Sunken</enum>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>nextButton</cstring>
</property>
<property name="text">
<string>&amp;Next</string>
</property>
<property name="accel">
<string>Alt+N</string>
</property>
</widget>
<widget class="QPushButton">
<property name="name">
<cstring>prevButton</cstring>
</property>
<property name="text">
<string>&amp;Previous</string>
</property>
<property name="accel">
<string>Alt+P</string>
</property>
</widget>
<widget class="QCheckBox">
<property name="name">
<cstring>matchCheck</cstring>
</property>
<property name="text">
<string>Match &amp;Case</string>
</property>
<property name="accel">
<string>Alt+C</string>
</property>
</widget>
</hbox>
</widget>
</vbox>
</widget>
</vbox>
</widget>
<connections>
<connection>
<sender>searchTextLine</sender>
<signal>textChanged(const QString&amp;)</signal>
<receiver>Preview</receiver>
<slot>searchTextLine_textChanged(const QString&amp;)</slot>
</connection>
<connection>
<sender>nextButton</sender>
<signal>clicked()</signal>
<receiver>Preview</receiver>
<slot>nextPressed()</slot>
</connection>
<connection>
<sender>prevButton</sender>
<signal>clicked()</signal>
<receiver>Preview</receiver>
<slot>prevPressed()</slot>
</connection>
</connections>
<includes>
<include location="local" impldecl="in implementation">qapplication.h</include>
<include location="local" impldecl="in implementation">preview.ui.h</include>
</includes>
<variables>
<variable>int matchIndex;</variable>
<variable>int matchPara;</variable>
<variable>bool dynSearchActive;</variable>
<variable>bool canBeep;</variable>
</variables>
<slots>
<slot>searchTextLine_textChanged( const QString &amp; text )</slot>
<slot>doSearch( bool next, bool reverse )</slot>
<slot>nextPressed()</slot>
<slot>prevPressed()</slot>
</slots>
<functions>
<function access="private" specifier="non virtual">init()</function>
<function returnType="bool">eventFilter( QObject * target, QEvent * event )</function>
</functions>
<layoutdefaults spacing="6" margin="11"/>
</UI>

View File

@ -0,0 +1,121 @@
/****************************************************************************
** ui.h extension file, included from the uic-generated form implementation.
**
** If you want to add, delete, or rename functions or slots, use
** Qt Designer to update this file, preserving your code.
**
** You should not define a constructor or destructor in this file.
** Instead, write your code in functions called init() and destroy().
** These will automatically be called by the form's constructor and
** destructor.
*****************************************************************************/
void Preview::init()
{
pvEdit->installEventFilter(this);
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);
QKeyEvent *keyEvent = (QKeyEvent *)event;
if (dynSearchActive) {
if (keyEvent->key() == Key_F3) {
doSearch(true, false);
return true;
}
if (target != searchTextLine)
return QApplication::sendEvent(searchTextLine, event);
} else {
if (keyEvent->key() == Key_Slash && target == pvEdit) {
dynSearchActive = true;
return true;
}
}
return QWidget::eventFilter(target, event);
}
void Preview::searchTextLine_textChanged(const QString & text)
{
//fprintf(stderr, "search line text changed. text: '%s'\n", text.ascii());
if (text.isEmpty()) {
dynSearchActive = false;
} else {
dynSearchActive = true;
doSearch(false, false);
}
}
// Perform text search. If next is true, we look for the next match of the
// current search, trying to advance and possibly wrapping around. If next is
// false, the search string has been modified, we search for the new string,
// 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);
bool matchCase = matchCheck->isChecked();
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);
}
} 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);
}
}
bool found = pvEdit->find(searchTextLine->text(), matchCase, false,
!reverse, &matchPara, &matchIndex);
if (!found && next && true) { // need a 'canwrap' test here
if (reverse) {
matchPara = pvEdit->paragraphs();
matchIndex = pvEdit->paragraphLength(matchPara);
} else {
matchPara = matchIndex = 0;
}
found = pvEdit->find(searchTextLine->text(), matchCase, false,
!reverse, &matchPara, &matchIndex);
}
if (found) {
canBeep = true;
} else {
if (canBeep)
QApplication::beep();
canBeep = false;
}
}
void Preview::nextPressed()
{
doSearch(true, false);
}
void Preview::prevPressed()
{
doSearch(true, true);
}

View File

@ -0,0 +1,42 @@
#ifndef lint
static char rcsid[] = "@(#$Id: pvmain.cpp,v 1.1 2005-09-27 06:20:16 dockes Exp $ (C) 2005 J.F.Dockes";
#endif
#include <stdio.h>
#include <unistd.h>
#include <string>
#include <list>
using std::string;
using std::list;
using std::pair;
#include <qapplication.h>
#include <qobject.h>
#include <qtextedit.h>
#include "preview.h"
#include "../plaintorich.h"
#include "readfile.h"
const char *filename = "/home/dockes/tmp/tstpv-utf8.txt";
int main( int argc, char ** argv )
{
QApplication a(argc, argv);
Preview w;
w.show();
string text;
if (!file_to_string(filename, text)) {
fprintf(stderr, "Could not read %s\n", filename);
exit(1);
}
list<string> terms;
list<pair<int, int> > termoffs;
string rich = plaintorich(text, terms, termoffs);
QString str = QString::fromUtf8(rich.c_str(), rich.length());
w.pvEdit->setText(str);
return a.exec();
}