summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/QTReader.cpp
Unidiff
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 @@
10 10
11const int _SBARHEIGHT = 3;
12
13#include "useqpe.h"
14#include <qpainter.h>
15//#include <qdirectpainter_qws.h>
16#include <qimage.h>
17#include <qtimer.h>
18#include "config.h"
11#include "QTReader.h" 19#include "QTReader.h"
12#include "QTReaderApp.h" 20//#include "QTReaderApp.h"
21#include "CDrawBuffer.h"
13#ifdef USEQPE 22#ifdef USEQPE
@@ -24,2 +33,4 @@
24#endif 33#endif
34#include <qfileinfo.h>
35#include <qdir.h>
25 36
@@ -41,4 +52,8 @@ tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>'
41 52
53
42QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : 54QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
43 QWidget(parent, name, f), 55 QWidget(parent, name, f),
56 m_default_fg(0,0,0),
57 m_default_bg(255,255,255),
58 m_bg(255,255,255),
44 m_delay(100), 59 m_delay(100),
@@ -46,2 +61,3 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
46 m_scrolldy2(0), 61 m_scrolldy2(0),
62 m_totalscroll(0),
47 m_autoScroll(false), 63 m_autoScroll(false),
@@ -59,3 +75,18 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
59#endif 75#endif
60 m_border(2) 76 m_left_border(2),
77 m_right_border(2),
78 m_rotated(true),
79 pBkmklist(NULL),
80 m_scrollpos(0),
81 // bNegative(false),
82 bInverse(false),
83 m_highlightfilter(NULL),
84 m_bgIsScaled(false),
85 m_scrollstep(2),
86 m_topmargin(5),
87 m_bottommargin(5),
88 m_reparastring("{\\n[\\n ]}"),
89 m_currentlinkstyle(NULL),
90 m_currentlinkoffset(-1),
91 m_currentlink(-1)
61{ 92{
@@ -63,3 +94,10 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
63 setKeyCompression ( true ); 94 setKeyCompression ( true );
95#ifdef DOUBLEBUFFER
96 dbuff = new QPixmap();
97 dbp = new QPainter();
98 // if (painter->isActive()) painter->end();
99 // painter->begin(frame);
100#endif
64// init(); 101// init();
102
65} 103}
@@ -82,3 +120,3 @@ QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *nam
82 init(); 120 init();
83// // odebug << "Load_file(1)" << oendl; 121// // qDebug("Load_file(1)");
84 load_file((const tchar*)filename); 122 load_file((const tchar*)filename);
@@ -93,3 +131,3 @@ void QTReader::mouseMoveEvent(QMouseEvent* _e)
93 131
94 odebug << "MouseMove:[" << _e->pos().x() << ", " << _e->pos().y() << "]" << oendl; 132 qDebug("MouseMove:[%d, %d]", _e->pos().x(), _e->pos().y());
95} 133}
@@ -98,3 +136,3 @@ long QTReader::real_delay()
98{ 136{
99 return ( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 137 return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
100} 138}
@@ -104,5 +142,20 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
104 buffdoc.unsuspend(); 142 buffdoc.unsuspend();
143 int x, y, ht, wh;
144 if (m_rotated)
145 {
146 x = _e->y();
147 y = width()-_e->x();
148 ht = width();
149 wh = height();
150 }
151 else
152 {
153 x = _e->x();
154 y = _e->y();
155 ht = height();
156 wh = width();
157 }
105 if (_e->button() == RightButton) 158 if (_e->button() == RightButton)
106 { 159 {
107 //odebug << "MousePress" << oendl; 160 //qDebug("MousePress");
108 mouseUpOn = false; 161 mouseUpOn = false;
@@ -111,9 +164,12 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
111 int lineno = 0; 164 int lineno = 0;
112 int ht = textarray[0]->lineSpacing(); 165 /*
113 while ((ht < _e->y()) && (lineno < numlines)) 166 int hgt = textarray[0]->lineSpacing();
167 while ((hgt < y) && (lineno < numlines))
114 { 168 {
115 ht += textarray[++lineno]->lineSpacing(); 169 hgt += textarray[++lineno]->lineSpacing();
116 } 170 }
117 size_t startpos, startoffset, tgt; 171 */
118 getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt); 172 size_t startpos, startoffset, tgt, tgtoffset, pictgt;
173 QImage* img;
174 getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img);
119 processmousewordevent(startpos, startoffset, _e, lineno); 175 processmousewordevent(startpos, startoffset, _e, lineno);
@@ -127,5 +183,20 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
127{ 183{
184 int x, y, ht, wh;
185 if (m_rotated)
186 {
187 x = _e->y();
188 y = width()-_e->x();
189 ht = width();
190 wh = height();
191 }
192 else
193 {
194 x = _e->x();
195 y = _e->y();
196 ht = height();
197 wh = width();
198 }
128 if (buffdoc.hasnavigation()) 199 if (buffdoc.hasnavigation())
129 { 200 {
130 if (_e->y() > (2*height())/3) 201 if (y > (2*ht)/3)
131 { 202 {
@@ -133,3 +204,3 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
133 } 204 }
134 else if (_e->y() < height()/3) 205 else if (y < ht/3)
135 { 206 {
@@ -139,3 +210,3 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
139 { 210 {
140 if (_e->x() < width()/3) 211 if (x < wh/3)
141 { 212 {
@@ -143,3 +214,3 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
143 } 214 }
144 else if (_e->x() > (2*width())/3) 215 else if (x > (2*wh)/3)
145 { 216 {
@@ -155,3 +226,3 @@ void QTReader::processmousepositionevent( QMouseEvent* _e )
155 { 226 {
156 if (_e->y() > height()/2) 227 if (y > ht/2)
157 { 228 {
@@ -174,3 +245,3 @@ void QTReader::goHome()
174 { 245 {
175 buffdoc.saveposn(current); 246 buffdoc.saveposn(m_lastfile, current);
176 locate(home); 247 locate(home);
@@ -178,2 +249,4 @@ void QTReader::goHome()
178 } 249 }
250 else
251 locate(0);
179} 252}
@@ -185,4 +258,14 @@ void QTReader::goBack()
185 size_t target = pagelocate(); 258 size_t target = pagelocate();
186 buffdoc.writeposn(target); 259 QString nxt = m_lastfile;
187 if (buffdoc.back(target)) 260 buffdoc.writeposn(m_lastfile, target);
261 linkType lt = buffdoc.back(nxt, target);
262 if ((lt & eFile) != 0)
263 {
264 if (nxt != m_lastfile)
265 {
266 emit NewFileRequest(nxt);
267 }
268 locate(target);
269 }
270 else if ((lt & eLink) != 0)
188 { 271 {
@@ -198,3 +281,13 @@ void QTReader::goForward()
198 size_t target = pagelocate(); 281 size_t target = pagelocate();
199 if (buffdoc.forward(target)) 282 QString nxt = m_lastfile;
283 linkType lt = buffdoc.forward(nxt, target);
284 if ((lt & eFile) != 0)
285 {
286 if (nxt != m_lastfile)
287 {
288 emit NewFileRequest(nxt);
289 }
290 locate(target);
291 }
292 else if ((lt & eLink) != 0)
200 { 293 {
@@ -205,7 +298,29 @@ void QTReader::goForward()
205 298
206linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, size_t& tgt) 299linkType 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)
207{ 300{
208 int lineno = 0; 301 int ht;
209 int ht = textarray[0]->lineSpacing(); 302 if (m_scrolldy == m_topmargin)
210 while ((ht < y) && (lineno < numlines)) 303 {
304 lineno = 0;
305 ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin;
306 }
307 else
308 {
309 if (y >= m_scrolldy)
310 {
311 lineno = 0;
312 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy + m_topmargin;
313 }
314 else
315 {
316 lineno = 0;
317 ht = textarray[0]->lineSpacing()-m_scrolldy1+m_scrolldy+m_topmargin;
318 while ((ht < h) && (lineno < numlines-1))
319 {
320 ht += textarray[++lineno]->lineSpacing();
321 }
322 ht = textarray[lineno]->lineSpacing();
323 }
324 }
325 while ((ht < y) && (lineno < numlines-1))
211 { 326 {
@@ -213,6 +328,8 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si
213 } 328 }
329 if (ht < y && textarray[numlines]->showPartial()) lineno = numlines;
214 start = locnarray[lineno]; 330 start = locnarray[lineno];
331 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
215 if (m_bMonoSpaced) 332 if (m_bMonoSpaced)
216 { 333 {
217 offset = (x - textarray[lineno]->offset(width(), m_border))/m_charWidth; 334 offset = (x - textarray[lineno]->offset(w, m_left_border, m_right_border, availht))/m_charWidth;
218 } 335 }
@@ -222,7 +339,7 @@ linkType QTReader::getcurrentpos(int x, int y, size_t& start, size_t& offset, si
222 CDrawBuffer* t = textarray[lineno]; 339 CDrawBuffer* t = textarray[lineno];
223 x = x - t->offset(width(), m_border); 340 x = x - t->offset(width(), m_left_border, m_right_border, availht);
224 for (i = t->length(); i >= 0 && t->width(i, true, width(), m_border) > x; i--); 341 for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--);
225 offset = i; 342 offset = i;
226 } 343 }
227 return textarray[lineno]->getLinkType(offset, tgt); 344 return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img);
228} 345}
@@ -231,3 +348,4 @@ void QTReader::suspend()
231{ 348{
232#ifdef OPIE 349 buffdoc.suspend();
350 /*#ifdef OPIE
233 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend(); 351 if (memcmp("/mnt/", m_lastfile.latin1(), 5) == 0) buffdoc.suspend();
@@ -236,2 +354,3 @@ void QTReader::suspend()
236#endif 354#endif
355 */
237} 356}
@@ -240,3 +359,3 @@ void QTReader::setTwoTouch(bool _b)
240{ 359{
241 setBackgroundColor( white ); 360 setBackgroundColor( m_bg );
242 m_twotouch = m_touchone = _b; 361 m_twotouch = m_touchone = _b;
@@ -252,3 +371,5 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
252{ 371{
372 unsigned long wrdstart, wrdend;
253 QString wrd; 373 QString wrd;
374 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
254 if (m_twotouch) 375 if (m_twotouch)
@@ -265,3 +386,3 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
265 m_touchone = true; 386 m_touchone = true;
266 setBackgroundColor( white ); 387 setBackgroundColor( m_bg );
267 size_t endpos, endoffset; 388 size_t endpos, endoffset;
@@ -277,2 +398,3 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
277 } 398 }
399 wrdstart = buffdoc.explocate();
278 if (m_startpos == endpos) 400 if (m_startpos == endpos)
@@ -295,2 +417,3 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
295 } 417 }
418 wrdend = buffdoc.explocate();
296 jumpto(currentpos); 419 jumpto(currentpos);
@@ -301,3 +424,6 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
301 { 424 {
302 int chno = (_e->x()-textarray[lineno]->offset(width(), m_border))/m_charWidth; 425 int chno = (m_rotated) ?
426 (_e->y()-textarray[lineno]->offset(height(), m_left_border, m_right_border, availht))/m_charWidth
427 :
428 (_e->x()-textarray[lineno]->offset(width(), m_left_border, m_right_border, availht))/m_charWidth;
303 if (chno < ustrlen(textarray[lineno]->data())) 429 if (chno < ustrlen(textarray[lineno]->data()))
@@ -311,3 +437,5 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
311 int first = 0; 437 int first = 0;
312 int tgt = _e->x() - t->offset(width(), m_border); 438 int tgt = (m_rotated) ?
439 _e->y() - t->offset(height(), m_left_border, m_right_border, availht) :
440 _e->x() - t->offset(width(), m_left_border, m_right_border, availht);
313 while (1) 441 while (1)
@@ -315,7 +443,8 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
315 int i = first+1; 443 int i = first+1;
444 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
316 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++; 445 while (QChar((*t)[i]).isLetter() && (*t)[i] != 0) i++;
317 if (t->width(i, true, width(), m_border) > tgt) 446 if (t->width(availht, i, true, (m_rotated) ? height() : width(), m_left_border, m_right_border) > tgt)
318 { 447 {
319 wrd = toQString(t->data()+first, i - first); 448 wrd = toQString(t->data()+first, i - first);
320 // odebug << "Got " << (const char *)wrd << "" << oendl; 449 // qDebug("Got %s", (const char *)wrd);
321 break; 450 break;
@@ -329,4 +458,12 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
329 { 458 {
330 //odebug << "Selected:" << wrd << "" << oendl; 459 qDebug("Selecteed:%s", (const char*)wrd);
331 emit OnWordSelected(wrd, locnarray[lineno], (m_twotouch) ? wrd : toQString(textarray[lineno]->data())); 460 if (m_twotouch)
461 {
462 emit OnWordSelected(wrd, wrdstart, wrdend, wrd);
463 }
464 else
465 {
466 QString line = toQString(textarray[lineno]->data());
467 emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line);
468 }
332 } 469 }
@@ -337,2 +474,17 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
337 buffdoc.unsuspend(); 474 buffdoc.unsuspend();
475 int x, y, ht, wh;
476 if (m_rotated)
477 {
478 x = _e->y();
479 y = width()-_e->x();
480 ht = width();
481 wh = height();
482 }
483 else
484 {
485 x = _e->x();
486 y = _e->y();
487 ht = height();
488 wh = width();
489 }
338 if (_e->button() == LeftButton) 490 if (_e->button() == LeftButton)
@@ -341,8 +493,30 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
341 { 493 {
342 // odebug << "MouseRelease" << oendl; 494 // qDebug("MouseRelease");
343 if (_e->x() > width() - m_border) 495 switch(m_scrollpos)
496 {
497 case 1: // Bottom
498 if (y > ht - 5)
499 {
500 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh);
501 return;
502 }
503 break;
504 case 2: // right
505 if (x > wh - m_right_border)
344 { 506 {
345 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*_e->y()+height()/2)/height()); 507 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
346 return; 508 return;
347 } 509 }
510 break;
511 case 3: // left
512 if (x < m_left_border)
513 {
514 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
515 return;
516 }
517 break;
518 case 0:
519 default:
520 break;
521 }
348 if (textarray[0] != NULL) 522 if (textarray[0] != NULL)
@@ -352,4 +526,5 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
352 int lineno = 0; 526 int lineno = 0;
527 /*
353 int ht = textarray[0]->lineSpacing(); 528 int ht = textarray[0]->lineSpacing();
354 while ((ht < _e->y()) && (lineno < numlines)) 529 while ((ht < y) && (lineno < numlines))
355 { 530 {
@@ -357,13 +532,84 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
357 } 532 }
358 size_t startpos, startoffset, tgt; 533 */
359 switch (getcurrentpos(_e->x(), _e->y(), startpos, startoffset, tgt)) 534 size_t startpos, startoffset, tgt, tgtoffset, pictgt;
535 QImage* img;
536 if (m_currentlinkstyle != NULL)
537 {
538 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
539 m_currentlinkstyle = NULL;
540 m_currentlink = -1;
541 m_currentlinkoffset = -1;
542 }
543 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img);
544 if ((glt & eLink) != 0)
545 {
546 if ((glt & ePicture) != 0)
547 {
548 qDebug("Big Picture:%x", pictgt);
549 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
550 {
551 QImage* pm = buffdoc.getPicture(pictgt);
552 if (pm != NULL)
360 { 553 {
361 case eLink: 554 emit OnShowPicture(*pm);
555 delete pm;
556 return;
557 }
558 }
559 }
560 else if (img != NULL)
362 { 561 {
562 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
563 {
564 emit OnShowPicture(*img);
565 return;
566 }
567 }
363 size_t saveposn = pagelocate(); 568 size_t saveposn = pagelocate();
364 QString href; 569 QString href, nm;
365 linkType lt = buffdoc.hyperlink(tgt, href); 570 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
366 if (lt == eLink) 571 qDebug("URL(1):%s", (const char*)href);
572 if ((lt & eFile) != 0)
573 {
574 buffdoc.saveposn(m_lastfile, saveposn);
575#ifdef USEQPE
576 {
577 QCopEnvelope e("QPE/System", "busy()");
578 }
579#endif
580 ResetScroll();
581 if (!href.isEmpty())
582 {
583 if (!buffdoc.getFile(href))
584 {
585 emit NewFileRequest(href);
586 }
587 else
588 {
589 ResetScroll();
590 fillbuffer();
591 update();
592 }
593 }
594 if (!nm.isEmpty())
595 {
596 qDebug("QTReader:Finding %s", (const char*)nm);
597 if (buffdoc.findanchor(nm))
598 {
599 fillbuffer();
600 update();
601 }
602 }
603 //fillbuffer();
604 //update();
605#ifdef USEQPE
606 {
607 QCopEnvelope e("QPE/System", "notBusy()");
608 }
609#endif
610 }
611 else if ((lt & eLink) != 0)
367 { 612 {
368 buffdoc.saveposn(saveposn); 613 buffdoc.saveposn(m_lastfile, saveposn);
614 ResetScroll();
369 fillbuffer(); 615 fillbuffer();
@@ -373,3 +619,3 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
373 { 619 {
374 if (lt == ePicture) 620 if ((lt & ePicture) != 0)
375 { 621 {
@@ -387,3 +633,3 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
387 { 633 {
388 emit OnURLSelected(href); 634 emit OnURLSelected(href, tgt);
389 } 635 }
@@ -394,6 +640,6 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
394 } 640 }
395 case ePicture: 641 else if ((glt & ePicture) != 0)
396 { 642 {
397 // odebug << "Picture:" << tgt << "" << oendl; 643 qDebug("Big Picture:%x", pictgt);
398 QImage* pm = buffdoc.getPicture(tgt); 644 QImage* pm = buffdoc.getPicture(pictgt);
399 if (pm != NULL) 645 if (pm != NULL)
@@ -409,6 +655,5 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
409 } 655 }
410 case eNone: 656 else if (img != NULL)
411 break; 657 {
412 default: 658 emit OnShowPicture(*img);
413 // odebug << "Unknown linktype" << oendl;
414 return; 659 return;
@@ -443,2 +688,4 @@ void QTReader::focusOutEvent(QFocusEvent* e)
443 688
689#include <qapplication.h>
690#include <qdrawutil.h>
444#ifndef _WINDOWS 691#ifndef _WINDOWS
@@ -516,8 +763,7 @@ void QTReader::zoomin()
516 bool sc = m_autoScroll; 763 bool sc = m_autoScroll;
764 setautoscroll(false);
517 setfont(); 765 setfont();
518 m_autoScroll = false;
519 locate(pagelocate()); 766 locate(pagelocate());
520 update(); 767 repaint();
521 m_autoScroll = sc; 768 setautoscroll(sc);
522 if (m_autoScroll) autoscroll();
523 } 769 }
@@ -530,8 +776,7 @@ void QTReader::zoomout()
530 bool sc = m_autoScroll; 776 bool sc = m_autoScroll;
531 m_autoScroll = false; 777 setautoscroll(false);
532 setfont(); 778 setfont();
533 locate(pagelocate()); 779 locate(pagelocate());
534 update(); 780 repaint();
535 m_autoScroll = sc; 781 setautoscroll(sc);
536 if (m_autoScroll) autoscroll();
537 } 782 }
@@ -554,3 +799,3 @@ void QTReader::increaseScroll()
554{ 799{
555 if (m_delay > 1024) 800 if (m_delay > 454)
556 { 801 {
@@ -561,3 +806,3 @@ void QTReader::increaseScroll()
561 { 806 {
562 m_delay = 1024; 807 m_delay = 454;
563 } 808 }
@@ -568,3 +813,5 @@ void QTReader::keyPressEvent(QKeyEvent* e)
568 buffdoc.unsuspend(); 813 buffdoc.unsuspend();
569 ((QTReaderApp*)parent()->parent())->handlekey(e); 814
815 //((QTReaderApp*)parent()->parent())->handlekey(e);
816 emit HandleKeyRequest(e);
570// e->ignore(); 817// e->ignore();
@@ -583,3 +830,4 @@ void QTReader::keyPressEvent(QKeyEvent* e)
583 } 830 }
584 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 831 //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
832 emit SetScrollState(m_autoScroll);
585 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 833 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
@@ -594,79 +842,65 @@ void QTReader::keyPressEvent(QKeyEvent* e)
594#endif 842#endif
595/*
596 switch (e->key())
597 {
598 case Key_Down:
599 {
600 e->accept();
601 if (m_autoScroll)
602 {
603 if (m_delay < 59049)
604 {
605 m_delay = (3*m_delay)/2;
606 timer->changeInterval(real_delay());
607 } 843 }
608 else 844
845void QTReader::CalculateScrollParameters()
609 { 846 {
610 m_delay = 59049; 847 int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
611 } 848 if (bmargin < m_bottommargin) bmargin = m_bottommargin;
612 } 849 switch (m_scrolltype)
613 else
614 { 850 {
615 goDown(); 851 case 0:
616 }
617 }
618 break;
619 case Key_Up:
620 { 852 {
621 e->accept(); 853 if (m_scrolldy == m_topmargin)
622 if (m_autoScroll)
623 { 854 {
624 if (m_delay > 1024) 855 m_scrolldy1 = 0;
625 { 856 m_scrolldy2 = 0;
626 m_delay = (2*m_delay)/3; 857 m_totalscroll = 0;
627 timer->changeInterval(real_delay()); 858 return;
628 } 859 }
629 else 860 if (m_scrolldy < textarray[0]->lineSpacing())
630 { 861 {
631 m_delay = 1024; 862 m_scrolldy2 = m_scrolldy;
632 } 863 return;
633 } 864 }
634 else 865 int ht = m_scrolldy - m_scrolldy1;
866 int i;
867 for (i = 0; (ht < ((m_rotated) ? width() : height())-bmargin) && (i < numlines); i++)
635 { 868 {
636 goUp(); 869 ht += textarray[i]->lineSpacing();
637 } 870 }
638 } 871 ht = 0;
639 break; 872 int j;
640 case Key_Right: 873 i--;
641 { 874 for (j = i; j < numlines; j++)
642 e->accept();
643 if (m_navkeys && buffdoc.hasnavigation())
644 {
645 size_t target = pagelocate();
646 if (buffdoc.forward(target))
647 { 875 {
648 locate(target); 876 ht += textarray[j]->lineSpacing();
649 }
650 } 877 }
651 else zoomin(); 878 ht -= (
879 textarray[i]->lineExtraSpacing()
880 +
881 (i != 0) ? textarray[numlines-1]->lineExtraSpacing() : 0
882 )/2-2;
883
884 m_scrolldy2 = m_scrolldy-ht;
652 } 885 }
653 break; 886 break;
654 case Key_Left: 887 case 1:
655 { 888 case 2:
656 e->accept(); 889 case 3:
657 if (m_navkeys && buffdoc.hasnavigation())
658 { 890 {
659 size_t target = pagelocate(); 891 int ypos = m_topmargin;
660 if (buffdoc.back(target)) 892 for (int i = 0; i < numlines; i++)
661 { 893 {
662 locate(target); 894 ypos += textarray[i]->lineSpacing();
663 }
664 } 895 }
665 else zoomout(); 896 ypos -= (
897 textarray[0]->lineExtraSpacing()
898 +
899 ((numlines > 1) ? textarray[numlines-1]->lineExtraSpacing() : 0)
900 )/2 +
901 m_scrolldy1 - 2;
902 m_scrolldy2 = ((m_rotated) ? width() : height()) - ypos - bmargin;
666 } 903 }
667 break; 904 break;
668 default:
669 e->ignore();
670 } 905 }
671*/
672} 906}
@@ -689,2 +923,4 @@ void QTReader::setautoscroll(bool _sc)
689#endif 923#endif
924 //m_scrolldy1 = 0;
925 //refresh();
690 } 926 }
@@ -695,2 +931,4 @@ void QTReader::setautoscroll(bool _sc)
695 m_autoScroll = true; 931 m_autoScroll = true;
932 CalculateScrollParameters();
933
696#ifdef _SCROLLPIPE 934#ifdef _SCROLLPIPE
@@ -698,3 +936,3 @@ void QTReader::setautoscroll(bool _sc)
698 { 936 {
699 // odebug << "Opening pipe to " << m_pipetarget << "" << oendl; 937 // qDebug("Opening pipe to %s", (const char*)m_pipetarget);
700 m_pipeout = popen((const char*)m_pipetarget, "w"); 938 m_pipeout = popen((const char*)m_pipetarget, "w");
@@ -713,5 +951,7 @@ bool QTReader::getline(CDrawBuffer *buff)
713 buffdoc.unsuspend(); 951 buffdoc.unsuspend();
952 bool bRet;
953 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
714 if (m_bMonoSpaced) 954 if (m_bMonoSpaced)
715 { 955 {
716 return buffdoc.getline(buff ,width(), m_charWidth, m_border); 956 bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht);
717 } 957 }
@@ -719,4 +959,6 @@ bool QTReader::getline(CDrawBuffer *buff)
719 { 959 {
720 return buffdoc.getline(buff, width(), m_border); 960 bRet = buffdoc.getline(buff, (m_rotated) ? height() : width(), m_left_border, m_right_border, hyphenate, availht);
721 } 961 }
962 buff->resize(availht);
963 return bRet;
722} 964}
@@ -730,10 +972,41 @@ void QTReader::doscroll()
730 } 972 }
731// timer->changeInterval(real_delay()); 973 switch (m_scrolltype)
732 QPainter p( this ); 974 {
733 QBrush b( white); 975 case 0:
734 bitBlt(this,0,0,this,0,1,width(),-1); 976 doinplacescroll();
735 qDrawPlainRect(&p,0,height() - 2,width(),2,white,1,&b); 977 break;
978 case 1:
979 dorollingscroll(false);
980 break;
981 case 2:
982 dorollingscroll(true);
983 break;
984 case 3:
985 dostaticscroll();
986 break;
987 }
988}
736 989
737 if (++m_scrolldy1 == textarray[0]->lineSpacing()) 990void QTReader::doinplacescroll()
991{
992 QPainter p( this );
993 // p.setBackgroundMode(OpaqueMode);
994 int wh, ht;
995 int bmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
996 if (bmargin < m_bottommargin) bmargin = m_bottommargin;
997 if (m_rotated)
998 {
999 ht = width()-bmargin;
1000 wh = height();
1001 }
1002 else
738 { 1003 {
1004 ht = height()-bmargin;
1005 wh = width();
1006 }
1007 int lastdy = m_scrolldy;
1008 m_scrolldy += m_scrollstep;
1009 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
1010 {
1011 int ht = textarray[0]->lineSpacing();
739#ifdef _SCROLLPIPE 1012#ifdef _SCROLLPIPE
@@ -752,5 +1025,2 @@ void QTReader::doscroll()
752 } 1025 }
753 // write(m_pipeout, (const char*)outstr, outstr.length());
754 // write(m_pipeout, "\n", 1);
755 // fputc(10, m_pipeout);
756 } 1026 }
@@ -765,7 +1035,211 @@ void QTReader::doscroll()
765 --numlines; 1035 --numlines;
766 m_scrolldy1 = 0; 1036 m_scrolldy1 -= ht;
1037 }
1038 if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing())
1039 {
1040 m_scrolldy2 -= textarray[numlines]->lineSpacing();
1041 numlines++;
1042
1043 if (textarray[numlines] == NULL)
1044 {
1045 textarray[numlines] = new CDrawBuffer(&m_fontControl);
1046 }
1047 locnarray[numlines] = locate();
1048 int ch = getline(textarray[numlines]);
1049 if (m_rotated)
1050 {
1051 blitRot(width()-m_scrolldy, 0, height(), -1, textarray[numlines-1]);
1052 }
1053 else
1054 {
1055 if (m_bgpm.isNull())
1056 {
1057 p.fillRect(m_left_border,m_scrolldy-textarray[numlines-1]->lineSpacing(),width()-(m_left_border+m_right_border),textarray[numlines-1]->lineSpacing(),m_bg);
1058 }
1059 else
1060 {
1061 int h_tmp = textarray[numlines-1]->lineSpacing();
1062 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);
1063 }
1064 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);
1065 }
1066 mylastpos = locate();
1067 if (!ch)
1068 {
1069 /*
1070 if (m_rotated)
1071 {
1072 blitRot2(0,0,height(),width()-m_scrolldy,NULL);
1073 // blitRot2(0,0,0,height(),width()-m_scrolldy,NULL);
1074 }
1075 else
1076 {
1077 if (m_bgpm.isNull())
1078 {
1079 p.fillRect(0,m_scrolldy,width(),height()-m_scrolldy,m_bg);
1080 }
1081 else
1082 {
1083 bitBlt(this, 0, m_scrolldy, dbuff, 0, m_scrolldy, width(), height()-m_scrolldy);
1084 }
767 } 1085 }
768 if (++m_scrolldy2 == textarray[numlines]->lineSpacing()) 1086 */
1087 m_scrolldy = m_topmargin;
1088 m_autoScroll = false;
1089#ifdef _SCROLLPIPE
1090 for (int i = 0; i < numlines; i++)
1091 {
1092 if (m_pipeout != NULL)
769 { 1093 {
1094 QString outstr = toQString(textarray[i]->data());
1095 if (!outstr.isEmpty())
1096 {
1097 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1098 fflush(m_pipeout);
1099 }
1100 }
1101 }
1102#endif
1103 //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
1104 emit SetScrollState(m_autoScroll);
1105#ifdef USEQPE
1106 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1107#endif
1108 }
1109 if (m_scrolldy > ht-textarray[numlines]->lineSpacing())
1110 {
1111 if (m_rotated)
1112 {
1113 if (m_bgpm.isNull())
1114 {
1115 p.fillRect(bmargin, m_left_border, ht-m_scrolldy, wh-(m_left_border+m_right_border), m_bg);
1116 }
1117 else
1118 {
1119 blitRot(bmargin, 0,height(), ht-m_scrolldy, NULL);
1120 }
1121 }
1122 else
1123 if (m_bgpm.isNull())
1124 {
1125 p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),height()-m_scrolldy,m_bg);
1126 }
1127 else
1128 {
1129 bitBlt(this,m_left_border,m_scrolldy,dbuff,m_left_border,m_scrolldy,width()-(m_left_border+m_right_border), height()-m_scrolldy);
1130 }
1131 m_scrolldy = m_topmargin;
770 m_scrolldy2 = 0; 1132 m_scrolldy2 = 0;
1133 }
1134 redrawScroll(&p);
1135 emitRedraw();
1136 lastdy = -1;
1137 }
1138 // else
1139 {
1140 if (m_rotated)
1141 {
1142 if (lastdy >= 0)
1143 {
1144 if (m_bgpm.isNull())
1145 {
1146 p.fillRect(width()-lastdy, m_left_border, m_scrollstep, wh-(m_left_border+m_right_border),m_bg);
1147 }
1148 else
1149 {
1150 blitRot(width()-lastdy,m_left_border,wh-(m_left_border+m_right_border), m_scrollstep, NULL);
1151 }
1152 }
1153 p.fillRect(width()-m_scrolldy, m_left_border, 1,wh-(m_left_border+m_right_border),m_scrollcolor);
1154 }
1155 else
1156 {
1157 if (lastdy >= 0)
1158 {
1159 if (m_bgpm.isNull())
1160 {
1161 p.fillRect(m_left_border,lastdy,width()-(m_left_border+m_right_border),m_scrollstep,m_bg);
1162 }
1163 else
1164 {
1165 bitBlt(this, m_left_border, lastdy, dbuff, m_left_border, lastdy, width()-(m_left_border+m_right_border), m_scrollstep);
1166 }
1167 }
1168 p.fillRect(m_left_border,m_scrolldy,width()-(m_left_border+m_right_border),1,m_scrollcolor);
1169 }
1170 }
1171}
1172
1173void QTReader::dorollingscroll(bool _statbord)
1174{
1175 bool bredrawscroll = false;
1176 QPainter p( this );
1177 // 2 = right, 3 = left
1178 int tmargin = (_statbord) ? m_topmargin : 0;
1179 int lmargin = (m_scrollpos == 3 || _statbord) ? m_left_border : 0;
1180 int rmargin = (m_scrollpos == 2 || _statbord) ? m_right_border : 0;
1181 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1182 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1183 if (m_rotated)
1184 {
1185 m_totalscroll = (m_totalscroll+m_scrollstep) % width();
1186 bitBlt(this, m_scrollstep+hmargin, lmargin, this, hmargin, lmargin, width()-tmargin-hmargin, height()-(lmargin+rmargin));
1187 if (!m_bgpm.isNull())
1188 {
1189 blitRot(hmargin, tmargin, height(), m_scrollstep, NULL);
1190 }
1191 else
1192 {
1193 p.fillRect(hmargin, rmargin, m_scrollstep, height()-lmargin-rmargin, m_bg);
1194 }
1195 }
1196 else
1197 {
1198 m_totalscroll = (m_totalscroll+m_scrollstep) % height();
1199 bitBlt(this,lmargin,tmargin,this,lmargin,tmargin+m_scrollstep,width()-(lmargin+rmargin),height() - tmargin - hmargin - m_scrollstep);
1200 if (m_bgpm.isNull())
1201 {
1202 p.fillRect(0, height() - (m_scrollstep+1) - hmargin, width(), (m_scrollstep+1), m_bg);
1203 }
1204 else
1205 {
1206 int loff = (_statbord) ? 0 : m_totalscroll;
1207 bitBlt(this,0,height() - (m_scrollstep+1) - hmargin, dbuff, 0, (loff+height() - (m_scrollstep+1) - hmargin) % height(), width(), (m_scrollstep+1));
1208 }
1209 }
1210
1211 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
1212 {
1213 int ht = textarray[0]->lineSpacing();
1214 bredrawscroll = true;
1215#ifdef _SCROLLPIPE
1216 if (m_pipeout != NULL)
1217 {
1218 QString outstr = toQString(textarray[0]->data());
1219 if (!outstr.isEmpty())
1220 {
1221 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1222 fflush(m_pipeout);
1223 }
1224 else if (m_pauseAfterEachPara)
1225 {
1226 m_isPaused = true;
1227 timer->stop();
1228 }
1229 }
1230#endif
1231 CDrawBuffer* buff = textarray[0];
1232 for (int i = 1; i <= numlines; i++)
1233 {
1234 textarray[i-1] = textarray[i];
1235 locnarray[i-1] = locnarray[i];
1236 }
1237 textarray[numlines] = buff;
1238 --numlines;
1239 m_scrolldy1 -= ht;
1240 }
1241 if ((m_scrolldy2 = m_scrolldy2+m_scrollstep) >= textarray[numlines]->lineSpacing())
1242 {
1243 bredrawscroll = true;
1244 m_scrolldy2 -= textarray[numlines]->lineSpacing();
771 numlines++; 1245 numlines++;
@@ -778,3 +1252,12 @@ void QTReader::doscroll()
778 int ch = getline(textarray[numlines]); 1252 int ch = getline(textarray[numlines]);
779 textarray[numlines-1]->render(&p, height() - textarray[numlines-1]->descent() - 2, m_bMonoSpaced, m_charWidth, width(), m_border); 1253 if (m_rotated)
1254 {
1255 blitRot(hmargin, 0, height(), -1, textarray[numlines-1]);
1256 }
1257 else
1258 {
1259 // 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);
1260 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);
1261
1262 }
780 mylastpos = locate(); 1263 mylastpos = locate();
@@ -782,2 +1265,4 @@ void QTReader::doscroll()
782 { 1265 {
1266 redrawScroll(&p);
1267 emitRedraw();
783 m_autoScroll = false; 1268 m_autoScroll = false;
@@ -797,3 +1282,3 @@ void QTReader::doscroll()
797#endif 1282#endif
798 ((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll); 1283 emit SetScrollState(m_autoScroll);
799#ifdef USEQPE 1284#ifdef USEQPE
@@ -801,5 +1286,209 @@ void QTReader::doscroll()
801#endif 1286#endif
1287 return;
802 } 1288 }
803 emit OnRedraw();
804 } 1289 }
1290 if (!bredrawscroll && ((m_scrolldy2/m_scrollstep) % 10 == 5) && textarray[numlines]->showPartial())
1291 {
1292 if (m_rotated)
1293 {
1294 blitRot(hmargin + m_scrolldy2 - textarray[numlines]->lineSpacing(), 0, height(), -1, textarray[numlines]);
1295 }
1296 else
1297 {
1298 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);
1299 }
1300 }
1301 if (m_scrollpos != 0)
1302 {
1303 redrawScroll(&p);
1304 }
1305 if (bredrawscroll) emitRedraw();
1306}
1307
1308void QTReader::dostaticscroll()
1309{
1310 redrawall();
1311 bool bredraw = false;
1312 if ((m_scrolldy1 = m_scrolldy1+m_scrollstep) >= textarray[0]->lineSpacing())
1313 {
1314 int ht = textarray[0]->lineSpacing();
1315 bredraw = true;
1316#ifdef _SCROLLPIPE
1317 if (m_pipeout != NULL)
1318 {
1319 QString outstr = toQString(textarray[0]->data());
1320 if (!outstr.isEmpty())
1321 {
1322 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1323 fflush(m_pipeout);
1324 }
1325 else if (m_pauseAfterEachPara)
1326 {
1327 m_isPaused = true;
1328 timer->stop();
1329 }
1330 }
1331#endif
1332 CDrawBuffer* buff = textarray[0];
1333 for (int i = 1; i <= numlines; i++)
1334 {
1335 textarray[i-1] = textarray[i];
1336 locnarray[i-1] = locnarray[i];
1337 }
1338 textarray[numlines] = buff;
1339 --numlines;
1340 m_scrolldy1 -= ht;
1341 }
1342 if ((m_scrolldy2 = m_scrolldy2 + m_scrollstep) >= textarray[numlines]->lineSpacing())
1343 {
1344 bredraw = true;
1345 m_scrolldy2 -= textarray[numlines]->lineSpacing();
1346 numlines++;
1347
1348 if (textarray[numlines] == NULL)
1349 {
1350 textarray[numlines] = new CDrawBuffer(&m_fontControl);
1351 }
1352 locnarray[numlines] = locate();
1353 int ch = getline(textarray[numlines]);
1354 mylastpos = locate();
1355 if (!ch)
1356 {
1357 redrawall();
1358 emitRedraw();
1359 m_autoScroll = false;
1360#ifdef _SCROLLPIPE
1361 for (int i = 0; i < numlines; i++)
1362 {
1363 if (m_pipeout != NULL)
1364 {
1365 QString outstr = toQString(textarray[i]->data());
1366 if (!outstr.isEmpty())
1367 {
1368 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1369 fflush(m_pipeout);
1370 }
1371 }
1372 }
1373#endif
1374 emit SetScrollState(m_autoScroll);
1375#ifdef USEQPE
1376 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1377#endif
1378 return;
1379 }
1380 }
1381 if (bredraw) emitRedraw();
1382}
1383
1384void QTReader::redrawScroll(QPainter* p)
1385{
1386 int offset = (m_scrolltype == 1) ? m_totalscroll : 0;
1387 switch (m_scrollpos)
1388 {
1389 case 1:
1390 {
1391 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1392 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1393 if (m_rotated)
1394 {
1395 if (m_bgpm.isNull())
1396 {
1397 p->fillRect(0,0,hmargin,height(),m_bg);
1398 }
1399 else
1400 {
1401 blitRot(0,0, height(), hmargin, NULL);
1402 }
1403 }
1404 else
1405 {
1406 if (m_bgpm.isNull())
1407 {
1408 p->fillRect(0,height() - hmargin,width(),hmargin,m_bg);
1409 }
1410 else
1411 {
1412 int toffset = (offset+height()-hmargin) % height();
1413 if (toffset+hmargin > height())
1414 {
1415 int fp = height()-toffset;
1416 bitBlt(this,
1417 0,height() - hmargin,
1418 dbuff,
1419 0, toffset, width(), fp);
1420 bitBlt(this,
1421 0,height()-hmargin+fp,
1422 dbuff,
1423 0, 0, width(), hmargin-fp);
1424 }
1425 else
1426 {
1427 bitBlt(this,
1428 0,height() - hmargin,
1429 dbuff,
1430 0, toffset, width(), hmargin);
1431 }
1432 }
1433 }
1434 }
1435 break;
1436 case 2: //right
1437 if (m_rotated)
1438 {
1439 if (m_bgpm.isNull())
1440 {
1441 p->fillRect(0,height()-m_right_border,width(),m_right_border,m_bg);
1442 }
1443 else
1444 {
1445 blitRot(0,height()-m_right_border, m_right_border, width(), NULL);
1446 }
1447 }
1448 else
1449 {
1450 if (m_bgpm.isNull())
1451 {
1452 p->fillRect(width()-m_right_border,0,m_right_border,height(),m_bg);
1453 }
1454 else
1455 {
1456 int x = width() - m_right_border;
1457 int fp = height()-offset;
1458 bitBlt(this, x, 0, dbuff, x, offset, m_right_border, fp);
1459 bitBlt(this, x, fp, dbuff, x, 0, m_right_border, height()-fp);
1460 }
1461 }
1462 break;
1463 case 3: //left
1464 if (m_rotated)
1465 {
1466 if (m_bgpm.isNull())
1467 {
1468 p->fillRect(0,0,width(),m_left_border,m_bg);
1469 }
1470 else
1471 {
1472 blitRot(0,0, m_left_border, width(), NULL);
1473 }
1474 }
1475 else
1476 {
1477 if (m_bgpm.isNull())
1478 {
1479 p->fillRect(0,0,m_left_border,height(),m_bg);
1480 }
1481 else
1482 {
1483 int fp = height()-offset;
1484 bitBlt(this, 0, 0, dbuff, 0, offset, m_left_border, fp);
1485 bitBlt(this, 0, fp, dbuff, 0, 0, m_left_border, height()-fp);
1486 }
1487 }
1488 break;
1489 case 0:
1490 default:
1491 break;
1492 }
1493 if (m_scrollpos != 0) DrawScroll(p, width(), height());
805} 1494}
@@ -808,2 +1497,4 @@ void QTReader::autoscroll()
808{ 1497{
1498 drawBackground();
1499 dbp->end();
809 timer->start(real_delay(), false); 1500 timer->start(real_delay(), false);
@@ -821,3 +1512,87 @@ void QTReader::setfont()
821 1512
822void QTReader::drawFonts( QPainter *p ) 1513void QTReader::DrawStraight(QPainter* p, int w, int h)
1514{
1515 if (m_scrolldy == m_topmargin)
1516 {
1517 int ypos = textarray[0]->ascent()-m_scrolldy1+m_topmargin;
1518 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1519 int i;
1520 for (i = 1; i < numlines; i++)
1521 {
1522 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1523 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1524 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1525 }
1526 if (textarray[i]->showPartial())
1527 {
1528 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1529 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1530 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1531 }
1532 }
1533 else
1534 {
1535 int ypos = textarray[0]->ascent()-m_scrolldy1+m_scrolldy+m_topmargin;
1536 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1537 // p->fillRect(m_border, 0, w-2*m_border, m_scrolldy, m_bg);
1538 for (int i = 1; i < numlines; i++)
1539 {
1540 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1541 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1542 if (ypos+textarray[i]->descent() > h)
1543 {
1544 ypos = textarray[i]->ascent();
1545 }
1546 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, w, m_left_border, m_right_border, m_bg, h-m_topmargin-m_bottommargin);
1547 }
1548 p->fillRect(m_left_border,m_scrolldy,w-(m_left_border+m_right_border),1,m_scrollcolor);
1549 }
1550 bool wasrotated = m_rotated;
1551 m_rotated = false;
1552 DrawScroll(p, w, h);
1553 m_rotated = wasrotated;
1554
1555}
1556
1557void QTReader::redrawall()
1558{
1559 if (m_rotated)
1560 {
1561#ifdef DOUBLEBUFFER
1562 drawBackground();
1563 DrawStraight(dbp, height(), width());
1564 dbp->end();
1565
1566 QWMatrix m;
1567 m.rotate(90);
1568 QPixmap rp = dbuff->xForm(m);
1569 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1570#else
1571 QPixmap dbuff(height(), width());
1572 QPainter dbp(&dbuff);
1573 // dbp.setBackgroundMode(OpaqueMode);
1574 dbp.fillRect(dbuff.rect(), m_bg);
1575
1576 DrawStraight(&dbp, height(), width());
1577
1578 QWMatrix m;
1579 m.rotate(90);
1580 QPixmap rp = dbuff.xForm(m);
1581 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1582#endif
1583 }
1584 else
1585 {
1586#ifdef DOUBLEBUFFER
1587 drawBackground();
1588 DrawStraight(dbp, width(), height());
1589 dbp->end();
1590 bitBlt(this, 0,0,dbuff,0,0,-1,-1);
1591#else
1592 DrawStraight(p, width(), height());
1593#endif
1594 }
1595}
1596
1597void QTReader::drawFonts()
823{ 1598{
@@ -825,13 +1600,65 @@ void QTReader::drawFonts( QPainter *p )
825 { 1600 {
826 //odebug << "How refreshing..." << oendl; 1601 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1602 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1603 //qDebug("How refreshing...");
827 if (buffdoc.empty()) return; 1604 if (buffdoc.empty()) return;
828 setfont(); 1605 setfont();
1606 //if (!m_autoScroll) m_scrolldy1 = 0;
1607#ifdef ROTATION_ENABLED
1608 if (m_lastwidth != ((m_rotated) ? height() : width()))
1609 {
1610 m_scrolldy = m_topmargin;
1611 // qDebug("Not Optimised %d", m_lastwidth);
1612 m_lastwidth = ((m_rotated) ? height() : width());
1613 m_lastheight = ((m_rotated) ? width() : height());
1614 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1615 locate(pagelocate());
1616 // qDebug("Not Optimised %d", m_lastwidth);
1617 }
1618 else
1619 {
1620 int newht = ((m_rotated) ? width() : height());
1621 if (m_lastheight > newht)
1622 {
1623 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
1624 m_scrolldy = m_topmargin;
1625 int ypos = m_scrolldy1+m_topmargin;
1626 for (int i = 0; i < numlines; i++)
1627 {
1628 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
1629 {
1630 numlines = i;
1631 jumpto(mylastpos = locnarray[i+1]);
1632 break;
1633 }
1634 }
1635 // qDebug("Optimised < %d", numlines);
1636 m_lastheight = newht;
1637 }
1638 else if (m_lastheight < newht)
1639 {
1640 m_scrolldy = m_topmargin;
1641 // qDebug("Optimised > %d", numlines);
1642 int ypos = m_scrolldy1+m_topmargin;
1643 for (int i = 0; i <= numlines; i++)
1644 {
1645 ypos += textarray[i]->lineSpacing();
1646 }
1647 fillbuffer(numlines+1, ypos, newht);
1648 // qDebug("Optimised > %d", numlines);
1649 }
1650 if (numlines > 0)
1651 {
1652 redrawall();
1653 }
1654 }
1655#else
829 if (m_lastwidth != width()) 1656 if (m_lastwidth != width())
830 { 1657 {
831 // odebug << "Not Optimised " << m_lastwidth << "" << oendl; 1658 // qDebug("Not Optimised %d", m_lastwidth);
832 m_lastwidth = width(); 1659 m_lastwidth = width();
833 m_lastheight = height(); 1660 m_lastheight = height();
834 buffdoc.setwidth(m_lastwidth-2*m_border); 1661 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
835 locate(pagelocate()); 1662 locate(pagelocate());
836 // odebug << "Not Optimised " << m_lastwidth << "" << oendl; 1663 // qDebug("Not Optimised %d", m_lastwidth);
837 } 1664 }
@@ -842,7 +1669,7 @@ void QTReader::drawFonts( QPainter *p )
842 { 1669 {
843 // odebug << "Optimised < " << numlines << " " << m_lastheight << " " << newht << "" << oendl; 1670 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
844 int ypos = 0; 1671 int ypos = m_topmargin;
845 for (int i = 0; i < numlines; i++) 1672 for (int i = 0; i < numlines; i++)
846 { 1673 {
847 if ((ypos += textarray[i]->lineSpacing()) > newht) 1674 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
848 { 1675 {
@@ -853,3 +1680,3 @@ void QTReader::drawFonts( QPainter *p )
853 } 1680 }
854 // odebug << "Optimised < " << numlines << "" << oendl; 1681 // qDebug("Optimised < %d", numlines);
855 m_lastheight = newht; 1682 m_lastheight = newht;
@@ -858,4 +1685,4 @@ void QTReader::drawFonts( QPainter *p )
858 { 1685 {
859 // odebug << "Optimised > " << numlines << "" << oendl; 1686 // qDebug("Optimised > %d", numlines);
860 int ypos = 0; 1687 int ypos = m_topmargin;
861 for (int i = 0; i <= numlines; i++) 1688 for (int i = 0; i <= numlines; i++)
@@ -865,3 +1692,3 @@ void QTReader::drawFonts( QPainter *p )
865 fillbuffer(numlines+1, ypos, newht); 1692 fillbuffer(numlines+1, ypos, newht);
866 // odebug << "Optimised > " << numlines << "" << oendl; 1693 // qDebug("Optimised > %d", numlines);
867 } 1694 }
@@ -869,4 +1696,4 @@ void QTReader::drawFonts( QPainter *p )
869 { 1696 {
870 int ypos = textarray[0]->ascent(); 1697 int ypos = textarray[0]->ascent()+m_topmargin;
871 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); 1698 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
872 // int last = (m_showlast) ? numlines : numlines-1; 1699 // int last = (m_showlast) ? numlines : numlines-1;
@@ -878,3 +1705,3 @@ void QTReader::drawFonts( QPainter *p )
878 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2; 1705 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
879 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_border); 1706 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
880 } 1707 }
@@ -883,23 +1710,184 @@ void QTReader::drawFonts( QPainter *p )
883 } 1710 }
1711#endif
1712 emitRedraw();
1713 }
1714/*
1715 else
1716 {
1717 qDebug("Not so refreshing...");
1718 }
1719*/
1720}
884 1721
885 m_scrolldy1 = m_scrolldy2 = m_scrollpart; 1722void QTReader::DrawScroll( QPainter *p, int _w, int _h )
886 if (m_border > 5 && !buffdoc.empty()) 1723{
1724 if (!buffdoc.empty())
1725 {
1726 QBrush checkered = QBrush( Dense4Pattern );
1727 checkered.setColor(m_scrollbarcolor);
1728 switch (m_scrollpos)
1729 {
1730 case 1:
1731 if (m_rotated)
1732 {
1733 p->fillRect(0, 0, 2, _h, checkered);
1734 }
1735 else
1736 {
1737 p->fillRect(0, _h-2, _w, 2, checkered);
1738 }
1739 break;
1740 case 2:
1741 if (m_rotated)
1742 {
1743 p->fillRect(0, _h-2, _w, 2, checkered);
1744 }
1745 else
1746 {
1747 p->fillRect(_w-2, 0, 2, _h, checkered);
1748 }
1749 break;
1750 case 3:
1751 if (m_rotated)
1752 {
1753 p->fillRect(0, 0, _w, 2, checkered);
1754 }
1755 else
1756 {
1757 p->fillRect(0, 0, 2, _h, checkered);
1758 }
1759 break;
1760 case 0:
1761 default:
1762 break;
1763 }
1764 switch (m_scrollpos)
887 { 1765 {
888 p->fillRect(width()-2, 0, 2, height(), cyan); 1766 case 1:
1767 {
1768 int ht;
1769 if (m_rotated)
1770 {
1771 ht = _h;
1772 }
1773 else
1774 {
1775 ht = _w;
1776 }
889 int sectionsize = (buffdoc.endSection()-buffdoc.startSection()); 1777 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
890 int mid = (height()*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize); 1778 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
891 p->fillRect(width()-2, mid-5, 2, 10, yellow); 1779 int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize;
892 p->fillRect(width()-2, (height()*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*height()+sectionsize/2)/sectionsize, magenta); 1780 int sliderpos;
1781 if (sliderheight < 10)
1782 {
1783 sliderheight = 10;
1784 sliderpos = mid-5;
893 } 1785 }
894 1786 else
895 emit OnRedraw(); 1787 {
1788 sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize;
1789 }
1790 if (m_rotated)
1791 {
1792 p->fillRect(0, sliderpos, 3, sliderheight, m_scrollbarcolor);
896 } 1793 }
897/*
898 else 1794 else
899 { 1795 {
900 odebug << "Not so refreshing..." << oendl; 1796 p->fillRect(sliderpos, _h-3, sliderheight, 3, m_scrollbarcolor);
1797 }
1798 }
1799 break;
1800 case 2:
1801 case 3:
1802 {
1803 int ht;
1804 if (m_rotated)
1805 {
1806 ht = _w;
1807 }
1808 else
1809 {
1810 ht = _h;
1811 }
1812 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
1813 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
1814 int sliderheight = ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize;
1815 int sliderpos;
1816 if (sliderheight < 10)
1817 {
1818 sliderheight = 10;
1819 sliderpos = mid-5;
1820 }
1821 else
1822 {
1823 sliderpos = (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize;
1824 }
1825 if (m_rotated)
1826 {
1827 int hoff;
1828 if (m_scrollpos == 2) //right
1829 {
1830 hoff = _h-3;
1831 }
1832 else
1833 {
1834 hoff = 0;
1835 }
1836 p->fillRect(ht-sliderpos-sliderheight, hoff, sliderheight, 3, m_scrollbarcolor);
1837 }
1838 else
1839 {
1840 int hoff;
1841 if (m_scrollpos == 2) //right
1842 {
1843 hoff = _w-3;
1844 }
1845 else
1846 {
1847 hoff = 0;
1848 }
1849 p->fillRect(hoff, sliderpos, 3, sliderheight, m_scrollbarcolor);
1850 }
1851 }
1852 break;
1853 case 0:
1854 default:
1855 break;
1856 }
901 } 1857 }
902*/
903} 1858}
904 1859
1860/*
1861void QTReader::DrawScroll( QPainter *p )
1862{
1863 if (m_border > 5 && !buffdoc.empty())
1864 {
1865 int ht, wh;
1866 if (m_rotated)
1867 {
1868 ht = width();
1869 wh = height()g;
1870 p->fillRect(0, wh-2, ht, 2, cyan);
1871 }
1872 else
1873 {
1874 ht = height();
1875 wh = width();
1876 p->fillRect(wh-2, 0, 2, ht, cyan);
1877 }
1878 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
1879 int mid = (ht*(locnarray[numlines]+locnarray[0]-2*buffdoc.startSection())+sectionsize)/(2*sectionsize);
1880 if (m_rotated)
1881 {
1882 p->fillRect(ht-mid-5, wh-2, 10, 2, yellow);
1883 p->fillRect(ht-(ht*(locnarray[numlines]-buffdoc.startSection())+sectionsize/2)/sectionsize, wh-2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, 2, magenta);
1884 }
1885 else
1886 {
1887 p->fillRect(wh-2, mid-5, 2, 10, yellow);
1888 p->fillRect(wh-2, (ht*(locnarray[0]-buffdoc.startSection())+sectionsize/2)/sectionsize, 2, ((locnarray[numlines]-locnarray[0])*ht+sectionsize/2)/sectionsize, magenta);
1889 }
1890 }
1891}
1892*/
905QString QTReader::firstword() 1893QString QTReader::firstword()
@@ -943,9 +1931,4 @@ void QTReader::init()
943{ 1931{
944// m_showlast = true;
945 // setCaption( "Qt Draw Demo Application" );
946
947 buffdoc.unsuspend(); 1932 buffdoc.unsuspend();
948 setBackgroundColor( white ); 1933 setBackgroundColor( m_bg );
949// QPainter p(this);
950// p.setBackgroundMode( Qt::OpaqueMode );
951 buffdoc.setfilter(getfilter()); 1934 buffdoc.setfilter(getfilter());
@@ -953,4 +1936,2 @@ void QTReader::init()
953 setFocusPolicy(QWidget::StrongFocus); 1936 setFocusPolicy(QWidget::StrongFocus);
954 // resize( 240, 320 );
955 //setFocus();
956 timer = new QTimer(this); 1937 timer = new QTimer(this);
@@ -959,9 +1940,2 @@ void QTReader::init()
959 setfont(); 1940 setfont();
960/*
961 if (!m_lastfile.isEmpty())
962 {
963 m_string = DocLnk(m_lastfile).name();
964 load_file(m_lastfile);
965 }
966*/
967} 1941}
@@ -973,2 +1947,6 @@ QTReader::~QTReader()
973{ 1947{
1948#ifdef DOUBLEBUFFER
1949 delete dbuff;
1950 delete dbp;
1951#endif
974#ifdef USEQPE 1952#ifdef USEQPE
@@ -988,11 +1966,2 @@ QTReader::~QTReader()
988// 1966//
989// Calls the drawing function as specified by the radio buttons.
990//
991
992void QTReader::drawIt( QPainter *p )
993{
994 drawFonts(p);
995}
996
997//
998// Called when the print button is clicked. 1967// Called when the print button is clicked.
@@ -1018,4 +1987,3 @@ void QTReader::paintEvent( QPaintEvent * )
1018{ 1987{
1019 QPainter paint( this ); 1988 drawFonts();
1020 drawIt( &paint );
1021} 1989}
@@ -1030,3 +1998,3 @@ void QTReader::resizeEvent( QResizeEvent * )
1030{ 1998{
1031// // odebug << "resize:(" << width() << "," << height() << ")" << oendl; 1999// // qDebug("resize:(%u,%u)", width(), height());
1032 // bgroup->move( width()-bgroup->width(), 0 ); 2000 // bgroup->move( width()-bgroup->width(), 0 );
@@ -1055,7 +2023,9 @@ bool QTReader::locate(unsigned long n) {
1055 buffdoc.locate(n); 2023 buffdoc.locate(n);
1056// // odebug << "&buffdoc.located" << oendl; 2024// // qDebug("&buffdoc.located");
2025 ResetScroll();
1057 fillbuffer(); 2026 fillbuffer();
1058// // odebug << "&Buffer filled" << oendl; 2027// // qDebug("&Buffer filled");
1059 update(); 2028 update();
1060// // odebug << "&Located" << oendl; 2029// // qDebug("&Located");
2030 emitRedraw();
1061 return true; 2031 return true;
@@ -1073,5 +2043,8 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
1073 buffdoc.unsuspend(); 2043 buffdoc.unsuspend();
2044 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
2045 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
2046 if (ht < 0) ht = m_topmargin;
1074 if (buffdoc.empty()) return false; 2047 if (buffdoc.empty()) return false;
1075 if (newht < 0) 2048 if (newht < 0)
1076 m_lastheight = height(); 2049 m_lastheight = (m_rotated) ? width() : height();
1077 else 2050 else
@@ -1083,3 +2056,3 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
1083 numlines = reuse; 2056 numlines = reuse;
1084 while (ypos < m_lastheight || numlines < 2) 2057 while (ypos < m_lastheight - hmargin || numlines < 2)
1085 { 2058 {
@@ -1098,2 +2071,3 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
1098 { 2071 {
2072 qDebug("FALSE");
1099 locate(oldpagepos); 2073 locate(oldpagepos);
@@ -1103,2 +2077,3 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
1103 { 2077 {
2078 qDebug("TRUE");
1104 --numlines; 2079 --numlines;
@@ -1108,2 +2083,8 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
1108 } 2083 }
2084 if (numlines > 1 && textarray[numlines-2]->isBop())
2085 {
2086 --numlines;
2087 mylastpos = locate();
2088 return true;
2089 }
1109 } 2090 }
@@ -1112,4 +2093,7 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
1112 mylastpos = locate(); 2093 mylastpos = locate();
1113 m_scrolldy1 = m_scrolldy2 = m_scrollpart = m_lastheight - lastypos; 2094 m_scrollpart = m_lastheight - lastypos - hmargin;
1114 2095 if (m_autoScroll)
2096 {
2097 CalculateScrollParameters();
2098 }
1115 return true; 2099 return true;
@@ -1119,8 +2103,8 @@ void QTReader::dopagedn()
1119{ 2103{
1120// odebug << "HEIGHT(2):" << m_lastheight << "" << oendl; 2104// qDebug("HEIGHT(2):%d", m_lastheight);
1121 buffdoc.unsuspend(); 2105 buffdoc.unsuspend();
1122 int skip = 0, ypos = 0; 2106 ResetScroll();
2107 int skip = 0, ypos = m_topmargin;
1123 if (locate() != mylastpos) 2108 if (locate() != mylastpos)
1124 { 2109 {
1125 ////odebug << "Jumping to " << mylastpos << "" << oendl;
1126 jumpto(mylastpos); 2110 jumpto(mylastpos);
@@ -1128,5 +2112,5 @@ void QTReader::dopagedn()
1128 CDrawBuffer* reusebuffer = textarray[numlines]; 2112 CDrawBuffer* reusebuffer = textarray[numlines];
1129 if (reusebuffer != NULL && reusebuffer->eof()) return;
1130 if (reusebuffer != NULL) 2113 if (reusebuffer != NULL)
1131 { 2114 {
2115 if (reusebuffer->eof()) return;
1132 for (int i = 0; i <= m_overlap; i++) 2116 for (int i = 0; i <= m_overlap; i++)
@@ -1145,5 +2129,11 @@ void QTReader::dopagedn()
1145 } 2129 }
2130 if (numlines <= 1)
2131 {
2132 skip = 0;
2133 ypos = 0;
2134 qDebug("Doing extra skip");
2135 }
1146 if (fillbuffer(skip, ypos)) 2136 if (fillbuffer(skip, ypos))
1147 { 2137 {
1148 update(); 2138 drawFonts();
1149 } 2139 }
@@ -1153,3 +2143,2 @@ void QTReader::dopageup()
1153{ 2143{
1154 buffdoc.unsuspend();
1155 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]); 2144 dopageup(locnarray[(m_overlap < numlines) ? m_overlap : numlines/2]);
@@ -1165,2 +2154,3 @@ bool QTReader::synch(size_t start, size_t end)
1165 if (ch == UEOF) return false; 2154 if (ch == UEOF) return false;
2155 if (ch == 6) return false;
1166 } 2156 }
@@ -1172,2 +2162,3 @@ void QTReader::dopageup(unsigned int target)
1172 buffdoc.unsuspend(); 2162 buffdoc.unsuspend();
2163 ResetScroll();
1173 CBufferFace<CDrawBuffer*> buff; 2164 CBufferFace<CDrawBuffer*> buff;
@@ -1177,3 +2168,3 @@ void QTReader::dopageup(unsigned int target)
1177 bool ch = true; 2168 bool ch = true;
1178 int nbfl, ypos = 0; 2169 int nbfl, ypos = m_topmargin;
1179 if (guess < 128) guess = 128; 2170 if (guess < 128) guess = 128;
@@ -1181,2 +2172,4 @@ void QTReader::dopageup(unsigned int target)
1181 { 2172 {
2173 // qDebug("Guess:%u", guess);
2174
1182 ch = true; 2175 ch = true;
@@ -1211,3 +2204,3 @@ void QTReader::dopageup(unsigned int target)
1211 nbfl = 0; 2204 nbfl = 0;
1212 ypos = 0; 2205 ypos = m_topmargin;
1213 2206
@@ -1222,3 +2215,3 @@ void QTReader::dopageup(unsigned int target)
1222 } 2215 }
1223 if (guess < 4000 && ypos < height() && (delta != 0)) 2216 if (guess < 4000 && ypos < ((m_rotated) ? width() : height())-(m_bottommargin) && (delta != 0))
1224 { 2217 {
@@ -1252,5 +2245,5 @@ void QTReader::dopageup(unsigned int target)
1252 2245
1253 ypos = 0; 2246 ypos = m_topmargin;
1254 numlines = 0; 2247 numlines = 0;
1255 while (ypos < height() && numlines+2 <= nbfl) 2248 while (ypos < ((m_rotated) ? width() : height())-m_bottommargin && numlines+2 <= nbfl)
1256 { 2249 {
@@ -1264,3 +2257,3 @@ void QTReader::dopageup(unsigned int target)
1264 offset -= numlines; 2257 offset -= numlines;
1265 ypos = 0; 2258 ypos = m_topmargin;
1266 for (int i = 0; i <= numlines; i++) 2259 for (int i = 0; i <= numlines; i++)
@@ -1281,3 +2274,3 @@ void QTReader::dopageup(unsigned int target)
1281 2274
1282 while (ypos < height()) 2275 while (ypos < ((m_rotated) ? width() : height())-m_bottommargin)
1283 { 2276 {
@@ -1291,4 +2284,5 @@ void QTReader::dopageup(unsigned int target)
1291 mylastpos = locate(); 2284 mylastpos = locate();
1292 2285 CalculateScrollParameters();
1293 update(); 2286 drawFonts();
2287 // repaint();
1294} 2288}
@@ -1299,5 +2293,6 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
1299// QMessageBox::information(this, "load_file", newfile, 1); 2293// QMessageBox::information(this, "load_file", newfile, 1);
1300 2294 int prog = 0;
1301 bool bRC = false; 2295 bool bRC = false;
1302 unsigned int lcn = _lcn; 2296 unsigned int lcn = _lcn;
2297 ResetScroll();
1303 if (m_lastfile == newfile) 2298 if (m_lastfile == newfile)
@@ -1307,4 +2302,12 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
1307 // QMessageBox::information(0, "Opening...", newfile); 2302 // QMessageBox::information(0, "Opening...", newfile);
2303 if (m_rotated)
2304 {
2305 m_lastwidth = height();
2306 m_lastheight = width();
2307 }
2308 else
2309 {
1308 m_lastwidth = width(); 2310 m_lastwidth = width();
1309 m_lastheight = height(); 2311 m_lastheight = height();
2312 }
1310 if (buffdoc.openfile(this,newfile) == 0) 2313 if (buffdoc.openfile(this,newfile) == 0)
@@ -1312,12 +2315,11 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
1312 m_lastfile = newfile; 2315 m_lastfile = newfile;
1313 buffdoc.setwidth(m_lastwidth-2*m_border); 2316 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1314 bRC = true; 2317 bRC = true;
1315 buffdoc.setContinuous(m_continuousDocument); 2318 buffdoc.setContinuous(m_continuousDocument);
1316// // odebug << "buffdoc.openfile done" << oendl; 2319 qDebug("buffdoc.openfile done");
1317 locate(lcn); 2320 locate(lcn);
1318// // odebug << "buffdoc.locate done" << oendl; 2321 qDebug("buffdoc.locate done");
1319 } 2322 }
1320 setfilter(getfilter()); 2323 setfilter(getfilter());
1321 update(); 2324 qDebug("Updated");
1322// // odebug << "Updated" << oendl;
1323 return bRC; 2325 return bRC;
@@ -1327,3 +2329,4 @@ void QTReader::lineDown()
1327{ 2329{
1328 int ypos = 0; 2330 int ypos = m_topmargin;
2331 ResetScroll();
1329 int offset = numlines; 2332 int offset = numlines;
@@ -1332,3 +2335,3 @@ void QTReader::lineDown()
1332 { 2335 {
1333 if ((ypos += textarray[numlines-i]->lineSpacing()) > height()) 2336 if ((ypos += textarray[numlines-i]->lineSpacing()) > ((m_rotated) ? width() : height()))
1334 { 2337 {
@@ -1443,5 +2446,22 @@ void QTReader::lineUp()
1443*/ 2446*/
2447
2448void QTReader::ResetScroll()
2449{
2450 m_totalscroll = 0;
2451 m_scrolldy1 = 0;
2452 m_scrolldy = m_topmargin;
2453 if (m_autoScroll && ((m_scrolltype == 0) || !m_bgpm.isNull()))
2454 {
2455 setautoscroll(false);
2456 }
2457}
2458
1444void QTReader::lineUp() 2459void QTReader::lineUp()
1445{ 2460{
2461 dopageup(locnarray[numlines-1]);
2462
2463 /*
1446 buffdoc.unsuspend(); 2464 buffdoc.unsuspend();
2465 ResetScroll();
2466
1447 CDrawBuffer* buff = textarray[numlines]; 2467 CDrawBuffer* buff = textarray[numlines];
@@ -1512,3 +2532,3 @@ void QTReader::lineUp()
1512 int start = numlines; 2532 int start = numlines;
1513 int ypos = 0; 2533 int ypos = m_topmargin;
1514#ifdef _WINDOWS 2534#ifdef _WINDOWS
@@ -1520,3 +2540,3 @@ void QTReader::lineUp()
1520 ypos += textarray[i]->lineSpacing(); 2540 ypos += textarray[i]->lineSpacing();
1521 if (ypos > height()) 2541 if (ypos > ((m_rotated) ? width() : height()))
1522 { 2542 {
@@ -1529,3 +2549,4 @@ void QTReader::lineUp()
1529 fillbuffer(start, ypos); 2549 fillbuffer(start, ypos);
1530 update(); 2550 repaint();
2551 */
1531} 2552}
@@ -1554 +2575,412 @@ MarkupType QTReader::PreferredMarkup()
1554} 2575}
2576#ifdef DOUBLEBUFFER
2577void QTReader::resizeEvent( QResizeEvent * p )
2578{
2579 if (m_rotated)
2580 {
2581 dbuff->resize(p->size().height(),p->size().width());
2582 }
2583 else
2584 {
2585 dbuff->resize(p->size());
2586 }
2587 m_bgIsScaled = false;
2588 if (m_bgtype == bgStretched)
2589 {
2590 emit RefreshBitmap();
2591 }
2592
2593 {
2594 int h, w;
2595 if (m_rotated)
2596 {
2597 h = p->size().width();
2598 w = p->size().height();
2599 }
2600 else
2601 {
2602 w = p->size().width();
2603 h = p->size().height();
2604 }
2605 m_topmargin = (h*m_abstopmargin+500)/1000;
2606 m_bottommargin = (h*m_absbottommargin+500)/1000;
2607 m_left_border = (w*m_absleft_border+500)/1000;
2608 m_right_border = (w*m_absright_border+500)/1000;
2609
2610 qDebug("Top margin:%u", m_topmargin );
2611 qDebug("Bottom margin:%u", m_bottommargin );
2612 qDebug("Left margin:%u", m_left_border );
2613 qDebug("Right margin:%u", m_right_border );
2614 }
2615}
2616#endif
2617
2618void QTReader::setrotated(bool sfs)
2619{
2620 m_rotated = sfs;
2621#ifdef DOUBLEBUFFER
2622 if (m_rotated)
2623 {
2624 dbuff->resize(height(), width());
2625 }
2626 else
2627 {
2628 dbuff->resize(width(), height());
2629 }
2630 m_bgIsScaled = false;
2631#endif
2632 int h, w;
2633 if (m_rotated)
2634 {
2635 h = width();
2636 w = height();
2637 }
2638 else
2639 {
2640 w = width();
2641 h = height();
2642 }
2643 m_topmargin = (h*m_abstopmargin+500)/1000;
2644 m_bottommargin = (h*m_absbottommargin+500)/1000;
2645 m_left_border = (w*m_absleft_border+500)/1000;
2646 m_right_border = (w*m_absright_border+500)/1000;
2647
2648 qDebug("Top margin:%u", m_topmargin );
2649 qDebug("Bottom margin:%u", m_bottommargin );
2650 qDebug("Left margin:%u", m_left_border );
2651 qDebug("Right margin:%u", m_right_border );
2652}
2653
2654void QTReader::drawBackground()
2655{
2656 dbp->begin(dbuff);
2657 // dbp->setBackgroundMode(OpaqueMode);
2658 dbp->setBackgroundColor(m_bg);
2659 dbp->eraseRect(dbuff->rect());
2660 if (!m_bgpm.isNull())
2661 {
2662 // dbp->setBackgroundMode(TransparentMode);
2663 switch (m_bgtype)
2664 {
2665 case bgCentred:
2666 {
2667 int w = (dbuff->rect().width()-m_bgpm.width())/2;
2668 int h = (dbuff->rect().height()-m_bgpm.height())/2;
2669 dbp->drawPixmap(w,h,m_bgpm);
2670 }
2671 break;
2672 case bgTiled:
2673 {
2674 dbp->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm);
2675 /*
2676 for (int h = 0; h < dbuff->rect().height(); h += m_bgpm.height())
2677 {
2678 for (int w = 0; w < dbuff->rect().width(); w += m_bgpm.width())
2679 {
2680 dbp->drawPixmap(w,h,m_bgpm);
2681 }
2682 }
2683 */
2684 }
2685 break;
2686 case bgStretched:
2687 {
2688 if (!m_bgIsScaled)
2689 {
2690 m_bgIsScaled = true;
2691 QImage im = m_bgpm.convertToImage();
2692 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height()));
2693 }
2694 dbp->drawPixmap(0,0,m_bgpm);
2695 }
2696 break;
2697 default:
2698 qDebug("Unknown background type");
2699 }
2700 // dbp->setBackgroundMode(OpaqueMode);
2701 }
2702}
2703
2704void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
2705{
2706 if (txt != NULL)
2707 {
2708 sh = txt->lineSpacing();
2709 }
2710 int sy = width()-dx-sh;
2711 if (m_autoScroll && !(m_scrolltype == 0))
2712 {
2713 sy = (sy+m_totalscroll+1)%width();
2714 }
2715
2716 QPixmap pm(sw, sh);
2717
2718 QPainter pd(&pm, this);
2719 if (m_bgpm.isNull())
2720 {
2721 pd.eraseRect(pm.rect());
2722 }
2723 else
2724 {
2725 if (sy+pm.height() > dbuff->height())
2726 {
2727 // pd.eraseRect(pm.rect());
2728 int fh = dbuff->height() - sy;
2729 if (sy+fh > dbuff->height())
2730 {
2731 qDebug("Oh no!");
2732 }
2733
2734 if (fh > pm.height())
2735 {
2736 qDebug("Oh no! - 2");
2737 }
2738
2739 bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),fh);
2740 bitBlt(&pm,0,fh,dbuff,dy,0,pm.width(),pm.height()-fh);
2741 }
2742 else
2743 {
2744 bitBlt(&pm,0,0,dbuff,dy,sy,pm.width(),pm.height());
2745 }
2746 }
2747 if (txt != NULL)
2748 {
2749 // txt->render(&pd, txt->lineSpacing() - txt->descent() - txt->lineExtraSpacing(), m_bMonoSpaced, m_charWidth, sw, m_left_border, m_right_border, m_bg);
2750 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);
2751 }
2752 QWMatrix m;
2753 m.rotate(90);
2754 QPixmap rp = pm.xForm(m);
2755 /*
2756 p.drawPixmap(QPoint(dx, dy), rp);
2757 */
2758 bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP);
2759}
2760
2761QString QTReader::about()
2762{
2763 return QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka";
2764}
2765
2766void QTReader::getNextLink()
2767{
2768 if (m_scrolldy != 0)
2769 {
2770 setautoscroll(false);
2771 ResetScroll();
2772 redrawall();
2773 }
2774 bool redraw = false;
2775 bool found = false;
2776 if (m_currentlink >= 0)
2777 {
2778 m_currentlinkoffset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2779 if ((m_currentlinkstyle = textarray[m_currentlink]->getNextLink(m_currentlinkoffset)) != NULL)
2780 {
2781 qDebug("Found a link at %u", m_currentlinkoffset);
2782 int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2783 qDebug("Finishes at %u", offset);
2784 found = true;
2785 }
2786 redraw = true;
2787 drawSingleLine(m_currentlink);
2788 // if (found) return;
2789 }
2790 if (!found)
2791 {
2792 m_currentlinkoffset = -1;
2793 for (int i = m_currentlink+1; i < numlines; ++i)
2794 {
2795 if ((m_currentlinkstyle = textarray[i]->getNextLink(m_currentlinkoffset)) != NULL)
2796 {
2797 m_currentlink = i;
2798 qDebug("Found a link at %u", m_currentlinkoffset);
2799 int offset = textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2800 qDebug("Finishes at %u", offset);
2801 //drawSingleLine(i);
2802 redraw = true;
2803 found = true;
2804 drawSingleLine(m_currentlink);
2805 break;
2806 }
2807 }
2808 }
2809 if (redraw)
2810 {
2811 // redrawall();
2812 }
2813 if (!found)
2814 {
2815 m_currentlink = -1;
2816 m_currentlinkstyle = NULL;
2817 m_currentlinkoffset = -1;
2818 dopagedn();
2819 }
2820}
2821
2822void QTReader::emitRedraw()
2823{
2824 m_currentlinkstyle = NULL;
2825 m_currentlink = -1;
2826 m_currentlinkoffset = -1;
2827 emit OnRedraw();
2828};
2829
2830void QTReader::drawSingleLine(int lineno)
2831{
2832 QPainter p( this );
2833 int ypos = textarray[0]->ascent()+m_topmargin;
2834 if (lineno == 0)
2835 {
2836 if (m_rotated)
2837 {
2838 blitRot(width()-(ypos+textarray[lineno]->descent()+textarray[lineno]->lineExtraSpacing()), 0, height(), -1, textarray[lineno]);
2839 }
2840 else
2841 {
2842 if (m_bgpm.isNull())
2843 {
2844 p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg);
2845 }
2846 else
2847 {
2848 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());
2849 }
2850 textarray[lineno]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
2851 }
2852 }
2853 for (int i = 1; i < numlines; i++)
2854 {
2855 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
2856 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
2857 if (i == lineno)
2858 {
2859 if (m_rotated)
2860 {
2861 blitRot(width()-(ypos+textarray[i]->descent()+textarray[i]->lineExtraSpacing()), 0, height(), -1, textarray[i]);
2862 }
2863 else
2864 {
2865 if (m_bgpm.isNull())
2866 {
2867 p.fillRect(m_left_border,ypos-textarray[lineno]->ascent(),width()-(m_left_border+m_right_border),textarray[lineno]->lineSpacing(),m_bg);
2868 }
2869 else
2870 {
2871 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());
2872 }
2873 textarray[i]->render( &p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
2874 }
2875 }
2876 }
2877}
2878
2879
2880void QTReader::gotoLink()
2881{
2882 if (m_currentlinkstyle == NULL) return;
2883 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
2884 size_t saveposn = pagelocate();
2885 QString href, nm;
2886 unsigned long tgt = m_currentlinkstyle->getData();
2887 unsigned long tgtoffset = m_currentlinkstyle->getOffset();
2888 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
2889 qDebug("URL(1):%s", (const char*)href);
2890 if ((lt & eFile) != 0)
2891 {
2892 buffdoc.saveposn(m_lastfile, saveposn);
2893#ifdef USEQPE
2894 {
2895 QCopEnvelope e("QPE/System", "busy()");
2896 }
2897#endif
2898 ResetScroll();
2899 if (!href.isEmpty())
2900 {
2901 if (!buffdoc.getFile(href))
2902 {
2903 emit NewFileRequest(href);
2904 }
2905 else
2906 {
2907 ResetScroll();
2908 fillbuffer();
2909 update();
2910 }
2911 }
2912 if (!nm.isEmpty())
2913 {
2914 qDebug("QTReader:Finding %s", (const char*)nm);
2915 if (buffdoc.findanchor(nm))
2916 {
2917 fillbuffer();
2918 update();
2919 }
2920 }
2921 //fillbuffer();
2922 //update();
2923#ifdef USEQPE
2924 {
2925 QCopEnvelope e("QPE/System", "notBusy()");
2926 }
2927#endif
2928 }
2929 else if ((lt & eLink) != 0)
2930 {
2931 buffdoc.saveposn(m_lastfile, saveposn);
2932 ResetScroll();
2933 fillbuffer();
2934 update();
2935 }
2936 else
2937 {
2938 if ((lt & ePicture) != 0)
2939 {
2940 QImage* pm = buffdoc.getPicture(tgt);
2941 if (pm != NULL)
2942 {
2943 emit OnShowPicture(*pm);
2944 delete pm;
2945 }
2946 }
2947 else
2948 {
2949 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
2950 if (!href.isEmpty())
2951 {
2952 emit OnURLSelected(href, tgt);
2953 }
2954 }
2955 locate(pagelocate());
2956 }
2957 m_currentlinkstyle = NULL;
2958 m_currentlink = -1;
2959 m_currentlinkoffset = -1;
2960}
2961
2962void QTReader::refresh(bool full)
2963{
2964 int h, w;
2965 if (m_rotated)
2966 {
2967 h = width();
2968 w = height();
2969 }
2970 else
2971 {
2972 w = width();
2973 h = height();
2974 }
2975 m_topmargin = (h*m_abstopmargin+500)/1000;
2976 m_bottommargin = (h*m_absbottommargin+500)/1000;
2977 m_left_border = (w*m_absleft_border+500)/1000;
2978 m_right_border = (w*m_absright_border+500)/1000;
2979
2980 qDebug("Top margin:%u", m_topmargin );
2981 qDebug("Bottom margin:%u", m_bottommargin );
2982 qDebug("Left margin:%u", m_left_border );
2983 qDebug("Right margin:%u", m_right_border );
2984 if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate());
2985 locate(pagelocate());
2986}