-rw-r--r-- | noncore/apps/opie-reader/Bkmks.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-reader/CBuffer.cpp | 4 | ||||
-rw-r--r-- | noncore/apps/opie-reader/CDrawBuffer.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-reader/QTReader.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-reader/QTReaderApp.cpp | 2 | ||||
-rw-r--r-- | noncore/apps/opie-reader/infowin.cpp | 2 |
6 files changed, 7 insertions, 7 deletions
diff --git a/noncore/apps/opie-reader/Bkmks.cpp b/noncore/apps/opie-reader/Bkmks.cpp index 0cb9ea9..30d2881 100644 --- a/noncore/apps/opie-reader/Bkmks.cpp +++ b/noncore/apps/opie-reader/Bkmks.cpp @@ -1,240 +1,240 @@ #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 tchar* _nm, const tchar* _anno, unsigned int _p) : m_position(_p) { int len = ustrlen(_nm)+1; m_name = new tchar[len]; for (int i = 0; i < len; i++) m_name[i] = _nm[i]; if (_anno == NULL) { m_anno = new tchar[1]; m_anno[0] = 0; } else { len = ustrlen(_anno)+1; m_anno = new tchar[len]; for (int i = 0; i < len; i++) m_anno[i] = _anno[i]; } } 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) { int len = ustrlen(rhs.m_name)+1; m_name = new tchar[len]; for (int i = 0; i < len; i++) m_name[i] = rhs.m_name[i]; } else m_name = NULL; if (rhs.m_anno != NULL) { int len = ustrlen(rhs.m_anno)+1; m_anno = new tchar[len]; for (int i = 0; i < len; i++) m_anno[i] = rhs.m_anno[i]; } else m_anno = NULL; m_position = rhs.m_position; return *this; } bool Bkmk::operator==(const Bkmk& rhs) { return (m_position == rhs.m_position && ustrcmp(m_name,rhs.m_name) == 0); } void Bkmk::setAnno(tchar* t) { if (m_anno != NULL) { delete [] m_anno; m_anno = NULL; } if (t != NULL) { int len = ustrlen(t)+1; m_anno = new tchar[len]; for (int i = 0; i < len; i++) m_anno[i] = t[i]; } else m_anno = NULL; } -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(tchar* nm, tchar* an, const unsigned int& pos) { if (f != NULL) { unsigned short ln = ustrlen(nm); fwrite(&ln,sizeof(ln),1,f); fwrite(nm,sizeof(tchar),ln,f); ln = ustrlen(an); fwrite(&ln,sizeof(ln),1,f); if (ln > 0) fwrite(an,sizeof(tchar),ln,f); fwrite(&pos,sizeof(pos),1,f); } } void BkmkFile::write(const Bkmk& b) { write(b.name(), b.anno(), b.value()); } 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); } } } Bkmk* BkmkFile::read() { Bkmk* b = NULL; if (f != NULL) { unsigned short ln; if (fread(&ln,sizeof(ln),1,f) == 1) { b = new Bkmk; b->m_name = new tchar[ln+1]; fread(b->m_name,sizeof(tchar),ln,f); b->m_name[ln] = 0; fread(&ln,sizeof(ln),1,f); b->m_anno = new tchar[ln+1]; if (ln > 0) fread(b->m_anno,sizeof(tchar),ln,f); b->m_anno[ln] = 0; fread(&b->m_position,sizeof(b->m_position),1,f); } } return b; } CList<Bkmk>* BkmkFile::readall() { CList<Bkmk>* bl = NULL; if (f != NULL) { unsigned long newmagic; fread(&newmagic, sizeof(newmagic), 1, f); if (newmagic != magic) { if (QMessageBox::warning(NULL, "Old bookmark file!", "Which version of OpieReader\ndid you upgrade from?", "0_4*", "Any other version") == 0) { fseek(f,0,SEEK_SET); bl = readall04(); } else { fseek(f,0,SEEK_SET); bl = readall03(); } isUpgraded = true; } else { bl = readall04(); } } return bl; } CList<Bkmk>* BkmkFile::readall04() { CList<Bkmk>* bl = new CList<Bkmk>; while (1) { Bkmk* b = read(); if (b == NULL) break; bl->push_back(*b); delete b; } return bl; } CList<Bkmk>* BkmkFile::readall03() { CList<Bkmk>* bl = new CList<Bkmk>; while (1) { Bkmk* b = read03(); if (b == NULL) break; bl->push_back(*b); delete b; } return bl; } Bkmk* BkmkFile::read03() { Bkmk* b = NULL; if (f != NULL) { unsigned short ln; if (fread(&ln,sizeof(ln),1,f) == 1) { b = new Bkmk; b->m_name = new tchar[ln+1]; fread(b->m_name,sizeof(tchar),ln,f); b->m_name[ln] = 0; ln = 0; b->m_anno = new tchar[ln+1]; b->m_anno[ln] = 0; 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/CDrawBuffer.cpp b/noncore/apps/opie-reader/CDrawBuffer.cpp index 2ceb2d5..892456f 100644 --- a/noncore/apps/opie-reader/CDrawBuffer.cpp +++ b/noncore/apps/opie-reader/CDrawBuffer.cpp @@ -1,211 +1,211 @@ #include "CDrawBuffer.h" #include "FontControl.h" #include <qfontmetrics.h> #include <qpainter.h> void CDrawBuffer::setright(CDrawBuffer& rhs, int f) { int i; // qDebug("Trying 1:%d:%s", f, (const char*)toQString(rhs.data())); len = rhs.len; m_maxstyle = rhs.m_maxstyle; m_ascent = rhs.m_ascent; m_descent = rhs.m_descent; m_lineSpacing = rhs.m_lineSpacing; while (!segs.isEmpty()) segs.erase(0); for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); ) { CList<textsegment>::iterator next = iter; iter++; if (iter == rhs.segs.end() || iter->start > f) { int st = next->start-f; if (st < 0) st = 0; segs.push_back(textsegment(st,next->style)); } } for (i = f; rhs[i] != '\0'; i++) (*this)[i-f] = rhs[i]; (*this)[i-f] = '\0'; len = i; // qDebug("Tried 1"); } CDrawBuffer& CDrawBuffer::operator=(CDrawBuffer& rhs) { int i; // qDebug("Trying 2"); len = rhs.len; m_maxstyle = rhs.m_maxstyle; m_ascent = rhs.m_ascent; m_descent = rhs.m_descent; m_lineSpacing = rhs.m_lineSpacing; while (!segs.isEmpty()) segs.erase(0); for (CList<textsegment>::iterator iter = rhs.segs.begin(); iter != rhs.segs.end(); iter++) { segs.push_back(*iter); } for (i = 0; rhs[i] != '\0'; i++) (*this)[i] = rhs[i]; (*this)[i] = '\0'; len = i; // qDebug("Tried 2"); return *this; } CDrawBuffer& CDrawBuffer::operator=(const tchar*sztmp) { int i; while (!segs.isEmpty()) segs.erase(0); segs.push_back(textsegment(0, CStyle())); for (i = 0; sztmp[i] != '\0'; i++) (*this)[i] = sztmp[i]; (*this)[i] = '\0'; len = i; return *this; } void CDrawBuffer::empty() { len = 0; (*this)[0] = 0; while (!segs.isEmpty()) segs.erase(0); segs.push_back(textsegment(0,CStyle())); m_maxstyle = m_ascent = m_descent = m_lineSpacing = 0; } void CDrawBuffer::addch(tchar ch, CStyle _style/* = ucFontBase*/) { if (len == 0) { int thissize = fc->getsize(_style); m_maxstyle = thissize; m_ascent = fc->ascent(_style); m_descent = fc->descent(_style); m_lineSpacing = fc->lineSpacing(_style); segs.first().start = 0; segs.first().style = _style; } else if (_style != segs.last().style) { int thissize = fc->getsize(_style); if (thissize > m_maxstyle) { m_maxstyle = thissize; m_ascent = fc->ascent(_style); m_descent = fc->descent(_style); m_lineSpacing = fc->lineSpacing(_style); } segs.push_back(textsegment(len, _style)); } (*this)[len++] = ch; } void CDrawBuffer::truncate(int n) { len = n; (*this)[n] = 0; } -int CDrawBuffer::width(int numchars = -1) +int CDrawBuffer::width(int numchars) { int currentx = 0, end = 0; QString text = toQString(data()); CList<textsegment>::iterator textstart = segs.begin(); CList<textsegment>::iterator textend = textstart; do { textend++; end = (textend != segs.end()) ? textend->start : length(); if (numchars >= 0 && end > numchars) { end = numchars; } CStyle currentstyle = textstart->style; QFont f(fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); QString str = text.mid(textstart->start, end-textstart->start); QFontMetrics fm(f); currentx += fm.width(str); textstart = textend; } while (textend != segs.end() && end != numchars); return currentx; } void CDrawBuffer::render(QPainter* _p, int _y, bool _bMono, int _charWidth, int scwidth) { int currentx = 0; QString text = toQString(data()); CList<textsegment>::iterator textstart = segs.begin(); StyleType align = textstart->style.getJustify(); switch (align) { case CStyle::m_AlignRight: { // int linelength = width(); currentx = scwidth - width(); } break; case CStyle::m_AlignCentre: { // int linelength = width(); currentx = (scwidth - width())/2; } break; case CStyle::m_AlignJustify: case CStyle::m_AlignLeft: break; } CList<textsegment>::iterator textend = textstart; do { textend++; int end = (textend != segs.end()) ? textend->start : length(); CStyle currentstyle = textstart->style; QFont f(fc->name(), fc->getsize(currentstyle), (currentstyle.isBold()) ? QFont::Bold : QFont::Normal, (currentstyle.isItalic()) ); _p->setFont(f); QString str = text.mid(textstart->start, end-textstart->start); _p->setPen(QColor(currentstyle.Red(), currentstyle.Green(), currentstyle.Blue())); if (_bMono) { for (int i = 0; i < str.length(); i++) { _p->drawText( currentx + i*_charWidth, _y, QString(str[i])); } currentx += str.length()*_charWidth; } else { _p->drawText( currentx, _y, str); QFontMetrics fm(f); currentx += fm.width(str); } textstart = textend; } while (textend != segs.end()); } CStyle CDrawBuffer::laststyle() { return segs.last().style; } bool CDrawBuffer::isLink(int numchars, size_t& tgt) { int end = 0; CStyle currentstyle; CList<textsegment>::iterator textstart = segs.begin(); CList<textsegment>::iterator textend = textstart; do { textend++; end = (textend != segs.end()) ? textend->start : length(); if (numchars >= 0 && end > numchars) { end = numchars; } currentstyle = textstart->style; textstart = textend; } while (textend != segs.end() && end != numchars); tgt = currentstyle.getData(); return currentstyle.getLink(); } diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp index e7bfc28..7cf08e5 100644 --- a/noncore/apps/opie-reader/QTReader.cpp +++ b/noncore/apps/opie-reader/QTReader.cpp @@ -1,806 +1,806 @@ /**************************************************************************** ** $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> #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) { m_overlap = 1; // init(); } /* QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : 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 ) { if (_e->button() == RightButton) { mouseUpOn = false; if (_e->y() > height()/2) { goDown(); } else { goUp(); } } } bool 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]; for (i = t->length(); t->width(i) > x; i--); offset = i; } return textarray[lineno]->isLink(offset, tgt); } void QTReader::setTwoTouch(bool _b) { setBackgroundColor( white ); m_twotouch = m_touchone = _b; } void QTReader::mouseReleaseEvent( QMouseEvent* _e ) { 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; if (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt)) { if (buffdoc.hyperlink(tgt)) { fillbuffer(); update(); } else { locate(pagelocate()); } 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; while (1) { int i = first+1; while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; if (t->width(i) > _e->x()) { 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::keyPressEvent(QKeyEvent* e) { 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_fontControl.increasesize()) { bool sc = m_autoScroll; setfont(); m_autoScroll = false; locate(pagelocate()); update(); m_autoScroll = sc; if (m_autoScroll) autoscroll(); } } break; case Key_Left: { e->accept(); if (m_fontControl.decreasesize()) { bool sc = m_autoScroll; m_autoScroll = false; setfont(); locate(pagelocate()); update(); m_autoScroll = sc; if (m_autoScroll) autoscroll(); } } 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 { m_autoScroll = true; autoscroll(); QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed } } bool QTReader::getline(CDrawBuffer *buff) { 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; } locnarray[numlines] = locate(); int ch = getline(textarray[numlines]); textarray[numlines-1]->render(&p, height() - textarray[numlines]->descent() - 2, m_bMonoSpaced, m_charWidth, width()); mylastpos = locate(); if (!ch) { m_autoScroll = false; ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); emit OnRedraw(); } 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 ) { setfont(); if (m_lastwidth != width() || m_lastheight != height()) { m_lastwidth = width(); m_lastheight = height(); locate(pagelocate()); } else { /* int sl = screenlines(); if (sl < numlines) { // qDebug("df:<%u,%u>",sl,numlines); size_t newpos = locnarray[sl]; CDrawBuffer** nta = new CDrawBuffer*[sl]; size_t* nla = new size_t[sl]; for (int i = 0; i < sl; i++) { nta[i] = textarray[i]; nla[i] = locnarray[i]; } for (int i = sl; i < numlines; i++) delete textarray[i]; delete [] locnarray; delete [] textarray; textarray = nta; locnarray = nla; numlines = sl; jumpto(mylastpos = newpos); } if (sl > numlines) { // qDebug("df:<%u,%u>",sl,numlines); CDrawBuffer** nta = new CDrawBuffer*[sl]; size_t* nla = new size_t[sl]; for (int i = 0; i < numlines; i++) { nta[i] = textarray[i]; nla[i] = locnarray[i]; } if (locate() != mylastpos) jumpto(mylastpos); for (int i = numlines; i < sl; i++) { nta[i] = new CDrawBuffer(&m_fontControl); nla[i] = locate(); getline(nta[i]); } mylastpos = locate(); delete [] locnarray; delete [] textarray; textarray = nta; locnarray = nla; numlines = sl; } */ 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; textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); } // mylastpos = locate(); } } m_scrolldy1 = m_scrolldy2 = 0; emit OnRedraw(); } 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" ); 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); m_lastwidth = width(); m_lastheight = height(); 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.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) { 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()) { 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[0] == buffdoc.locate()*/) { locate(oldpagepos); return false; } else { --numlines; mylastpos = locate(); return true; } } } --numlines; mylastpos = locate(); return true; } void QTReader::dopagedn() { int skip = 0, ypos = 0; if (locate() != mylastpos) { // qDebug("Jumping to %u", mylastpos); jumpto(mylastpos); } CDrawBuffer* reusebuffer = textarray[numlines]; 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; locnarray[offset] = locnarray[i]; locnarray[i] = reuselocn; ypos += textarray[i]->lineSpacing(); skip++; } } if (fillbuffer(skip, ypos)) { update(); } } void QTReader::dopageup() { CBufferFace<CDrawBuffer*> buff; CBufferFace<size_t> loc; unsigned int target = locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]; size_t delta; if (target < 2048) { delta = target; jumpto(0); } else { delta = 2048; diff --git a/noncore/apps/opie-reader/QTReaderApp.cpp b/noncore/apps/opie-reader/QTReaderApp.cpp index ef1f4f1..8726df7 100644 --- a/noncore/apps/opie-reader/QTReaderApp.cpp +++ b/noncore/apps/opie-reader/QTReaderApp.cpp @@ -944,1086 +944,1086 @@ void QTReaderApp::fileOpen() if (QMessageBox::warning(this, "OpieReader", "Save bookmarks?", "Save", "Don't bother") == 0) savebkmks(); } delete pBkmklist; pBkmklist = NULL; m_fBkmksChanged = false; } reader->disableAutoscroll(); /* editorStack->raiseWidget( fileSelector ); fileSelector->reread(); */ fileBrowser* fb = new fileBrowser(this,"OpieReader",TRUE, 0, // WStyle_Customize | WStyle_NoBorderEx, "*", QFileInfo(reader->m_lastfile).dirPath(true)); if (fb->exec()) { QString fn(fb->fileList[0]); // fb->populateList(); if (!fn.isEmpty() && QFileInfo(fn).isFile()) openFile(fn); } delete fb; reader->setFocus(); } void QTReaderApp::showinfo() { unsigned long fs, ts, pl; if (reader->empty()) { QMessageBox::information(this, "OpieReader", "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, "OpieReader", "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, "OpieReader", "No file loaded", 1); } else { m_annoWin->setName(""); m_annoWin->setAnno(""); m_annoWin->setPosn(reader->pagelocate()); m_annoIsEditing = true; editorStack->raiseWidget( m_annoWin ); 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->goUp(); } void QTReaderApp::pagedn() { reader->goDown(); } void QTReaderApp::stripcr(bool _b) { reader->setstripcr(_b); } 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::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, "OpieReader", "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, "OpieReader", "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 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(""); 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(); 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; size_t pos = reader->locate(); reader->buffdoc.getline(&test,reader->width()); #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(); 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; } } 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 ) { openFile(DocLnk(f)); } void QTReaderApp::openFile( const DocLnk &f ) { clear(); FileManager fm; if ( fm.exists( f ) ) { // QMessageBox::information(0, "Progress", "Calling fileNew()"); clear(); // editorStack->raiseWidget( reader ); // reader->setFocus(); // QMessageBox::information(0, "DocLnk", "Begin"); doc = new DocLnk(f); // QMessageBox::information(0, "DocLnk done", doc->file()); // QMessageBox::information(0, "Progress", "Calling setText()"); // QMessageBox::information(0, "Progress", "Textset"); // updateCaption(); showEditTools(); reader->setText(doc->name(), doc->file()); readbkmks(); } else { QMessageBox::information(this, "OpieReader", "File does not exist"); } } void QTReaderApp::showEditTools() { if ( !doc ) close(); // fileSelector->hide(); //tjw menu->show(); editBar->show(); if ( searchVisible ) searchBar->show(); if ( regVisible ) regBar->show(); if (m_fontVisible) m_fontBar->show(); updateCaption(); editorStack->raiseWidget( reader ); 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, "QTReader", "Deleting doc", 1); delete doc; // QMessageBox::information(this, "QTReader", "Deleted doc", 1); doc = 0; } reader->clear(); } void QTReaderApp::updateCaption() { if ( !doc ) setCaption( tr("OpieReader") ); else { QString s = doc->name(); if ( s.isEmpty() ) s = tr( "Unnamed" ); setCaption( s + " - " + tr("OpieReader") ); } } void QTReaderApp::setDocument(const QString& fileref) { bFromDocView = TRUE; //QMessageBox::information(0, "setDocument", fileref); openFile(DocLnk(fileref)); // showEditTools(); } void QTReaderApp::closeEvent( QCloseEvent *e ) { if (m_dontSave) { e->accept(); } else { if (editorStack->visibleWidget() == reader) { if (m_fontVisible) { m_fontBar->hide(); m_fontVisible = false; } if (regVisible) { regBar->hide(); regVisible = false; return; } if (searchVisible) { searchBar->hide(); searchVisible = false; return; } if (m_fBkmksChanged && pBkmklist != NULL) { if (QMessageBox::warning(this, "OpieReader", "Save bookmarks?", "Save", "Don't bother") == 0) savebkmks(); delete pBkmklist; pBkmklist = NULL; m_fBkmksChanged = false; } bFromDocView = FALSE; saveprefs(); e->accept(); } else { showEditTools(); } } } void QTReaderApp::do_gotomark() { m_nRegAction = cGotoBkmk; listbkmk(); } void QTReaderApp::do_delmark() { m_nRegAction = cDelBkmk; listbkmk(); } void QTReaderApp::listbkmk() { bkmkselector->clear(); int cnt = 0; if (pBkmklist != NULL) { for (CList<Bkmk>::iterator i = pBkmklist->begin(); i != pBkmklist->end(); i++) { #ifdef _UNICODE 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) regBar->hide(); if (searchVisible) searchBar->hide(); editorStack->raiseWidget( bkmkselector ); } else QMessageBox::information(this, "OpieReader", "No bookmarks in memory"); } void QTReaderApp::do_autogen() { m_nRegAction = cAutoGen; regEdit->setText(m_autogenstr); do_regedit(); } void QTReaderApp::do_regedit() { // editBar->hide(); regBar->show(); regVisible = true; regEdit->setFocus(); } void QTReaderApp::gotobkmk(int ind) { switch (m_nRegAction) { 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("uqtreader",bkmkselector->text(ind))); break; } showEditTools(); } void QTReaderApp::cancelbkmk() { 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, "OpieReader", "Must be a number"); } void QTReaderApp::do_regaction() { regBar->hide(); 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(); } void QTReaderApp::do_settarget(const QString& _txt) { int ind = _txt.find('/'); if (ind == -1) { m_targetapp = ""; m_targetmsg = ""; QMessageBox::information(this, "OpieReader", "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*/); bkmkselector->setFont( f ); regEdit->setFont( f ); searchEdit->setFont( f ); m_annoWin->setFont( f ); reader->m_fontname = lcn; if (!reader->ChangeFont(size)) { reader->ChangeFont(size); } reader->refresh(); m_fontBar->hide(); m_fontVisible = false; showEditTools(); } 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( "uqtreader" ); 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( "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( "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); config.writeEntry( "Remap", reader->bremap ); config.writeEntry( "Peanut", reader->bpeanut ); config.writeEntry( "MakeBold", reader->bmakebold ); } 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("uqtreader",reader->m_string), true); bf.write(*pBkmklist); } m_fBkmksChanged = false; } void QTReaderApp::readbkmks() { if (pBkmklist != NULL) { delete pBkmklist; } BkmkFile bf((const char *)Global::applicationFileName("uqtreader",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, "OpieReader", "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; 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; 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; default: { qDebug("Unknown ActionType:%u", m_spaceTarget); } break; } } void QTReaderApp::setTwoTouch(bool _b) { reader->setTwoTouch(_b); } void QTReaderApp::restoreFocus() { reader->setFocus(); } diff --git a/noncore/apps/opie-reader/infowin.cpp b/noncore/apps/opie-reader/infowin.cpp index 9637a62..7b8f280 100644 --- a/noncore/apps/opie-reader/infowin.cpp +++ b/noncore/apps/opie-reader/infowin.cpp @@ -1,42 +1,42 @@ #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, "QT Reader 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); } |