From 39fbfd5eb7e45d73d38e8a2ce9437a3d7e1b8e91 Mon Sep 17 00:00:00 2001 From: pohly Date: Thu, 05 May 2005 14:39:33 +0000 Subject: new opie-reader sources with support for ArriereGo, Reb input and flite output plugins --- (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 33884a0..0c56dd4 100644 --- a/noncore/apps/opie-reader/QTReader.cpp +++ b/noncore/apps/opie-reader/QTReader.cpp @@ -32,12 +32,16 @@ const int _SBARHEIGHT = 3; #endif #include #include +#include "TableDialog.h" +#include "outputcodec.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 }; @@ -49,9 +53,9 @@ 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), + QWidget(parent, name, f | WRepaintNoErase | WResizeNoErase), + m_outofdate(true), m_default_fg(0,0,0), m_default_bg(255,255,255), m_bg(255,255,255), @@ -89,16 +93,12 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : m_currentlinkoffset(-1), m_currentlink(-1) { + m_output = NULL; m_overlap = 1; setKeyCompression ( true ); -#ifdef DOUBLEBUFFER - dbuff = new QPixmap(); - dbp = new QPainter(); - // if (painter->isActive()) painter->end(); - // painter->begin(frame); -#endif -// init(); + dbuff = NULL; + dbp = NULL; } /* @@ -117,7 +117,7 @@ QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *nam m_fm(NULL) { init(); -// // qDebug("Load_file(1)"); +// // qDeb2ug("Load_file(1)"); load_file((const tchar*)filename); } */ @@ -138,7 +138,8 @@ long QTReader::real_delay() void QTReader::mousePressEvent( QMouseEvent* _e ) { - buffdoc.unsuspend(); + m_drageligible = false; + qDebug("Mouse pressed at (%u, %u)", _e->x(), _e->y()); int x, y, ht, wh; if (m_rotated) { @@ -154,27 +155,171 @@ void QTReader::mousePressEvent( QMouseEvent* _e ) ht = height(); wh = width(); } - if (_e->button() == RightButton) + if (x >= m_left_border && x <= wh - m_right_border && y >= m_topmargin && y <= ht-m_bottommargin) { -// qDebug("MousePress"); - mouseUpOn = false; - if (m_swapmouse) + if (_e->button() == RightButton) { - int lineno = 0; - /* + // qDebug("MousePress"); + mouseUpOn = false; + if (m_swapmouse) + { + int lineno = 0; + /* int hgt = textarray[0]->lineSpacing(); while ((hgt < y) && (lineno < numlines)) { - hgt += textarray[++lineno]->lineSpacing(); + hgt += textarray[++lineno]->lineSpacing(); } - */ - 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); + */ + size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt; + QImage* img; + getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt); + processmousewordevent(startpos, startoffset, _e, lineno); + } + else + { + processmousepositionevent(_e); + } + } + } + else + { + int ln = -1; + int mp; + int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); + switch (m_scrollpos) + { + case 1: + { + if (m_rotated) + { + if (_e->x() < m_bottommargin) + { + ln = height(); + mp = _e->y(); + } + } + else + { + if (_e->y() > height()-m_bottommargin) + { + ln = width(); + mp = _e->x(); + } + } + } + break; + case 2: + { + if (m_rotated) + { + if (_e->y() > height() - m_right_border) + { + ln = width(); + mp = width()-_e->x(); + } + } + else + { + if (_e->x() > width() - m_right_border) + { + ln = height(); + mp = _e->y(); + } + } + } + break; + case 3: + { + if (m_rotated) + { + if (_e->y() < m_left_border) + { + ln = width(); + mp = width()-_e->x(); + } + } + else + { + if (_e->x() < m_left_border) + { + ln = height(); + mp = _e->y(); + } + } + } + break; + case 0: + default: + ln = -1; + break; + } + if (ln >= 0) + { + int dp = (sectionsize*mp+ln/2)/ln + buffdoc.startSection(); + int winsize = locnarray[numlines]-locnarray[0]; + int slidersize = 10*(sectionsize+ln/2)/ln; + if (slidersize > winsize) + { + int mid = (locnarray[0] + locnarray[numlines])/2; + slidersize /= 2; + if (dp < mid-slidersize) + { + dopageup(); + } + else if (dp > mid+slidersize) + { + dopagedn(); + } + //if (mid-slidersize < dp && dp < mid+slidersize) + else + { + m_drageligible = true; + } + } + else + { + if (dp < locnarray[0]) + { + dopageup(); + } + else if (dp > locnarray[numlines]) + { + dopagedn(); + } + //if (locnarray[0] < dp && dp < locnarray[numlines]) + else + { + m_drageligible = true; + } + } + qDebug("Drag eligible:%s", (m_drageligible) ? "true" : "false"); + } + else + { + if (m_scrollpos == 1) + { + if (x < m_left_border) + { + lineUp(); + } + if (y > ht - m_bottommargin) + { + lineDown(); + } + } + else if (m_scrollpos != 0) + { + if (y < m_topmargin) + { + lineUp(); + } + if (y > ht - m_bottommargin) + { + lineDown(); + } + } } - else - processmousepositionevent(_e); } } @@ -295,7 +440,7 @@ void QTReader::goForward() } } -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) +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, size_t& tabtgt) { int ht; if (m_scrolldy == m_topmargin) @@ -340,7 +485,7 @@ linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t 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); + return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img, tabtgt); } void QTReader::suspend() @@ -354,6 +499,38 @@ void QTReader::suspend() */ } +void QTReader::setDoubleBuffer(bool _b) +{ + m_doubleBuffered = _b; + if (_b || m_rotated) + { + if (dbuff == NULL) + { + dbuff = new QPixmap(); + dbp = new QPainter(); + } + if (m_rotated) + { + dbuff->resize(height(), width()); + } + else + { + dbuff->resize(width(), height()); + } + m_outofdate = true; + } + else + { + if (dbuff != NULL) + { + delete dbuff; + delete dbp; + } + dbuff = NULL; + dbp = NULL; + } +} + void QTReader::setTwoTouch(bool _b) { setBackgroundColor( m_bg ); @@ -362,7 +539,6 @@ void QTReader::setTwoTouch(bool _b) void QTReader::setContinuous(bool _b) { - buffdoc.unsuspend(); buffdoc.setContinuous(m_continuousDocument = _b); } @@ -455,7 +631,7 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse } if (!wrd.isEmpty()) { - qDebug("Selecteed:%s", (const char*)wrd); + qDebug("Selected:%s", (const char*)wrd); if (m_twotouch) { emit OnWordSelected(wrd, wrdstart, wrdend, wrd); @@ -468,211 +644,347 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse } } -void QTReader::mouseReleaseEvent( QMouseEvent* _e ) +#ifdef USETIMER +void QTReader::actionDrag() { - buffdoc.unsuspend(); - int x, y, ht, wh; - if (m_rotated) + if (m_drageligible) { - x = _e->y(); - y = width()-_e->x(); - ht = width(); - wh = height(); + int fivepages = 5*((2*width()+m_textsize/2)/m_textsize)*((height()+m_textsize/2)/m_textsize); + if (m_dragtarget > fivepages && locnarray[numlines] < m_dragtarget - fivepages) + { + int tgt = m_dragtarget - fivepages/2; + //qDebug("Jumping to %u (%u)", tgt, fivepages); + if (tgt < buffdoc.startSection()) + { + tgt = buffdoc.startSection(); + } + locate(tgt); + drawFonts(); + } + else if (locnarray[0] > m_dragtarget+fivepages) + { + int tgt = m_dragtarget + fivepages/2; + //qDebug("Jumping to %u (%u)", tgt, fivepages); + if (tgt > buffdoc.endSection()) + { + dopageup(); + } + else + { + locate(tgt); + drawFonts(); + } + } + else if (locnarray[numlines] <= m_dragtarget) + { + dopagedn(); + } + else if (locnarray[0] > m_dragtarget) + { + dopageup(); + } } else { - x = _e->x(); - y = _e->y(); - ht = height(); - wh = width(); + m_dragtimer->stop(); } - if (_e->button() == LeftButton) +} +#endif + +void QTReader::mouseMoveEvent( QMouseEvent* _e ) +{ + if (m_drageligible) { - if (mouseUpOn) + int ht; + int mp; + int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); + //qDebug("Mouse moved to (%u, %u)", _e->x(), _e->y()); + switch (m_scrollpos) { -// qDebug("MouseRelease"); - switch(m_scrollpos) + case 1: + { + if (m_rotated) + { + ht = height(); + mp = _e->y(); + } + else + { + ht = width(); + mp = _e->x(); + } + } + break; + case 2: + case 3: + { + if (m_rotated) + { + ht = width(); + mp = width()-_e->x(); + } + else + { + ht = height(); + mp = _e->y(); + } + } + break; + case 0: + default: + ht = -1; + break; + } + if (ht >= 0) + { +#ifdef USETIMER + m_dragtarget = (sectionsize*mp+ht/2)/ht + buffdoc.startSection(); + if (!m_dragtimer->isActive()) { - 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; + m_dragtimer->start(0, false); } - if (textarray[0] != NULL) +#else + int dp = (sectionsize*mp+ht/2)/ht + buffdoc.startSection(); + locate(dp); +#endif + } + } +} + +void QTReader::mouseReleaseEvent( QMouseEvent* _e ) +{ + qDebug("Mouse released at (%u, %u)", _e->x(), _e->y()); + if (m_drageligible) + { + m_drageligible = false; + } + else + { + 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) { - QString line; -// int lineno = _e->y()/m_linespacing; - int lineno = 0; - /* - int ht = textarray[0]->lineSpacing(); - while ((ht < y) && (lineno < numlines)) + // qDebug("MouseRelease"); + /* + switch(m_scrollpos) { - ht += textarray[++lineno]->lineSpacing(); + case 1: // Bottom + if (y > ht - 5) + { + locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh); + return; } - */ - 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); + 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 < y) && (lineno < numlines)) + { + ht += textarray[++lineno]->lineSpacing(); + } + */ + size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt; + 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, tabtgt); + if (bNoInlineTables && ((glt & eTable) != 0)) + { + size_t currentpos = locate(); + QString tabtext = buffdoc.getTableAsHtml(tabtgt); + qDebug("TABLE:%u:%u:%s", currentpos, tabtgt, (const char*)tabtext); + QFont f(m_fontname, m_fontControl.currentsize()); #ifdef USEQPE + CTableDialog td(f, tabtext, true, this); +#else + CTableDialog td(f, tabtext, false, this); +#endif + td.exec(); + jumpto(currentpos); + } + if ((glt & eLink) != 0) + { + if ((glt & ePicture) != 0) { - QCopEnvelope e("QPE/System", "busy()"); + 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; + } + } } -#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 + else if (img != NULL) { - QCopEnvelope e("QPE/System", "notBusy()"); + if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) + { + emit OnShowPicture(*img); + return; + } } -#endif - } - else if ((lt & eLink) != 0) - { - buffdoc.saveposn(m_lastfile, saveposn); - ResetScroll(); - fillbuffer(); - update(); - } - else - { - if ((lt & ePicture) != 0) + 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 { - QImage* pm = buffdoc.getPicture(tgt); - if (pm != NULL) - { - emit OnShowPicture(*pm); - delete pm; - } + QCopEnvelope e("QPE/System", "busy()"); } - else +#endif + ResetScroll(); + if (!href.isEmpty()) + { + if (!buffdoc.getFile(href, nm)) + { + emit NewFileRequest(href); + } + else + { + qDebug("BEFORE:%u", pagelocate()); + buffdoc.resetPos(); + ResetScroll(); + fillbuffer(); + qDebug("AFTER:%u", pagelocate()); + m_outofdate = true; + update(); + } + } + if (!nm.isEmpty()) + { + qDebug("QTReader:Finding %s", (const char*)nm); + if (buffdoc.findanchor(nm)) + { + buffdoc.resetPos(); + fillbuffer(); + m_outofdate = true; + update(); + } + } + //fillbuffer(); + //update(); +#ifdef USEQPE { - // QString anchortext = textarray[lineno]->getanchortext(startoffset); - if (!href.isEmpty()) - { - emit OnURLSelected(href, tgt); - } + QCopEnvelope e("QPE/System", "notBusy()"); } - 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) +#endif + } + else if ((lt & eLink) != 0) + { + buffdoc.saveposn(m_lastfile, saveposn); + ResetScroll(); + fillbuffer(); + m_outofdate = true; + 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); + } + } + } + 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 + { + update(); + } + return; + } + else if (img != NULL) + { + emit OnShowPicture(*img); + return; + } + if (m_swapmouse) processmousepositionevent(_e); - else + else processmousewordevent(startpos, startoffset, _e, lineno); + } + } + else + { + mouseUpOn = true; } - } - else - { - mouseUpOn = true; } } } void QTReader::focusInEvent(QFocusEvent* e) { - if (m_autoScroll) timer->start(real_delay(), false); + if (m_autoScroll && (m_scrolltype != 4)) timer->start(real_delay(), false); update(); } @@ -680,7 +992,14 @@ void QTReader::focusOutEvent(QFocusEvent* e) { if (m_autoScroll) { - timer->stop(); + if (m_scrolltype != 4) + { + timer->stop(); + } + else + { + m_autoScroll = false; + } // m_scrolldy1 = m_scrolldy2 = 0; } } @@ -717,7 +1036,6 @@ void QTReader::goUp() void QTReader::NavUp() { - buffdoc.unsuspend(); if (buffdoc.hasnavigation()) { /* @@ -737,7 +1055,6 @@ void QTReader::NavUp() void QTReader::NavDown() { - buffdoc.unsuspend(); if (buffdoc.hasnavigation()) { /* @@ -762,8 +1079,7 @@ void QTReader::zoomin() bool sc = m_autoScroll; setautoscroll(false); setfont(); - locate(pagelocate()); - repaint(); + refresh(); setautoscroll(sc); } } @@ -775,8 +1091,7 @@ void QTReader::zoomout() bool sc = m_autoScroll; setautoscroll(false); setfont(); - locate(pagelocate()); - repaint(); + refresh(); setautoscroll(sc); } } @@ -809,8 +1124,7 @@ void QTReader::increaseScroll() void QTReader::keyPressEvent(QKeyEvent* e) { - buffdoc.unsuspend(); - + //((QTReaderApp*)parent()->parent())->handlekey(e); emit HandleKeyRequest(e); // e->ignore(); @@ -906,6 +1220,7 @@ void QTReader::CalculateScrollParameters() void QTReader::setautoscroll(bool _sc) { + m_outofdate = true; if (_sc == m_autoScroll) return; if (m_autoScroll) { @@ -927,6 +1242,9 @@ void QTReader::setautoscroll(bool _sc) { CDrawBuffer* reusebuffer = textarray[numlines]; if (reusebuffer == NULL || reusebuffer->eof()) return; +#ifndef __STATIC + if ((m_scrolltype == 4) && !checkoutput()) return; +#endif m_autoScroll = true; CalculateScrollParameters(); @@ -947,7 +1265,6 @@ 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) @@ -1065,24 +1382,6 @@ void QTReader::doinplacescroll() 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 @@ -1099,7 +1398,6 @@ void QTReader::doinplacescroll() } } #endif - //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); emit SetScrollState(m_autoScroll); #ifdef USEQPE QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; @@ -1494,9 +1792,20 @@ void QTReader::redrawScroll(QPainter* p) void QTReader::autoscroll() { - drawBackground(); - dbp->end(); - timer->start(real_delay(), false); + if (m_scrolltype == 4) + { + readAloud(); + } + else + { + if (dbuff != NULL) + { + dbp->begin(dbuff); + drawBackground(dbp); + dbp->end(); + } + timer->start(real_delay(), false); + } } void QTReader::setfont() @@ -1557,39 +1866,49 @@ 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 + if (dbuff != NULL) + { + dbp->begin(dbuff); + drawBackground(dbp); + 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 + { + qDebug("This shouldn't happen but it doesn't matter if it does (rotated == double buffered)"); + QPixmap dbuff(height(), width()); + QPainter dbp(&dbuff); + + drawBackground(&dbp); + DrawStraight(&dbp, height(), width()); + + QWMatrix m; + m.rotate(90); + QPixmap rp = dbuff.xForm(m); + bitBlt(this, 0,0,&rp,0,0,-1,-1); + } } 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 + if (dbuff != NULL) + { + dbp->begin(dbuff); + drawBackground(dbp); + DrawStraight(dbp, width(), height()); + dbp->end(); + bitBlt(this, 0,0,dbuff,0,0,-1,-1); + } + else + { + QPainter p(this); + drawBackground(&p); + DrawStraight(&p, width(), height()); + } } } @@ -1600,10 +1919,36 @@ void QTReader::drawFonts() int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); if (hmargin < m_bottommargin) hmargin = m_bottommargin; // qDebug("How refreshing..."); - if (buffdoc.empty()) return; + if (buffdoc.empty()) + { + if (dbuff != NULL) + { + dbp->begin(dbuff); + drawBackground(dbp); + dbp->end(); + } + else + { + QPainter p(this); + drawBackground(&p); + } + return; + } setfont(); // if (!m_autoScroll) m_scrolldy1 = 0; -#ifdef ROTATION_ENABLED + if (dbuff != NULL && (dbuff->width() != width() || dbuff->height() != height())) + { + qDebug("Oh no! A resize event was missed..."); + if (m_rotated) + { + dbuff->resize(height(), width()); + } + else + { + dbuff->resize(width(), height()); + } + m_lastwidth = 0; + } if (m_lastwidth != ((m_rotated) ? height() : width())) { m_scrolldy = m_topmargin; @@ -1611,7 +1956,9 @@ void QTReader::drawFonts() m_lastwidth = ((m_rotated) ? height() : width()); m_lastheight = ((m_rotated) ? width() : height()); buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); - locate(pagelocate()); + buffdoc.locate(pagelocate()); + fillbuffer(); + redrawall(); // qDebug("Not Optimised %d", m_lastwidth); } else @@ -1651,63 +1998,6 @@ void QTReader::drawFonts() redrawall(); } } -#else - if (m_lastwidth != width()) - { - // qDebug("Not Optimised %d", m_lastwidth); - m_lastwidth = width(); - m_lastheight = height(); - buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); - locate(pagelocate()); -// qDebug("Not Optimised %d", m_lastwidth); - } - else - { - int newht = height(); - if (m_lastheight > newht) - { -// 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 - hmargin) - { - numlines = i; - jumpto(mylastpos = locnarray[i+1]); - break; - } - } -// qDebug("Optimised < %d", numlines); - m_lastheight = newht; - } - else if (m_lastheight < newht) - { -// qDebug("Optimised > %d", numlines); - int ypos = 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) - { - 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++) - { -// 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_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin); - } -// mylastpos = locate(); - } - } -#endif emitRedraw(); } /* @@ -1928,13 +2218,16 @@ bool QTReader::ChangeFont(int tgt) void QTReader::init() { - buffdoc.unsuspend(); setBackgroundColor( m_bg ); buffdoc.setfilter(getfilter()); ChangeFont(m_textsize); setFocusPolicy(QWidget::StrongFocus); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); +#ifdef USETIMER + m_dragtimer = new QTimer(this); + connect(m_dragtimer, SIGNAL(timeout()), this, SLOT(actionDrag())); +#endif // QMessageBox::information(this, "init", m_lastfile, 1); setfont(); } @@ -1944,10 +2237,15 @@ void QTReader::init() // QTReader::~QTReader() { -#ifdef DOUBLEBUFFER - delete dbuff; - delete dbp; -#endif + if (m_output != NULL) + { + delete m_output; + } + if (dbuff != NULL) + { + delete dbuff; + delete dbp; + } #ifdef USEQPE if (m_autoScroll) { @@ -1982,9 +2280,47 @@ void QTReader::printIt() // Called when the widget needs to be updated. // -void QTReader::paintEvent( QPaintEvent * ) +void QTReader::paintEvent( QPaintEvent * p ) { - drawFonts(); + if ((dbuff != NULL) && !m_outofdate) + { + if (m_rotated) + { + if ((p->rect().width() != width()) || (p->rect().height() != height())) + { + qDebug("Partial paint"); + QRect r; + r.setTop(width()-p->rect().right()-1); + r.setLeft(p->rect().top()); + r.setHeight(p->rect().width()); + r.setWidth(p->rect().height()); + QPixmap p1(r.width(), r.height()); + bitBlt(&p1, QPoint(0, 0), dbuff, r); + QWMatrix m; + m.rotate(90); + QPixmap p2 = p1.xForm(m); + bitBlt(this, p->rect().left(), p->rect().top(), &p2, 0, 0, -1, -1); + } + else + { + qDebug("Full paint"); + QWMatrix m; + m.rotate(90); + QPixmap rp = dbuff->xForm(m); + bitBlt(this, 0,0,&rp,0,0,-1,-1); + } + } + else + { + //bitBlt(this, 0,0,dbuff,0,0,-1,-1); + bitBlt(this,p->rect().topLeft(),dbuff,p->rect()); + } + } + else + { + drawFonts(); + } + m_outofdate = false; } // @@ -2016,20 +2352,30 @@ int main( int argc, tchar **argv ) */ +bool QTReader::locate(unsigned long n) +{ + m_outofdate = true; + m_lastwidth = 0; + locnarray[0] = n; + ResetScroll(); + update(); + return true; +} +/* bool QTReader::locate(unsigned long n) { //printf("Locate\n"); - buffdoc.unsuspend(); buffdoc.locate(n); // // qDebug("&buffdoc.located"); ResetScroll(); fillbuffer(); + m_outofdate = true; // // qDebug("&Buffer filled"); update(); // // qDebug("&Located"); emitRedraw(); return true; } - +*/ unsigned int QTReader::screenlines() { // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; @@ -2039,7 +2385,6 @@ 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; @@ -2063,14 +2408,23 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht) locnarray[numlines] = locate(); int ch = getline(textarray[numlines]); ypos += textarray[numlines]->lineSpacing(); + /* + QString tmp = toQString(textarray[numlines]->data()); + printf("[%u, %u, %u](%s):%s\n", lastypos, m_lastheight-hmargin, ypos, + ((textarray[numlines]->showPartial()) ? "TRUE" : "FALSE"), + (const char*)tmp); + */ numlines++; if (!ch) { - if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/) + if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/) { qDebug("FALSE"); + if (oldpagepos < buffdoc.endSection()) locate(oldpagepos); - return false; + else + dopageup(buffdoc.endSection()); + return false; } else { @@ -2101,7 +2455,6 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht) void QTReader::dopagedn() { // qDebug("HEIGHT(2):%d", m_lastheight); - buffdoc.unsuspend(); ResetScroll(); int skip = 0, ypos = m_topmargin; if (locate() != mylastpos) @@ -2150,20 +2503,21 @@ 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; + if ((ch == UEOF) || (ch == 6)) + { + return false; + } } return false; } void QTReader::dopageup(unsigned int target) { - buffdoc.unsuspend(); ResetScroll(); CBufferFace buff; CBufferFace loc; - size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; + qDebug("dopageup:: locate():%u pagelocate():%u guess:%u", locate(), pagelocate(), guess); bool ch = true; int nbfl, ypos = m_topmargin; if (guess < 128) guess = 128; @@ -2180,6 +2534,7 @@ void QTReader::dopageup(unsigned int target) else if (!m_continuousDocument && (target - guess < buffdoc.startSection())) { delta = 0; // 0 is a flag to say don't guess any more + qDebug("Jumping to startsection:%d", buffdoc.startSection()); jumpto(buffdoc.startSection()); } else @@ -2187,15 +2542,15 @@ void QTReader::dopageup(unsigned int target) delta = guess; if (!synch(target-delta, target-lastdelta)) { - lastdelta = delta; - if (guess < 4000) + lastdelta = delta; + if (guess < 4000) { - guess <<= 1; - continue; + guess <<= 1; + continue; } - else + else { - jumpto(target-delta); + jumpto(target-delta); } } } @@ -2293,8 +2648,9 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) int prog = 0; bool bRC = false; unsigned int lcn = _lcn; + bDoUpdates = false; ResetScroll(); - if (m_lastfile == newfile) + if (m_lastfile == newfile && lcn == 0) { lcn = m_lastposn; } @@ -2316,11 +2672,11 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn) bRC = true; buffdoc.setContinuous(m_continuousDocument); qDebug("buffdoc.openfile done"); - locate(lcn); - qDebug("buffdoc.locate done"); } setfilter(getfilter()); qDebug("Updated"); + bDoUpdates = true; + locate(lcn); return bRC; } @@ -2358,6 +2714,7 @@ void QTReader::lineDown() } getline(textarray[numlines]); mylastpos = locate(); + m_outofdate = true; update(); } /* @@ -2572,16 +2929,21 @@ MarkupType QTReader::PreferredMarkup() } return m; } -#ifdef DOUBLEBUFFER + void QTReader::resizeEvent( QResizeEvent * p ) { - if (m_rotated) - { - dbuff->resize(p->size().height(),p->size().width()); - } - else + qDebug("Resizing"); + m_outofdate = true; + if (dbuff != NULL) { - dbuff->resize(p->size()); + if (m_rotated) + { + dbuff->resize(p->size().height(),p->size().width()); + } + else + { + dbuff->resize(p->size()); + } } m_bgIsScaled = false; if (m_bgtype == bgStretched) @@ -2605,29 +2967,23 @@ void QTReader::resizeEvent( QResizeEvent * p ) 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 (dbuff != NULL && buffdoc.empty()) + { + dbp->begin(dbuff); + drawBackground(dbp); + dbp->end(); + } } -#endif void QTReader::setrotated(bool sfs) { + qDebug("Rotating"); m_rotated = sfs; -#ifdef DOUBLEBUFFER - if (m_rotated) - { - dbuff->resize(height(), width()); - } - else - { - dbuff->resize(width(), height()); - } + setDoubleBuffer(m_doubleBuffered); m_bgIsScaled = false; -#endif + m_outofdate = true; + /* int h, w; if (m_rotated) { @@ -2648,38 +3004,57 @@ void QTReader::setrotated(bool sfs) qDebug("Bottom margin:%u", m_bottommargin ); qDebug("Left margin:%u", m_left_border ); qDebug("Right margin:%u", m_right_border ); + */ } -void QTReader::drawBackground() +void QTReader::drawBackground(QPainter *p) { - dbp->begin(dbuff); - // dbp->setBackgroundMode(OpaqueMode); - dbp->setBackgroundColor(m_bg); - dbp->eraseRect(dbuff->rect()); + // p->setBackgroundMode(OpaqueMode); + p->setBackgroundColor(m_bg); + if (dbuff != NULL) + { + p->eraseRect(dbuff->rect()); + } + else + { + if (m_rotated) + { + p->eraseRect(0,0,height(),width()); + } + else + { + p->eraseRect(rect()); + } + } if (!m_bgpm.isNull()) { - // dbp->setBackgroundMode(TransparentMode); + // p->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); + if (dbuff == NULL) + { + p->drawPixmap(width(),height(),m_bgpm); + } + else + { + int w = (dbuff->rect().width()-m_bgpm.width())/2; + int h = (dbuff->rect().height()-m_bgpm.height())/2; + p->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()) + if (dbuff == NULL) { - for (int w = 0; w < dbuff->rect().width(); w += m_bgpm.width()) - { - dbp->drawPixmap(w,h,m_bgpm); - } + p->drawTiledPixmap(0,0,width(),height(),m_bgpm); + } + else + { + p->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm); } - */ } break; case bgStretched: @@ -2688,15 +3063,22 @@ void QTReader::drawBackground() { m_bgIsScaled = true; QImage im = m_bgpm.convertToImage(); - m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height())); + if (dbuff == NULL) + { + m_bgpm.convertFromImage(im.smoothScale(width(),height())); + } + else + { + m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height())); + } } - dbp->drawPixmap(0,0,m_bgpm); + p->drawPixmap(0,0,m_bgpm); } break; default: qDebug("Unknown background type"); } - // dbp->setBackgroundMode(OpaqueMode); + // p->setBackgroundMode(OpaqueMode); } } @@ -2759,7 +3141,12 @@ void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt) QString QTReader::about() { - return QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka"; + QString ab = QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka"; + if (m_output != NULL) + { + ab += QString("\n") + m_output->about(); + } + return ab; } void QTReader::getNextLink() @@ -2897,7 +3284,7 @@ void QTReader::gotoLink() ResetScroll(); if (!href.isEmpty()) { - if (!buffdoc.getFile(href)) + if (!buffdoc.getFile(href, nm)) { emit NewFileRequest(href); } @@ -2905,6 +3292,7 @@ void QTReader::gotoLink() { ResetScroll(); fillbuffer(); + m_outofdate = true; update(); } } @@ -2913,7 +3301,9 @@ void QTReader::gotoLink() qDebug("QTReader:Finding %s", (const char*)nm); if (buffdoc.findanchor(nm)) { + buffdoc.resetPos(); fillbuffer(); + m_outofdate = true; update(); } } @@ -2930,6 +3320,7 @@ void QTReader::gotoLink() buffdoc.saveposn(m_lastfile, saveposn); ResetScroll(); fillbuffer(); + m_outofdate = true; update(); } else @@ -2949,9 +3340,9 @@ void QTReader::gotoLink() if (!href.isEmpty()) { emit OnURLSelected(href, tgt); + refresh(); } } - locate(pagelocate()); } m_currentlinkstyle = NULL; m_currentlink = -1; @@ -2960,6 +3351,7 @@ void QTReader::gotoLink() void QTReader::refresh(bool full) { + qDebug("Refreshing"); int h, w; if (m_rotated) { @@ -2981,5 +3373,120 @@ void QTReader::refresh(bool full) qDebug("Left margin:%u", m_left_border ); qDebug("Right margin:%u", m_right_border ); if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate()); + m_outofdate = true; locate(pagelocate()); } + +#include "striphtml.h" + +CFilterChain* QTReader::getfilter() +{ + CFilterChain * filt = new CFilterChain(getencoding()); + if (bstripcr) filt->addfilter(new stripcr); + + if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt); + if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter); + // if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile)); + +#ifdef __STATIC + if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile)); + if (bautofmt && (PreferredMarkup() == cCHM)) + { + striphtml* f = new striphtml(m_lastfile); + f->setchm(true); + filt->addfilter(f); + } +#else + if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new ExternFilter("HTMLfilter", m_lastfile)); + if (bautofmt && (PreferredMarkup() == cCHM)) + { + ExternFilter* f = new ExternFilter("HTMLfilter",m_lastfile); + ((striphtml*)f->filter())->setchm(true); + filt->addfilter(f); + } +#endif + m_highlightfilter = new HighlightFilter(this); + filt->addfilter(m_highlightfilter); + + if (bdehyphen) filt->addfilter(new dehyphen); + if (bunindent) filt->addfilter(new unindent); + if (brepara) filt->addfilter(new repara(m_reparastring)); + if (bonespace) filt->addfilter(new OnePara); + if (bindenter) filt->addfilter(new indenter(bindenter)); + if (bdblspce) filt->addfilter(new dblspce); + if (bdepluck) filt->addfilter(new DePluck(pluckernextpart)); + if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart)); + if (brepalm) filt->addfilter(new repalm); + if (bunderlineLink) filt->addfilter(new underlineLink); + if (bkern) filt->addfilter(new kern); + if (bremap) filt->addfilter(new remap); + if (bmakebold) filt->addfilter(new embolden); + if (bfulljust) filt->addfilter(new FullJust); + int r,g,b; + m_default_bg.rgb(&r, &g, &b); + if (r != 255 || g != 255 || b != 255) + filt->addfilter(new setbg(r,g,b)); + m_default_fg.rgb(&r, &g, &b); + if (r != 0 || g != 0 || b != 0) + filt->addfilter(new setfg(r,g,b)); + // if (bNegative) filt->addfilter(new makeNegative); + if (bInverse) filt->addfilter(new makeInverse); + if (bNoInlineTables) filt->addfilter(new tableLink); + return filt; +} + +void QTReader::readAloud() +{ +#ifdef __STATIC + return; +#else + CBuffer para; + jumpto(pagelocate()); + while (m_autoScroll && (buffdoc.getpara(para) != -1)) + { + if (para.length() > 0) + { + unsigned long lastpos = buffdoc.explocate(); + while (lastpos > mylastpos) + { + dopagedn(); + qApp->processEvents(); + } + jumpto(lastpos); + QString txt = toQString(para.data()); + + doOutput(txt); + } + qApp->processEvents(); + } +#endif +} + +bool QTReader::doOutput(const QString& wrd) +{ + if (m_output != NULL) + { + m_output->output(wrd); + return true; + } + else + { + return false; + } +} + +bool QTReader::checkoutput() +{ + if (m_output == NULL) + { + m_output = new outputcodec(m_outputName); + if (reinterpret_cast(m_output)->getStatus() != 0) + { + delete m_output; + m_output = NULL; + QMessageBox::warning(this, PROGNAME, QString("Couldn't find output codec\n")+m_outputName); + return false; + } + } + return true; +} -- cgit v0.9.0.2