author | groucho <groucho> | 2003-05-07 09:01:39 (UTC) |
---|---|---|
committer | groucho <groucho> | 2003-05-07 09:01:39 (UTC) |
commit | 118d03d815a7615b9c53363218a7ac45b3f4c514 (patch) (side-by-side diff) | |
tree | 356953e2413cddcec0f35bd47bb6439767da7051 /noncore/apps/opie-reader/QTReader.cpp | |
parent | 00894537decf01c5a5cdc565b2740b5e67a2e90f (diff) | |
download | opie-118d03d815a7615b9c53363218a7ac45b3f4c514.zip opie-118d03d815a7615b9c53363218a7ac45b3f4c514.tar.gz opie-118d03d815a7615b9c53363218a7ac45b3f4c514.tar.bz2 |
Incorporated TimWs current source tree and make it compile
Diffstat (limited to 'noncore/apps/opie-reader/QTReader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/QTReader.cpp | 716 |
1 files changed, 476 insertions, 240 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp index f2ee027..03c8fbe 100644 --- a/noncore/apps/opie-reader/QTReader.cpp +++ b/noncore/apps/opie-reader/QTReader.cpp @@ -10,3 +10,6 @@ +#include "useqpe.h" #include <qpainter.h> +#include <qimage.h> +#include <qtimer.h> #include "config.h" @@ -15,3 +18,5 @@ #include "CDrawBuffer.h" +#ifdef USEQPE #include <qpe/qpeapplication.h> +#endif #include <math.h> @@ -19,8 +24,9 @@ #include <stdio.h> //for sprintf +#ifdef USEQPE #include <qpe/config.h> #include <qpe/applnk.h> -#include <qfontdatabase.h> #include <qpe/global.h> #include <qpe/qcopenvelope_qws.h> -#include "StateData.h" +#endif +#include <qfontdatabase.h> @@ -38,2 +44,6 @@ const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; +tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; +tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; +//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; + QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : @@ -53,9 +63,14 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : bDoUpdates(false), - m_navkeys(true) +#ifdef _SCROLLPIPE + m_pipeout(NULL), +#endif + m_border(2) { m_overlap = 1; + setKeyCompression ( true ); // init(); } + /* -QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, WFlags f ) : +QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : QWidget(parent, name, f), @@ -74,3 +89,3 @@ QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, init(); - // qDebug("Load_file(1)"); +// // qDebug("Load_file(1)"); load_file((const tchar*)filename); @@ -79,2 +94,11 @@ QTReader::QTReader( const QString& filename, QWidget *parent, const tchar *name, +/* +void QTReader::mouseMoveEvent(QMouseEvent* _e) +{ + + mouseUpOn = !(_e->pos().x() == -1); + + qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y()); +} +*/ long QTReader::real_delay() @@ -89,37 +113,32 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) { +// qDebug("MousePress"); mouseUpOn = false; - if (buffdoc.hasnavigation()) + if (m_swapmouse) { - 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 + int lineno = 0; + int ht = textarray[0]->lineSpacing(); + while ((ht < _e->y()) && (lineno < numlines)) { - buffdoc.saveposn(pagelocate()); - locate(buffdoc.getHome()); + ht += textarray[++lineno]->lineSpacing(); } - } + size_t startpos, startoffset, tgt; + getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt); + processmousewordevent(startpos, startoffset, _e, lineno); + } + else + processmousepositionevent(_e); + } +} + +void QTReader::processmousepositionevent( QMouseEvent* _e ) +{ + if (buffdoc.hasnavigation()) + { + if (_e->y() > (2*height())/3) + { + goDown(); + } + else if (_e->y() < height()/3) + { + goUp(); } @@ -127,5 +146,9 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) { - if (_e->y() > height()/2) + if (_e->x() < width()/3) { - goDown(); + goBack(); + } + else if (_e->x() > (2*width())/3) + { + goForward(); } @@ -133,3 +156,3 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) { - goUp(); + goHome(); } @@ -137,2 +160,52 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) } + else + { + if (_e->y() > height()/2) + { + goDown(); + } + else + { + goUp(); + } + } +} + +void QTReader::goHome() +{ + if (buffdoc.hasnavigation()) + { + size_t current=pagelocate(); + size_t home=buffdoc.getHome(); + if (current!=home) + { + buffdoc.saveposn(current); + locate(home); + } + } +} + +void QTReader::goBack() +{ + if (buffdoc.hasnavigation()) + { + size_t target = pagelocate(); + buffdoc.writeposn(target); + if (buffdoc.back(target)) + { + locate(target); + } + } +} + +void QTReader::goForward() +{ + if (buffdoc.hasnavigation()) + { + size_t target = pagelocate(); + if (buffdoc.forward(target)) + { + locate(target); + } + } } @@ -150,3 +223,3 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si { - offset = x/m_charWidth; + offset = (x - textarray[lineno]->offset(width(), m_border))/m_charWidth; } @@ -156,4 +229,4 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si CDrawBuffer* t = textarray[lineno]; - x = x - t->offset(width()); - for (i = t->length(); i >= 0 && t->width(i) > x; i--); + x = x - t->offset(width(), m_border); + for (i = t->length(); i >= 0 && t->width(i, true, width(), m_border) > x; i--); offset = i; @@ -163,2 +236,11 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si +void QTReader::suspend() +{ +#ifdef OPIE + if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend(); +#else + if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend(); +#endif +} + void QTReader::setTwoTouch(bool _b) @@ -175,2 +257,86 @@ void QTReader::setContinuous(bool _b) +void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) +{ + QString wrd; + 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()-textarray[lineno]->offset(width(), m_border))/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(), m_border); + while (1) + { + int i = first+1; + while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; + if (t->width(i, true, width(), m_border) > tgt) + { + wrd = toQString(t->data()+first, i - first); +// qDebug("Got %s", (const char *)wrd); + break; + } + while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; + if ((*t)[i] == 0) break; + first = i; + } + } + if (!wrd.isEmpty()) + { +// qDebug("Selected:%s", (const char*)wrd); + emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); + } +} + void QTReader::mouseReleaseEvent( QMouseEvent* _e ) @@ -182,5 +348,11 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) { +// qDebug("MouseRelease"); + if (_e->x() > width() - m_border) + { + locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*_e->y()+height()/2)/height()); + return; + } if (textarray[0] != NULL) { - QString wrd, line; + QString line; // int lineno = _e->y()/m_linespacing; @@ -198,3 +370,5 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) size_t saveposn = pagelocate(); - if (buffdoc.hyperlink(tgt)) + QString href; + linkType lt = buffdoc.hyperlink(tgt, href); + if (lt == eLink) { @@ -206,2 +380,19 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) { + if (lt == ePicture) + { + QImage* pm = buffdoc.getPicture(tgt); + if (pm != NULL) + { + emit OnShowPicture(*pm); + delete pm; + } + } + else + { +// QString anchortext = textarray[lineno]->getanchortext(startoffset); + if (!href.isEmpty()) + { + emit OnURLSelected(href); + } + } locate(pagelocate()); @@ -212,4 +403,4 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) { - qDebug("Picture:%x", tgt); - QPixmap* pm = buffdoc.getPicture(tgt); +// qDebug("Picture:%x", tgt); + QImage* pm = buffdoc.getPicture(tgt); if (pm != NULL) @@ -228,82 +419,9 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e ) default: - qDebug("Unknown linktype"); +// 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]; - } - } + if (m_swapmouse) + processmousepositionevent(_e); 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())); - } + processmousewordevent(startpos, startoffset, _e, lineno); } @@ -328,3 +446,3 @@ void QTReader::focusOutEvent(QFocusEvent* e) timer->stop(); - m_scrolldy1 = m_scrolldy2 = 0; +// m_scrolldy1 = m_scrolldy2 = 0; } @@ -334,3 +452,5 @@ void QTReader::focusOutEvent(QFocusEvent* e) #include <qdrawutil.h> +#ifndef _WINDOWS #include <unistd.h> +#endif @@ -428,2 +548,28 @@ void QTReader::zoomout() +void QTReader::reduceScroll() +{ + if (m_delay < 59049) + { + m_delay = (3*m_delay)/2; + timer->changeInterval(real_delay()); + } + else + { + m_delay = 59049; + } +} + +void QTReader::increaseScroll() +{ + if (m_delay > 1024) + { + m_delay = (2*m_delay)/3; + timer->changeInterval(real_delay()); + } + else + { + m_delay = 1024; + } +} + void QTReader::keyPressEvent(QKeyEvent* e) @@ -431,2 +577,29 @@ void QTReader::keyPressEvent(QKeyEvent* e) buffdoc.unsuspend(); + ((QTReaderApp*)parent()->parent())->handlekey(e); +// e->ignore(); + return; +#ifdef _SCROLLPIPE + if (m_isPaused) + { + m_isPaused = false; + if (e->key() != Key_Space) + { + m_autoScroll = false; + if (m_pipeout != NULL) + { + pclose(m_pipeout); + m_pipeout = NULL; + } + ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); + QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; + } + else + { + timer->start(real_delay(), false); + } + e->accept(); + return; + } +#endif +/* switch (e->key()) @@ -475,31 +648,2 @@ void QTReader::keyPressEvent(QKeyEvent* e) 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: @@ -532,9 +676,2 @@ void QTReader::keyPressEvent(QKeyEvent* e) break; - case Key_Space: - case Key_Return: - { - e->accept(); - emit OnActionPressed(); - } - break; default: @@ -542,2 +679,3 @@ void QTReader::keyPressEvent(QKeyEvent* e) } +*/ } @@ -550,3 +688,12 @@ void QTReader::setautoscroll(bool _sc) m_autoScroll = false; +#ifdef USEQPE QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; +#endif +#ifdef _SCROLLPIPE + if (m_pipeout != NULL) + { + pclose(m_pipeout); + m_pipeout = NULL; + } +#endif } @@ -557,4 +704,14 @@ void QTReader::setautoscroll(bool _sc) m_autoScroll = true; +#ifdef _SCROLLPIPE + if (!m_pipetarget.isEmpty()) + { +// qDebug("Opening pipe to %s", (const char*)m_pipetarget); + m_pipeout = popen((const char*)m_pipetarget, "w"); + m_isPaused = false; + } +#endif autoscroll(); +#ifdef USEQPE QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; // light is even not dimmed +#endif } @@ -567,3 +724,3 @@ bool QTReader::getline(CDrawBuffer *buff) { - return buffdoc.getline(buff ,width(), m_charWidth); + return buffdoc.getline(buff ,width(), m_charWidth, m_border); } @@ -571,3 +728,3 @@ bool QTReader::getline(CDrawBuffer *buff) { - return buffdoc.getline(buff, width()); + return buffdoc.getline(buff, width(), m_border); } @@ -590,2 +747,21 @@ void QTReader::doscroll() { +#ifdef _SCROLLPIPE + if (m_pipeout != NULL) + { + QString outstr = toQString(textarray[0]->data()); + if (!outstr.isEmpty()) + { + fprintf(m_pipeout, "%s\n", (const char*)outstr); + fflush(m_pipeout); + } + else if (m_pauseAfterEachPara) + { + m_isPaused = true; + timer->stop(); + } +// write(m_pipeout, (const char*)outstr, outstr.length()); +// write(m_pipeout, "\n", 1); +// fputc(10, m_pipeout); + } +#endif CDrawBuffer* buff = textarray[0]; @@ -611,3 +787,3 @@ void QTReader::doscroll() int ch = getline(textarray[numlines]); - textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width()); + textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width(), m_border); mylastpos = locate(); @@ -616,3 +792,20 @@ void QTReader::doscroll() m_autoScroll = false; +#ifdef _SCROLLPIPE + for (int i = 0; i < numlines; i++) + { + if (m_pipeout != NULL) + { + QString outstr = toQString(textarray[i]->data()); + if (!outstr.isEmpty()) + { + fprintf(m_pipeout, "%s\n", (const char*)outstr); + fflush(m_pipeout); + } + } + } +#endif ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); +#ifdef USEQPE + QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; +#endif } @@ -641,3 +834,3 @@ void QTReader::drawFonts( QPainter *p ) { - qDebug("How refreshing..."); +// qDebug("How refreshing..."); if (buffdoc.empty()) return; @@ -646,7 +839,8 @@ void QTReader::drawFonts( QPainter *p ) { - qDebug("Not Optimised %d", m_lastwidth); +// qDebug("Not Optimised %d", m_lastwidth); m_lastwidth = width(); m_lastheight = height(); + buffdoc.setwidth(m_lastwidth-2*m_border); locate(pagelocate()); - qDebug("Not Optimised %d", m_lastwidth); +// qDebug("Not Optimised %d", m_lastwidth); } @@ -654,5 +848,6 @@ void QTReader::drawFonts( QPainter *p ) { - if (m_lastheight > height()) + int newht = height(); + if (m_lastheight > newht) { - qDebug("Optimised < %d", numlines); +// qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht); int ypos = 0; @@ -660,6 +855,6 @@ void QTReader::drawFonts( QPainter *p ) { - if ((ypos += textarray[i]->lineSpacing()) > height()) + if ((ypos += textarray[i]->lineSpacing()) > newht) { numlines = i; - jumpto(locnarray[i+1]); + jumpto(mylastpos = locnarray[i+1]); break; @@ -667,8 +862,8 @@ void QTReader::drawFonts( QPainter *p ) } - qDebug("Optimised < %d", numlines); - m_lastheight = height(); +// qDebug("Optimised < %d", numlines); + m_lastheight = newht; } - else if (m_lastheight < height()) + else if (m_lastheight < newht) { - qDebug("Optimised > %d", numlines); +// qDebug("Optimised > %d", numlines); int ypos = 0; @@ -678,5 +873,4 @@ void QTReader::drawFonts( QPainter *p ) } - fillbuffer(numlines+1, ypos); - qDebug("Optimised > %d", numlines); - m_lastheight = height(); + fillbuffer(numlines+1, ypos, newht); +// qDebug("Optimised > %d", numlines); } @@ -685,3 +879,5 @@ void QTReader::drawFonts( QPainter *p ) int ypos = textarray[0]->ascent(); - textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); + textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); +// int last = (m_showlast) ? numlines : numlines-1; +// for (int i = 1; i <= last; i++) for (int i = 1; i < numlines; i++) @@ -691,3 +887,3 @@ void QTReader::drawFonts( QPainter *p ) (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; - textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width()); + textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); } @@ -696,5 +892,16 @@ void QTReader::drawFonts( QPainter *p ) } - m_scrolldy1 = m_scrolldy2 = 0; + + m_scrolldy1 = m_scrolldy2 = m_scrollpart; + if (m_border > 5 && !buffdoc.empty()) + { + p->fillRect(width()-2, 0, 2, height(), cyan); + int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); + int mid = (height()*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); + p->fillRect(width()-2, mid-5, 2, 10, yellow); + p->fillRect(width()-2, (height()*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*height()+sectionsize/2)/sectionsize, magenta); + } + emit OnRedraw(); } +/* else @@ -703,2 +910,3 @@ void QTReader::drawFonts( QPainter *p ) } +*/ } @@ -744,2 +952,3 @@ void QTReader::init() { +// m_showlast = true; // setCaption( "Qt Draw Demo Application" ); @@ -773,2 +982,14 @@ QTReader::~QTReader() { +#ifdef USEQPE + if (m_autoScroll) + { + QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; + } +#endif +#ifdef _SCROLLPIPE + if (m_pipeout != NULL) + { + fclose(m_pipeout); + } +#endif } @@ -818,3 +1039,3 @@ void QTReader::resizeEvent( QResizeEvent * ) { - // qDebug("resize:(%u,%u)", width(), height()); +// // qDebug("resize:(%u,%u)", width(), height()); // bgroup->move( width()-bgroup->width(), 0 ); @@ -843,7 +1064,7 @@ bool QTReader::locate(unsigned long n) { buffdoc.locate(n); - // qDebug("&buffdoc.located"); +// // qDebug("&buffdoc.located"); fillbuffer(); - // qDebug("&Buffer filled"); +// // qDebug("&Buffer filled"); update(); - // qDebug("&Located"); +// // qDebug("&Located"); return true; @@ -858,3 +1079,3 @@ unsigned int QTReader::screenlines() -bool QTReader::fillbuffer(int reuse, int ht) +bool QTReader::fillbuffer(int reuse, int ht, int newht) { @@ -862,3 +1083,6 @@ bool QTReader::fillbuffer(int reuse, int ht) if (buffdoc.empty()) return false; - m_scrolldy1 = m_scrolldy2 = 0; + if (newht < 0) + m_lastheight = height(); + else + m_lastheight = newht; int ch; @@ -866,6 +1090,7 @@ bool QTReader::fillbuffer(int reuse, int ht) unsigned int oldpagepos = locnarray[reuse]; - int ypos = ht; + int lastypos = ht, ypos = ht; numlines = reuse; - while (ypos < height() || numlines < 2) + while (ypos < m_lastheight || numlines < 2) { + lastypos = ypos; if (textarray[numlines] == NULL) @@ -896,2 +1121,3 @@ bool QTReader::fillbuffer(int reuse, int ht) mylastpos = locate(); + m_scrolldy1 = m_scrolldy2 = m_scrollpart = m_lastheight - lastypos; @@ -900,5 +1126,5 @@ bool QTReader::fillbuffer(int reuse, int ht) - void QTReader::dopagedn() { +// qDebug("HEIGHT(2):%d", m_lastheight); buffdoc.unsuspend(); @@ -907,3 +1133,3 @@ void QTReader::dopagedn() { -// qDebug("Jumping to %u", mylastpos); +//// qDebug("Jumping to %u", mylastpos); jumpto(mylastpos); @@ -940,2 +1166,14 @@ void QTReader::dopageup() +bool QTReader::synch(size_t start, size_t end) +{ + jumpto(start); + while (start++ < end) + { + tchar ch = getch(); + if (ch == 10) return true; + if (ch == UEOF) return false; + } + return false; +} + void QTReader::dopageup(unsigned int target) @@ -946,6 +1184,6 @@ void QTReader::dopageup(unsigned int target) - size_t delta, guess = 2048; + size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; bool ch = true; int nbfl, ypos = 0; - + if (guess < 128) guess = 128; while (1) @@ -953,3 +1191,2 @@ void QTReader::dopageup(unsigned int target) ch = true; - nbfl = 0; if (target < guess) @@ -967,18 +1204,20 @@ void QTReader::dopageup(unsigned int target) delta = guess; - - jumpto(target - delta); - - buff[0] = new CDrawBuffer(&m_fontControl); - - do + if (!synch(target-delta, target-lastdelta)) { - - if (!getline(buff[0])) break; - - if (locate() > target) break; + lastdelta = delta; + if (guess < 4000) + { + guess <<= 1; + continue; + } + else + { + jumpto(target-delta); + } } - while (!buffdoc.iseol()); } + nbfl = 0; ypos = 0; + while (locate() < target) @@ -992,3 +1231,3 @@ void QTReader::dopageup(unsigned int target) } - if (ypos < height() && (delta != 0)) + if (guess < 4000 && ypos < height() && (delta != 0)) { @@ -1011,2 +1250,3 @@ void QTReader::dopageup(unsigned int target) } +/* ypos = 0; @@ -1019,2 +1259,14 @@ void QTReader::dopageup(unsigned int target) --numlines; +*/ + + ypos = 0; + numlines = 0; + while (ypos < height() && numlines+2 <= nbfl) + { + ypos += buff[nbfl - numlines - 2]->lineSpacing(); + numlines++; + } + if (numlines > 0) --numlines; + if (numlines == 0 && nbfl > 1) numlines = 1; + int offset = nbfl-1; @@ -1029,3 +1281,7 @@ void QTReader::dopageup(unsigned int target) } +#ifdef _WINDOWS + for (i = 0; i < nbfl - numlines - 1; i++) +#else for (int i = 0; i < nbfl - numlines - 1; i++) +#endif { @@ -1059,3 +1315,2 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) } - m_lastfile = newfile; // QMessageBox::information(0, "Opening...", newfile); @@ -1064,8 +1319,10 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) if (buffdoc.openfile(this,newfile) == 0) - { + { + m_lastfile = newfile; + buffdoc.setwidth(m_lastwidth-2*m_border); bRC = true; buffdoc.setContinuous(m_continuousDocument); - // qDebug("buffdoc.openfile done"); +// // qDebug("buffdoc.openfile done"); locate(lcn); - // qDebug("buffdoc.locate done"); +// // qDebug("buffdoc.locate done"); } @@ -1073,3 +1330,3 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) update(); - // qDebug("Updated"); +// // qDebug("Updated"); return bRC; @@ -1091,3 +1348,7 @@ void QTReader::lineDown() offset = numlines - offset; +#ifdef _WINDOWS + for (i = offset; i <= numlines; i++) +#else for (int i = offset; i <= numlines; i++) +#endif { @@ -1261,3 +1522,7 @@ void QTReader::lineUp() int ypos = 0; - for (int i = 0; i <= numlines; i++) +#ifdef _WINDOWS + for (i = 0; i <= numlines; i++) +#else + for (int i = 0; i <= numlines; i++) +#endif { @@ -1298,30 +1563 @@ MarkupType QTReader::PreferredMarkup() } - -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(); -} |