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) (show whitespace changes)
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp1890
1 files changed, 1661 insertions, 229 deletions
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
@@ -10,4 +10,13 @@
+const int _SBARHEIGHT = 3;
+
+#include "useqpe.h"
+#include <qpainter.h>
+//#include <qdirectpainter_qws.h>
+#include <qimage.h>
+#include <qtimer.h>
+#include "config.h"
#include "QTReader.h"
-#include "QTReaderApp.h"
+//#include "QTReaderApp.h"
+#include "CDrawBuffer.h"
#ifdef USEQPE
@@ -24,2 +33,4 @@
#endif
+#include <qfileinfo.h>
+#include <qdir.h>
@@ -41,4 +52,8 @@ tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>'
+
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),
@@ -46,2 +61,3 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
m_scrolldy2(0),
+ m_totalscroll(0),
m_autoScroll(false),
@@ -59,3 +75,18 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
#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)
{
@@ -63,3 +94,10 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
setKeyCompression ( true );
+#ifdef DOUBLEBUFFER
+ dbuff = new QPixmap();
+ dbp = new QPainter();
+ // if (painter->isActive()) painter->end();
+ // painter->begin(frame);
+#endif
// init();
+
}
@@ -82,3 +120,3 @@ QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *nam
init();
-// // odebug << "Load_file(1)" << oendl;
+// // qDebug("Load_file(1)");
load_file((const tchar*)filename);
@@ -93,3 +131,3 @@ void QTReader::mouseMoveEvent(QMouseEvent* _e)
- odebug << "MouseMove:[" << _e->pos().x() << ", " << _e->pos().y() << "]" << oendl;
+ qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y());
}
@@ -98,3 +136,3 @@ long QTReader::real_delay()
{
- return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
+ return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
}
@@ -104,5 +142,20 @@ 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;
@@ -111,9 +164,12 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
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);
@@ -127,5 +183,20 @@ 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)
{
@@ -133,3 +204,3 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
}
- else if (_e->y() < height()/3)
+ else if (y < ht/3)
{
@@ -139,3 +210,3 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
{
- if (_e->x() < width()/3)
+ if (x < wh/3)
{
@@ -143,3 +214,3 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
}
- else if (_e->x() > (2*width())/3)
+ else if (x > (2*wh)/3)
{
@@ -155,3 +226,3 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
{
- if (_e->y() > height()/2)
+ if (y > ht/2)
{
@@ -174,3 +245,3 @@ void QTReader::goHome()
{
- buffdoc.saveposn(current);
+ buffdoc.saveposn(m_lastfile, current);
locate(home);
@@ -178,2 +249,4 @@ void QTReader::goHome()
}
+ else
+ locate(0);
}
@@ -185,4 +258,14 @@ void QTReader::goBack()
size_t target = pagelocate();
- buffdoc.writeposn(target);
- if (buffdoc.back(target))
+ QString nxt = m_lastfile;
+ buffdoc.writeposn(m_lastfile, target);
+ linkType lt = buffdoc.back(nxt, target);
+ if ((lt & eFile) != 0)
+ {
+ if (nxt != m_lastfile)
+ {
+ emit NewFileRequest(nxt);
+ }
+ locate(target);
+ }
+ else if ((lt & eLink) != 0)
{
@@ -198,3 +281,13 @@ void QTReader::goForward()
size_t target = pagelocate();
- if (buffdoc.forward(target))
+ QString nxt = m_lastfile;
+ linkType lt = buffdoc.forward(nxt, target);
+ if ((lt & eFile) != 0)
+ {
+ if (nxt != m_lastfile)
+ {
+ emit NewFileRequest(nxt);
+ }
+ locate(target);
+ }
+ else if ((lt & eLink) != 0)
{
@@ -205,7 +298,29 @@ void QTReader::goForward()
-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)
+ {
+ lineno = 0;
+ ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin;
+ }
+ 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))
{
@@ -213,6 +328,8 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si
}
+ if (ht < y && textarray[numlines]->showPartial()) lineno = numlines;
start = locnarray[lineno];
+ int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
if (m_bMonoSpaced)
{
- offset = (x - textarray[lineno]->offset(width(), m_border))/m_charWidth;
+ offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth;
}
@@ -222,7 +339,7 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si
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--);
+ 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);
+ return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img);
}
@@ -231,3 +348,4 @@ void QTReader::suspend()
{
-#ifdef OPIE
+ buffdoc.suspend();
+ /*#ifdef OPIE
if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend();
@@ -236,2 +354,3 @@ void QTReader::suspend()
#endif
+ */
}
@@ -240,3 +359,3 @@ void QTReader::setTwoTouch(bool _b)
{
- setBackgroundColor( white );
+ setBackgroundColor( m_bg );
m_twotouch = m_touchone = _b;
@@ -252,3 +371,5 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
{
+ unsigned long wrdstart, wrdend;
QString wrd;
+ int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
if (m_twotouch)
@@ -265,3 +386,3 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
m_touchone = true;
- setBackgroundColor( white );
+ setBackgroundColor( m_bg );
size_t endpos, endoffset;
@@ -277,2 +398,3 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
}
+ wrdstart = buffdoc.explocate();
if (m_startpos == endpos)
@@ -295,2 +417,3 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
}
+ wrdend = buffdoc.explocate();
jumpto(currentpos);
@@ -301,3 +424,6 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
{
- 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()))
@@ -311,3 +437,5 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
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)
@@ -315,7 +443,8 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
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;
@@ -329,4 +458,12 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
{
-// 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);
+ }
}
@@ -337,2 +474,17 @@ 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)
@@ -341,8 +493,30 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
{
-// odebug << "MouseRelease" << oendl;
- if (_e->x() > width() - m_border)
+// qDebug("MouseRelease");
+ switch(m_scrollpos)
+ {
+ 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())*_e->y()+height()/2)/height());
+ 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)
@@ -352,4 +526,5 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
int lineno = 0;
+ /*
int ht = textarray[0]->lineSpacing();
- while ((ht < _e->y()) && (lineno < numlines))
+ while ((ht < y) && (lineno < numlines))
{
@@ -357,13 +532,84 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
}
- size_t startpos, startoffset, tgt;
- switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt))
+ */
+ 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)
{
- case eLink:
+ 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;
- linkType lt = buffdoc.hyperlink(tgt, href);
- if (lt == eLink)
+ 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
+ {
+ 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(saveposn);
+ buffdoc.saveposn(m_lastfile, saveposn);
+ ResetScroll();
fillbuffer();
@@ -373,3 +619,3 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
{
- if (lt == ePicture)
+ if ((lt & ePicture) != 0)
{
@@ -387,3 +633,3 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
{
- emit OnURLSelected(href);
+ emit OnURLSelected(href, tgt);
}
@@ -394,6 +640,6 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
}
- case ePicture:
+ else if ((glt & ePicture) != 0)
{
-// odebug << "Picture:" << tgt << "" << oendl;
- QImage* pm = buffdoc.getPicture(tgt);
+ qDebug("Big Picture:%x", pictgt);
+ QImage* pm = buffdoc.getPicture(pictgt);
if (pm != NULL)
@@ -409,6 +655,5 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
}
- case eNone:
- break;
- default:
-// odebug << "Unknown linktype" << oendl;
+ else if (img != NULL)
+ {
+ emit OnShowPicture(*img);
return;
@@ -443,2 +688,4 @@ void QTReader::focusOutEvent(QFocusEvent* e)
+#include <qapplication.h>
+#include <qdrawutil.h>
#ifndef _WINDOWS
@@ -516,8 +763,7 @@ void QTReader::zoomin()
bool sc = m_autoScroll;
+ setautoscroll(false);
setfont();
- m_autoScroll = false;
locate(pagelocate());
- update();
- m_autoScroll = sc;
- if (m_autoScroll) autoscroll();
+ repaint();
+ setautoscroll(sc);
}
@@ -530,8 +776,7 @@ void QTReader::zoomout()
bool sc = m_autoScroll;
- m_autoScroll = false;
+ setautoscroll(false);
setfont();
locate(pagelocate());
- update();
- m_autoScroll = sc;
- if (m_autoScroll) autoscroll();
+ repaint();
+ setautoscroll(sc);
}
@@ -554,3 +799,3 @@ void QTReader::increaseScroll()
{
- if (m_delay > 1024)
+ if (m_delay > 454)
{
@@ -561,3 +806,3 @@ void QTReader::increaseScroll()
{
- m_delay = 1024;
+ m_delay = 454;
}
@@ -568,3 +813,5 @@ void QTReader::keyPressEvent(QKeyEvent* e)
buffdoc.unsuspend();
- ((QTReaderApp*)parent()->parent())->handlekey(e);
+
+ //((QTReaderApp*)parent()->parent())->handlekey(e);
+ emit HandleKeyRequest(e);
// e->ignore();
@@ -583,3 +830,4 @@ void QTReader::keyPressEvent(QKeyEvent* e)
}
- ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
+ //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
+ emit SetScrollState(m_autoScroll);
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
@@ -594,79 +842,65 @@ void QTReader::keyPressEvent(QKeyEvent* e)
#endif
-/*
- switch (e->key())
- {
- case Key_Down:
- {
- e->accept();
- if (m_autoScroll)
- {
- if (m_delay < 59049)
- {
- m_delay = (3*m_delay)/2;
- timer->changeInterval(real_delay());
}
- else
+
+void QTReader::CalculateScrollParameters()
{
- m_delay = 59049;
- }
- }
- else
+ int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
+ if (bmargin < m_bottommargin) bmargin = m_bottommargin;
+ switch (m_scrolltype)
{
- goDown();
- }
- }
- break;
- case Key_Up:
+ case 0:
{
- e->accept();
- if (m_autoScroll)
+ if (m_scrolldy == m_topmargin)
{
- if (m_delay > 1024)
- {
- m_delay = (2*m_delay)/3;
- timer->changeInterval(real_delay());
+ m_scrolldy1 = 0;
+ m_scrolldy2 = 0;
+ m_totalscroll = 0;
+ return;
}
- else
+ if (m_scrolldy < textarray[0]->lineSpacing())
{
- m_delay = 1024;
- }
+ m_scrolldy2 = m_scrolldy;
+ return;
}
- else
+ int ht = m_scrolldy - m_scrolldy1;
+ int i;
+ for (i = 0; (ht < ((m_rotated) ? width() : height())-bmargin) && (i < numlines); i++)
{
- goUp();
+ ht += textarray[i]->lineSpacing();
}
- }
- break;
- case Key_Right:
- {
- e->accept();
- if (m_navkeys && buffdoc.hasnavigation())
- {
- size_t target = pagelocate();
- if (buffdoc.forward(target))
+ ht = 0;
+ int j;
+ i--;
+ for (j = i; j < numlines; j++)
{
- locate(target);
- }
+ ht += textarray[j]->lineSpacing();
}
- else zoomin();
+ ht -= (
+ textarray[i]->lineExtraSpacing()
+ +
+ (i != 0) ? textarray[numlines-1]->lineExtraSpacing() : 0
+ )/2-2;
+
+ m_scrolldy2 = m_scrolldy-ht;
}
break;
- case Key_Left:
- {
- e->accept();
- if (m_navkeys && buffdoc.hasnavigation())
+ case 1:
+ case 2:
+ case 3:
{
- size_t target = pagelocate();
- if (buffdoc.back(target))
+ int ypos = m_topmargin;
+ for (int i = 0; i < numlines; i++)
{
- locate(target);
- }
+ ypos += textarray[i]->lineSpacing();
}
- else zoomout();
+ ypos -= (
+ textarray[0]->lineExtraSpacing()
+ +
+ ((numlines > 1) ? textarray[numlines-1]->lineExtraSpacing() : 0)
+ )/2 +
+ m_scrolldy1 - 2;
+ m_scrolldy2 = ((m_rotated) ? width() : height()) - ypos - bmargin;
}
break;
- default:
- e->ignore();
}
-*/
}
@@ -689,2 +923,4 @@ void QTReader::setautoscroll(bool _sc)
#endif
+ // m_scrolldy1 = 0;
+ //refresh();
}
@@ -695,2 +931,4 @@ void QTReader::setautoscroll(bool _sc)
m_autoScroll = true;
+ CalculateScrollParameters();
+
#ifdef _SCROLLPIPE
@@ -698,3 +936,3 @@ void QTReader::setautoscroll(bool _sc)
{
-// odebug << "Opening pipe to " << m_pipetarget << "" << oendl;
+// qDebug("Opening pipe to %s", (const char*)m_pipetarget);
m_pipeout = popen((const char*)m_pipetarget, "w");
@@ -713,5 +951,7 @@ 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);
}
@@ -719,4 +959,6 @@ bool QTReader::getline(CDrawBuffer *buff)
{
- 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;
}
@@ -730,10 +972,41 @@ void QTReader::doscroll()
}
-// timer->changeInterval(real_delay());
- QPainter p( this );
- QBrush b( white);
- bitBlt(this,0,0,this,0,1,width(),-1);
- qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b);
+ switch (m_scrolltype)
+ {
+ case 0:
+ doinplacescroll();
+ break;
+ case 1:
+ dorollingscroll(false);
+ break;
+ case 2:
+ dorollingscroll(true);
+ break;
+ case 3:
+ dostaticscroll();
+ break;
+ }
+}
- if (++m_scrolldy1 == textarray[0]->lineSpacing())
+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
@@ -752,5 +1025,2 @@ void QTReader::doscroll()
}
-// write(m_pipeout, (const char*)outstr, outstr.length());
-// write(m_pipeout, "\n", 1);
-// fputc(10, m_pipeout);
}
@@ -765,7 +1035,211 @@ void QTReader::doscroll()
--numlines;
- m_scrolldy1 = 0;
+ 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);
+ }
}
- if (++m_scrolldy2 == textarray[numlines]->lineSpacing())
+ */
+ 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 );
+ // 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 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
+ {
+ int ht = textarray[0]->lineSpacing();
+ bredrawscroll = 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())
+ {
+ bredrawscroll = true;
+ m_scrolldy2 -= textarray[numlines]->lineSpacing();
numlines++;
@@ -778,3 +1252,12 @@ void QTReader::doscroll()
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();
@@ -782,2 +1265,4 @@ void QTReader::doscroll()
{
+ redrawScroll(&p);
+ emitRedraw();
m_autoScroll = false;
@@ -797,3 +1282,3 @@ void QTReader::doscroll()
#endif
- ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
+ emit SetScrollState(m_autoScroll);
#ifdef USEQPE
@@ -801,5 +1286,209 @@ void QTReader::doscroll()
#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());
}
@@ -808,2 +1497,4 @@ void QTReader::autoscroll()
{
+ drawBackground();
+ dbp->end();
timer->start(real_delay(), false);
@@ -821,3 +1512,87 @@ void QTReader::setfont()
-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()
{
@@ -825,13 +1600,65 @@ void QTReader::drawFonts( QPainter *p )
{
-// 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);
}
@@ -842,7 +1669,7 @@ void QTReader::drawFonts( QPainter *p )
{
-// 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)
{
@@ -853,3 +1680,3 @@ void QTReader::drawFonts( QPainter *p )
}
-// odebug << "Optimised < " << numlines << "" << oendl;
+// qDebug("Optimised < %d", numlines);
m_lastheight = newht;
@@ -858,4 +1685,4 @@ void QTReader::drawFonts( QPainter *p )
{
-// odebug << "Optimised > " << numlines << "" << oendl;
- int ypos = 0;
+// qDebug("Optimised > %d", numlines);
+ int ypos = m_topmargin;
for (int i = 0; i <= numlines; i++)
@@ -865,3 +1692,3 @@ void QTReader::drawFonts( QPainter *p )
fillbuffer(numlines+1, ypos, newht);
-// odebug << "Optimised > " << numlines << "" << oendl;
+// qDebug("Optimised > %d", numlines);
}
@@ -869,4 +1696,4 @@ void QTReader::drawFonts( QPainter *p )
{
- 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;
@@ -878,3 +1705,3 @@ void QTReader::drawFonts( QPainter *p )
(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);
}
@@ -883,23 +1710,184 @@ void QTReader::drawFonts( QPainter *p )
}
+#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 = (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;
}
-
- emit OnRedraw();
+ else
+ {
+ sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize;
+ }
+ if (m_rotated)
+ {
+ p->fillRect(0, sliderpos, 3, sliderheight, m_scrollbarcolor);
}
-/*
else
{
- odebug << "Not so refreshing..." << oendl;
+ 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 = (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;
+ }
}
-*/
}
+/*
+void QTReader::DrawScroll( QPainter *p )
+{
+ if (m_border > 5 && !buffdoc.empty())
+ {
+ 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()
@@ -943,9 +1931,4 @@ void QTReader::init()
{
-// m_showlast = true;
- // setCaption( "Qt Draw Demo Application" );
-
buffdoc.unsuspend();
- setBackgroundColor( white );
-// QPainter p(this);
-// p.setBackgroundMode( Qt::OpaqueMode );
+ setBackgroundColor( m_bg );
buffdoc.setfilter(getfilter());
@@ -953,4 +1936,2 @@ void QTReader::init()
setFocusPolicy(QWidget::StrongFocus);
- // resize( 240, 320 );
- //setFocus();
timer = new QTimer(this);
@@ -959,9 +1940,2 @@ void QTReader::init()
setfont();
-/*
- if (!m_lastfile.isEmpty())
- {
- m_string = DocLnk(m_lastfile).name();
- load_file(m_lastfile);
- }
-*/
}
@@ -973,2 +1947,6 @@ QTReader::~QTReader()
{
+#ifdef DOUBLEBUFFER
+ delete dbuff;
+ delete dbp;
+#endif
#ifdef USEQPE
@@ -988,11 +1966,2 @@ 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.
@@ -1018,4 +1987,3 @@ void QTReader::paintEvent( QPaintEvent * )
{
- QPainter paint( this );
- drawIt( &paint );
+ drawFonts();
}
@@ -1030,3 +1998,3 @@ void QTReader::resizeEvent( QResizeEvent * )
{
-// // odebug << "resize:(" << width() << "," << height() << ")" << oendl;
+// // qDebug("resize:(%u,%u)", width(), height());
// bgroup->move( width()-bgroup->width(), 0 );
@@ -1055,7 +2023,9 @@ bool QTReader::locate(unsigned long n) {
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;
@@ -1073,5 +2043,8 @@ 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
@@ -1083,3 +2056,3 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
numlines = reuse;
- while (ypos < m_lastheight || numlines < 2)
+ while (ypos < m_lastheight - hmargin || numlines < 2)
{
@@ -1098,2 +2071,3 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
{
+ qDebug("FALSE");
locate(oldpagepos);
@@ -1103,2 +2077,3 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
{
+ qDebug("TRUE");
--numlines;
@@ -1108,2 +2083,8 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
}
+ if (numlines > 1 && textarray[numlines-2]->isBop())
+ {
+ --numlines;
+ mylastpos = locate();
+ return true;
+ }
}
@@ -1112,4 +2093,7 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
mylastpos = locate();
- m_scrolldy1 = m_scrolldy2 = m_scrollpart = m_lastheight - lastypos;
-
+ m_scrollpart = m_lastheight - lastypos - hmargin;
+ if (m_autoScroll)
+ {
+ CalculateScrollParameters();
+ }
return true;
@@ -1119,8 +2103,8 @@ 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);
@@ -1128,5 +2112,5 @@ void QTReader::dopagedn()
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++)
@@ -1145,5 +2129,11 @@ void QTReader::dopagedn()
}
+ if (numlines <= 1)
+ {
+ skip = 0;
+ ypos = 0;
+ qDebug("Doing extra skip");
+ }
if (fillbuffer(skip, ypos))
{
- update();
+ drawFonts();
}
@@ -1153,3 +2143,2 @@ void QTReader::dopageup()
{
- buffdoc.unsuspend();
dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
@@ -1165,2 +2154,3 @@ bool QTReader::synch(size_t start, size_t end)
if (ch == UEOF) return false;
+ if (ch == 6) return false;
}
@@ -1172,2 +2162,3 @@ void QTReader::dopageup(unsigned int target)
buffdoc.unsuspend();
+ ResetScroll();
CBufferFace<CDrawBuffer*> buff;
@@ -1177,3 +2168,3 @@ void QTReader::dopageup(unsigned int target)
bool ch = true;
- int nbfl, ypos = 0;
+ int nbfl, ypos = m_topmargin;
if (guess < 128) guess = 128;
@@ -1181,2 +2172,4 @@ void QTReader::dopageup(unsigned int target)
{
+ // qDebug("Guess:%u", guess);
+
ch = true;
@@ -1211,3 +2204,3 @@ void QTReader::dopageup(unsigned int target)
nbfl = 0;
- ypos = 0;
+ ypos = m_topmargin;
@@ -1222,3 +2215,3 @@ void QTReader::dopageup(unsigned int target)
}
- if (guess < 4000 && ypos < height() && (delta != 0))
+ if (guess < 4000 && ypos < ((m_rotated) ? width() : height())-(m_bottommargin) && (delta != 0))
{
@@ -1252,5 +2245,5 @@ void QTReader::dopageup(unsigned int target)
- ypos = 0;
+ ypos = m_topmargin;
numlines = 0;
- while (ypos < height() && numlines+2 <= nbfl)
+ while (ypos < ((m_rotated) ? width() : height())-m_bottommargin && numlines+2 <= nbfl)
{
@@ -1264,3 +2257,3 @@ void QTReader::dopageup(unsigned int target)
offset -= numlines;
- ypos = 0;
+ ypos = m_topmargin;
for (int i = 0; i <= numlines; i++)
@@ -1281,3 +2274,3 @@ void QTReader::dopageup(unsigned int target)
- while (ypos < height())
+ while (ypos < ((m_rotated) ? width() : height())-m_bottommargin)
{
@@ -1291,4 +2284,5 @@ void QTReader::dopageup(unsigned int target)
mylastpos = locate();
-
- update();
+ CalculateScrollParameters();
+ drawFonts();
+ // repaint();
}
@@ -1299,5 +2293,6 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
// QMessageBox::information(this, "load_file", newfile, 1);
-
+ int prog = 0;
bool bRC = false;
unsigned int lcn = _lcn;
+ ResetScroll();
if (m_lastfile == newfile)
@@ -1307,4 +2302,12 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
// QMessageBox::information(0, "Opening...", newfile);
+ if (m_rotated)
+ {
+ m_lastwidth = height();
+ m_lastheight = width();
+ }
+ else
+ {
m_lastwidth = width();
m_lastheight = height();
+ }
if (buffdoc.openfile(this,newfile) == 0)
@@ -1312,12 +2315,11 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
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;
@@ -1327,3 +2329,4 @@ void QTReader::lineDown()
{
- int ypos = 0;
+ int ypos = m_topmargin;
+ ResetScroll();
int offset = numlines;
@@ -1332,3 +2335,3 @@ void QTReader::lineDown()
{
- if ((ypos += textarray[numlines-i]->lineSpacing()) > height())
+ if ((ypos += textarray[numlines-i]->lineSpacing()) > ((m_rotated) ? width() : height()))
{
@@ -1443,5 +2446,22 @@ void QTReader::lineUp()
*/
+
+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()
{
+ dopageup(locnarray[numlines-1]);
+
+ /*
buffdoc.unsuspend();
+ ResetScroll();
+
CDrawBuffer* buff = textarray[numlines];
@@ -1512,3 +2532,3 @@ void QTReader::lineUp()
int start = numlines;
- int ypos = 0;
+ int ypos = m_topmargin;
#ifdef _WINDOWS
@@ -1520,3 +2540,3 @@ void QTReader::lineUp()
ypos += textarray[i]->lineSpacing();
- if (ypos > height())
+ if (ypos > ((m_rotated) ? width() : height()))
{
@@ -1529,3 +2549,4 @@ void QTReader::lineUp()
fillbuffer(start, ypos);
- update();
+ repaint();
+ */
}
@@ -1554 +2575,412 @@ MarkupType QTReader::PreferredMarkup()
}
+#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());
+}