From 73253e93327cf4ef0932de1b4afb56af22a0f37e Mon Sep 17 00:00:00 2001 From: pohly Date: Tue, 24 Aug 2004 20:52:45 +0000 Subject: updated source to opie-reader 0.7g --- (limited to 'noncore/apps/opie-reader/QTReader.cpp') diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp index b356ba5..dfdba28 100644 --- a/noncore/apps/opie-reader/QTReader.cpp +++ b/noncore/apps/opie-reader/QTReader.cpp @@ -8,8 +8,17 @@ ** *****************************************************************************/ +const int _SBARHEIGHT = 3; + +#include "useqpe.h" +#include +//#include +#include +#include +#include "config.h" #include "QTReader.h" -#include "QTReaderApp.h" +//#include "QTReaderApp.h" +#include "CDrawBuffer.h" #ifdef USEQPE #include #endif @@ -22,6 +31,8 @@ #include #include #endif +#include +#include #ifdef _UNICODE const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; @@ -39,11 +50,16 @@ tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' 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) : QWidget(parent, name, f), + m_default_fg(0,0,0), + m_default_bg(255,255,255), + m_bg(255,255,255), m_delay(100), m_scrolldy1(0), m_scrolldy2(0), + m_totalscroll(0), m_autoScroll(false), //textarray(NULL), //locnarray(NULL), @@ -57,11 +73,33 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : #ifdef _SCROLLPIPE m_pipeout(NULL), #endif - m_border(2) + m_left_border(2), + m_right_border(2), + m_rotated(true), + pBkmklist(NULL), + m_scrollpos(0), + // bNegative(false), + bInverse(false), + m_highlightfilter(NULL), + m_bgIsScaled(false), + m_scrollstep(2), + m_topmargin(5), + m_bottommargin(5), + m_reparastring("{\\n[\\n ]}"), + m_currentlinkstyle(NULL), + m_currentlinkoffset(-1), + m_currentlink(-1) { m_overlap = 1; setKeyCompression ( true ); +#ifdef DOUBLEBUFFER + dbuff = new QPixmap(); + dbp = new QPainter(); + // if (painter->isActive()) painter->end(); + // painter->begin(frame); +#endif // init(); + } /* @@ -80,7 +118,7 @@ QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *nam m_fm(NULL) { init(); -// // odebug << "Load_file(1)" << oendl; +// // qDebug("Load_file(1)"); load_file((const tchar*)filename); } */ @@ -91,31 +129,49 @@ void QTReader::mouseMoveEvent(QMouseEvent* _e) mouseUpOn = !(_e->pos().x() == -1); - odebug << "MouseMove:[" << _e->pos().x() << ", " << _e->pos().y() << "]" << oendl; + qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y()); } */ long QTReader::real_delay() { - return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); + return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); } void QTReader::mousePressEvent( QMouseEvent* _e ) { buffdoc.unsuspend(); + int x, y, ht, wh; + if (m_rotated) + { + x = _e->y(); + y = width()-_e->x(); + ht = width(); + wh = height(); + } + else + { + x = _e->x(); + y = _e->y(); + ht = height(); + wh = width(); + } if (_e->button() == RightButton) { -// odebug << "MousePress" << oendl; +// qDebug("MousePress"); mouseUpOn = false; if (m_swapmouse) { int lineno = 0; - int ht = textarray[0]->lineSpacing(); - while ((ht < _e->y()) && (lineno < numlines)) + /* + int hgt = textarray[0]->lineSpacing(); + while ((hgt < y) && (lineno < numlines)) { - ht += textarray[++lineno]->lineSpacing(); + hgt += textarray[++lineno]->lineSpacing(); } - size_t startpos, startoffset, tgt; - getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt); + */ + size_t startpos, startoffset, tgt, tgtoffset, pictgt; + QImage* img; + getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img); processmousewordevent(startpos, startoffset, _e, lineno); } else @@ -125,23 +181,38 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) void QTReader::processmousepositionevent( QMouseEvent* _e ) { + int x, y, ht, wh; + if (m_rotated) + { + x = _e->y(); + y = width()-_e->x(); + ht = width(); + wh = height(); + } + else + { + x = _e->x(); + y = _e->y(); + ht = height(); + wh = width(); + } if (buffdoc.hasnavigation()) { - if (_e->y() > (2*height())/3) + if (y > (2*ht)/3) { goDown(); } - else if (_e->y() < height()/3) + else if (y < ht/3) { goUp(); } else { - if (_e->x() < width()/3) + if (x < wh/3) { goBack(); } - else if (_e->x() > (2*width())/3) + else if (x > (2*wh)/3) { goForward(); } @@ -153,7 +224,7 @@ void QTReader::processmousepositionevent( QMouseEvent* _e ) } else { - if (_e->y() > height()/2) + if (y > ht/2) { goDown(); } @@ -172,73 +243,121 @@ void QTReader::goHome() size_t home=buffdoc.getHome(); if (current!=home) { - buffdoc.saveposn(current); + buffdoc.saveposn(m_lastfile, current); locate(home); } } + else + locate(0); } void QTReader::goBack() { - if (buffdoc.hasnavigation()) + if (buffdoc.hasnavigation()) { - size_t target = pagelocate(); - buffdoc.writeposn(target); - if (buffdoc.back(target)) + size_t target = pagelocate(); + QString nxt = m_lastfile; + buffdoc.writeposn(m_lastfile, target); + linkType lt = buffdoc.back(nxt, target); + if ((lt & eFile) != 0) { - locate(target); + if (nxt != m_lastfile) + { + emit NewFileRequest(nxt); + } + locate(target); + } + else if ((lt & eLink) != 0) + { + locate(target); } } } void QTReader::goForward() { - if (buffdoc.hasnavigation()) + if (buffdoc.hasnavigation()) { - size_t target = pagelocate(); - if (buffdoc.forward(target)) + size_t target = pagelocate(); + QString nxt = m_lastfile; + linkType lt = buffdoc.forward(nxt, target); + if ((lt & eFile) != 0) { - locate(target); + if (nxt != m_lastfile) + { + emit NewFileRequest(nxt); + } + locate(target); + } + else if ((lt & eLink) != 0) + { + locate(target); } } } -linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) +linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*& img) { - int lineno = 0; - int ht = textarray[0]->lineSpacing(); - while ((ht < y) && (lineno < numlines)) + int ht; + if (m_scrolldy == m_topmargin) { - ht += textarray[++lineno]->lineSpacing(); + lineno = 0; + ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin; } - start = locnarray[lineno]; - if (m_bMonoSpaced) + else + { + if (y >= m_scrolldy) + { + lineno = 0; + ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin; + } + else + { + lineno = 0; + ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy+m_topmargin; + while ((ht < h) && (lineno < numlines-1)) + { + ht += textarray[++lineno]->lineSpacing(); + } + ht = textarray[lineno]->lineSpacing(); + } + } + while ((ht < y) && (lineno < numlines-1)) { - offset = (x - textarray[lineno]->offset(width(), m_border))/m_charWidth; + ht += textarray[++lineno]->lineSpacing(); } - else + if (ht < y && textarray[numlines]->showPartial()) lineno = numlines; + start = locnarray[lineno]; + int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; + if (m_bMonoSpaced) { - int i; - CDrawBuffer* t = textarray[lineno]; - x = x - t->offset(width(), m_border); - for (i = t->length(); i >= 0 && t->width(i, true, width(), m_border) > x; i--); - offset = i; + offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth; } - return textarray[lineno]->getLinkType(offset, tgt); + else + { + int i; + CDrawBuffer* t = textarray[lineno]; + x = x - t->offset(width(), m_left_border, m_right_border, availht); + for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--); + offset = i; + } + return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img); } void QTReader::suspend() { -#ifdef OPIE + buffdoc.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) { - setBackgroundColor( white ); + setBackgroundColor( m_bg ); m_twotouch = m_touchone = _b; } @@ -250,7 +369,9 @@ void QTReader::setContinuous(bool _b) void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) { + unsigned long wrdstart, wrdend; QString wrd; + int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; if (m_twotouch) { if (m_touchone) @@ -263,7 +384,7 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse else { m_touchone = true; - setBackgroundColor( white ); + setBackgroundColor( m_bg ); size_t endpos, endoffset; endpos = startpos; endoffset = startoffset; @@ -275,6 +396,7 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse { getch(); } + wrdstart = buffdoc.explocate(); if (m_startpos == endpos) { for (int i = m_startoffset; i <= endoffset; i++) @@ -293,13 +415,17 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse wrd += QChar(getch()); } } + wrdend = buffdoc.explocate(); jumpto(currentpos); } } } else if (m_bMonoSpaced) { - int chno = (_e->x()-textarray[lineno]->offset(width(), m_border))/m_charWidth; + int chno = (m_rotated) ? + (_e->y()-textarray[lineno]->offset(height(), m_left_border, m_right_border, availht))/m_charWidth + : + (_e->x()-textarray[lineno]->offset(width(), m_left_border, m_right_border, availht))/m_charWidth; if (chno < ustrlen(textarray[lineno]->data())) { wrd[0] = textarray[lineno]->data()[chno]; @@ -309,15 +435,18 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse { CDrawBuffer* t = textarray[lineno]; int first = 0; - int tgt = _e->x() - t->offset(width(), m_border); + int tgt = (m_rotated) ? + _e->y() - t->offset(height(), m_left_border, m_right_border, availht) : + _e->x() - t->offset(width(), m_left_border, m_right_border, availht); while (1) { int i = first+1; + int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; - if (t->width(i, true, width(), m_border) > tgt) + if (t->width(availht, i, true, (m_rotated) ? height() : width(), m_left_border, m_right_border) > tgt) { wrd = toQString(t->data()+first, i - first); -// odebug << "Got " << (const char *)wrd << "" << oendl; +// qDebug("Got %s", (const char *)wrd); break; } while (!QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; @@ -327,92 +456,208 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse } if (!wrd.isEmpty()) { -// odebug << "Selected:" << wrd << "" << oendl; - emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); + qDebug("Selecteed:%s", (const char*)wrd); + if (m_twotouch) + { + emit OnWordSelected(wrd, wrdstart, wrdend, wrd); + } + else + { + QString line = toQString(textarray[lineno]->data()); + emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line); + } } } void QTReader::mouseReleaseEvent( QMouseEvent* _e ) { buffdoc.unsuspend(); + int x, y, ht, wh; + if (m_rotated) + { + x = _e->y(); + y = width()-_e->x(); + ht = width(); + wh = height(); + } + else + { + x = _e->x(); + y = _e->y(); + ht = height(); + wh = width(); + } if (_e->button() == LeftButton) { if (mouseUpOn) { -// odebug << "MouseRelease" << oendl; - if (_e->x() > width() - m_border) +// qDebug("MouseRelease"); + switch(m_scrollpos) { - locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*_e->y()+height()/2)/height()); - return; + case 1: // Bottom + if (y > ht - 5) + { + locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh); + return; + } + break; + case 2: // right + if (x > wh - m_right_border) + { + locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht); + return; + } + break; + case 3: // left + if (x < m_left_border) + { + locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht); + return; + } + break; + case 0: + default: + break; } if (textarray[0] != NULL) { QString line; // int lineno = _e->y()/m_linespacing; int lineno = 0; + /* int ht = textarray[0]->lineSpacing(); - while ((ht < _e->y()) && (lineno < numlines)) + while ((ht < 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(); - QString href; - linkType lt = buffdoc.hyperlink(tgt, href); - if (lt == eLink) + */ + size_t startpos, startoffset, tgt, tgtoffset, pictgt; + QImage* img; + if (m_currentlinkstyle != NULL) + { + textarray[m_currentlink]->invertLink(m_currentlinkoffset); + m_currentlinkstyle = NULL; + m_currentlink = -1; + m_currentlinkoffset = -1; + } + linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img); + if ((glt & eLink) != 0) + { + if ((glt & ePicture) != 0) + { + qDebug("Big Picture:%x", pictgt); + if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) + { + QImage* pm = buffdoc.getPicture(pictgt); + if (pm != NULL) + { + emit OnShowPicture(*pm); + delete pm; + return; + } + } + } + else if (img != NULL) + { + if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) + { + emit OnShowPicture(*img); + return; + } + } + size_t saveposn = pagelocate(); + QString href, nm; + linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm); + qDebug("URL(1):%s", (const char*)href); + if ((lt & eFile) != 0) + { + buffdoc.saveposn(m_lastfile, saveposn); +#ifdef USEQPE { - buffdoc.saveposn(saveposn); - fillbuffer(); - update(); + QCopEnvelope e("QPE/System", "busy()"); } - else - { - if (lt == ePicture) - { - QImage* pm = buffdoc.getPicture(tgt); - if (pm != NULL) - { - emit OnShowPicture(*pm); - delete pm; - } - } +#endif + ResetScroll(); + if (!href.isEmpty()) + { + if (!buffdoc.getFile(href)) + { + emit NewFileRequest(href); + } else - { -// QString anchortext = textarray[lineno]->getanchortext(startoffset); - if (!href.isEmpty()) - { - emit OnURLSelected(href); - } - } - locate(pagelocate()); - } - return; - } - case ePicture: - { -// odebug << "Picture:" << tgt << "" << oendl; - QImage* pm = buffdoc.getPicture(tgt); - if (pm != NULL) + { + ResetScroll(); + fillbuffer(); + update(); + } + } + if (!nm.isEmpty()) + { + qDebug("QTReader:Finding %s", (const char*)nm); + if (buffdoc.findanchor(nm)) + { + fillbuffer(); + update(); + } + } + //fillbuffer(); + //update(); +#ifdef USEQPE { - emit OnShowPicture(*pm); - delete pm; + QCopEnvelope e("QPE/System", "notBusy()"); } +#endif + } + else if ((lt & eLink) != 0) + { + buffdoc.saveposn(m_lastfile, saveposn); + ResetScroll(); + fillbuffer(); + update(); + } + else + { + if ((lt & ePicture) != 0) + { + QImage* pm = buffdoc.getPicture(tgt); + if (pm != NULL) + { + emit OnShowPicture(*pm); + delete pm; + } + } else - { - locate(pagelocate()); - } - return; - } - case eNone: - break; - default: -// odebug << "Unknown linktype" << oendl; - return; - } + { + // QString anchortext = textarray[lineno]->getanchortext(startoffset); + if (!href.isEmpty()) + { + emit OnURLSelected(href, tgt); + } + } + locate(pagelocate()); + } + return; + } + else if ((glt & ePicture) != 0) + { + qDebug("Big Picture:%x", pictgt); + QImage* pm = buffdoc.getPicture(pictgt); + if (pm != NULL) + { + emit OnShowPicture(*pm); + delete pm; + } + else + { + locate(pagelocate()); + } + return; + } + else if (img != NULL) + { + emit OnShowPicture(*img); + return; + } if (m_swapmouse) processmousepositionevent(_e); else @@ -441,6 +686,8 @@ void QTReader::focusOutEvent(QFocusEvent* e) } } +#include +#include #ifndef _WINDOWS #include #endif @@ -514,12 +761,11 @@ void QTReader::zoomin() if (m_fontControl.increasesize()) { bool sc = m_autoScroll; + setautoscroll(false); setfont(); - m_autoScroll = false; locate(pagelocate()); - update(); - m_autoScroll = sc; - if (m_autoScroll) autoscroll(); + repaint(); + setautoscroll(sc); } } @@ -528,12 +774,11 @@ void QTReader::zoomout() if (m_fontControl.decreasesize()) { bool sc = m_autoScroll; - m_autoScroll = false; + setautoscroll(false); setfont(); locate(pagelocate()); - update(); - m_autoScroll = sc; - if (m_autoScroll) autoscroll(); + repaint(); + setautoscroll(sc); } } @@ -552,21 +797,23 @@ void QTReader::reduceScroll() void QTReader::increaseScroll() { - if (m_delay > 1024) + if (m_delay > 454) { m_delay = (2*m_delay)/3; timer->changeInterval(real_delay()); } else { - m_delay = 1024; + m_delay = 454; } } void QTReader::keyPressEvent(QKeyEvent* e) { buffdoc.unsuspend(); - ((QTReaderApp*)parent()->parent())->handlekey(e); + + //((QTReaderApp*)parent()->parent())->handlekey(e); + emit HandleKeyRequest(e); // e->ignore(); return; #ifdef _SCROLLPIPE @@ -581,7 +828,8 @@ void QTReader::keyPressEvent(QKeyEvent* e) pclose(m_pipeout); m_pipeout = NULL; } - ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); + //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); + emit SetScrollState(m_autoScroll); QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; } else @@ -592,83 +840,69 @@ void QTReader::keyPressEvent(QKeyEvent* e) return; } #endif -/* - switch (e->key()) +} + +void QTReader::CalculateScrollParameters() +{ + int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); + if (bmargin < m_bottommargin) bmargin = m_bottommargin; + switch (m_scrolltype) { - case Key_Down: - { - e->accept(); - if (m_autoScroll) + case 0: + { + if (m_scrolldy == m_topmargin) { - if (m_delay < 59049) - { - m_delay = (3*m_delay)/2; - timer->changeInterval(real_delay()); - } - else - { - m_delay = 59049; - } + m_scrolldy1 = 0; + m_scrolldy2 = 0; + m_totalscroll = 0; + return; } - else + if (m_scrolldy < textarray[0]->lineSpacing()) { - goDown(); + m_scrolldy2 = m_scrolldy; + return; } - } - break; - case Key_Up: - { - e->accept(); - if (m_autoScroll) + int ht = m_scrolldy - m_scrolldy1; + int i; + for (i = 0; (ht < ((m_rotated) ? width() : height())-bmargin) && (i < numlines); i++) { - if (m_delay > 1024) - { - m_delay = (2*m_delay)/3; - timer->changeInterval(real_delay()); - } - else - { - m_delay = 1024; - } + ht += textarray[i]->lineSpacing(); } - else + ht = 0; + int j; + i--; + for (j = i; j < numlines; j++) { - goUp(); + ht += textarray[j]->lineSpacing(); } - } + ht -= ( + textarray[i]->lineExtraSpacing() + + + (i != 0) ? textarray[numlines-1]->lineExtraSpacing() : 0 + )/2-2; + + m_scrolldy2 = m_scrolldy-ht; + } + break; + case 1: + case 2: + case 3: + { + int ypos = m_topmargin; + for (int i = 0; i < numlines; i++) + { + ypos += textarray[i]->lineSpacing(); + } + ypos -= ( + textarray[0]->lineExtraSpacing() + + + ((numlines > 1) ? textarray[numlines-1]->lineExtraSpacing() : 0) + )/2 + + m_scrolldy1 - 2; + m_scrolldy2 = ((m_rotated) ? width() : height()) - ypos - bmargin; + } 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; - default: - e->ignore(); } -*/ } void QTReader::setautoscroll(bool _sc) @@ -687,16 +921,20 @@ void QTReader::setautoscroll(bool _sc) m_pipeout = NULL; } #endif + // m_scrolldy1 = 0; + //refresh(); } else { CDrawBuffer* reusebuffer = textarray[numlines]; if (reusebuffer == NULL || reusebuffer->eof()) return; m_autoScroll = true; + CalculateScrollParameters(); + #ifdef _SCROLLPIPE if (!m_pipetarget.isEmpty()) { -// odebug << "Opening pipe to " << m_pipetarget << "" << oendl; +// qDebug("Opening pipe to %s", (const char*)m_pipetarget); m_pipeout = popen((const char*)m_pipetarget, "w"); m_isPaused = false; } @@ -711,14 +949,18 @@ void QTReader::setautoscroll(bool _sc) bool QTReader::getline(CDrawBuffer *buff) { buffdoc.unsuspend(); + bool bRet; + int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; if (m_bMonoSpaced) { - return buffdoc.getline(buff ,width(), m_charWidth, m_border); + bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht); } else { - return buffdoc.getline(buff, width(), m_border); + bRet = buffdoc.getline(buff, (m_rotated) ? height() : width(), m_left_border, m_right_border, hyphenate, availht); } + buff->resize(availht); + return bRet; } void QTReader::doscroll() @@ -728,14 +970,248 @@ void QTReader::doscroll() timer->stop(); return; } -// timer->changeInterval(real_delay()); + switch (m_scrolltype) + { + case 0: + doinplacescroll(); + break; + case 1: + dorollingscroll(false); + break; + case 2: + dorollingscroll(true); + break; + case 3: + dostaticscroll(); + break; + } +} + +void QTReader::doinplacescroll() +{ + QPainter p( this ); + // p.setBackgroundMode(OpaqueMode); + int wh, ht; + int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); + if (bmargin < m_bottommargin) bmargin = m_bottommargin; + if (m_rotated) + { + ht = width()-bmargin; + wh = height(); + } + else + { + ht = height()-bmargin; + wh = width(); + } + int lastdy = m_scrolldy; + m_scrolldy += m_scrollstep; + if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing()) + { + int ht = textarray[0]->lineSpacing(); +#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(); + } + } +#endif + 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 -= ht; + } + if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing()) + { + m_scrolldy2 -= textarray[numlines]->lineSpacing(); + numlines++; + + if (textarray[numlines] == NULL) + { + textarray[numlines] = new CDrawBuffer(&m_fontControl); + } + locnarray[numlines] = locate(); + int ch = getline(textarray[numlines]); + if (m_rotated) + { + blitRot(width()-m_scrolldy, 0, height(), -1, textarray[numlines-1]); + } + else + { + if (m_bgpm.isNull()) + { + p.fillRect(m_left_border,m_scrolldy-textarray[numlines-1]->lineSpacing(),width()-(m_left_border+m_right_border),textarray[numlines-1]->lineSpacing(),m_bg); + } + else + { + int h_tmp = textarray[numlines-1]->lineSpacing(); + bitBlt(this, m_left_border, m_scrolldy-h_tmp, dbuff, m_left_border, m_scrolldy-h_tmp, width()-(m_left_border+m_right_border), h_tmp); + } + textarray[numlines-1]->render(&p, m_scrolldy -textarray[numlines-1]->lineSpacing()+ textarray[numlines-1]->ascent(), m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); + } + mylastpos = locate(); + if (!ch) + { + /* + if (m_rotated) + { + blitRot2(0,0,height(),width()-m_scrolldy,NULL); +// blitRot2(0,0,0,height(),width()-m_scrolldy,NULL); + } + else + { + if (m_bgpm.isNull()) + { + p.fillRect(0,m_scrolldy,width(),height()-m_scrolldy,m_bg); + } + else + { + bitBlt(this, 0, m_scrolldy, dbuff, 0, m_scrolldy, width(), height()-m_scrolldy); + } + } + */ + m_scrolldy = m_topmargin; + 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); + emit SetScrollState(m_autoScroll); +#ifdef USEQPE + QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; +#endif + } + if (m_scrolldy > ht-textarray[numlines]->lineSpacing()) + { + if (m_rotated) + { + if (m_bgpm.isNull()) + { + p.fillRect(bmargin, m_left_border, ht-m_scrolldy, wh-(m_left_border+m_right_border), m_bg); + } + else + { + blitRot(bmargin, 0,height(), ht-m_scrolldy, NULL); + } + } + else + if (m_bgpm.isNull()) + { + p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),height()-m_scrolldy,m_bg); + } + else + { + bitBlt(this,m_left_border,m_scrolldy,dbuff,m_left_border,m_scrolldy,width()-(m_left_border+m_right_border), height()-m_scrolldy); + } + m_scrolldy = m_topmargin; + m_scrolldy2 = 0; + } + redrawScroll(&p); + emitRedraw(); + lastdy = -1; + } + // else + { + if (m_rotated) + { + if (lastdy >= 0) + { + if (m_bgpm.isNull()) + { + p.fillRect(width()-lastdy, m_left_border, m_scrollstep, wh-(m_left_border+m_right_border),m_bg); + } + else + { + blitRot(width()-lastdy,m_left_border,wh-(m_left_border+m_right_border), m_scrollstep, NULL); + } + } + p.fillRect(width()-m_scrolldy, m_left_border, 1,wh-(m_left_border+m_right_border),m_scrollcolor); + } + else + { + if (lastdy >= 0) + { + if (m_bgpm.isNull()) + { + p.fillRect(m_left_border,lastdy,width()-(m_left_border+m_right_border),m_scrollstep,m_bg); + } + else + { + bitBlt(this, m_left_border, lastdy, dbuff, m_left_border, lastdy, width()-(m_left_border+m_right_border), m_scrollstep); + } + } + p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),1,m_scrollcolor); + } + } +} + +void QTReader::dorollingscroll(bool _statbord) +{ + bool bredrawscroll = false; 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); + // 2 = right, 3 = left + int tmargin = (_statbord) ? m_topmargin : 0; + int lmargin = (m_scrollpos == 3 || _statbord) ? m_left_border : 0; + int rmargin = (m_scrollpos == 2 || _statbord) ? m_right_border : 0; + int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); + if (hmargin < m_bottommargin) hmargin = m_bottommargin; + if (m_rotated) + { + m_totalscroll = (m_totalscroll+m_scrollstep) % width(); + bitBlt(this, m_scrollstep+hmargin, lmargin, this, hmargin, lmargin, width()-tmargin-hmargin, height()-(lmargin+rmargin)); + if (!m_bgpm.isNull()) + { + blitRot(hmargin, tmargin, height(), m_scrollstep, NULL); + } + else + { + p.fillRect(hmargin, rmargin, m_scrollstep, height()-lmargin-rmargin, m_bg); + } + } + else + { + m_totalscroll = (m_totalscroll+m_scrollstep) % height(); + bitBlt(this,lmargin,tmargin,this,lmargin,tmargin+m_scrollstep,width()-(lmargin+rmargin),height() - tmargin - hmargin - m_scrollstep); + if (m_bgpm.isNull()) + { + p.fillRect(0, height() - (m_scrollstep+1) - hmargin, width(), (m_scrollstep+1), m_bg); + } + else + { + int loff = (_statbord) ? 0 : m_totalscroll; + bitBlt(this,0,height() - (m_scrollstep+1) - hmargin, dbuff, 0, (loff+height() - (m_scrollstep+1) - hmargin) % height(), width(), (m_scrollstep+1)); + } + } - if (++m_scrolldy1 == textarray[0]->lineSpacing()) + if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing()) { + int ht = textarray[0]->lineSpacing(); + bredrawscroll = true; #ifdef _SCROLLPIPE if (m_pipeout != NULL) { @@ -750,9 +1226,6 @@ void QTReader::doscroll() 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]; @@ -763,11 +1236,12 @@ void QTReader::doscroll() } textarray[numlines] = buff; --numlines; - m_scrolldy1 = 0; + m_scrolldy1 -= ht; } - if (++m_scrolldy2 == textarray[numlines]->lineSpacing()) + if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing()) { - m_scrolldy2 = 0; + bredrawscroll = true; + m_scrolldy2 -= textarray[numlines]->lineSpacing(); numlines++; if (textarray[numlines] == NULL) @@ -776,10 +1250,21 @@ void QTReader::doscroll() } locnarray[numlines] = locate(); int ch = getline(textarray[numlines]); - textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width(), m_border); + if (m_rotated) + { + blitRot(hmargin, 0, height(), -1, textarray[numlines-1]); + } + else + { + // textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2 - hmargin, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg); + textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - textarray[numlines-1]->lineExtraSpacing() - 1 - hmargin, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); + + } mylastpos = locate(); if (!ch) { + redrawScroll(&p); + emitRedraw(); m_autoScroll = false; #ifdef _SCROLLPIPE for (int i = 0; i < numlines; i++) @@ -795,18 +1280,224 @@ void QTReader::doscroll() } } #endif - ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); + emit SetScrollState(m_autoScroll); #ifdef USEQPE QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; #endif + return; } - emit OnRedraw(); } + if (!bredrawscroll && ((m_scrolldy2/m_scrollstep) % 10 == 5) && textarray[numlines]->showPartial()) + { + if (m_rotated) + { + blitRot(hmargin + m_scrolldy2 - textarray[numlines]->lineSpacing(), 0, height(), -1, textarray[numlines]); + } + else + { + textarray[numlines]->render( &p, height() + textarray[numlines]->lineSpacing() - textarray[numlines]->descent() - 2 - hmargin-m_scrolldy2, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); + } + } + if (m_scrollpos != 0) + { + redrawScroll(&p); + } + if (bredrawscroll) emitRedraw(); +} + +void QTReader::dostaticscroll() +{ + redrawall(); + bool bredraw = false; + if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing()) + { + int ht = textarray[0]->lineSpacing(); + bredraw = true; +#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(); + } + } +#endif + 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 -= ht; + } + if ((m_scrolldy2 = m_scrolldy2 + m_scrollstep) >= textarray[numlines]->lineSpacing()) + { + bredraw = true; + m_scrolldy2 -= textarray[numlines]->lineSpacing(); + numlines++; + + if (textarray[numlines] == NULL) + { + textarray[numlines] = new CDrawBuffer(&m_fontControl); + } + locnarray[numlines] = locate(); + int ch = getline(textarray[numlines]); + mylastpos = locate(); + if (!ch) + { + redrawall(); + emitRedraw(); + 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 + emit SetScrollState(m_autoScroll); +#ifdef USEQPE + QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; +#endif + return; + } + } + if (bredraw) emitRedraw(); +} + +void QTReader::redrawScroll(QPainter* p) +{ + int offset = (m_scrolltype == 1) ? m_totalscroll : 0; + switch (m_scrollpos) + { + case 1: + { + int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); + if (hmargin < m_bottommargin) hmargin = m_bottommargin; + if (m_rotated) + { + if (m_bgpm.isNull()) + { + p->fillRect(0,0,hmargin,height(),m_bg); + } + else + { + blitRot(0,0, height(), hmargin, NULL); + } + } + else + { + if (m_bgpm.isNull()) + { + p->fillRect(0,height() - hmargin,width(),hmargin,m_bg); + } + else + { + int toffset = (offset+height()-hmargin) % height(); + if (toffset+hmargin > height()) + { + int fp = height()-toffset; + bitBlt(this, + 0,height() - hmargin, + dbuff, + 0, toffset, width(), fp); + bitBlt(this, + 0,height()-hmargin+fp, + dbuff, + 0, 0, width(), hmargin-fp); + } + else + { + bitBlt(this, + 0,height() - hmargin, + dbuff, + 0, toffset, width(), hmargin); + } + } + } + } + break; + case 2: //right + if (m_rotated) + { + if (m_bgpm.isNull()) + { + p->fillRect(0,height()-m_right_border,width(),m_right_border,m_bg); + } + else + { + blitRot(0,height()-m_right_border, m_right_border, width(), NULL); + } + } + else + { + if (m_bgpm.isNull()) + { + p->fillRect(width()-m_right_border,0,m_right_border,height(),m_bg); + } + else + { + int x = width() - m_right_border; + int fp = height()-offset; + bitBlt(this, x, 0, dbuff, x, offset, m_right_border, fp); + bitBlt(this, x, fp, dbuff, x, 0, m_right_border, height()-fp); + } + } + break; + case 3: //left + if (m_rotated) + { + if (m_bgpm.isNull()) + { + p->fillRect(0,0,width(),m_left_border,m_bg); + } + else + { + blitRot(0,0, m_left_border, width(), NULL); + } + } + else + { + if (m_bgpm.isNull()) + { + p->fillRect(0,0,m_left_border,height(),m_bg); + } + else + { + int fp = height()-offset; + bitBlt(this, 0, 0, dbuff, 0, offset, m_left_border, fp); + bitBlt(this, 0, fp, dbuff, 0, 0, m_left_border, height()-fp); + } + } + break; + case 0: + default: + break; + } + if (m_scrollpos != 0) DrawScroll(p, width(), height()); } void QTReader::autoscroll() { - timer->start(real_delay(), false); + drawBackground(); + dbp->end(); + timer->start(real_delay(), false); } void QTReader::setfont() @@ -819,56 +1510,192 @@ void QTReader::setfont() m_linespacing = m_fontControl.lineSpacing(); } -void QTReader::drawFonts( QPainter *p ) +void QTReader::DrawStraight(QPainter* p, int w, int h) +{ + if (m_scrolldy == m_topmargin) + { + int ypos = textarray[0]->ascent()-m_scrolldy1+m_topmargin; + textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); + int i; + for (i = 1; i < numlines; i++) + { + 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, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); + } + if (textarray[i]->showPartial()) + { + 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, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); + } + } + else + { + int ypos = textarray[0]->ascent()-m_scrolldy1+m_scrolldy+m_topmargin; + textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); + // p->fillRect(m_border, 0, w-2*m_border, m_scrolldy, m_bg); + for (int i = 1; i < numlines; i++) + { + ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ + (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; + if (ypos+textarray[i]->descent() > h) + { + ypos = textarray[i]->ascent(); + } + textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin); + } + p->fillRect(m_left_border,m_scrolldy,w-(m_left_border+m_right_border),1,m_scrollcolor); + } + bool wasrotated = m_rotated; + m_rotated = false; + DrawScroll(p, w, h); + m_rotated = wasrotated; + +} + +void QTReader::redrawall() +{ + if (m_rotated) + { +#ifdef DOUBLEBUFFER + drawBackground(); + DrawStraight(dbp, height(), width()); + dbp->end(); + + QWMatrix m; + m.rotate(90); + QPixmap rp = dbuff->xForm(m); + bitBlt(this, 0,0,&rp,0,0,-1,-1); +#else + QPixmap dbuff(height(), width()); + QPainter dbp(&dbuff); + // dbp.setBackgroundMode(OpaqueMode); + dbp.fillRect(dbuff.rect(), m_bg); + + DrawStraight(&dbp, height(), width()); + + QWMatrix m; + m.rotate(90); + QPixmap rp = dbuff.xForm(m); + bitBlt(this, 0,0,&rp,0,0,-1,-1); +#endif + } + else + { +#ifdef DOUBLEBUFFER + drawBackground(); + DrawStraight(dbp, width(), height()); + dbp->end(); + bitBlt(this, 0,0,dbuff,0,0,-1,-1); +#else + DrawStraight(p, width(), height()); +#endif + } +} + +void QTReader::drawFonts() { if (bDoUpdates) { -// odebug << "How refreshing..." << oendl; + int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); + if (hmargin < m_bottommargin) hmargin = m_bottommargin; +// qDebug("How refreshing..."); if (buffdoc.empty()) return; setfont(); + // if (!m_autoScroll) m_scrolldy1 = 0; +#ifdef ROTATION_ENABLED + if (m_lastwidth != ((m_rotated) ? height() : width())) + { + m_scrolldy = m_topmargin; + // qDebug("Not Optimised %d", m_lastwidth); + m_lastwidth = ((m_rotated) ? height() : width()); + m_lastheight = ((m_rotated) ? width() : height()); + buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); + locate(pagelocate()); + // qDebug("Not Optimised %d", m_lastwidth); + } + else + { + int newht = ((m_rotated) ? width() : height()); + if (m_lastheight > newht) + { + // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht); + m_scrolldy = m_topmargin; + int ypos = m_scrolldy1+m_topmargin; + for (int i = 0; i < numlines; i++) + { + if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin) + { + numlines = i; + jumpto(mylastpos = locnarray[i+1]); + break; + } + } + // qDebug("Optimised < %d", numlines); + m_lastheight = newht; + } + else if (m_lastheight < newht) + { + m_scrolldy = m_topmargin; + // qDebug("Optimised > %d", numlines); + int ypos = m_scrolldy1+m_topmargin; + for (int i = 0; i <= numlines; i++) + { + ypos += textarray[i]->lineSpacing(); + } + fillbuffer(numlines+1, ypos, newht); + // qDebug("Optimised > %d", numlines); + } + if (numlines > 0) + { + redrawall(); + } + } +#else if (m_lastwidth != width()) - { -// odebug << "Not Optimised " << m_lastwidth << "" << oendl; + { + // qDebug("Not Optimised %d", m_lastwidth); m_lastwidth = width(); m_lastheight = height(); - buffdoc.setwidth(m_lastwidth-2*m_border); + buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); locate(pagelocate()); -// odebug << "Not Optimised " << m_lastwidth << "" << oendl; +// qDebug("Not Optimised %d", m_lastwidth); } else { int newht = height(); if (m_lastheight > newht) { -// odebug << "Optimised < " << numlines << " " << m_lastheight << " " << newht << "" << oendl; - int ypos = 0; +// qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht); + int ypos = m_topmargin; for (int i = 0; i < numlines; i++) { - if ((ypos += textarray[i]->lineSpacing()) > newht) + if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin) { numlines = i; jumpto(mylastpos = locnarray[i+1]); break; } } -// odebug << "Optimised < " << numlines << "" << oendl; +// qDebug("Optimised < %d", numlines); m_lastheight = newht; } else if (m_lastheight < newht) { -// odebug << "Optimised > " << numlines << "" << oendl; - int ypos = 0; +// qDebug("Optimised > %d", numlines); + int ypos = m_topmargin; for (int i = 0; i <= numlines; i++) { ypos += textarray[i]->lineSpacing(); } fillbuffer(numlines+1, ypos, newht); -// odebug << "Optimised > " << numlines << "" << oendl; +// qDebug("Optimised > %d", numlines); } if (numlines > 0) { - int ypos = textarray[0]->ascent(); - textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); + int ypos = textarray[0]->ascent()+m_topmargin; + textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); // int last = (m_showlast) ? numlines : numlines-1; // for (int i = 1; i <= last; i++) for (int i = 1; i < numlines; i++) @@ -876,32 +1703,193 @@ void QTReader::drawFonts( QPainter *p ) // 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(), m_border); + textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); } // mylastpos = locate(); } } +#endif + emitRedraw(); + } +/* + else + { + qDebug("Not so refreshing..."); + } +*/ +} - m_scrolldy1 = m_scrolldy2 = m_scrollpart; - if (m_border > 5 && !buffdoc.empty()) +void QTReader::DrawScroll( QPainter *p, int _w, int _h ) +{ + if (!buffdoc.empty()) + { + QBrush checkered = QBrush( Dense4Pattern ); + checkered.setColor(m_scrollbarcolor); + switch (m_scrollpos) + { + case 1: + if (m_rotated) + { + p->fillRect(0, 0, 2, _h, checkered); + } + else + { + p->fillRect(0, _h-2, _w, 2, checkered); + } + break; + case 2: + if (m_rotated) + { + p->fillRect(0, _h-2, _w, 2, checkered); + } + else + { + p->fillRect(_w-2, 0, 2, _h, checkered); + } + break; + case 3: + if (m_rotated) + { + p->fillRect(0, 0, _w, 2, checkered); + } + else + { + p->fillRect(0, 0, 2, _h, checkered); + } + break; + case 0: + default: + break; + } + switch (m_scrollpos) { - p->fillRect(width()-2, 0, 2, height(), cyan); + case 1: + { + int ht; + if (m_rotated) + { + ht = _h; + } + else + { + ht = _w; + } + int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); + int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); + int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize; + int sliderpos; + if (sliderheight < 10) + { + sliderheight = 10; + sliderpos = mid-5; + } + else + { + sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize; + } + if (m_rotated) + { + p->fillRect(0, sliderpos, 3, sliderheight, m_scrollbarcolor); + } + else + { + p->fillRect(sliderpos, _h-3, sliderheight, 3, m_scrollbarcolor); + } + } + break; + case 2: + case 3: + { + int ht; + if (m_rotated) + { + ht = _w; + } + else + { + ht = _h; + } 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); + int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); + int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize; + int sliderpos; + if (sliderheight < 10) + { + sliderheight = 10; + sliderpos = mid-5; + } + else + { + sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize; + } + if (m_rotated) + { + int hoff; + if (m_scrollpos == 2) //right + { + hoff = _h-3; + } + else + { + hoff = 0; + } + p->fillRect(ht-sliderpos-sliderheight, hoff, sliderheight, 3, m_scrollbarcolor); + } + else + { + int hoff; + if (m_scrollpos == 2) //right + { + hoff = _w-3; + } + else + { + hoff = 0; + } + p->fillRect(hoff, sliderpos, 3, sliderheight, m_scrollbarcolor); + } + } + break; + case 0: + default: + break; } - - emit OnRedraw(); } +} + /* - else +void QTReader::DrawScroll( QPainter *p ) +{ + if (m_border > 5 && !buffdoc.empty()) { - odebug << "Not so refreshing..." << oendl; + int ht, wh; + if (m_rotated) + { + ht = width(); + wh = height()g; + p->fillRect(0, wh-2, ht, 2, cyan); + } + else + { + ht = height(); + wh = width(); + p->fillRect(wh-2, 0, 2, ht, cyan); + } + int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); + int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); + if (m_rotated) + { + p->fillRect(ht-mid-5, wh-2, 10, 2, yellow); + p->fillRect(ht-(ht*(locnarray[numlines]-buffdoc.startSection())+sectionsize/2)/sectionsize, wh-2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, 2, magenta); + } + else + { + p->fillRect(wh-2, mid-5, 2, 10, yellow); + p->fillRect(wh-2, (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, magenta); + } } -*/ } - +*/ QString QTReader::firstword() { if (m_bMonoSpaced) @@ -941,29 +1929,15 @@ bool QTReader::ChangeFont(int tgt) void QTReader::init() { -// m_showlast = true; - // setCaption( "Qt Draw Demo Application" ); - - buffdoc.unsuspend(); - setBackgroundColor( white ); -// QPainter p(this); -// p.setBackgroundMode( Qt::OpaqueMode ); + buffdoc.unsuspend(); + setBackgroundColor( m_bg ); 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); - } -*/ + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); + // QMessageBox::information(this, "init", m_lastfile, 1); + setfont(); } // @@ -971,6 +1945,10 @@ void QTReader::init() // QTReader::~QTReader() { +#ifdef DOUBLEBUFFER + delete dbuff; + delete dbp; +#endif #ifdef USEQPE if (m_autoScroll) { @@ -986,15 +1964,6 @@ 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. // /* @@ -1016,8 +1985,7 @@ void QTReader::printIt() void QTReader::paintEvent( QPaintEvent * ) { - QPainter paint( this ); - drawIt( &paint ); + drawFonts(); } // @@ -1028,7 +1996,7 @@ void QTReader::paintEvent( QPaintEvent * ) /* void QTReader::resizeEvent( QResizeEvent * ) { -// // odebug << "resize:(" << width() << "," << height() << ")" << oendl; +// // qDebug("resize:(%u,%u)", width(), height()); // bgroup->move( width()-bgroup->width(), 0 ); } */ @@ -1053,11 +2021,13 @@ bool QTReader::locate(unsigned long n) { //printf("Locate\n"); buffdoc.unsuspend(); buffdoc.locate(n); -// // odebug << "&buffdoc.located" << oendl; +// // qDebug("&buffdoc.located"); + ResetScroll(); fillbuffer(); -// // odebug << "&Buffer filled" << oendl; +// // qDebug("&Buffer filled"); update(); -// // odebug << "&Located" << oendl; +// // qDebug("&Located"); + emitRedraw(); return true; } @@ -1071,17 +2041,20 @@ unsigned int QTReader::screenlines() bool QTReader::fillbuffer(int reuse, int ht, int newht) { buffdoc.unsuspend(); + int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); + if (hmargin < m_bottommargin) hmargin = m_bottommargin; + if (ht < 0) ht = m_topmargin; if (buffdoc.empty()) return false; if (newht < 0) - m_lastheight = height(); + m_lastheight = (m_rotated) ? width() : height(); else - m_lastheight = newht; + m_lastheight = newht; int ch; bool ret = false; unsigned int oldpagepos = locnarray[reuse]; int lastypos = ht, ypos = ht; numlines = reuse; - while (ypos < m_lastheight || numlines < 2) + while (ypos < m_lastheight - hmargin || numlines < 2) { lastypos = ypos; if (textarray[numlines] == NULL) @@ -1096,39 +2069,50 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht) { if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/) { + qDebug("FALSE"); locate(oldpagepos); return false; } else { + qDebug("TRUE"); --numlines; mylastpos = locate(); return true; } } + if (numlines > 1 && textarray[numlines-2]->isBop()) + { + --numlines; + mylastpos = locate(); + return true; + } } --numlines; mylastpos = locate(); - m_scrolldy1 = m_scrolldy2 = m_scrollpart = m_lastheight - lastypos; - + m_scrollpart = m_lastheight - lastypos - hmargin; + if (m_autoScroll) + { + CalculateScrollParameters(); + } return true; } void QTReader::dopagedn() { -// odebug << "HEIGHT(2):" << m_lastheight << "" << oendl; +// qDebug("HEIGHT(2):%d", m_lastheight); buffdoc.unsuspend(); - int skip = 0, ypos = 0; + ResetScroll(); + int skip = 0, ypos = m_topmargin; if (locate() != mylastpos) { -//// odebug << "Jumping to " << mylastpos << "" << oendl; jumpto(mylastpos); } CDrawBuffer* reusebuffer = textarray[numlines]; - if (reusebuffer != NULL && reusebuffer->eof()) return; if (reusebuffer != NULL) { + if (reusebuffer->eof()) return; for (int i = 0; i <= m_overlap; i++) { int offset = numlines - m_overlap + i; @@ -1143,15 +2127,20 @@ void QTReader::dopagedn() skip++; } } + if (numlines <= 1) + { + skip = 0; + ypos = 0; + qDebug("Doing extra skip"); + } if (fillbuffer(skip, ypos)) { - update(); + drawFonts(); } } void QTReader::dopageup() { - buffdoc.unsuspend(); dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); } @@ -1163,6 +2152,7 @@ bool QTReader::synch(size_t start, size_t end) tchar ch = getch(); if (ch == 10) return true; if (ch == UEOF) return false; + if (ch == 6) return false; } return false; } @@ -1170,15 +2160,18 @@ bool QTReader::synch(size_t start, size_t end) void QTReader::dopageup(unsigned int target) { buffdoc.unsuspend(); + ResetScroll(); CBufferFace buff; CBufferFace loc; - size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; + size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; bool ch = true; - int nbfl, ypos = 0; + int nbfl, ypos = m_topmargin; if (guess < 128) guess = 128; while (1) { + // qDebug("Guess:%u", guess); + ch = true; if (target < guess) { @@ -1209,7 +2202,7 @@ void QTReader::dopageup(unsigned int target) } nbfl = 0; - ypos = 0; + ypos = m_topmargin; while (locate() < target) { @@ -1220,7 +2213,7 @@ void QTReader::dopageup(unsigned int target) nbfl++; if (!ch) break; } - if (guess < 4000 && ypos < height() && (delta != 0)) + if (guess < 4000 && ypos < ((m_rotated) ? width() : height())-(m_bottommargin) && (delta != 0)) { for (int i = 0; i < nbfl; i++) { @@ -1250,9 +2243,9 @@ void QTReader::dopageup(unsigned int target) --numlines; */ - ypos = 0; + ypos = m_topmargin; numlines = 0; - while (ypos < height() && numlines+2 <= nbfl) + while (ypos < ((m_rotated) ? width() : height())-m_bottommargin && numlines+2 <= nbfl) { ypos += buff[nbfl - numlines - 2]->lineSpacing(); numlines++; @@ -1262,7 +2255,7 @@ void QTReader::dopageup(unsigned int target) int offset = nbfl-1; offset -= numlines; - ypos = 0; + ypos = m_topmargin; for (int i = 0; i <= numlines; i++) { delete textarray[i]; @@ -1279,7 +2272,7 @@ void QTReader::dopageup(unsigned int target) delete buff[i]; } - while (ypos < height()) + while (ypos < ((m_rotated) ? width() : height())-m_bottommargin) { numlines++; locnarray[numlines] = locate(); @@ -1289,48 +2282,58 @@ void QTReader::dopageup(unsigned int target) } mylastpos = locate(); - - update(); + CalculateScrollParameters(); + drawFonts(); + // repaint(); } bool QTReader::load_file(const char *newfile, unsigned int _lcn) { // QMessageBox::information(this, "Name", name, 1); // QMessageBox::information(this, "load_file", newfile, 1); - + int prog = 0; bool bRC = false; unsigned int lcn = _lcn; + ResetScroll(); if (m_lastfile == newfile) { lcn = m_lastposn; } // QMessageBox::information(0, "Opening...", newfile); - m_lastwidth = width(); - m_lastheight = height(); + if (m_rotated) + { + m_lastwidth = height(); + m_lastheight = width(); + } + else + { + m_lastwidth = width(); + m_lastheight = height(); + } if (buffdoc.openfile(this,newfile) == 0) { m_lastfile = newfile; - buffdoc.setwidth(m_lastwidth-2*m_border); + buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); bRC = true; buffdoc.setContinuous(m_continuousDocument); -// // odebug << "buffdoc.openfile done" << oendl; + qDebug("buffdoc.openfile done"); locate(lcn); -// // odebug << "buffdoc.locate done" << oendl; + qDebug("buffdoc.locate done"); } setfilter(getfilter()); - update(); -// // odebug << "Updated" << oendl; + qDebug("Updated"); return bRC; } void QTReader::lineDown() { - int ypos = 0; + int ypos = m_topmargin; + ResetScroll(); int offset = numlines; for (int i = 0; i <= numlines; i++) { - if ((ypos += textarray[numlines-i]->lineSpacing()) > height()) + if ((ypos += textarray[numlines-i]->lineSpacing()) > ((m_rotated) ? width() : height())) { offset = i-1; break; @@ -1441,9 +2444,26 @@ void QTReader::lineUp() update(); } */ + +void QTReader::ResetScroll() +{ + m_totalscroll = 0; + m_scrolldy1 = 0; + m_scrolldy = m_topmargin; + if (m_autoScroll && ((m_scrolltype == 0) || !m_bgpm.isNull())) + { + setautoscroll(false); + } +} + void QTReader::lineUp() { - buffdoc.unsuspend(); + dopageup(locnarray[numlines-1]); + + /* + buffdoc.unsuspend(); + ResetScroll(); + CDrawBuffer* buff = textarray[numlines]; unsigned int loc; unsigned int end = locnarray[numlines]; @@ -1510,7 +2530,7 @@ void QTReader::lineUp() textarray[0] = buff; locnarray[0] = loc; int start = numlines; - int ypos = 0; + int ypos = m_topmargin; #ifdef _WINDOWS for (i = 0; i <= numlines; i++) #else @@ -1518,7 +2538,7 @@ void QTReader::lineUp() #endif { ypos += textarray[i]->lineSpacing(); - if (ypos > height()) + if (ypos > ((m_rotated) ? width() : height())) { start = i; ypos -= textarray[i]->lineSpacing(); @@ -1527,7 +2547,8 @@ void QTReader::lineUp() } jumpto(locnarray[start]); fillbuffer(start, ypos); - update(); + repaint(); + */ } bool QTReader::empty() @@ -1552,3 +2573,414 @@ MarkupType QTReader::PreferredMarkup() } return m; } +#ifdef DOUBLEBUFFER +void QTReader::resizeEvent( QResizeEvent * p ) +{ + if (m_rotated) + { + dbuff->resize(p->size().height(),p->size().width()); + } + else + { + dbuff->resize(p->size()); + } + m_bgIsScaled = false; + if (m_bgtype == bgStretched) + { + emit RefreshBitmap(); + } + + { + int h, w; + if (m_rotated) + { + h = p->size().width(); + w = p->size().height(); + } + else + { + w = p->size().width(); + h = p->size().height(); + } + m_topmargin = (h*m_abstopmargin+500)/1000; + m_bottommargin = (h*m_absbottommargin+500)/1000; + m_left_border = (w*m_absleft_border+500)/1000; + m_right_border = (w*m_absright_border+500)/1000; + + qDebug("Top margin:%u", m_topmargin ); + qDebug("Bottom margin:%u", m_bottommargin ); + qDebug("Left margin:%u", m_left_border ); + qDebug("Right margin:%u", m_right_border ); + } +} +#endif + +void QTReader::setrotated(bool sfs) +{ + m_rotated = sfs; +#ifdef DOUBLEBUFFER + if (m_rotated) + { + dbuff->resize(height(), width()); + } + else + { + dbuff->resize(width(), height()); + } + m_bgIsScaled = false; +#endif + int h, w; + if (m_rotated) + { + h = width(); + w = height(); + } + else + { + w = width(); + h = height(); + } + m_topmargin = (h*m_abstopmargin+500)/1000; + m_bottommargin = (h*m_absbottommargin+500)/1000; + m_left_border = (w*m_absleft_border+500)/1000; + m_right_border = (w*m_absright_border+500)/1000; + + qDebug("Top margin:%u", m_topmargin ); + qDebug("Bottom margin:%u", m_bottommargin ); + qDebug("Left margin:%u", m_left_border ); + qDebug("Right margin:%u", m_right_border ); +} + +void QTReader::drawBackground() +{ + dbp->begin(dbuff); + // dbp->setBackgroundMode(OpaqueMode); + dbp->setBackgroundColor(m_bg); + dbp->eraseRect(dbuff->rect()); + if (!m_bgpm.isNull()) + { + // dbp->setBackgroundMode(TransparentMode); + switch (m_bgtype) + { + case bgCentred: + { + int w = (dbuff->rect().width()-m_bgpm.width())/2; + int h = (dbuff->rect().height()-m_bgpm.height())/2; + dbp->drawPixmap(w,h,m_bgpm); + } + break; + case bgTiled: + { + dbp->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm); + /* + for (int h = 0; h < dbuff->rect().height(); h += m_bgpm.height()) + { + for (int w = 0; w < dbuff->rect().width(); w += m_bgpm.width()) + { + dbp->drawPixmap(w,h,m_bgpm); + } + } + */ + } + break; + case bgStretched: + { + if (!m_bgIsScaled) + { + m_bgIsScaled = true; + QImage im = m_bgpm.convertToImage(); + m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height())); + } + dbp->drawPixmap(0,0,m_bgpm); + } + break; + default: + qDebug("Unknown background type"); + } + // dbp->setBackgroundMode(OpaqueMode); + } +} + +void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt) +{ + if (txt != NULL) + { + sh = txt->lineSpacing(); + } + int sy = width()-dx-sh; + if (m_autoScroll && !(m_scrolltype == 0)) + { + sy = (sy+m_totalscroll+1)%width(); + } + + QPixmap pm(sw, sh); + + QPainter pd(&pm, this); + if (m_bgpm.isNull()) + { + pd.eraseRect(pm.rect()); + } + else + { + if (sy+pm.height() > dbuff->height()) + { + // pd.eraseRect(pm.rect()); + int fh = dbuff->height() - sy; + if (sy+fh > dbuff->height()) + { + qDebug("Oh no!"); + } + + if (fh > pm.height()) + { + qDebug("Oh no! - 2"); + } + + bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),fh); + bitBlt(&pm,0,fh,dbuff,dy,0,pm.width(),pm.height()-fh); + } + else + { + bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),pm.height()); + } + } + if (txt != NULL) + { + // txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg); + txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg, width()-m_topmargin-m_bottommargin); + } + QWMatrix m; + m.rotate(90); + QPixmap rp = pm.xForm(m); + /* + p.drawPixmap(QPoint(dx, dy), rp); + */ + bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP); +} + +QString QTReader::about() +{ + return QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka"; +} + +void QTReader::getNextLink() +{ + if (m_scrolldy != 0) + { + setautoscroll(false); + ResetScroll(); + redrawall(); + } + bool redraw = false; + bool found = false; + if (m_currentlink >= 0) + { + m_currentlinkoffset = textarray[m_currentlink]->invertLink(m_currentlinkoffset); + if ((m_currentlinkstyle = textarray[m_currentlink]->getNextLink(m_currentlinkoffset)) != NULL) + { + qDebug("Found a link at %u", m_currentlinkoffset); + int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset); + qDebug("Finishes at %u", offset); + found = true; + } + redraw = true; + drawSingleLine(m_currentlink); + // if (found) return; + } + if (!found) + { + m_currentlinkoffset = -1; + for (int i = m_currentlink+1; i < numlines; ++i) + { + if ((m_currentlinkstyle = textarray[i]->getNextLink(m_currentlinkoffset)) != NULL) + { + m_currentlink = i; + qDebug("Found a link at %u", m_currentlinkoffset); + int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset); + qDebug("Finishes at %u", offset); + //drawSingleLine(i); + redraw = true; + found = true; + drawSingleLine(m_currentlink); + break; + } + } + } + if (redraw) + { + // redrawall(); + } + if (!found) + { + m_currentlink = -1; + m_currentlinkstyle = NULL; + m_currentlinkoffset = -1; + dopagedn(); + } +} + +void QTReader::emitRedraw() +{ + m_currentlinkstyle = NULL; + m_currentlink = -1; + m_currentlinkoffset = -1; + emit OnRedraw(); +}; + +void QTReader::drawSingleLine(int lineno) +{ + QPainter p( this ); + int ypos = textarray[0]->ascent()+m_topmargin; + if (lineno == 0) + { + if (m_rotated) + { + blitRot(width()-(ypos+textarray[lineno]->descent()+textarray[lineno]->lineExtraSpacing()), 0, height(), -1, textarray[lineno]); + } + else + { + if (m_bgpm.isNull()) + { + p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg); + } + else + { + bitBlt(this, m_left_border, ypos-textarray[lineno]->ascent(), dbuff, m_left_border, ypos-textarray[lineno]->ascent(), width()-(m_left_border+m_right_border), textarray[lineno]->lineSpacing()); + } + textarray[lineno]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); + } + } + for (int i = 1; i < numlines; i++) + { + ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+ + (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; + if (i == lineno) + { + if (m_rotated) + { + blitRot(width()-(ypos+textarray[i]->descent()+textarray[i]->lineExtraSpacing()), 0, height(), -1, textarray[i]); + } + else + { + if (m_bgpm.isNull()) + { + p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg); + } + else + { + bitBlt(this, m_left_border, ypos-textarray[lineno]->ascent(), dbuff, m_left_border, ypos-textarray[lineno]->ascent(), width()-(m_left_border+m_right_border), textarray[lineno]->lineSpacing()); + } + textarray[i]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); + } + } + } +} + + +void QTReader::gotoLink() +{ + if (m_currentlinkstyle == NULL) return; + textarray[m_currentlink]->invertLink(m_currentlinkoffset); + size_t saveposn = pagelocate(); + QString href, nm; + unsigned long tgt = m_currentlinkstyle->getData(); + unsigned long tgtoffset = m_currentlinkstyle->getOffset(); + linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm); + qDebug("URL(1):%s", (const char*)href); + if ((lt & eFile) != 0) + { + buffdoc.saveposn(m_lastfile, saveposn); +#ifdef USEQPE + { + QCopEnvelope e("QPE/System", "busy()"); + } +#endif + ResetScroll(); + if (!href.isEmpty()) + { + if (!buffdoc.getFile(href)) + { + emit NewFileRequest(href); + } + else + { + ResetScroll(); + fillbuffer(); + update(); + } + } + if (!nm.isEmpty()) + { + qDebug("QTReader:Finding %s", (const char*)nm); + if (buffdoc.findanchor(nm)) + { + fillbuffer(); + update(); + } + } + //fillbuffer(); + //update(); +#ifdef USEQPE + { + QCopEnvelope e("QPE/System", "notBusy()"); + } +#endif + } + else if ((lt & eLink) != 0) + { + buffdoc.saveposn(m_lastfile, saveposn); + ResetScroll(); + fillbuffer(); + update(); + } + else + { + if ((lt & ePicture) != 0) + { + 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, tgt); + } + } + locate(pagelocate()); + } + m_currentlinkstyle = NULL; + m_currentlink = -1; + m_currentlinkoffset = -1; +} + +void QTReader::refresh(bool full) +{ + int h, w; + if (m_rotated) + { + h = width(); + w = height(); + } + else + { + w = width(); + h = height(); + } + m_topmargin = (h*m_abstopmargin+500)/1000; + m_bottommargin = (h*m_absbottommargin+500)/1000; + m_left_border = (w*m_absleft_border+500)/1000; + m_right_border = (w*m_absright_border+500)/1000; + + qDebug("Top margin:%u", m_topmargin ); + qDebug("Bottom margin:%u", m_bottommargin ); + qDebug("Left margin:%u", m_left_border ); + qDebug("Right margin:%u", m_right_border ); + if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate()); + locate(pagelocate()); +} -- cgit v0.9.0.2