summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/QTReader.cpp
Side-by-side diff
Diffstat (limited to 'noncore/apps/opie-reader/QTReader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp1301
1 files changed, 904 insertions, 397 deletions
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
@@ -29,32 +29,36 @@ const int _SBARHEIGHT = 3;
#include <qpe/applnk.h>
#include <qpe/global.h>
#include <qpe/qcopenvelope_qws.h>
#endif
#include <qfileinfo.h>
#include <qdir.h>
+#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 };
//const int QTReader::fontsizes[] = {10,16,17,22,0};
//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0};
tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 };
tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
-
QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
- 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),
m_delay(100),
m_scrolldy1(0),
m_scrolldy2(0),
@@ -86,22 +90,18 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
m_bottommargin(5),
m_reparastring("{\\n[\\n ]}"),
m_currentlinkstyle(NULL),
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;
}
/*
QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
QWidget(parent, name, f),
m_textfont(0),
@@ -114,13 +114,13 @@ QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *nam
bdblspce(false),
btight(false),
bindenter(0),
m_fm(NULL)
{
init();
-// // qDebug("Load_file(1)");
+// // qDeb2ug("Load_file(1)");
load_file((const tchar*)filename);
}
*/
/*
void QTReader::mouseMoveEvent(QMouseEvent* _e)
@@ -135,13 +135,14 @@ long QTReader::real_delay()
{
return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
}
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)
{
x = _e->y();
y = width()-_e->x();
ht = width();
@@ -151,33 +152,177 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
{
x = _e->x();
y = _e->y();
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);
}
}
void QTReader::processmousepositionevent( QMouseEvent* _e )
{
int x, y, ht, wh;
@@ -292,13 +437,13 @@ void QTReader::goForward()
{
locate(target);
}
}
}
-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)
{
lineno = 0;
ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin;
@@ -337,13 +482,13 @@ linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t
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);
+ return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img, tabtgt);
}
void QTReader::suspend()
{
buffdoc.suspend();
/*#ifdef OPIE
@@ -351,21 +496,52 @@ void QTReader::suspend()
#else
if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend();
#endif
*/
}
+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 );
m_twotouch = m_touchone = _b;
}
void QTReader::setContinuous(bool _b)
{
- buffdoc.unsuspend();
buffdoc.setContinuous(m_continuousDocument = _b);
}
void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno)
{
unsigned long wrdstart, wrdend;
@@ -452,238 +628,381 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
if ((*t)[i] == 0) break;
first = i;
}
}
if (!wrd.isEmpty())
{
- qDebug("Selecteed:%s", (const char*)wrd);
+ qDebug("Selected:%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 )
+#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();
}
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;
}
}
#include <qapplication.h>
#include <qdrawutil.h>
@@ -714,13 +1033,12 @@ void QTReader::goUp()
lineUp();
}
}
void QTReader::NavUp()
{
- buffdoc.unsuspend();
if (buffdoc.hasnavigation())
{
/*
size_t target = pagelocate();
if (buffdoc.back(target))
{
@@ -734,13 +1052,12 @@ void QTReader::NavUp()
goUp();
}
}
void QTReader::NavDown()
{
- buffdoc.unsuspend();
if (buffdoc.hasnavigation())
{
/*
size_t target = pagelocate();
if (buffdoc.forward(target))
{
@@ -759,27 +1076,25 @@ void QTReader::zoomin()
{
if (m_fontControl.increasesize())
{
bool sc = m_autoScroll;
setautoscroll(false);
setfont();
- locate(pagelocate());
- repaint();
+ refresh();
setautoscroll(sc);
}
}
void QTReader::zoomout()
{
if (m_fontControl.decreasesize())
{
bool sc = m_autoScroll;
setautoscroll(false);
setfont();
- locate(pagelocate());
- repaint();
+ refresh();
setautoscroll(sc);
}
}
void QTReader::reduceScroll()
{
@@ -806,14 +1121,13 @@ void QTReader::increaseScroll()
m_delay = 454;
}
}
void QTReader::keyPressEvent(QKeyEvent* e)
{
- buffdoc.unsuspend();
-
+
//((QTReaderApp*)parent()->parent())->handlekey(e);
emit HandleKeyRequest(e);
// e->ignore();
return;
#ifdef _SCROLLPIPE
if (m_isPaused)
@@ -903,12 +1217,13 @@ void QTReader::CalculateScrollParameters()
break;
}
}
void QTReader::setautoscroll(bool _sc)
{
+ m_outofdate = true;
if (_sc == m_autoScroll) return;
if (m_autoScroll)
{
m_autoScroll = false;
#ifdef USEQPE
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
@@ -924,12 +1239,15 @@ void QTReader::setautoscroll(bool _sc)
//refresh();
}
else
{
CDrawBuffer* reusebuffer = textarray[numlines];
if (reusebuffer == NULL || reusebuffer->eof()) return;
+#ifndef __STATIC
+ if ((m_scrolltype == 4) && !checkoutput()) return;
+#endif
m_autoScroll = true;
CalculateScrollParameters();
#ifdef _SCROLLPIPE
if (!m_pipetarget.isEmpty())
{
@@ -944,13 +1262,12 @@ void QTReader::setautoscroll(bool _sc)
#endif
}
}
bool QTReader::getline(CDrawBuffer *buff)
{
- buffdoc.unsuspend();
bool bRet;
int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
if (m_bMonoSpaced)
{
bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht);
}
@@ -1062,30 +1379,12 @@ void QTReader::doinplacescroll()
}
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)
@@ -1096,13 +1395,12 @@ void QTReader::doinplacescroll()
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())
@@ -1491,15 +1789,26 @@ void QTReader::redrawScroll(QPainter* p)
}
if (m_scrollpos != 0) DrawScroll(p, width(), height());
}
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()
{
// m_fontControl.Change
m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
@@ -1554,67 +1863,105 @@ void QTReader::DrawStraight(QPainter* p, int w, int h)
}
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());
+ }
}
}
void QTReader::drawFonts()
{
if (bDoUpdates)
{
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;
// 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());
+ buffdoc.locate(pagelocate());
+ fillbuffer();
+ redrawall();
// qDebug("Not Optimised %d", m_lastwidth);
}
else
{
int newht = ((m_rotated) ? width() : height());
if (m_lastheight > newht)
@@ -1648,69 +1995,12 @@ void QTReader::drawFonts()
}
if (numlines > 0)
{
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();
}
/*
else
{
qDebug("Not so refreshing...");
@@ -1925,32 +2215,40 @@ bool QTReader::ChangeFont(int tgt)
{
return m_fontControl.ChangeFont(m_fontname, 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();
}
//
// Clean up
//
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)
{
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
}
#endif
@@ -1979,15 +2277,53 @@ 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;
}
//
// Called when the widget has been resized.
// Moves the button group to the upper right corner
// of the widget.
@@ -2013,36 +2349,45 @@ int main( int argc, tchar **argv )
draw.show();
return app.exec();
}
*/
+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;
// return (height()-m_descent)/(m_linespacing);
return (height()-2)/(m_linespacing);
};
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 = (m_rotated) ? width() : height();
@@ -2060,20 +2405,29 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
{
textarray[numlines] = new CDrawBuffer(&m_fontControl);
}
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
{
qDebug("TRUE");
--numlines;
mylastpos = locate();
@@ -2098,13 +2452,12 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
return true;
}
void QTReader::dopagedn()
{
// qDebug("HEIGHT(2):%d", m_lastheight);
- buffdoc.unsuspend();
ResetScroll();
int skip = 0, ypos = m_topmargin;
if (locate() != mylastpos)
{
jumpto(mylastpos);
}
@@ -2147,26 +2500,27 @@ bool QTReader::synch(size_t start, size_t end)
{
jumpto(start);
while (start++ < end)
{
tchar ch = getch();
if (ch == 10) return true;
- if (ch == UEOF) return false;
- if (ch == 6) return false;
+ if ((ch == UEOF) || (ch == 6))
+ {
+ return false;
+ }
}
return false;
}
void QTReader::dopageup(unsigned int target)
{
- buffdoc.unsuspend();
ResetScroll();
CBufferFace<CDrawBuffer*> buff;
CBufferFace<size_t> 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;
while (1)
{
// qDebug("Guess:%u", guess);
@@ -2177,28 +2531,29 @@ void QTReader::dopageup(unsigned int target)
delta = 0; // 0 is a flag to say don't guess any more
jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
}
else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
{
delta = 0; // 0 is a flag to say don't guess any more
+ qDebug("Jumping to startsection:%d", buffdoc.startSection());
jumpto(buffdoc.startSection());
}
else
{
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);
}
}
}
nbfl = 0;
ypos = m_topmargin;
@@ -2290,14 +2645,15 @@ 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;
+ bDoUpdates = false;
ResetScroll();
- if (m_lastfile == newfile)
+ if (m_lastfile == newfile && lcn == 0)
{
lcn = m_lastposn;
}
// QMessageBox::information(0, "Opening...", newfile);
if (m_rotated)
{
@@ -2313,17 +2669,17 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
{
m_lastfile = newfile;
buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
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;
}
void QTReader::lineDown()
{
int ypos = m_topmargin;
@@ -2355,12 +2711,13 @@ void QTReader::lineDown()
if (textarray[numlines] == NULL)
{
textarray[numlines] = new CDrawBuffer(&m_fontControl);
}
getline(textarray[numlines]);
mylastpos = locate();
+ m_outofdate = true;
update();
}
/*
void QTReader::lineUp()
{
CBuffer** buff = textarray;
@@ -2569,22 +2926,27 @@ MarkupType QTReader::PreferredMarkup()
m = cHTML;
}
}
}
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)
{
emit RefreshBitmap();
}
@@ -2602,35 +2964,29 @@ void QTReader::resizeEvent( QResizeEvent * p )
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 );
}
+ 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)
{
h = width();
w = height();
}
@@ -2645,61 +3001,87 @@ void QTReader::setrotated(bool sfs)
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()
+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:
{
if (!m_bgIsScaled)
{
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);
}
}
void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
{
if (txt != NULL)
@@ -2756,13 +3138,18 @@ void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
*/
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";
+ 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()
{
if (m_scrolldy != 0)
{
@@ -2894,29 +3281,32 @@ void QTReader::gotoLink()
QCopEnvelope e("QPE/System", "busy()");
}
#endif
ResetScroll();
if (!href.isEmpty())
{
- if (!buffdoc.getFile(href))
+ if (!buffdoc.getFile(href, nm))
{
emit NewFileRequest(href);
}
else
{
ResetScroll();
fillbuffer();
+ 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
@@ -2927,12 +3317,13 @@ void QTReader::gotoLink()
}
else if ((lt & eLink) != 0)
{
buffdoc.saveposn(m_lastfile, saveposn);
ResetScroll();
fillbuffer();
+ m_outofdate = true;
update();
}
else
{
if ((lt & ePicture) != 0)
{
@@ -2946,23 +3337,24 @@ void QTReader::gotoLink()
else
{
// QString anchortext = textarray[lineno]->getanchortext(startoffset);
if (!href.isEmpty())
{
emit OnURLSelected(href, tgt);
+ refresh();
}
}
- locate(pagelocate());
}
m_currentlinkstyle = NULL;
m_currentlink = -1;
m_currentlinkoffset = -1;
}
void QTReader::refresh(bool full)
{
+ qDebug("Refreshing");
int h, w;
if (m_rotated)
{
h = width();
w = height();
}
@@ -2978,8 +3370,123 @@ void QTReader::refresh(bool full)
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());
+ 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<outputcodec*>(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;
+}