summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-01-23 13:26:21 (UTC)
committer mickeyl <mickeyl>2003-01-23 13:26:21 (UTC)
commit6464e96567a07c3104b31292e8a23945b13d0da6 (patch) (side-by-side diff)
tree79f75c9402edab972e099f6bdd7dbd092f370095
parent197b10539409b5650170879b904b9f781294866e (diff)
downloadopie-6464e96567a07c3104b31292e8a23945b13d0da6.zip
opie-6464e96567a07c3104b31292e8a23945b13d0da6.tar.gz
opie-6464e96567a07c3104b31292e8a23945b13d0da6.tar.bz2
g++ 3.2 fixes... repeat after me "I won't repeat default arguments in the definition I have already given in the declaration"
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/Bkmks.cpp2
-rw-r--r--noncore/apps/opie-reader/CBuffer.cpp4
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp4
-rw-r--r--noncore/apps/opie-reader/QTReaderApp.cpp2
-rw-r--r--noncore/apps/opie-reader/infowin.cpp2
5 files changed, 7 insertions, 7 deletions
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp
index 998601a..a8bee13 100644
--- a/noncore/apps/opie-reader/Bkmks.cpp
+++ b/noncore/apps/opie-reader/Bkmks.cpp
@@ -1,322 +1,322 @@
#include "name.h"
#include <qmessagebox.h>
#include "Bkmks.h"
#include "StyleConsts.h"
#include "Markups.h"
#include "my_list.h"
#include "version.h"
const unsigned long BkmkFile::magic = ((unsigned long)'q' << 24) | ((unsigned long)'t' << 16) | ((unsigned long)'r' << 8) | ((unsigned long)BKMKTYPE);
Bkmk::Bkmk(const unsigned char* _nm, unsigned short _nmlen, const unsigned char* _anno, unsigned short _annolen, unsigned int _p) : m_position(_p)
{
init(_nm, _nmlen, _anno, _annolen, _p);
}
Bkmk::Bkmk(const tchar* _nm, const unsigned char* _anno, unsigned short annolen, unsigned int _p) : m_position(_p)
{
init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, annolen, _p);
}
Bkmk::Bkmk(const tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p)
{
if (_anno == NULL)
{
tchar t = 0;
init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), &t, sizeof(t), _p);
}
else
{
init(_nm, sizeof(tchar)*(ustrlen(_nm)+1), _anno, sizeof(tchar)*(ustrlen(_anno)+1), _p);
}
}
void Bkmk::init(const void* _nm, unsigned short _nmlen, const void* _anno, unsigned short _annolen, unsigned int _p)
{
m_namelen = _nmlen;
if (m_namelen > 0)
{
m_name = new unsigned char[m_namelen];
memcpy(m_name, _nm, m_namelen);
}
else
{
m_name = NULL;
}
m_annolen = _annolen;
if (m_annolen > 0)
{
m_anno = new unsigned char[m_annolen];
memcpy(m_anno, _anno, m_annolen);
}
else
{
m_anno = NULL;
}
m_position = _p;
}
Bkmk::~Bkmk()
{
if (m_name != NULL) delete [] m_name;
m_name = NULL;
if (m_anno != NULL) delete [] m_anno;
m_anno = NULL;
}
Bkmk& Bkmk::operator=(const Bkmk& rhs)
{
if (m_name != NULL)
{
delete [] m_name;
m_name = NULL;
}
if (m_anno != NULL)
{
delete [] m_anno;
m_anno = NULL;
}
if (rhs.m_name != NULL)
{
m_namelen = rhs.m_namelen;
m_name = new unsigned char[m_namelen];
memcpy(m_name, rhs.m_name, m_namelen);
}
else
m_name = NULL;
if (rhs.m_anno != NULL)
{
m_annolen = rhs.m_annolen;
m_anno = new unsigned char[m_annolen];
memcpy(m_anno, rhs.m_anno, m_annolen);
}
else
m_anno = NULL;
m_position = rhs.m_position;
return *this;
}
bool Bkmk::operator==(const Bkmk& rhs)
{
return (m_position == rhs.m_position && (rhs.m_namelen == m_namelen) && memcmp(m_name,rhs.m_name,m_namelen) == 0);
}
void Bkmk::setAnno(unsigned char* t, unsigned short len)
{
if (m_anno != NULL)
{
delete [] m_anno;
m_anno = NULL;
}
if (t != NULL)
{
m_annolen = len;
m_anno = new unsigned char[m_annolen];
memcpy(m_anno, t, m_annolen);
}
else
{
m_annolen = sizeof(tchar);
m_anno = new unsigned char[m_annolen];
*((tchar*)m_anno) = 0;
}
}
void Bkmk::setAnno(tchar* t)
{
if (m_anno != NULL)
{
delete [] m_anno;
m_anno = NULL;
}
if (t != NULL)
{
unsigned short len = ustrlen(t)+1;
m_annolen = sizeof(tchar)*len;
m_anno = new unsigned char[m_annolen];
memcpy(m_anno, t, m_annolen);
}
else
{
m_annolen = sizeof(tchar);
m_anno = new unsigned char[m_annolen];
*((tchar*)m_anno) = 0;
}
}
-BkmkFile::BkmkFile(const char *fnm, bool w = false)
+BkmkFile::BkmkFile(const char *fnm, bool w)
:
wt(w), isUpgraded(false)
{
if (w)
{
f = fopen(fnm, "wb");
}
else
{
f = fopen(fnm, "rb");
}
}
BkmkFile::~BkmkFile()
{
if (f != NULL) fclose(f);
}
void BkmkFile::write(const Bkmk& b)
{
if (f != NULL)
{
fwrite(&b.m_namelen, sizeof(b.m_namelen),1,f);
fwrite(b.m_name,1,b.m_namelen,f);
fwrite(&b.m_annolen, sizeof(b.m_annolen),1,f);
fwrite(b.m_anno,1,b.m_annolen,f);
fwrite(&b.m_position,sizeof(b.m_position),1,f);
}
}
void BkmkFile::write(CList<Bkmk>& bl)
{
if (f != NULL)
{
fwrite(&magic, sizeof(magic), 1, f);
for (CList<Bkmk>::iterator i = bl.begin(); i != bl.end(); i++)
{
write(*i);
}
}
}
CList<Bkmk>* BkmkFile::readall()
{
CList<Bkmk>* bl = NULL;
if (f != NULL)
{
unsigned long newmagic;
fread(&newmagic, sizeof(newmagic), 1, f);
if ((newmagic & 0xffffff00) != (magic & 0xffffff00))
{
if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of " PROGNAME "\ndid you upgrade from?", "0_4*", "Any other version") == 0)
{
fseek(f,0,SEEK_SET);
bl = readall00(&read05);
}
else
{
fseek(f,0,SEEK_SET);
bl = readall00(&read03);
}
isUpgraded = true;
}
else
{
switch(newmagic & 0xff)
{
case 6:
isUpgraded = false;
bl = readall00(read06);
qDebug("Correct version!");
break;
case 5:
isUpgraded = true;
bl = readall00(read05);
qDebug("Known version!");
break;
default:
qDebug("Unknown version!");
isUpgraded = true;
bl = readall00(read05);
}
}
}
return bl;
}
CList<Bkmk>* BkmkFile::readall00(Bkmk* (*readfn)(FILE*))
{
CList<Bkmk>* bl = new CList<Bkmk>;
while (1)
{
Bkmk* b = (*readfn)(f);
if (b == NULL) break;
bl->push_back(*b);
delete b;
}
return bl;
}
Bkmk* BkmkFile::read03(FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
tchar* name = new tchar[ln+1];
fread(name,sizeof(tchar),ln,f);
name[ln] = 0;
ln = 0;
tchar* anno = new tchar[ln+1];
anno[ln] = 0;
unsigned int pos;
fread(&pos,sizeof(pos),1,f);
b = new Bkmk(name,anno,pos);
}
}
return b;
}
Bkmk* BkmkFile::read05(FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
tchar* nm = new tchar[ln+1];
fread(nm,sizeof(tchar),ln,f);
nm[ln] = 0;
fread(&ln,sizeof(ln),1,f);
tchar* anno = new tchar[ln+1];
if (ln > 0) fread(anno,sizeof(tchar),ln,f);
anno[ln] = 0;
unsigned int pos;
fread(&pos,sizeof(pos),1,f);
b = new Bkmk(nm,anno,pos);
}
}
return b;
}
Bkmk* BkmkFile::read06(FILE* f)
{
Bkmk* b = NULL;
if (f != NULL)
{
unsigned short ln;
if (fread(&ln,sizeof(ln),1,f) == 1)
{
b = new Bkmk;
b->m_namelen = ln;
b->m_name = new unsigned char[b->m_namelen];
fread(b->m_name,1,b->m_namelen,f);
fread(&(b->m_annolen),sizeof(b->m_annolen),1,f);
if (b->m_annolen > 0)
{
b->m_anno = new unsigned char[b->m_annolen];
fread(b->m_anno,1,b->m_annolen,f);
}
fread(&(b->m_position),sizeof(b->m_position),1,f);
}
}
return b;
}
diff --git a/noncore/apps/opie-reader/CBuffer.cpp b/noncore/apps/opie-reader/CBuffer.cpp
index 526b25f..0780a88 100644
--- a/noncore/apps/opie-reader/CBuffer.cpp
+++ b/noncore/apps/opie-reader/CBuffer.cpp
@@ -1,46 +1,46 @@
#include "CBuffer.h"
CBufferBase& CBufferBase::assign(const void* sztmp, size_t ms)
{
if (ms*membersize > len)
{
delete [] buffer;
buffer = new unsigned char[len = ms*membersize];
}
memcpy(buffer, sztmp, ms*membersize);
return *this;
}
-CBufferBase::CBufferBase(size_t ms, size_t n = 16) : len(n), membersize(ms)
+CBufferBase::CBufferBase(size_t ms, size_t n) : len(n), membersize(ms)
{
buffer = new unsigned char[len*membersize];
memset(buffer, 0, len*membersize);
}
void* CBufferBase::operator[](int i)
{
if ((i+1)*membersize > len)
{
unsigned char* oldbuffer = buffer;
buffer = new unsigned char[(i+1)*membersize];
memcpy(buffer, oldbuffer, len);
memset(buffer+len, 0, (i+1)*membersize-len);
len = (i+1)*membersize;
delete [] oldbuffer;
}
return buffer+i*membersize;
}
-size_t CBufferBase::bstrlen(unsigned char* _buffer = NULL)
+size_t CBufferBase::bstrlen(unsigned char* _buffer)
{
if (_buffer == NULL) _buffer = buffer;
unsigned char* zero = new unsigned char[membersize];
memset(zero,0,membersize);
unsigned char* element = _buffer;
while (memcmp(element, zero, membersize) != 0)
{
element += membersize;
}
delete [] zero;
return (element - _buffer)/membersize;
}
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 3995ee7..f2ee027 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -1,1327 +1,1327 @@
/****************************************************************************
** $Id$
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of an example program for Qt. This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/
#include <qpainter.h>
#include "config.h"
#include "QTReader.h"
#include "QTReaderApp.h"
#include "CDrawBuffer.h"
#include <qpe/qpeapplication.h>
#include <math.h>
#include <ctype.h>
#include <stdio.h> //for sprintf
#include <qpe/config.h>
#include <qpe/applnk.h>
#include <qfontdatabase.h>
#include <qpe/global.h>
#include <qpe/qcopenvelope_qws.h>
#include "StateData.h"
#ifdef _UNICODE
const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
#else
const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
#endif
//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 };
//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 };
//const int QTReader::fontsizes[] = {10,16,17,22,0};
//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0};
-QTReader::QTReader( QWidget *parent=0, const char *name=0, WFlags f = 0) :
+QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
QWidget(parent, name, f),
m_delay(100),
m_scrolldy1(0),
m_scrolldy2(0),
m_autoScroll(false),
//textarray(NULL),
//locnarray(NULL),
numlines(0),
m_fontname("unifont"),
m_fm(NULL),
mouseUpOn(true),
m_twotouch(true),
m_touchone(true),
bDoUpdates(false),
m_navkeys(true)
{
m_overlap = 1;
// init();
}
/*
-QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
+QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, WFlags f ) :
QWidget(parent, name, f),
m_textfont(0),
m_textsize(1),
textarray(NULL),
numlines(0),
bstripcr(true),
bunindent(false),
brepara(false),
bdblspce(false),
btight(false),
bindenter(0),
m_fm(NULL)
{
init();
// qDebug("Load_file(1)");
load_file((const tchar*)filename);
}
*/
long QTReader::real_delay()
{
return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
}
void QTReader::mousePressEvent( QMouseEvent* _e )
{
buffdoc.unsuspend();
if (_e->button() == RightButton)
{
mouseUpOn = false;
if (buffdoc.hasnavigation())
{
if (_e->y() > (2*height())/3)
{
goDown();
}
else if (_e->y() < height()/3)
{
goUp();
}
else
{
if (_e->x() < width()/3)
{
size_t target = pagelocate();
if (buffdoc.back(target))
{
locate(target);
}
}
else if (_e->x() > (2*width())/3)
{
size_t target = pagelocate();
if (buffdoc.forward(target))
{
locate(target);
}
}
else
{
buffdoc.saveposn(pagelocate());
locate(buffdoc.getHome());
}
}
}
else
{
if (_e->y() > height()/2)
{
goDown();
}
else
{
goUp();
}
}
}
}
linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt)
{
int lineno = 0;
int ht = textarray[0]->lineSpacing();
while ((ht < y) && (lineno < numlines))
{
ht += textarray[++lineno]->lineSpacing();
}
start = locnarray[lineno];
if (m_bMonoSpaced)
{
offset = x/m_charWidth;
}
else
{
int i;
CDrawBuffer* t = textarray[lineno];
x = x - t->offset(width());
for (i = t->length(); i >= 0 && t->width(i) > x; i--);
offset = i;
}
return textarray[lineno]->getLinkType(offset, tgt);
}
void QTReader::setTwoTouch(bool _b)
{
setBackgroundColor( white );
m_twotouch = m_touchone = _b;
}
void QTReader::setContinuous(bool _b)
{
buffdoc.unsuspend();
buffdoc.setContinuous(m_continuousDocument = _b);
}
void QTReader::mouseReleaseEvent( QMouseEvent* _e )
{
buffdoc.unsuspend();
if (_e->button() == LeftButton)
{
if (mouseUpOn)
{
if (textarray[0] != NULL)
{
QString wrd, line;
// int lineno = _e->y()/m_linespacing;
int lineno = 0;
int ht = textarray[0]->lineSpacing();
while ((ht < _e->y()) && (lineno < numlines))
{
ht += textarray[++lineno]->lineSpacing();
}
size_t startpos, startoffset, tgt;
switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
{
case eLink:
{
size_t saveposn = pagelocate();
if (buffdoc.hyperlink(tgt))
{
buffdoc.saveposn(saveposn);
fillbuffer();
update();
}
else
{
locate(pagelocate());
}
return;
}
case ePicture:
{
qDebug("Picture:%x", tgt);
QPixmap* pm = buffdoc.getPicture(tgt);
if (pm != NULL)
{
emit OnShowPicture(*pm);
delete pm;
}
else
{
locate(pagelocate());
}
return;
}
case eNone:
break;
default:
qDebug("Unknown linktype");
return;
}
if (m_twotouch)
{
if (m_touchone)
{
m_touchone = false;
m_startpos = startpos;
m_startoffset = startoffset;
setBackgroundColor( lightGray );
}
else
{
m_touchone = true;
setBackgroundColor( white );
size_t endpos, endoffset;
endpos = startpos;
endoffset = startoffset;
size_t currentpos = locate();
if (endpos >= m_startpos)
{
jumpto(m_startpos);
for (int i = 0; i < m_startoffset; i++)
{
getch();
}
if (m_startpos == endpos)
{
for (int i = m_startoffset; i <= endoffset; i++)
{
wrd += QChar(getch());
}
}
else
{
while (buffdoc.explocate() <= endpos)
{
wrd += QChar(getch());
}
for (int i = 0; i < endoffset; i++)
{
wrd += QChar(getch());
}
}
jumpto(currentpos);
}
}
}
else if (m_bMonoSpaced)
{
int chno = _e->x()/m_charWidth;
if (chno < ustrlen(textarray[lineno]->data()))
{
wrd[0] = textarray[lineno]->data()[chno];
}
}
else
{
CDrawBuffer* t = textarray[lineno];
int first = 0;
int tgt = _e->x() - t->offset(width());
while (1)
{
int i = first+1;
while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
if (t->width(i) > tgt)
{
wrd = toQString(t->data()+first, i - first);
break;
}
while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
if ((*t)[i] == 0) break;
first = i;
}
}
if (!wrd.isEmpty())
{
emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data()));
}
}
}
else
{
mouseUpOn = true;
}
}
}
void QTReader::focusInEvent(QFocusEvent* e)
{
if (m_autoScroll) timer->start(real_delay(), false);
update();
}
void QTReader::focusOutEvent(QFocusEvent* e)
{
if (m_autoScroll)
{
timer->stop();
m_scrolldy1 = m_scrolldy2 = 0;
}
}
#include <qapplication.h>
#include <qdrawutil.h>
#include <unistd.h>
void QTReader::goDown()
{
if (m_bpagemode)
{
dopagedn();
}
else
{
lineDown();
}
}
void QTReader::goUp()
{
if (m_bpagemode)
{
dopageup();
}
else
{
lineUp();
}
}
void QTReader::NavUp()
{
buffdoc.unsuspend();
if (buffdoc.hasnavigation())
{
/*
size_t target = pagelocate();
if (buffdoc.back(target))
{
locate(target);
}
*/
locate(buffdoc.startSection());
}
else
{
goUp();
}
}
void QTReader::NavDown()
{
buffdoc.unsuspend();
if (buffdoc.hasnavigation())
{
/*
size_t target = pagelocate();
if (buffdoc.forward(target))
{
locate(target);
}
*/
dopageup(buffdoc.endSection());
}
else
{
goDown();
}
}
void QTReader::zoomin()
{
if (m_fontControl.increasesize())
{
bool sc = m_autoScroll;
setfont();
m_autoScroll = false;
locate(pagelocate());
update();
m_autoScroll = sc;
if (m_autoScroll) autoscroll();
}
}
void QTReader::zoomout()
{
if (m_fontControl.decreasesize())
{
bool sc = m_autoScroll;
m_autoScroll = false;
setfont();
locate(pagelocate());
update();
m_autoScroll = sc;
if (m_autoScroll) autoscroll();
}
}
void QTReader::keyPressEvent(QKeyEvent* e)
{
buffdoc.unsuspend();
switch (e->key())
{
case Key_Down:
{
e->accept();
if (m_autoScroll)
{
if (m_delay < 59049)
{
m_delay = (3*m_delay)/2;
timer->changeInterval(real_delay());
}
else
{
m_delay = 59049;
}
}
else
{
goDown();
}
}
break;
case Key_Up:
{
e->accept();
if (m_autoScroll)
{
if (m_delay > 1024)
{
m_delay = (2*m_delay)/3;
timer->changeInterval(real_delay());
}
else
{
m_delay = 1024;
}
}
else
{
goUp();
}
}
break;
/*
case Key_Left:
{
e->accept();
if (m_textfont > 0)
{
m_textfont--;
setfont(NULL);
locate(pagelocate());
update();
}
}
break;
case Key_Right:
{
e->accept();
if (fonts[++m_textfont] == 0)
{
m_textfont--;
}
else
{
setfont(NULL);
locate(pagelocate());
update();
}
}
break;
*/
case Key_Right:
{
e->accept();
if (m_navkeys && buffdoc.hasnavigation())
{
size_t target = pagelocate();
if (buffdoc.forward(target))
{
locate(target);
}
}
else zoomin();
}
break;
case Key_Left:
{
e->accept();
if (m_navkeys && buffdoc.hasnavigation())
{
size_t target = pagelocate();
if (buffdoc.back(target))
{
locate(target);
}
}
else zoomout();
}
break;
case Key_Space:
case Key_Return:
{
e->accept();
emit OnActionPressed();
}
break;
default:
e->ignore();
}
}
void QTReader::setautoscroll(bool _sc)
{
if (_sc == m_autoScroll) return;
if (m_autoScroll)
{
m_autoScroll = false;
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
}
else
{
CDrawBuffer* reusebuffer = textarray[numlines];
if (reusebuffer == NULL || reusebuffer->eof()) return;
m_autoScroll = true;
autoscroll();
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed
}
}
bool QTReader::getline(CDrawBuffer *buff)
{
buffdoc.unsuspend();
if (m_bMonoSpaced)
{
return buffdoc.getline(buff ,width(), m_charWidth);
}
else
{
return buffdoc.getline(buff, width());
}
}
void QTReader::doscroll()
{
if (!m_autoScroll)
{
timer->stop();
return;
}
// timer->changeInterval(real_delay());
QPainter p( this );
QBrush b( white);
bitBlt(this,0,0,this,0,1,width(),-1);
qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b);
if (++m_scrolldy1 == textarray[0]->lineSpacing())
{
CDrawBuffer* buff = textarray[0];
for (int i = 1; i <= numlines; i++)
{
textarray[i-1] = textarray[i];
locnarray[i-1] = locnarray[i];
}
textarray[numlines] = buff;
--numlines;
m_scrolldy1 = 0;
}
if (++m_scrolldy2 == textarray[numlines]->lineSpacing())
{
m_scrolldy2 = 0;
numlines++;
if (textarray[numlines] == NULL)
{
textarray[numlines] = new CDrawBuffer(&m_fontControl);
}
locnarray[numlines] = locate();
int ch = getline(textarray[numlines]);
textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width());
mylastpos = locate();
if (!ch)
{
m_autoScroll = false;
((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
}
emit OnRedraw();
}
}
void QTReader::autoscroll()
{
timer->start(real_delay(), false);
}
void QTReader::setfont()
{
// m_fontControl.Change
m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
if (m_charWidth <= 0) m_charWidth = 1;
m_ascent = m_fontControl.ascent();
m_descent = m_fontControl.descent();
m_linespacing = m_fontControl.lineSpacing();
}
void QTReader::drawFonts( QPainter *p )
{
if (bDoUpdates)
{
qDebug("How refreshing...");
if (buffdoc.empty()) return;
setfont();
if (m_lastwidth != width())
{
qDebug("Not Optimised %d", m_lastwidth);
m_lastwidth = width();
m_lastheight = height();
locate(pagelocate());
qDebug("Not Optimised %d", m_lastwidth);
}
else
{
if (m_lastheight > height())
{
qDebug("Optimised < %d", numlines);
int ypos = 0;
for (int i = 0; i < numlines; i++)
{
if ((ypos += textarray[i]->lineSpacing()) > height())
{
numlines = i;
jumpto(locnarray[i+1]);
break;
}
}
qDebug("Optimised < %d", numlines);
m_lastheight = height();
}
else if (m_lastheight < height())
{
qDebug("Optimised > %d", numlines);
int ypos = 0;
for (int i = 0; i <= numlines; i++)
{
ypos += textarray[i]->lineSpacing();
}
fillbuffer(numlines+1, ypos);
qDebug("Optimised > %d", numlines);
m_lastheight = height();
}
if (numlines > 0)
{
int ypos = textarray[0]->ascent();
textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
for (int i = 1; i < numlines; i++)
{
// ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
(textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width());
}
// mylastpos = locate();
}
}
m_scrolldy1 = m_scrolldy2 = 0;
emit OnRedraw();
}
else
{
qDebug("Not so refreshing...");
}
}
QString QTReader::firstword()
{
if (m_bMonoSpaced)
{
return toQString(textarray[0]->data());
}
else
{
int start, end, len, j;
for (j = 0; j < numlines; j++)
{
len = textarray[j]->length();
for (start = 0; start < len && !isalpha((*textarray[j])[start]); start++);
if (start < len) break;
}
if (j < numlines)
{
QString ret = "";
for (end = start; end < len && isalpha((*textarray[j])[end]); end++)
ret += (*textarray[j])[end];
if (ret.isEmpty()) ret = "Current position";
return ret;
}
else
return "Current position";
}
}
//
// Construct the QTReader with buttons.
//
bool QTReader::ChangeFont(int tgt)
{
return m_fontControl.ChangeFont(m_fontname, tgt);
}
void QTReader::init()
{
// setCaption( "Qt Draw Demo Application" );
buffdoc.unsuspend();
setBackgroundColor( white );
// QPainter p(this);
// p.setBackgroundMode( Qt::OpaqueMode );
buffdoc.setfilter(getfilter());
ChangeFont(m_textsize);
setFocusPolicy(QWidget::StrongFocus);
// resize( 240, 320 );
//setFocus();
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
// QMessageBox::information(this, "init", m_lastfile, 1);
setfont();
/*
if (!m_lastfile.isEmpty())
{
m_string = DocLnk(m_lastfile).name();
load_file(m_lastfile);
}
*/
}
//
// Clean up
//
QTReader::~QTReader()
{
}
//
// Calls the drawing function as specified by the radio buttons.
//
void QTReader::drawIt( QPainter *p )
{
drawFonts(p);
}
//
// Called when the print button is clicked.
//
/*
void QTReader::printIt()
{
#ifndef QT_NO_PRINTER
if ( printer->setup( this ) ) {
QPainter paint;
if ( !paint.begin( printer ) )
return;
drawIt( &paint );
}
#endif
}
*/
//
// Called when the widget needs to be updated.
//
void QTReader::paintEvent( QPaintEvent * )
{
QPainter paint( this );
drawIt( &paint );
}
//
// Called when the widget has been resized.
// Moves the button group to the upper right corner
// of the widget.
/*
void QTReader::resizeEvent( QResizeEvent * )
{
// qDebug("resize:(%u,%u)", width(), height());
// bgroup->move( width()-bgroup->width(), 0 );
}
*/
//
// Create and display our widget.
//
/*
int main( int argc, tchar **argv )
{
QApplication app( argc, argv );
QTReader draw;
app.setMainWidget( &draw );
draw.setCaption("Qt Example - Drawdemo");
draw.show();
return app.exec();
}
*/
bool QTReader::locate(unsigned long n) {
//printf("Locate\n");
buffdoc.unsuspend();
buffdoc.locate(n);
// qDebug("&buffdoc.located");
fillbuffer();
// qDebug("&Buffer filled");
update();
// qDebug("&Located");
return true;
}
unsigned int QTReader::screenlines()
{
// int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
// return (height()-m_descent)/(m_linespacing);
return (height()-2)/(m_linespacing);
};
bool QTReader::fillbuffer(int reuse, int ht)
{
buffdoc.unsuspend();
if (buffdoc.empty()) return false;
m_scrolldy1 = m_scrolldy2 = 0;
int ch;
bool ret = false;
unsigned int oldpagepos = locnarray[reuse];
int ypos = ht;
numlines = reuse;
while (ypos < height() || numlines < 2)
{
if (textarray[numlines] == NULL)
{
textarray[numlines] = new CDrawBuffer(&m_fontControl);
}
locnarray[numlines] = locate();
int ch = getline(textarray[numlines]);
ypos += textarray[numlines]->lineSpacing();
numlines++;
if (!ch)
{
if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/)
{
locate(oldpagepos);
return false;
}
else
{
--numlines;
mylastpos = locate();
return true;
}
}
}
--numlines;
mylastpos = locate();
return true;
}
void QTReader::dopagedn()
{
buffdoc.unsuspend();
int skip = 0, ypos = 0;
if (locate() != mylastpos)
{
// qDebug("Jumping to %u", mylastpos);
jumpto(mylastpos);
}
CDrawBuffer* reusebuffer = textarray[numlines];
if (reusebuffer != NULL && reusebuffer->eof()) return;
if (reusebuffer != NULL)
{
for (int i = 0; i <= m_overlap; i++)
{
int offset = numlines - m_overlap + i;
reusebuffer = textarray[offset];
size_t reuselocn = locnarray[offset];
textarray[offset] = textarray[i];
textarray[i] = reusebuffer;
// reusebuffer->empty();
locnarray[offset] = locnarray[i];
locnarray[i] = reuselocn;
ypos += textarray[i]->lineSpacing();
skip++;
}
}
if (fillbuffer(skip, ypos))
{
update();
}
}
void QTReader::dopageup()
{
buffdoc.unsuspend();
dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
}
void QTReader::dopageup(unsigned int target)
{
buffdoc.unsuspend();
CBufferFace<CDrawBuffer*> buff;
CBufferFace<size_t> loc;
size_t delta, guess = 2048;
bool ch = true;
int nbfl, ypos = 0;
while (1)
{
ch = true;
nbfl = 0;
if (target < guess)
{
delta = 0; // 0 is a flag to say don't guess any more
jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
}
else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
{
delta = 0; // 0 is a flag to say don't guess any more
jumpto(buffdoc.startSection());
}
else
{
delta = guess;
jumpto(target - delta);
buff[0] = new CDrawBuffer(&m_fontControl);
do
{
if (!getline(buff[0])) break;
if (locate() > target) break;
}
while (!buffdoc.iseol());
}
ypos = 0;
while (locate() < target)
{
if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
loc[nbfl] = locate();
ch = getline(buff[nbfl]);
ypos += buff[nbfl]->lineSpacing();
nbfl++;
if (!ch) break;
}
if (ypos < height() && (delta != 0))
{
for (int i = 0; i < nbfl; i++)
{
delete buff[i];
buff[i] = NULL;
}
guess <<= 1;
continue;
}
break;
}
if (ch)
{
if (buff[nbfl] == NULL) buff[nbfl] = new CDrawBuffer(&m_fontControl);
loc[nbfl] = locate();
int ch = getline(buff[nbfl]);
nbfl++;
}
ypos = 0;
numlines = 0;
while (ypos < height() && numlines <= nbfl-1)
{
ypos += buff[nbfl - numlines - 1]->lineSpacing();
numlines++;
}
--numlines;
int offset = nbfl-1;
offset -= numlines;
ypos = 0;
for (int i = 0; i <= numlines; i++)
{
delete textarray[i];
textarray[i] = buff[offset+i];
locnarray[i] = loc[offset + i];
ypos += textarray[i]->lineSpacing();
}
for (int i = 0; i < nbfl - numlines - 1; i++)
{
delete buff[i];
}
while (ypos < height())
{
numlines++;
locnarray[numlines] = locate();
if (textarray[numlines] == NULL) textarray[numlines] = new CDrawBuffer(&m_fontControl);
if (!getline(textarray[numlines])) break;
ypos += textarray[numlines]->lineSpacing();
}
mylastpos = locate();
update();
}
bool QTReader::load_file(const char *newfile, unsigned int _lcn)
{
// QMessageBox::information(this, "Name", name, 1);
// QMessageBox::information(this, "load_file", newfile, 1);
bool bRC = false;
unsigned int lcn = _lcn;
if (m_lastfile == newfile)
{
lcn = m_lastposn;
}
m_lastfile = newfile;
// QMessageBox::information(0, "Opening...", newfile);
m_lastwidth = width();
m_lastheight = height();
if (buffdoc.openfile(this,newfile) == 0)
{
bRC = true;
buffdoc.setContinuous(m_continuousDocument);
// qDebug("buffdoc.openfile done");
locate(lcn);
// qDebug("buffdoc.locate done");
}
setfilter(getfilter());
update();
// qDebug("Updated");
return bRC;
}
void QTReader::lineDown()
{
int ypos = 0;
int offset = numlines;
for (int i = 0; i <= numlines; i++)
{
if ((ypos += textarray[numlines-i]->lineSpacing()) > height())
{
offset = i-1;
break;
}
}
offset = numlines - offset;
for (int i = offset; i <= numlines; i++)
{
CDrawBuffer* buff = textarray[i-offset];
textarray[i-offset] = textarray[i];
locnarray[i-offset] = locnarray[i];
textarray[i] = buff;
}
numlines = numlines - offset + 1;
locnarray[numlines] = locate();
if (textarray[numlines] == NULL)
{
textarray[numlines] = new CDrawBuffer(&m_fontControl);
}
getline(textarray[numlines]);
mylastpos = locate();
update();
}
/*
void QTReader::lineUp()
{
CBuffer** buff = textarray;
unsigned int *loc = new unsigned int[numlines];
int cbptr = 0;
if (locate() != mylastpos) jumpto(mylastpos);
unsigned int target = locnarray[numlines-1];
if (buffdoc.hasrandomaccess())
{
unsigned int delta = locate()-pagelocate();
if (delta < 64) delta = 64;
do
{
delta <<= 1;
if (delta >= target)
{
delta = target;
jumpto(0);
for (int i = 0; i < numlines; i++)
{
loc[i] = locate();
getline(buff[i]);
}
break;
}
jumpto(target-delta);
do
{
buffdoc.getline(buff[0],width());
#ifdef WS
//printf("Trying:%s\n",buff[0]);
#endif
if (locate() > target) continue;
}
while (!buffdoc.iseol());
for (int i = 0; i < numlines; i++)
{
loc[i] = locate();
buffdoc.getline(buff[i],width());
#ifdef WS
//printf("Filling:%s\n",buff[i]);
#endif
}
}
while (locate() >= target && delta < 4096);
#ifdef WS
//printf("Delta:%u\n",delta);
#endif
}
else
{
jumpto(0);
for (int i = 0; i < numlines; i++)
{
loc[i] = locate();
buffdoc.getline(buff[i],width());
}
}
cbptr = 0;
while (locate() < target)
{
loc[cbptr] = locate();
buffdoc.getline(buff[cbptr], width());
#ifdef WS
//printf("Adding:%s\n",buff[cbptr]->data());
#endif
cbptr = (cbptr+1) % numlines;
}
pagepos = loc[cbptr];
textarray = new CBuffer*[numlines];
for (int i = 0; i < numlines; i++)
{
int j = (cbptr+i)%numlines;
textarray[i] = buff[j];
locnarray[i] = loc[j];
}
delete [] buff;
delete [] loc;
mylastpos = locate();
update();
}
*/
void QTReader::lineUp()
{
buffdoc.unsuspend();
CDrawBuffer* buff = textarray[numlines];
unsigned int loc;
unsigned int end = locnarray[numlines];
int cbptr = 0;
if (locate() != mylastpos) jumpto(mylastpos);
unsigned int target = locnarray[0];
if (target == 0) return;
if (!m_continuousDocument && (target == buffdoc.startSection())) return;
if (buffdoc.hasrandomaccess())
{
unsigned int delta = locate()-pagelocate();
if (delta < 64) delta = 64;
do
{
delta <<= 1;
if (delta >= target)
{
delta = target;
jumpto(0);
loc = locate();
getline(buff);
break;
}
else if (!m_continuousDocument && (target - delta < buffdoc.startSection()))
{
delta = target-buffdoc.startSection();
jumpto(buffdoc.startSection());
loc = locate();
getline(buff);
break;
}
jumpto(target-delta);
do
{
getline(buff);
#ifdef WS
//printf("Trying:%s\n",buff[0]);
#endif
if (locate() > target) continue;
}
while (!buffdoc.iseol());
loc = locate();
getline(buff);
}
while (locate() >= target && delta < 4096);
}
else
{
jumpto(0);
loc = locate();
getline(buff);
}
cbptr = 0;
while (locate() < target)
{
loc = locate();
getline(buff);
}
for (int i = numlines; i > 0; i--)
{
textarray[i] = textarray[i-1];
locnarray[i] = locnarray[i-1];
}
textarray[0] = buff;
locnarray[0] = loc;
int start = numlines;
int ypos = 0;
for (int i = 0; i <= numlines; i++)
{
ypos += textarray[i]->lineSpacing();
if (ypos > height())
{
start = i;
ypos -= textarray[i]->lineSpacing();
break;
}
}
jumpto(locnarray[start]);
fillbuffer(start, ypos);
update();
}
bool QTReader::empty()
{
return buffdoc.empty();
}
MarkupType QTReader::PreferredMarkup()
{
MarkupType m = buffdoc.PreferredMarkup();
if (m == cTEXT)
{
int ext = m_lastfile.findRev('.');
if (ext >= 0)
{
QString ft = m_lastfile.right(m_lastfile.length()-ext-1).upper();
if (ft.left(3) == "HTM")
{
m = cHTML;
}
}
}
return m;
}
void QTReader::setstate(const statedata& sd)
{
bstripcr = sd.bstripcr;
btextfmt = sd.btextfmt;
bautofmt = sd.bautofmt;
bstriphtml = sd.bstriphtml;
bpeanut = sd.bpeanut;
bdehyphen = sd.bdehyphen;
bonespace = sd.bonespace;
bunindent = sd.bunindent;
brepara = sd.brepara;
bdblspce = sd.bdblspce;
m_bpagemode = sd.m_bpagemode;
m_navkeys = sd.m_navkeys;
m_bMonoSpaced = sd.m_bMonoSpaced;
bremap = sd.bremap;
bmakebold = sd.bmakebold;
m_continuousDocument = sd.Continuous;
#ifdef REPALM
brepalm = sd.brepalm;
#endif
bindenter = sd.bindenter;
m_encd = sd.m_charpc;
m_fontname = sd.m_fontname;
setContinuous(sd.Continuous);
ChangeFont(sd.m_textsize);
refresh();
}
diff --git a/noncore/apps/opie-reader/QTReaderApp.cpp b/noncore/apps/opie-reader/QTReaderApp.cpp
index 2044b1d..7333a28 100644
--- a/noncore/apps/opie-reader/QTReaderApp.cpp
+++ b/noncore/apps/opie-reader/QTReaderApp.cpp
@@ -124,2483 +124,2483 @@ void QTReaderApp::listBkmkFiles()
else
QMessageBox::information(this, PROGNAME, "No bookmark files");
}
QTReaderApp::QTReaderApp( QWidget *parent, const char *name, WFlags f )
: QMainWindow( parent, name, f ), bFromDocView( FALSE ), m_dontSave(false)
{
// qDebug("Application directory = %s", (const tchar *)QPEApplication::documentDir());
// qDebug("Application directory = %s", (const tchar *)Global::applicationFileName("uqtreader","bkmks.xml"));
pBkmklist = NULL;
pOpenlist = NULL;
// doc = 0;
m_fBkmksChanged = false;
QString lang = getenv( "LANG" );
m_autogenstr = "^ *[A-Z].*[a-z] *$";
setToolBarsMovable( FALSE );
setIcon( Resource::loadPixmap( "uqtreader" ) );
// QPEToolBar *bar = new QPEToolBar( this );
QToolBar *bar = new QToolBar( this );
bar->setHorizontalStretchable( TRUE );
addToolBar(bar, "tool",QMainWindow::Top, true);
//tjw menu = bar;
QPEMenuBar *mb = new QPEMenuBar( bar );
// QMenuBar *mb = new QMenuBar( bar );
QPopupMenu *file = new QPopupMenu( this );
QPopupMenu *format = new QPopupMenu( this );
// QPopupMenu *edit = new QPopupMenu( this );
// bar = new QToolBar( this );
editBar = bar;
/*
QAction *a = new QAction( tr( "New" ), Resource::loadPixmap( "new" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fileNew() ) );
a->addTo( bar );
a->addTo( file );
*/
editorStack = new QWidgetStack( this );
setCentralWidget( editorStack );
searchVisible = FALSE;
regVisible = FALSE;
m_fontVisible = false;
pbar = new QProgressBar(this);
pbar->hide();
m_annoWin = new CAnnoEdit(editorStack);
editorStack->addWidget(m_annoWin, get_unique_id());
connect( m_annoWin, SIGNAL( finished(const QString&, const QString&) ), this, SLOT( addAnno(const QString&, const QString&) ) );
connect( m_annoWin, SIGNAL( cancelled() ), this, SLOT( infoClose() ) );
m_infoWin = new infowin(editorStack);
editorStack->addWidget(m_infoWin, get_unique_id());
connect( m_infoWin, SIGNAL( Close() ), this, SLOT( infoClose() ) );
m_graphicwin = new GraphicWin(editorStack);
editorStack->addWidget(m_graphicwin, get_unique_id());
connect( m_graphicwin, SIGNAL( Closed() ), this, SLOT( infoClose() ) );
// bkmkselector = new QListBox(editorStack, "Bookmarks");
bkmkselector = new CBkmkSelector(editorStack, "Bookmarks");
// connect(bkmkselector, SIGNAL( selected(const QString&) ), this, SLOT( gotobkmk(const QString&) ) );
connect(bkmkselector, SIGNAL( selected(int) ), this, SLOT( gotobkmk(int) ) );
connect(bkmkselector, SIGNAL( cancelled() ), this, SLOT( cancelbkmk() ) );
editorStack->addWidget( bkmkselector, get_unique_id() );
/*
importSelector = new FileSelector( "*", editorStack, "importselector", false );
connect( importSelector, SIGNAL( fileSelected( const DocLnk &) ), this, SLOT( importFile( const DocLnk & ) ) );
editorStack->addWidget( importSelector, get_unique_id() );
// don't need the close visible, it is redundant...
importSelector->setCloseVisible( FALSE );
*/
qDebug("Reading file list");
readfilelist();
reader = new QTReader( editorStack );
reader->bDoUpdates = false;
((QPEApplication*)qApp)->setStylusOperation(reader, QPEApplication::RightOnHold);
qDebug("Reading config");
Config config( APPDIR );
config.setGroup( "View" );
reader->bstripcr = config.readBoolEntry( "StripCr", true );
reader->btextfmt = config.readBoolEntry( "TextFmt", false );
reader->bautofmt = config.readBoolEntry( "AutoFmt", true );
reader->bstriphtml = config.readBoolEntry( "StripHtml", false );
reader->bpeanut = config.readBoolEntry( "Peanut", false );
reader->bdehyphen = config.readBoolEntry( "Dehyphen", false );
reader->bonespace = config.readBoolEntry( "OneSpace", false );
reader->bunindent = config.readBoolEntry( "Unindent", false );
reader->brepara = config.readBoolEntry( "Repara", false );
reader->bdblspce = config.readBoolEntry( "DoubleSpace", false );
reader->bindenter = config.readNumEntry( "Indent", 0 );
reader->m_textsize = config.readNumEntry( "FontSize", 12 );
reader->m_delay = config.readNumEntry( "ScrollDelay", 5184);
reader->m_lastfile = config.readEntry( "LastFile", QString::null );
reader->m_lastposn = config.readNumEntry( "LastPosn", 0 );
reader->m_bpagemode = config.readBoolEntry( "PageMode", true );
reader->m_navkeys = config.readBoolEntry( "CursorNavigation", false );
reader->m_bMonoSpaced = config.readBoolEntry( "MonoSpaced", false);
reader->m_fontname = config.readEntry( "Fontname", "helvetica" );
reader->m_encd = config.readNumEntry( "Encoding", 0 );
reader->m_charpc = config.readNumEntry( "CharSpacing", 100 );
reader->m_overlap = config.readNumEntry( "Overlap", 0 );
#ifdef REPALM
reader->brepalm = config.readBoolEntry( "Repalm", true );
#endif
reader->bremap = config.readBoolEntry( "Remap", true );
reader->bmakebold = config.readBoolEntry( "MakeBold", false );
reader->setContinuous(config.readBoolEntry( "Continuous", true ));
m_targetapp = config.readEntry( "TargetApp", QString::null );
m_targetmsg = config.readEntry( "TargetMsg", QString::null );
m_twoTouch = config.readBoolEntry( "TwoTouch", false);
m_doAnnotation = config.readBoolEntry( "Annotation", false);
m_doDictionary = config.readBoolEntry( "Dictionary", false);
m_doClipboard = config.readBoolEntry( "Clipboard", false);
m_spaceTarget = (ActionTypes)config.readNumEntry("SpaceTarget", cesAutoScroll);
setTwoTouch(m_twoTouch);
connect( reader, SIGNAL( OnShowPicture(QPixmap&) ), this, SLOT( showgraphic(QPixmap&) ) );
connect( reader, SIGNAL( OnRedraw() ), this, SLOT( OnRedraw() ) );
connect( reader, SIGNAL( OnActionPressed() ), this, SLOT( OnActionPressed() ) );
connect( reader, SIGNAL( OnWordSelected(const QString&, size_t, const QString&) ), this, SLOT( OnWordSelected(const QString&, size_t, const QString&) ) );
editorStack->addWidget( reader, get_unique_id() );
QAction *a = new QAction( tr( "Open" ), Resource::loadPixmap( "fileopen" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fileOpen() ) );
a->addTo( bar );
a->addTo( file );
a = new QAction( tr( "Close" ), Resource::loadPixmap( "fileclose" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fileClose() ) );
// a->addTo( bar );
a->addTo( file );
/*
a = new QAction( tr( "Revert" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( fileRevert() ) );
a->addTo( file );
a = new QAction( tr( "Cut" ), Resource::loadPixmap( "cut" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editCut() ) );
a->addTo( editBar );
a->addTo( edit );
*/
a = new QAction( tr( "Info" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( showinfo() ) );
a->addTo( file );
QActionGroup* ag = new QActionGroup(this);
QPopupMenu *spacemenu = new QPopupMenu(this);
file->insertItem( tr( "On Action..." ), spacemenu );
m_buttonAction[0] = new QAction( tr( "Open File" ), QString::null, 0, ag, NULL, true );
m_buttonAction[1] = new QAction( tr( "Autoscroll" ), QString::null, 0, ag, NULL, true );
m_buttonAction[2] = new QAction( tr( "Mark" ), QString::null, 0, ag, NULL, true );
m_buttonAction[3] = new QAction( tr( "Fullscreen" ), QString::null, 0, ag, NULL, true );
ag->addTo(spacemenu);
connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( buttonActionSelected(QAction*) ) );
file->insertSeparator();
ag = new QActionGroup(this);
ag->setExclusive(false);
QPopupMenu *encoding = new QPopupMenu(this);
file->insertItem( tr( "Navigation" ), encoding );
a = m_scrollButton = new QAction( tr( "Scroll" ), Resource::loadPixmap( PICDIR "panel-arrow-down" ), QString::null, 0, ag, 0, true );
a->setOn(false);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( autoScroll(bool) ) );
a->addTo( bar );
a = new QAction( tr( "Jump" ), QString::null, 0, ag, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( jump() ) );
a = new QAction( tr( "Page/Line Scroll" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( pagemode(bool) ) );
a->setOn(reader->m_bpagemode);
a = new QAction( tr( "Set Overlap" ), QString::null, 0, ag, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( setoverlap() ) );
a = new QAction( tr( "Use Cursor" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( navkeys(bool) ) );
a->setOn(reader->m_navkeys);
ag->addTo(encoding);
/*
a = new QAction( tr( "Find" ), QString::null, 0, this, NULL, true );
// connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
a->addTo( file );
a = new QAction( tr( "Find Again" ), QString::null, 0, this, NULL, true );
// connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
a->addTo( file );
*/
file->insertSeparator();
a = new QAction( tr( "Set Dictionary" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( settarget() ) );
a->addTo( file );
a = new QAction( tr( "Two/One Touch" ), QString::null, 0, this, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( setTwoTouch(bool) ) );
a->setOn(m_twoTouch);
a->addTo( file );
ag = new QActionGroup(this);
ag->setExclusive(false);
encoding = new QPopupMenu(this);
file->insertItem( tr( "Target" ), encoding );
a = new QAction( tr( "Annotation" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnAnnotation(bool) ) );
a->setOn(m_doAnnotation);
a = new QAction( tr( "Dictionary" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnDictionary(bool) ) );
a->setOn(m_doDictionary);
a = new QAction( tr( "Clipboard" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( OnClipboard(bool) ) );
a->setOn(m_doClipboard);
ag->addTo(encoding);
/*
a = new QAction( tr( "Import" ), QString::null, 0, this, NULL );
connect( a, SIGNAL( activated() ), this, SLOT( importFiles() ) );
a->addTo( file );
*/
a = new QAction( tr( "Up" ), Resource::loadPixmap( "up" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( pageup() ) );
a->addTo( editBar );
a = new QAction( tr( "Down" ), Resource::loadPixmap( "down" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( pagedn() ) );
a->addTo( editBar );
/*
a = new QAction( tr( "Paste" ), Resource::loadPixmap( "paste" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
a->addTo( editBar );
a->addTo( edit );
*/
// a = new QAction( tr( "Find..." ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
a = new QAction( tr( "Find..." ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( editFind() ) );
file->insertSeparator();
// a->addTo( bar );
a->addTo( file );
m_fullscreen = false;
a = m_actFullscreen = new QAction( tr( "Fullscreen" ), QString::null, 0, this, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( setfullscreen(bool) ) );
a->setOn(m_fullscreen);
a->addTo( file );
a = new QAction( tr( "Continuous" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( setcontinuous(bool) ) );
a->setOn(reader->m_continuousDocument);
a->addTo( file );
a = m_bkmkAvail = new QAction( tr( "Annotation" ), Resource::loadPixmap( "find" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( showAnnotation() ) );
a->addTo( bar );
m_bkmkAvail->setEnabled(false);
ag = new QActionGroup(this);
// ag->setExclusive(false);
encoding = new QPopupMenu(this);
format->insertItem( tr( "Markup" ), encoding );
a = new QAction( tr( "Auto" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->bautofmt);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( autofmt(bool) ) );
a = new QAction( tr( "None" ), QString::null, 0, ag, NULL, true );
a->setOn(!reader->bautofmt && !(reader->btextfmt || reader->bstriphtml || reader->bpeanut));
// connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) );
a = new QAction( tr( "Text" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->btextfmt);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( textfmt(bool) ) );
a = new QAction( tr( "HTML" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->bstriphtml);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( striphtml(bool) ) );
a = new QAction( tr( "Peanut/PML" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->bpeanut);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( peanut(bool) ) );
ag->addTo(encoding);
ag = new QActionGroup(this);
ag->setExclusive(false);
encoding = new QPopupMenu(this);
format->insertItem( tr( "Layout" ), encoding );
a = new QAction( tr( "Strip CR" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->bstripcr);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( stripcr(bool) ) );
a = new QAction( tr( "Dehyphen" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->bdehyphen);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( dehyphen(bool) ) );
// a->addTo( format );
a = new QAction( tr( "Single Space" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->bonespace);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( onespace(bool) ) );
a = new QAction( tr( "Unindent" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( unindent(bool) ) );
a->setOn(reader->bunindent);
// a->addTo( format );
a = new QAction( tr( "Re-paragraph" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( repara(bool) ) );
a->setOn(reader->brepara);
// a->addTo( format );
a = new QAction( tr( "Double Space" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( dblspce(bool) ) );
a->setOn(reader->bdblspce);
// a->addTo( format );
a = new QAction( tr( "Indent+" ), QString::null, 0, ag, NULL );
connect( a, SIGNAL( activated() ), this, SLOT( indentplus() ) );
// a->addTo( format );
a = new QAction( tr( "Indent-" ), QString::null, 0, ag, NULL );
connect( a, SIGNAL( activated() ), this, SLOT( indentminus() ) );
#ifdef REPALM
a = new QAction( tr( "Repalm" ), QString::null, 0, ag, NULL, true );
a->setOn(reader->brepalm);
connect( a, SIGNAL( toggled(bool) ), this, SLOT( repalm(bool) ) );
#endif
a = new QAction( tr( "Remap" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( remap(bool) ) );
a->setOn(reader->bremap);
a = new QAction( tr( "Embolden" ), QString::null, 0, ag, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( embolden(bool) ) );
a->setOn(reader->bmakebold);
ag->addTo(encoding);
// a = new QAction( tr( "Zoom" ), QString::null, 0, this, NULL, true );
// a = new QAction( tr( "Zoom" ), Resource::loadPixmap( "mag" ), QString::null, 0, this, 0 );
format->insertSeparator();
a = new QAction( tr( "Zoom In" ), QString::null, 0, this);
connect( a, SIGNAL( activated() ), this, SLOT( zoomin() ) );
a->addTo( format );
a = new QAction( tr( "Zoom Out" ), QString::null, 0, this);
connect( a, SIGNAL( activated() ), this, SLOT( zoomout() ) );
a->addTo( format );
// a->addTo( editBar );
format->insertSeparator();
a = new QAction( tr( "Ideogram/Word" ), QString::null, 0, this, NULL, true );
connect( a, SIGNAL( toggled(bool) ), this, SLOT( monospace(bool) ) );
a->setOn(reader->m_bMonoSpaced);
a->addTo( format );
a = new QAction( tr( "Set width" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( setspacing() ) );
a->addTo( format );
encoding = new QPopupMenu(this);
// format->insertSeparator();
format->insertItem( tr( "Encoding" ), encoding );
ag = new QActionGroup(this);
m_EncodingAction[0] = new QAction( tr( "Ascii" ), QString::null, 0, ag, NULL, true );
m_EncodingAction[1] = new QAction( tr( "UTF-8" ), QString::null, 0, ag, NULL, true );
m_EncodingAction[2] = new QAction( tr( "UCS-2(BE)" ), QString::null, 0, ag, NULL, true );
m_EncodingAction[3] = new QAction( tr( "USC-2(LE)" ), QString::null, 0, ag, NULL, true );
m_EncodingAction[4] = new QAction( tr( "Palm" ), QString::null, 0, ag, NULL, true );
m_EncodingAction[5] = new QAction( tr( "Windows(1252)" ), QString::null, 0, ag, NULL, true );
ag->addTo(encoding);
connect(ag, SIGNAL( selected(QAction*) ), this, SLOT( encodingSelected(QAction*) ) );
a = new QAction( tr( "Set Font" ), QString::null, 0, this);
connect( a, SIGNAL( activated() ), this, SLOT( setfont() ) );
format->insertSeparator();
a->addTo( format );
QPopupMenu *marks = new QPopupMenu( this );
a = new QAction( tr( "Mark" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( addbkmk() ) );
a->addTo( marks );
a = new QAction( tr( "Annotate" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( addanno() ) );
a->addTo( marks );
a = new QAction( tr( "Goto" ), QString::null, 0, this, NULL, false );
connect( a, SIGNAL( activated() ), this, SLOT( do_gotomark() ) );
a->addTo( marks );
a = new QAction( tr( "Delete" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( do_delmark() ) );
a->addTo( marks );
a = new QAction( tr( "Autogen" ), QString::null, 0, this, NULL, false );
connect( a, SIGNAL( activated() ), this, SLOT( do_autogen() ) );
marks->insertSeparator();
a->addTo( marks );
a = new QAction( tr( "Clear" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( clearBkmkList() ) );
a->addTo( marks );
a = new QAction( tr( "Save" ), QString::null, 0, this, NULL );
connect( a, SIGNAL( activated() ), this, SLOT( savebkmks() ) );
a->addTo( marks );
a = new QAction( tr( "Tidy" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( listBkmkFiles() ) );
marks->insertSeparator();
a->addTo( marks );
a = new QAction( tr( "Start Block" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( editMark() ) );
marks->insertSeparator();
a->addTo( marks );
a = new QAction( tr( "Copy Block" ), QString::null, 0, this, NULL);
connect( a, SIGNAL( activated() ), this, SLOT( editCopy() ) );
a->addTo( marks );
mb->insertItem( tr( "File" ), file );
// mb->insertItem( tr( "Edit" ), edit );
mb->insertItem( tr( "Format" ), format );
mb->insertItem( tr( "Marks" ), marks );
searchBar = new QFloatBar( "Search", this, QMainWindow::Top, TRUE );
searchBar->setHorizontalStretchable( TRUE );
connect(searchBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
searchEdit = new QLineEdit( searchBar, "searchEdit" );
// QFont f("unifont", 16 /*, QFont::Bold*/);
// searchEdit->setFont( f );
searchBar->setStretchableWidget( searchEdit );
#ifdef __ISEARCH
connect( searchEdit, SIGNAL( textChanged( const QString & ) ),
this, SLOT( search( const QString& ) ) );
#else
connect( searchEdit, SIGNAL( returnPressed( ) ),
this, SLOT( search( ) ) );
#endif
a = new QAction( tr( "Find Next" ), Resource::loadPixmap( "next" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findNext() ) );
a->addTo( searchBar );
a = new QAction( tr( "Close Find" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( findClose() ) );
a->addTo( searchBar );
searchBar->hide();
regBar = new QFloatBar( "Autogen", this, QMainWindow::Top, TRUE );
connect(regBar, SIGNAL( OnHide() ), this, SLOT( restoreFocus() ));
regBar->setHorizontalStretchable( TRUE );
regEdit = new QLineEdit( regBar, "regEdit" );
// regEdit->setFont( f );
regBar->setStretchableWidget( regEdit );
connect( regEdit, SIGNAL( returnPressed( ) ),
this, SLOT( do_regaction() ) );
a = new QAction( tr( "Do Reg" ), Resource::loadPixmap( "enter" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( do_regaction() ) );
a->addTo( regBar );
a = new QAction( tr( "Close Edit" ), Resource::loadPixmap( "close" ), QString::null, 0, this, 0 );
connect( a, SIGNAL( activated() ), this, SLOT( regClose() ) );
a->addTo( regBar );
regBar->hide();
m_fontBar = new QToolBar( "Autogen", this, QMainWindow::Top, TRUE );
m_fontBar->setHorizontalStretchable( TRUE );
qDebug("Font selector");
m_fontSelector = new QComboBox(false, m_fontBar);
m_fontBar->setStretchableWidget( m_fontSelector );
{
FontDatabase f;
QStringList flist = f.families();
m_fontSelector->insertStringList(flist);
bool realfont = false;
for (QStringList::Iterator nm = flist.begin(); nm != flist.end(); nm++)
{
if (reader->m_fontname == *nm)
{
realfont = true;
}
if (*nm == "courier") reader->m_fontControl.hasCourier(true);
}
if (!realfont) reader->m_fontname = flist[0];
} // delete the FontDatabase!!!
connect( m_fontSelector, SIGNAL( activated(const QString& ) ),
this, SLOT( do_setfont(const QString&) ) );
m_fontBar->hide();
m_fontVisible = false;
connect(qApp, SIGNAL( appMessage(const QCString&, const QByteArray& ) ),
this, SLOT( msgHandler(const QCString&, const QByteArray&) ) );
qDebug("Initing");
reader->init();
qDebug("Inited");
m_EncodingAction[reader->m_encd]->setOn(true);
m_buttonAction[m_spaceTarget]->setOn(true);
qDebug("fonting");
do_setfont(reader->m_fontname);
if (!reader->m_lastfile.isEmpty())
{
qDebug("doclnk");
// doc = new DocLnk(reader->m_lastfile);
qDebug("doclnk done");
if (pOpenlist != NULL)
{
/*
int ind = 0;
Bkmk* p = (*pOpenlist)[ind];
while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile)
{
p = (*pOpenlist)[++ind];
}
*/
Bkmk* p = NULL;
for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++)
{
p = iter.pContent();
if (toQString(CFiledata(p->anno()).name()) == reader->m_lastfile)
{
break;
}
qDebug("Item:%s", (const char*)toQString(CFiledata(p->anno()).name()));
p = NULL;
}
if (p != NULL)
{
qDebug("openfrombkmk");
openfrombkmk(p);
}
else
{
qDebug("openfile");
openFile( reader->m_lastfile );
}
}
else
{
qDebug("Openfile 2");
if (!reader->m_lastfile.isNull())
openFile( reader->m_lastfile );
}
}
qApp->processEvents();
reader->bDoUpdates = true;
reader->update();
qDebug("finished update");
}
void QTReaderApp::suspend() { reader->suspend(); }
void QTReaderApp::msgHandler(const QCString& _msg, const QByteArray& _data)
{
QString msg = QString::fromUtf8(_msg);
// qDebug("Received:%s", (const char*)msg);
QDataStream stream( _data, IO_ReadOnly );
if ( msg == "info(QString)" )
{
QString info;
stream >> info;
QMessageBox::information(this, PROGNAME, info);
}
else if ( msg == "warn(QString)" )
{
QString info;
stream >> info;
QMessageBox::warning(this, PROGNAME, info);
}
else if ( msg == "exit()" )
{
m_dontSave = true;
close();
}
else if ( msg == "pageDown()" )
{
reader->dopagedn();
}
else if ( msg == "pageUp()" )
{
reader->dopageup();
}
else if ( msg == "lineDown()" )
{
reader->lineDown();
}
else if ( msg == "lineUp()" )
{
reader->lineUp();
}
else if ( msg == "showText()" )
{
showEditTools();
}
else if ( msg == "File/Open(QString)" )
{
QString info;
stream >> info;
openFile( info );
}
else if ( msg == "File/Info()" )
{
showinfo();
}
else if ( msg == "File/Start Block()" )
{
editMark();
}
else if ( msg == "File/Copy Block()" )
{
editCopy();
}
else if ( msg == "File/Scroll(int)" )
{
int info;
stream >> info;
autoScroll(info);
}
else if ( msg == "File/Jump(int)" )
{
int info;
stream >> info;
reader->locate(info);
}
else if ( msg == "File/Page/Line Scroll(int)" )
{
int info;
stream >> info;
pagemode(info);
}
else if ( msg == "File/Set Overlap(int)" )
{
int info;
stream >> info;
reader->m_overlap = info;
}
else if ( msg == "File/Set Dictionary(QString)" )
{
QString info;
stream >> info;
do_settarget(info);
}
else if ( msg == "File/Two/One Touch(int)" )
{
int info;
stream >> info;
setTwoTouch(info);
}
else if ( msg == "Target/Annotation(int)" )
{
int info;
stream >> info;
OnAnnotation(info);
}
else if ( msg == "Target/Dictionary(int)" )
{
int info;
stream >> info;
OnDictionary(info);
}
else if ( msg == "Target/Clipboard(int)" )
{
int info;
stream >> info;
OnClipboard(info);
}
else if ( msg == "File/Find(QString)" )
{
QString info;
stream >> info;
QRegExp arg(info);
size_t pos = reader->pagelocate();
size_t start = pos;
CDrawBuffer test(&(reader->m_fontControl));
reader->buffdoc.getline(&test,reader->width());
while (arg.match(toQString(test.data())) == -1)
{
pos = reader->locate();
if (!reader->buffdoc.getline(&test,reader->width()))
{
QMessageBox::information(this, PROGNAME, QString("Can't find\n")+info);
pos = start;
break;
}
}
reader->locate(pos);
}
else if ( msg == "Layout/Strip CR(int)" )
{
int info;
stream >> info;
stripcr(info);
}
else if ( msg == "Layout/Single Space" )
{
int info;
stream >> info;
onespace(info);
}
#ifdef REPALM
else if ( msg == "Layout/Repalm(int)" )
{
int info;
stream >> info;
repalm(info);
}
#endif
else if ( msg == "Markup/Auto(int)" )
{
int info;
stream >> info;
autofmt(info);
}
else if ( msg == "Markup/Text(int)" )
{
int info;
stream >> info;
textfmt(info);
}
else if ( msg == "Markup/HTML(int)" )
{
int info;
stream >> info;
striphtml(info);
}
else if ( msg == "Markup/Peanut(int)" )
{
int info;
stream >> info;
peanut(info);
}
else if ( msg == "Layout/Dehyphen(int)" )
{
int info;
stream >> info;
dehyphen(info);
}
else if ( msg == "Layout/Unindent(int)" )
{
int info;
stream >> info;
unindent(info);
}
else if ( msg == "Layout/Re-paragraph(int)" )
{
int info;
stream >> info;
repara(info);
}
else if ( msg == "Layout/Double Space(int)" )
{
int info;
stream >> info;
dblspce(info);
}
else if ( msg == "Layout/Indent(int)" )
{
int info;
stream >> info;
reader->bindenter = info;
reader->setfilter(reader->getfilter());
}
else if ( msg == "Layout/Remap(int)" )
{
int info;
stream >> info;
remap(info);
}
else if ( msg == "Layout/Embolden(int)" )
{
int info;
stream >> info;
embolden(info);
}
else if ( msg == "Format/Ideogram/Word(int)" )
{
int info;
stream >> info;
monospace(info);
}
else if ( msg == "Format/Set width(int)" )
{
int info;
stream >> info;
reader->m_charpc = info;
reader->setfont();
reader->refresh();
}
else if ( msg == "Format/Encoding(QString)" )
{
QString info;
stream >> info;
reader->setencoding(EncNameToInt(info));
}
else if ( msg == "Format/Set Font(QString,int)" )
{
QString fontname;
int size;
stream >> fontname;
stream >> size;
setfontHelper(fontname, size);
}
else if ( msg == "Marks/Autogen(QString)" )
{
QString info;
stream >> info;
do_autogen(info);
}
}
ActionTypes QTReaderApp::ActNameToInt(const QString& _enc)
{
for (int i = 0; i < MAX_ACTIONS; i++)
{
if (m_buttonAction[i]->text() == _enc) return (ActionTypes)i;
}
return cesAutoScroll;
}
void QTReaderApp::setfullscreen(bool sfs)
{
reader->bDoUpdates = false;
m_fullscreen = sfs;
showEditTools();
qApp->processEvents();
reader->bDoUpdates = true;
reader->update();
}
void QTReaderApp::setcontinuous(bool sfs)
{
reader->setContinuous(sfs);
reader->refresh();
}
int QTReaderApp::EncNameToInt(const QString& _enc)
{
for (int i = 0; i < MAX_ENCODING; i++)
{
if (m_EncodingAction[i]->text() == _enc) return i;
}
return 0;
/*
if (_enc == "Ascii") return 0;
if (_enc == "UTF-8") return 1;
if (_enc == "UCS-2(BE)") return 2;
if (_enc == "USC-2(LE)") return 3;
*/
}
void QTReaderApp::encodingSelected(QAction* _a)
{
// qDebug("es:%x : %s", _a, (const char *)(_a->text()));
reader->setencoding(EncNameToInt(_a->text()));
}
void QTReaderApp::buttonActionSelected(QAction* _a)
{
// qDebug("es:%x : %s (%u)", _a, (const char *)(_a->text()), ActNameToInt(_a->text()));
m_spaceTarget = ActNameToInt(_a->text());
}
QTReaderApp::~QTReaderApp()
{
}
void QTReaderApp::autoScroll(bool _b)
{
reader->setautoscroll(_b);
setScrollState(reader->m_autoScroll);
}
void QTReaderApp::zoomin()
{
reader->zoomin();
}
void QTReaderApp::zoomout()
{
reader->zoomout();
}
void QTReaderApp::clearBkmkList()
{
delete pBkmklist;
pBkmklist = NULL;
m_fBkmksChanged = false;
}
void QTReaderApp::fileClose()
{
if (pOpenlist != NULL)
{
int ind = 0;
Bkmk* p = (*pOpenlist)[ind];
while (p != NULL && toQString(CFiledata(p->anno()).name()) != reader->m_lastfile)
{
p = (*pOpenlist)[++ind];
}
if (p != NULL) pOpenlist->erase(ind);
switch (QMessageBox::information ( this , PROGNAME, "What do you want to delete?", "Nothing", "Marks", "Marks\nFile", 1, 0 ))
{
case 0:
default:
break;
case 2:
unlink((const char*)reader->m_lastfile);
case 1:
unlink((const char *)Global::applicationFileName(APPDIR, reader->m_string));
}
}
fileOpen2();
}
void QTReaderApp::updatefileinfo()
{
if (reader->m_string.isNull()) return;
if (reader->m_lastfile.isNull()) return;
tchar* nm = fromQString(reader->m_string);
tchar* fl = fromQString(reader->m_lastfile);
qDebug("Lastfile:%x", fl);
bool notadded = true;
if (pOpenlist == NULL) pOpenlist = new CList<Bkmk>;
else
{
for (CList<Bkmk>::iterator iter = pOpenlist->begin(); iter != pOpenlist->end(); iter++)
{
if (ustrcmp(CFiledata(iter->anno()).name(), fl) == 0)
{
iter->value(reader->pagelocate());
unsigned short dlen;
unsigned char* data;
CFiledata fd(iter->anno());
reader->setSaveData(data, dlen, fd.content(), fd.length());
qDebug("Filedata(1):%u, %u", fd.length(), dlen);
// getstate(data, dlen);
iter->setAnno(data, dlen);
notadded = false;
delete [] data;
break;
}
}
}
qDebug("Added?:%x", notadded);
if (notadded)
{
struct stat fnstat;
stat((const char *)reader->m_lastfile, &fnstat);
CFiledata fd(fnstat.st_mtime, fl);
unsigned short dlen;
unsigned char* data;
reader->setSaveData(data, dlen, fd.content(), fd.length());
pOpenlist->push_front(Bkmk(nm, data, dlen, reader->pagelocate()));
qDebug("Filedata(2):%u, %u", fd.length(), dlen);
delete [] data;
}
delete [] nm;
delete [] fl;
}
void QTReaderApp::fileOpen()
{
/*
menu->hide();
editBar->hide();
if (regVisible) regBar->hide();
if (searchVisible) searchBar->hide();
*/
qDebug("fileOpen");
// if (!reader->m_lastfile.isEmpty())
updatefileinfo();
fileOpen2();
}
void QTReaderApp::fileOpen2()
{
if (pBkmklist != NULL)
{
if (m_fBkmksChanged)
{
if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0)
savebkmks();
}
delete pBkmklist;
pBkmklist = NULL;
m_fBkmksChanged = false;
}
reader->disableAutoscroll();
/*
editorStack->raiseWidget( fileSelector );
fileSelector->reread();
*/
if (pOpenlist != NULL)
{
m_nRegAction = cOpenFile;
listbkmk(pOpenlist, "Browse");
}
else
{
QString fn = usefilebrowser();
if (!fn.isEmpty() && QFileInfo(fn).isFile())
{
openFile(fn);
}
reader->setFocus();
}
}
QString QTReaderApp::usefilebrowser()
{
fileBrowser* fb = new fileBrowser(this,"QTReader",TRUE,
0,
// WStyle_Customize | WStyle_NoBorderEx,
"*", QFileInfo(reader->m_lastfile).dirPath(true));
QString fn;
if (fb->exec())
{
fn = fb->fileList[0];
}
qDebug("Selected %s", (const char*)fn);
delete fb;
return fn;
}
void QTReaderApp::showgraphic(QPixmap& pm)
{
m_graphicwin->setPixmap(pm);
editorStack->raiseWidget( m_graphicwin );
m_graphicwin->setFocus();
}
void QTReaderApp::showinfo()
{
unsigned long fs, ts, pl;
if (reader->empty())
{
QMessageBox::information(this, PROGNAME, "No file loaded", 1);
}
else
{
reader->sizes(fs,ts);
pl = reader->pagelocate();
m_infoWin->setFileSize(fs);
m_infoWin->setTextSize(ts);
m_infoWin->setRatio(100-(100*fs + (ts >> 1))/ts);
m_infoWin->setLocation(pl);
m_infoWin->setRead((100*pl + (ts >> 1))/ts);
editorStack->raiseWidget( m_infoWin );
m_infoWin->setFocus();
}
}
void QTReaderApp::addAnno(const QString& name, const QString& text, size_t posn)
{
if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
#ifdef _UNICODE
CBuffer buff(name.length()+1);
int i;
for (i = 0; i < name.length(); i++)
{
buff[i] = name[i].unicode();
}
buff[i] = 0;
CBuffer buff2(text.length()+1);
for (i = 0; i < text.length(); i++)
{
buff2[i] = text[i].unicode();
}
buff2[i] = 0;
pBkmklist->push_front(Bkmk(buff.data(), buff2.data(), posn));
#else
pBkmklist->push_front(Bkmk((const tchar*)text,posn));
#endif
m_fBkmksChanged = true;
pBkmklist->sort();
}
void QTReaderApp::addAnno(const QString& name, const QString& text)
{
if (m_annoIsEditing)
{
if (name.isEmpty())
{
QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nPlease try again", 1);
}
else
{
addAnno(name, text, m_annoWin->getPosn());
}
showEditTools();
}
else
{
if (m_annoWin->edited())
{
CBuffer buff(text.length()+1);
int i;
for (i = 0; i < text.length(); i++)
{
buff[i] = text[i].unicode();
}
buff[i] = 0;
m_fBkmksChanged = true;
m_anno->setAnno(buff.data());
}
bool found = findNextBookmark(m_anno->value()+1);
if (found)
{
m_annoWin->setName(toQString(m_anno->name()));
m_annoWin->setAnno(toQString(m_anno->anno()));
}
else
{
showEditTools();
}
}
}
bool QTReaderApp::findNextBookmark(size_t start)
{
bool found = false;
for (CList<Bkmk>::iterator iter = pBkmklist->begin(); iter != pBkmklist->end(); iter++)
{
if (iter->value() >= start)
{
if (iter->value() < reader->locate())
{
found = true;
m_anno = iter.pContent();
}
break;
}
}
return found;
}
void QTReaderApp::addanno()
{
if (reader->empty())
{
QMessageBox::information(this, PROGNAME, "No file loaded", 1);
}
else
{
m_annoWin->setName("");
m_annoWin->setAnno("");
m_annoWin->setPosn(reader->pagelocate());
m_annoIsEditing = true;
editorStack->raiseWidget( m_annoWin );
Global::showInputMethod();
m_annoWin->setFocus();
}
}
void QTReaderApp::infoClose()
{
showEditTools();
}
/*
void QTReaderApp::fileRevert()
{
clear();
fileOpen();
}
void QTReaderApp::editCut()
{
#ifndef QT_NO_CLIPBOARD
editor->cut();
#endif
}
*/
void QTReaderApp::editMark()
{
m_savedpos = reader->pagelocate();
}
void QTReaderApp::editCopy()
{
QClipboard* cb = QApplication::clipboard();
QString text;
int ch;
unsigned long currentpos = reader->pagelocate();
unsigned long endpos = reader->locate();
reader->jumpto(m_savedpos);
while (reader->explocate() < endpos && (ch = reader->getch()) != UEOF)
{
text += ch;
}
cb->setText(text);
reader->locate(currentpos);
}
void QTReaderApp::pageup()
{
reader->NavUp();
}
void QTReaderApp::pagedn()
{
reader->NavDown();
}
void QTReaderApp::stripcr(bool _b)
{
reader->setstripcr(_b);
}
void QTReaderApp::onespace(bool _b)
{
reader->setonespace(_b);
}
#ifdef REPALM
void QTReaderApp::repalm(bool _b)
{
reader->setrepalm(_b);
}
#endif
void QTReaderApp::remap(bool _b)
{
reader->setremap(_b);
}
void QTReaderApp::peanut(bool _b)
{
reader->setpeanut(_b);
}
void QTReaderApp::embolden(bool _b)
{
reader->setmakebold(_b);
}
void QTReaderApp::autofmt(bool _b)
{
reader->setautofmt(_b);
}
void QTReaderApp::textfmt(bool _b)
{
reader->settextfmt(_b);
}
void QTReaderApp::striphtml(bool _b)
{
reader->setstriphtml(_b);
}
void QTReaderApp::dehyphen(bool _b)
{
reader->setdehyphen(_b);
}
void QTReaderApp::unindent(bool _b)
{
reader->setunindent(_b);
}
void QTReaderApp::repara(bool _b)
{
reader->setrepara(_b);
}
void QTReaderApp::dblspce(bool _b)
{
reader->setdblspce(_b);
}
void QTReaderApp::pagemode(bool _b)
{
reader->setpagemode(_b);
}
void QTReaderApp::navkeys(bool _b)
{
reader->m_navkeys = _b;
}
void QTReaderApp::monospace(bool _b)
{
reader->setmono(_b);
}
void QTReaderApp::setspacing()
{
m_nRegAction = cMonoSpace;
char lcn[20];
sprintf(lcn, "%lu", reader->m_charpc);
regEdit->setText(lcn);
do_regedit();
}
void QTReaderApp::setoverlap()
{
m_nRegAction = cOverlap;
char lcn[20];
sprintf(lcn, "%lu", reader->m_overlap);
regEdit->setText(lcn);
do_regedit();
}
void QTReaderApp::settarget()
{
m_nRegAction = cSetTarget;
QString text = ((m_targetapp.isEmpty()) ? QString("") : m_targetapp)
+ "/"
+ ((m_targetmsg.isEmpty()) ? QString("") : m_targetmsg);
regEdit->setText(text);
do_regedit();
}
void QTReaderApp::do_overlap(const QString& lcn)
{
bool ok;
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
{
reader->m_overlap = ulcn;
}
else
QMessageBox::information(this, PROGNAME, "Must be a number");
}
void QTReaderApp::do_mono(const QString& lcn)
{
bool ok;
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
{
reader->m_charpc = ulcn;
reader->setfont();
reader->refresh();
// reader->setmono(true);
}
else
QMessageBox::information(this, PROGNAME, "Must be a number");
}
/*
void QTReaderApp::editPaste()
{
#ifndef QT_NO_CLIPBOARD
editor->paste();
#endif
}
*/
void QTReaderApp::editFind()
{
searchStart = reader->pagelocate();
#ifdef __ISEARCH
searchStack = new QStack<searchrecord>;
#endif
Global::showInputMethod();
searchBar->show();
searchVisible = TRUE;
searchEdit->setFocus();
#ifdef __ISEARCH
searchStack->push(new searchrecord("",reader->pagelocate()));
#endif
}
void QTReaderApp::findNext()
{
// qDebug("findNext called\n");
#ifdef __ISEARCH
QString arg = searchEdit->text();
#else
QRegExp arg = searchEdit->text();
#endif
CDrawBuffer test(&(reader->m_fontControl));
size_t start = reader->pagelocate();
reader->jumpto(start);
reader->buffdoc.getline(&test,reader->width());
dosearch(start, test, arg);
}
void QTReaderApp::findClose()
{
searchVisible = FALSE;
searchEdit->setText("");
Global::hideInputMethod();
searchBar->hide();
#ifdef __ISEARCH
// searchStack = new QStack<searchrecord>;
while (!searchStack->isEmpty())
{
delete searchStack->pop();
}
delete searchStack;
#endif
reader->setFocus();
}
void QTReaderApp::regClose()
{
regVisible = FALSE;
regEdit->setText("");
regBar->hide();
Global::hideInputMethod();
reader->setFocus();
}
#ifdef __ISEARCH
bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QString& arg)
#else
bool QTReaderApp::dosearch(size_t start, CDrawBuffer& test, const QRegExp& arg)
#endif
{
bool ret = true;
unsigned long fs, ts;
reader->sizes(fs,ts);
size_t pos = reader->locate();
reader->buffdoc.getline(&test,reader->width());
pbar->show();
pbar->resize(width(), editBar->height());
pbar->reset();
int lastpc = (100*pos)/ts;
pbar->setProgress(lastpc);
qApp->processEvents();
reader->setFocus();
#ifdef __ISEARCH
while (strstr(test.data(),(const tchar*)arg) == NULL)
#else
#ifdef _UNICODE
while (arg.match(toQString(test.data())) == -1)
#else
while (arg.match(test.data()) == -1)
#endif
#endif
{
pos = reader->locate();
unsigned int lcn = reader->locate();
int pc = (100*pos)/ts;
if (pc != lastpc)
{
pbar->setProgress(pc);
qApp->processEvents();
reader->setFocus();
lastpc = pc;
}
if (!reader->buffdoc.getline(&test,reader->width()))
{
if (QMessageBox::warning(this, "Can't find", searchEdit->text(), 1, 2) == 2)
pos = searchStart;
else
pos = start;
ret = false;
findClose();
break;
}
}
pbar->hide();
reader->locate(pos);
return ret;
}
#ifdef __ISEARCH
void QTReaderApp::search(const QString & arg)
{
searchrecord* ss = searchStack->top();
CBuffer test;
size_t start = reader->pagelocate();
bool haspopped = false;
while (arg.left(ss->s.length()) != ss->s)
{
haspopped = true;
start = ss->pos;
// reader->locate(start);
searchStack->pop();
delete ss;
}
if (haspopped) reader->locate(start);
/*
if (arg.length() < ss->len)
{
start = ss->pos;
reader->locate(start);
searchStack->pop();
delete ss;
}
*/
else
{
start = reader->pagelocate();
reader->jumpto(start);
searchStack->push(new searchrecord(arg,start));
}
dosearch(start, test, arg);
}
#else
void QTReaderApp::search()
{
findNext();
}
#endif
void QTReaderApp::openFile( const QString &f )
{
qDebug("File:%s", (const char*)f);
// openFile(DocLnk(f));
//}
//
//void QTReaderApp::openFile( const DocLnk &f )
//{
clear();
QFileInfo fm(f);
if ( fm.exists() )
{
// QMessageBox::information(0, "Progress", "Calling fileNew()");
if (fm.extension( FALSE ) == "desktop")
{
DocLnk d(f);
QFileInfo fnew(d.file());
fm = fnew;
if (!fm.exists()) return;
}
clear();
reader->setText(fm.baseName(), fm.absFilePath());
showEditTools();
readbkmks();
}
else
{
QMessageBox::information(this, PROGNAME, "File does not exist");
}
}
/*
void QTReaderApp::resizeEvent(QResizeEvent* e)
{
if (m_fullscreen)
{
showNormal();
showFullScreen();
}
}
*/
void QTReaderApp::keyPressEvent(QKeyEvent* e)
{
if (m_fullscreen)
{
switch(e->key())
{
case Key_Escape:
m_actFullscreen->setOn(false);
if (m_fullscreen)
{
qDebug("Fullscreen already set - remove this!");
}
else
{
m_fullscreen = false;
reader->bDoUpdates = false;
showEditTools();
qApp->processEvents();
reader->bDoUpdates = true;
reader->update();
}
e->accept();
break;
default:
e->ignore();
}
}
else
{
e->ignore();
}
}
void QTReaderApp::showEditTools()
{
// if ( !doc )
// close();
if (m_fullscreen)
{
editBar->hide();
searchBar->hide();
regBar->hide();
Global::hideInputMethod();
m_fontBar->hide();
// showNormal();
showFullScreen();
}
else
{
qDebug("him");
Global::hideInputMethod();
qDebug("eb");
editBar->show();
if ( searchVisible )
{
Global::showInputMethod();
searchBar->show();
}
if ( regVisible )
{
Global::showInputMethod();
regBar->show();
}
if (m_fontVisible) m_fontBar->show();
qDebug("sn");
showNormal();
qDebug("sm");
showMaximized();
// setCentralWidget(reader);
}
qDebug("uc");
updateCaption();
qDebug("rw");
editorStack->raiseWidget( reader );
qDebug("sf");
reader->setFocus();
}
/*
void QTReaderApp::save()
{
if ( !doc )
return;
if ( !editor->edited() )
return;
QString rt = editor->text();
QString pt = rt;
if ( doc->name().isEmpty() ) {
unsigned ispace = pt.find( ' ' );
unsigned ienter = pt.find( '\n' );
int i = (ispace < ienter) ? ispace : ienter;
QString docname;
if ( i == -1 ) {
if ( pt.isEmpty() )
docname = "Empty Text";
else
docname = pt;
} else {
docname = pt.left( i );
}
doc->setName(docname);
}
FileManager fm;
fm.saveFile( *doc, rt );
}
*/
void QTReaderApp::clear()
{
// if (doc != 0)
// {
// QMessageBox::information(this, PROGNAME, "Deleting doc", 1);
// delete doc;
// QMessageBox::information(this, PROGNAME, "Deleted doc", 1);
// doc = 0;
// }
reader->clear();
}
void QTReaderApp::updateCaption()
{
// if ( !doc )
// setCaption( tr("QTReader") );
// else {
// QString s = doc->name();
// if ( s.isEmpty() )
// s = tr( "Unnamed" );
setCaption( reader->m_string + " - " + tr(SHORTPROGNAME) );
// }
}
void QTReaderApp::setDocument(const QString& fileref)
{
bFromDocView = TRUE;
//QMessageBox::information(0, "setDocument", fileref);
openFile(fileref);
// showEditTools();
}
void QTReaderApp::closeEvent( QCloseEvent *e )
{
if (m_fullscreen)
{
m_fullscreen = false;
showEditTools();
e->accept();
}
else if (m_dontSave)
{
e->accept();
}
else
{
if (editorStack->visibleWidget() == reader)
{
if (m_fontVisible)
{
m_fontBar->hide();
m_fontVisible = false;
}
if (regVisible)
{
regBar->hide();
Global::hideInputMethod();
regVisible = false;
return;
}
if (searchVisible)
{
searchBar->hide();
Global::hideInputMethod();
searchVisible = false;
return;
}
if (m_fBkmksChanged && pBkmklist != NULL)
{
if (QMessageBox::warning(this, PROGNAME, "Save bookmarks?", "Save", "Don't bother") == 0)
savebkmks();
delete pBkmklist;
pBkmklist = NULL;
m_fBkmksChanged = false;
}
bFromDocView = FALSE;
updatefileinfo();
saveprefs();
e->accept();
}
else
{
showEditTools();
}
}
}
void QTReaderApp::do_gotomark()
{
m_nRegAction = cGotoBkmk;
listbkmk(pBkmklist);
}
void QTReaderApp::do_delmark()
{
m_nRegAction = cDelBkmk;
listbkmk(pBkmklist);
}
void QTReaderApp::listbkmk(CList<Bkmk>* plist, const QString& _lab)
{
bkmkselector->clear();
if (_lab.isNull())
bkmkselector->setText("Cancel");
else
bkmkselector->setText(_lab);
int cnt = 0;
if (plist != NULL)
{
for (CList<Bkmk>::iterator i = plist->begin(); i != plist->end(); i++)
{
#ifdef _UNICODE
qDebug("Item:%s", (const char*)toQString(i->name()));
bkmkselector->insertItem(toQString(i->name()));
#else
bkmkselector->insertItem(i->name());
#endif
cnt++;
}
}
if (cnt > 0)
{
//tjw menu->hide();
editBar->hide();
if (m_fontVisible) m_fontBar->hide();
if (regVisible)
{
Global::hideInputMethod();
regBar->hide();
}
if (searchVisible)
{
Global::hideInputMethod();
searchBar->hide();
}
editorStack->raiseWidget( bkmkselector );
}
else
QMessageBox::information(this, PROGNAME, "No bookmarks in memory");
}
void QTReaderApp::do_autogen()
{
m_nRegAction = cAutoGen;
regEdit->setText(m_autogenstr);
do_regedit();
}
void QTReaderApp::do_regedit()
{
// editBar->hide();
reader->bDoUpdates = false;
qDebug("Showing regbar");
regBar->show();
qDebug("Showing kbd");
Global::showInputMethod();
regVisible = true;
regEdit->setFocus();
qApp->processEvents();
reader->bDoUpdates = true;
reader->update();
}
bool QTReaderApp::openfrombkmk(Bkmk* bk)
{
QString fn = toQString(
CFiledata(bk->anno()).name()
);
qDebug("fileinfo");
if (!fn.isEmpty() && QFileInfo(fn).isFile())
{
qDebug("Opening");
openFile(fn);
struct stat fnstat;
stat((const char *)reader->m_lastfile, &fnstat);
if (CFiledata(bk->anno()).date()
!= fnstat.st_mtime)
{
CFiledata fd(bk->anno());
fd.setdate(fnstat.st_mtime);
bk->value(0);
}
else
{
unsigned short svlen = bk->filedatalen();
unsigned char* svdata = bk->filedata();
reader->putSaveData(svdata, svlen);
// setstate(svdata, svlen);
if (svlen != 0)
{
QMessageBox::warning(this, PROGNAME, "Not all file data used\nNew version?");
}
qDebug("updating");
reader->locate(bk->value());
}
return true;
}
else
{
return false;
}
}
void QTReaderApp::gotobkmk(int ind)
{
switch (m_nRegAction)
{
case cOpenFile:
{
if (!openfrombkmk((*pOpenlist)[ind]))
{
pOpenlist->erase(ind);
QMessageBox::information(this, PROGNAME, "Can't find file");
}
}
break;
case cGotoBkmk:
reader->locate((*pBkmklist)[ind]->value());
break;
case cDelBkmk:
// qDebug("Deleting:%s\n",(*pBkmklist)[ind]->name());
pBkmklist->erase(ind);
m_fBkmksChanged = true;
// pBkmklist->sort();
break;
case cRmBkmkFile:
unlink((const char *)Global::applicationFileName(APPDIR,bkmkselector->text(ind)));
break;
}
showEditTools();
}
void QTReaderApp::cancelbkmk()
{
if (m_nRegAction == cOpenFile)
{
QString fn = usefilebrowser();
if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn);
}
showEditTools();
}
void QTReaderApp::jump()
{
m_nRegAction = cJump;
char lcn[20];
sprintf(lcn, "%lu", reader->pagelocate());
regEdit->setText(lcn);
do_regedit();
}
void QTReaderApp::do_jump(const QString& lcn)
{
bool ok;
unsigned long ulcn = lcn.toULong(&ok);
if (ok)
reader->locate(ulcn);
else
QMessageBox::information(this, PROGNAME, "Must be a number");
}
void QTReaderApp::do_regaction()
{
reader->bDoUpdates = false;
regBar->hide();
Global::hideInputMethod();
regVisible = false;
switch(m_nRegAction)
{
case cAutoGen:
do_autogen(regEdit->text());
break;
case cAddBkmk:
do_addbkmk(regEdit->text());
break;
case cJump:
do_jump(regEdit->text());
break;
case cMonoSpace:
do_mono(regEdit->text());
break;
case cOverlap:
do_overlap(regEdit->text());
break;
case cSetTarget:
do_settarget(regEdit->text());
break;
}
reader->restore();
// editBar->show();
reader->setFocus();
qApp->processEvents();
reader->bDoUpdates = true;
reader->update();
}
void QTReaderApp::do_settarget(const QString& _txt)
{
int ind = _txt.find('/');
if (ind == -1)
{
m_targetapp = "";
m_targetmsg = "";
QMessageBox::information(this, PROGNAME, "Format is\nappname/messagename");
}
else
{
m_targetapp = _txt.left(ind);
m_targetmsg = _txt.right(_txt.length()-ind-1);
}
}
void QTReaderApp::setfont()
{
for (int i = 1; i <= m_fontSelector->count(); i++)
{
if (m_fontSelector->text(i) == reader->m_fontname)
{
m_fontSelector->setCurrentItem(i);
break;
}
}
m_fontBar->show();
m_fontVisible = true;
}
-void QTReaderApp::setfontHelper(const QString& lcn, int size = 0)
+void QTReaderApp::setfontHelper(const QString& lcn, int size)
{
if (size == 0) size = reader->m_fontControl.currentsize();
QFont f(lcn, 10 /*, QFont::Bold*/);
qDebug("bs");
bkmkselector->setFont( f );
qDebug("re");
regEdit->setFont( f );
qDebug("se");
searchEdit->setFont( f );
qDebug("aw");
m_annoWin->setFont( f );
reader->m_fontname = lcn;
qDebug("cf1");
if (!reader->ChangeFont(size))
{
qDebug("cf2");
reader->ChangeFont(size);
}
qDebug("ref");
reader->refresh();
m_fontBar->hide();
m_fontVisible = false;
qDebug("showedit");
if (reader->isVisible()) showEditTools();
qDebug("showeditdone");
}
void QTReaderApp::do_setfont(const QString& lcn)
{
setfontHelper(lcn);
}
void QTReaderApp::do_autogen(const QString& regText)
{
unsigned long fs, ts;
reader->sizes(fs,ts);
// qDebug("Reg:%s\n", (const tchar*)(regEdit->text()));
m_autogenstr = regText;
QRegExp re(regText);
CBuffer buff;
if (pBkmklist != NULL) delete pBkmklist;
pBkmklist = new CList<Bkmk>;
m_fBkmksChanged = true;
pbar->show();
pbar->resize(width(), editBar->height());
pbar->reset();
qApp->processEvents();
reader->setFocus();
reader->jumpto(0);
int lastpc = 0;
int i = 0;
while (i >= 0)
{
unsigned int lcn = reader->locate();
int pc = (100*lcn)/ts;
if (pc != lastpc)
{
pbar->setProgress(pc);
qApp->processEvents();
if (reader->locate() != lcn) reader->jumpto(lcn);
reader->setFocus();
lastpc = pc;
}
i = reader->buffdoc.getpara(buff);
#ifdef _UNICODE
if (re.match(toQString(buff.data())) != -1)
#else
if (re.match(buff.data()) != -1)
#endif
pBkmklist->push_back(Bkmk(buff.data(), NULL, lcn));
}
pBkmklist->sort();
pbar->setProgress(100);
qApp->processEvents();
pbar->hide();
}
void QTReaderApp::saveprefs()
{
// reader->saveprefs("uqtreader");
Config config( APPDIR );
config.setGroup( "View" );
reader->m_lastposn = reader->pagelocate();
config.writeEntry( "StripCr", reader->bstripcr );
config.writeEntry( "AutoFmt", reader->bautofmt );
config.writeEntry( "TextFmt", reader->btextfmt );
config.writeEntry( "StripHtml", reader->bstriphtml );
config.writeEntry( "Dehyphen", reader->bdehyphen );
config.writeEntry( "OneSpace", reader->bonespace );
config.writeEntry( "Unindent", reader->bunindent );
config.writeEntry( "Repara", reader->brepara );
config.writeEntry( "DoubleSpace", reader->bdblspce );
config.writeEntry( "Indent", reader->bindenter );
config.writeEntry( "FontSize", (int)(reader->m_fontControl.currentsize()) );
config.writeEntry( "ScrollDelay", reader->m_delay);
config.writeEntry( "LastFile", reader->m_lastfile );
config.writeEntry( "LastPosn", (int)(reader->pagelocate()) );
config.writeEntry( "PageMode", reader->m_bpagemode );
config.writeEntry( "CursorNavigation", reader->m_navkeys );
config.writeEntry( "MonoSpaced", reader->m_bMonoSpaced );
config.writeEntry( "Fontname", reader->m_fontname );
config.writeEntry( "Encoding", reader->m_encd );
config.writeEntry( "CharSpacing", reader->m_charpc );
config.writeEntry( "Overlap", (int)(reader->m_overlap) );
config.writeEntry( "TargetApp", m_targetapp );
config.writeEntry( "TargetMsg", m_targetmsg );
config.writeEntry( "TwoTouch", m_twoTouch );
config.writeEntry( "Annotation", m_doAnnotation);
config.writeEntry( "Dictionary", m_doDictionary);
config.writeEntry( "Clipboard", m_doClipboard);
config.writeEntry( "SpaceTarget", m_spaceTarget);
#ifdef REPALM
config.writeEntry( "Repalm", reader->brepalm );
#endif
config.writeEntry( "Remap", reader->bremap );
config.writeEntry( "Peanut", reader->bpeanut );
config.writeEntry( "MakeBold", reader->bmakebold );
config.writeEntry( "Continuous", reader->m_continuousDocument );
savefilelist();
}
void QTReaderApp::indentplus()
{
reader->indentplus();
}
void QTReaderApp::indentminus()
{
reader->indentminus();
}
/*
void QTReaderApp::oldFile()
{
qDebug("oldFile called");
reader->setText(true);
qDebug("settext called");
showEditTools();
qDebug("showedit called");
}
*/
/*
void info_cb(Fl_Widget* o, void* _data)
{
if (infowin == NULL)
{
infowin = new Fl_Window(160,240);
filename = new Fl_Output(45,5,110,14,"Filename");
filesize = new Fl_Output(45,25,110,14,"Filesize");
textsize = new Fl_Output(45,45,110,14,"Textsize");
comprat = new CBar(45,65,110,14,"Ratio %");
posn = new Fl_Output(45,85,110,14,"Location");
frcn = new CBar(45,105,110,14,"% Read");
about = new Fl_Multiline_Output(5,125,150,90);
about->value("TWReader - $Name$\n\nA file reader program for the Agenda\n\nReads text, PalmDoc and ppms format files");
Fl_Button *jump_accept = new Fl_Button(62,220,35,14,"Okay");
infowin->set_modal();
}
if (((reader_ui *)_data)->g_filename[0] != '\0')
{
unsigned long fs,ts;
tchar sz[20];
((reader_ui *)_data)->input->sizes(fs,ts);
unsigned long pl = ((reader_ui *)_data)->input->locate();
filename->value(((reader_ui *)_data)->g_filename);
sprintf(sz,"%u",fs);
filesize->value(sz);
sprintf(sz,"%u",ts);
textsize->value(sz);
comprat->value(100-(100*fs + (ts >> 1))/ts);
sprintf(sz,"%u",pl);
posn->value(sz);
frcn->value((100*pl + (ts >> 1))/ts);
}
infowin->show();
}
*/
void QTReaderApp::savebkmks()
{
if (pBkmklist != NULL)
{
BkmkFile bf((const char *)Global::applicationFileName(APPDIR, reader->m_string), true);
bf.write(*pBkmklist);
}
m_fBkmksChanged = false;
}
void QTReaderApp::readfilelist()
{
BkmkFile bf((const char *)Global::applicationFileName(APPDIR, ".openfiles"));
qDebug("Reading open files");
pOpenlist = bf.readall();
if (pOpenlist != NULL) qDebug("...with success");
else qDebug("...without success!");
}
void QTReaderApp::savefilelist()
{
if (pOpenlist != NULL)
{
BkmkFile bf((const char *)Global::applicationFileName(APPDIR, ".openfiles"), true);
qDebug("Writing open files");
bf.write(*pOpenlist);
}
}
void QTReaderApp::readbkmks()
{
if (pBkmklist != NULL)
{
delete pBkmklist;
}
struct stat fnstat;
struct stat bkstat;
if (
stat((const char *)reader->m_lastfile, &fnstat) == 0
&&
stat((const char *)Global::applicationFileName(APPDIR, reader->m_string), &bkstat) == 0
)
{
if (bkstat.st_mtime < fnstat.st_mtime)
{
unlink((const char *)Global::applicationFileName(APPDIR, reader->m_string));
}
}
BkmkFile bf((const char *)Global::applicationFileName(APPDIR, reader->m_string));
pBkmklist = bf.readall();
m_fBkmksChanged = bf.upgraded();
if (pBkmklist == NULL)
{
pBkmklist = reader->getbkmklist();
}
if (pBkmklist != NULL)
pBkmklist->sort();
}
void QTReaderApp::addbkmk()
{
m_nRegAction = cAddBkmk;
regEdit->setText(reader->firstword());
do_regedit();
}
void QTReaderApp::do_addbkmk(const QString& text)
{
if (text.isEmpty())
{
QMessageBox::information(this, PROGNAME, "Need a name for the bookmark\nSelect add again", 1);
}
else
{
if (pBkmklist == NULL) pBkmklist = new CList<Bkmk>;
#ifdef _UNICODE
CBuffer buff;
int i = 0;
for (i = 0; i < text.length(); i++)
{
buff[i] = text[i].unicode();
}
buff[i] = 0;
pBkmklist->push_front(Bkmk(buff.data(), NULL, reader->pagelocate()));
#else
pBkmklist->push_front(Bkmk((const tchar*)text, reader->pagelocate()));
#endif
m_fBkmksChanged = true;
pBkmklist->sort();
}
}
void QTReaderApp::OnRedraw()
{
if (pBkmklist != NULL)
{
bool found = findNextBookmark(reader->pagelocate());
m_bkmkAvail->setEnabled(found);
}
}
void QTReaderApp::showAnnotation()
{
m_annoWin->setName(toQString(m_anno->name()));
m_annoWin->setAnno(toQString(m_anno->anno()));
m_annoIsEditing = false;
Global::showInputMethod();
editorStack->raiseWidget( m_annoWin );
m_annoWin->setFocus();
}
void QTReaderApp::OnWordSelected(const QString& wrd, size_t posn, const QString& line)
{
// qDebug("OnWordSelected(%u):%s", posn, (const char*)wrd);
if (m_doClipboard)
{
QClipboard* cb = QApplication::clipboard();
cb->setText(wrd);
if (wrd.length() > 10)
{
Global::statusMessage(wrd.left(8) + "..");
}
else
{
Global::statusMessage(wrd);
}
}
if (m_doAnnotation)
{
// addAnno(wrd, "Need to be able to edit this", posn);
m_annoWin->setName(line);
m_annoWin->setAnno("");
m_annoWin->setPosn(posn);
m_annoIsEditing = true;
Global::showInputMethod();
editorStack->raiseWidget( m_annoWin );
}
if (m_doDictionary)
{
if (!m_targetapp.isEmpty() && !m_targetmsg.isEmpty())
{
QCopEnvelope e(("QPE/Application/"+m_targetapp).utf8(), (m_targetmsg+"(QString)").utf8());
e << wrd;
}
}
}
void QTReaderApp::OnActionPressed()
{
switch (m_spaceTarget)
{
case cesOpenFile:
{
fileOpen();
}
break;
case cesAutoScroll:
{
reader->setautoscroll(!reader->m_autoScroll);
setScrollState(reader->m_autoScroll);
}
break;
case cesActionMark:
{
addbkmk();
}
break;
case cesFullScreen:
{
m_actFullscreen->setOn(true);
}
break;
default:
{
qDebug("Unknown ActionType:%u", m_spaceTarget);
}
break;
}
}
void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); }
void QTReaderApp::restoreFocus() { reader->setFocus(); }
/*
void QTReaderApp::setstate(unsigned char* _sd, unsigned short _sdlen)
{
unsigned short sdlen;
memcpy(&sdlen, _sd, sizeof(sdlen));
sdlen -= sizeof(sdlen);
_sd += sizeof(sdlen);
statedata* sd;
char* data;
if (sdlen < sizeof(statedata)+1)
{
sdlen = sizeof(statedata)+1;
}
data = new char[sdlen];
sd = (statedata*)data;
memcpy(sd, _sd, sdlen);
data[sdlen] = 0;
reader->setstate(*sd);
delete [] data;
}
void QTReaderApp::getstate(unsigned char*& data, unsigned short& len)
{
unsigned char* olddata = data;
unsigned short oldlen = len;
len = oldlen+sizeof(unsigned short)+sizeof(statedata)+reader->m_fontname.length();
data = new unsigned char[len];
memcpy(data, olddata, oldlen);
delete [] olddata;
memcpy(data+oldlen, &len, sizeof(len));
statedata* sd = (statedata*)(data+oldlen+sizeof(unsigned short));
sd->bstripcr = reader->bstripcr;
sd->btextfmt = reader->btextfmt;
sd->bautofmt = reader->bautofmt;
sd->bstriphtml = reader->bstriphtml;
sd->bpeanut = reader->bpeanut;
sd->bdehyphen = reader->bdehyphen;
sd->bonespace = reader->bonespace;
sd->bunindent = reader->bunindent;
sd->brepara = reader->brepara;
sd->bdblspce = reader->bdblspce;
sd->m_bpagemode = reader->m_bpagemode;
sd->m_navkeys = reader->m_navkeys;
sd->m_bMonoSpaced = reader->m_bMonoSpaced;
sd->bremap = reader->bremap;
sd->bmakebold = reader->bmakebold;
sd->Continuous = reader->m_continuousDocument;
#ifdef REPALM
sd->brepalm = reader->brepalm;
#endif
sd->bindenter = reader->bindenter;
sd->m_textsize = reader->m_textsize; //reader->m_fontControl.currentsize()
sd->m_encd = reader->m_encd;
sd->m_charpc = reader->m_charpc;
strcpy(sd->m_fontname, reader->m_fontname.latin1());
}
*/
diff --git a/noncore/apps/opie-reader/infowin.cpp b/noncore/apps/opie-reader/infowin.cpp
index 30adebf..459b648 100644
--- a/noncore/apps/opie-reader/infowin.cpp
+++ b/noncore/apps/opie-reader/infowin.cpp
@@ -1,43 +1,43 @@
#include "name.h"
#include "infowin.h"
#include "version.h"
#include <stdio.h>
-infowin::infowin( QWidget *parent=0, const char *name=0, WFlags f = 0) :
+infowin::infowin( QWidget *parent, const char *name, WFlags f ) :
QWidget(parent, name, f)
{
grid = new QGridLayout(this, 6, 2);
QLabel* l;
l = new QLabel("Compressed file size", this);
grid->addWidget(l, 0, 0);
fileSize = new QLabel("0", this);
fileSize->setAlignment( AlignVCenter | AlignRight );
grid->addWidget(fileSize, 0, 1);
l = new QLabel("Original text size", this);
grid->addWidget(l, 1, 0);
textSize = new QLabel("0", this);
textSize->setAlignment( AlignVCenter | AlignRight );
grid->addWidget(textSize, 1, 1);
l = new QLabel("Compression Ratio", this);
grid->addWidget(l, 2, 0);
ratio = new QLabel("0", this);
grid->addWidget(ratio, 2, 1);
ratio->setAlignment( AlignVCenter | AlignRight );
l = new QLabel("Current location", this);
grid->addWidget(l, 3, 0);
location = new QLabel("0", this);
location->setAlignment( AlignVCenter | AlignRight );
grid->addWidget(location, 3, 1);
l = new QLabel("Per centage read", this);
grid->addWidget(l, 4, 0);
read = new QLabel("0", this);
read->setAlignment( AlignVCenter | AlignRight );
grid->addWidget(read, 4, 1);
char vstr[128];
sprintf(vstr, PROGNAME " v%u.%u%c (%s)\nA small e-text reader", MAJOR, BKMKTYPE, MINOR, RELEASE_TYPE);
l = new QLabel(vstr, this);
grid->addWidget(l, 5, 0);
QPushButton* exitbutton = new QPushButton("Cancel", this);
connect( exitbutton, SIGNAL( released() ), this, SLOT( infoClose() ) );
grid->addWidget(exitbutton, 5, 1);
}