summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/QTReader.cpp
Unidiff
Diffstat (limited to 'noncore/apps/opie-reader/QTReader.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/apps/opie-reader/QTReader.cpp1301
1 files changed, 904 insertions, 397 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 33884a0..0c56dd4 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -32,12 +32,16 @@ const int _SBARHEIGHT = 3;
32#endif 32#endif
33#include <qfileinfo.h> 33#include <qfileinfo.h>
34#include <qdir.h> 34#include <qdir.h>
35#include "TableDialog.h"
36#include "outputcodec.h"
35 37
38/*
36#ifdef _UNICODE 39#ifdef _UNICODE
37const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 }; 40const char *QTReader::fonts[] = { "unifont", "Courier", "Times", 0 };
38#else 41#else
39const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 }; 42const char *QTReader::fonts[] = { "Helvetica", "Courier", "Times", 0 };
40#endif 43#endif
44*/
41//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 }; 45//const int QTReader::fontsizes[] = { 8, 10, 12, 14, 18, 24, 30, 40, 50, 60, 70, 80, 90, 100, 0 };
42 46
43//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 }; 47//const tchar *QTReader::fonts[] = { "unifont", "fixed", "micro", "smoothtimes", "Courier", "Times", 0 };
@@ -49,9 +53,9 @@ tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e','
49tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; 53tchar QTReader::jplucknextpart[] = { 'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
50//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 }; 54//tchar QTReader::jplucknextpart[] = { 10,'#',10,'N','e','x','t',' ','P','a','r','t',' ','>','>',0 };
51 55
52
53QTReader::QTReader( QWidget *parent, const char *name, WFlags f) : 56QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
54 QWidget(parent, name, f), 57 QWidget(parent, name, f | WRepaintNoErase | WResizeNoErase),
58 m_outofdate(true),
55 m_default_fg(0,0,0), 59 m_default_fg(0,0,0),
56 m_default_bg(255,255,255), 60 m_default_bg(255,255,255),
57 m_bg(255,255,255), 61 m_bg(255,255,255),
@@ -89,16 +93,12 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
89 m_currentlinkoffset(-1), 93 m_currentlinkoffset(-1),
90 m_currentlink(-1) 94 m_currentlink(-1)
91{ 95{
96 m_output = NULL;
92 m_overlap = 1; 97 m_overlap = 1;
93 setKeyCompression ( true ); 98 setKeyCompression ( true );
94#ifdef DOUBLEBUFFER
95 dbuff = new QPixmap();
96 dbp = new QPainter();
97 // if (painter->isActive()) painter->end();
98 // painter->begin(frame);
99#endif
100// init();
101 99
100 dbuff = NULL;
101 dbp = NULL;
102} 102}
103 103
104/* 104/*
@@ -117,7 +117,7 @@ QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *nam
117 m_fm(NULL) 117 m_fm(NULL)
118{ 118{
119 init(); 119 init();
120// // qDebug("Load_file(1)"); 120// // qDeb2ug("Load_file(1)");
121 load_file((const tchar*)filename); 121 load_file((const tchar*)filename);
122} 122}
123*/ 123*/
@@ -138,7 +138,8 @@ long QTReader::real_delay()
138 138
139void QTReader::mousePressEvent( QMouseEvent* _e ) 139void QTReader::mousePressEvent( QMouseEvent* _e )
140{ 140{
141 buffdoc.unsuspend(); 141 m_drageligible = false;
142 qDebug("Mouse pressed at (%u, %u)", _e->x(), _e->y());
142 int x, y, ht, wh; 143 int x, y, ht, wh;
143 if (m_rotated) 144 if (m_rotated)
144 { 145 {
@@ -154,27 +155,171 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
154 ht = height(); 155 ht = height();
155 wh = width(); 156 wh = width();
156 } 157 }
157 if (_e->button() == RightButton) 158 if (x >= m_left_border && x <= wh - m_right_border && y >= m_topmargin && y <= ht-m_bottommargin)
158 { 159 {
159 //qDebug("MousePress"); 160 if (_e->button() == RightButton)
160 mouseUpOn = false;
161 if (m_swapmouse)
162 { 161 {
163 int lineno = 0; 162 //qDebug("MousePress");
164 /* 163 mouseUpOn = false;
164 if (m_swapmouse)
165 {
166 int lineno = 0;
167 /*
165 int hgt = textarray[0]->lineSpacing(); 168 int hgt = textarray[0]->lineSpacing();
166 while ((hgt < y) && (lineno < numlines)) 169 while ((hgt < y) && (lineno < numlines))
167 { 170 {
168 hgt += textarray[++lineno]->lineSpacing(); 171 hgt += textarray[++lineno]->lineSpacing();
169 } 172 }
170 */ 173 */
171 size_t startpos, startoffset, tgt, tgtoffset, pictgt; 174 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt;
172 QImage* img; 175 QImage* img;
173 getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img); 176 getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt);
174 processmousewordevent(startpos, startoffset, _e, lineno); 177 processmousewordevent(startpos, startoffset, _e, lineno);
178 }
179 else
180 {
181 processmousepositionevent(_e);
182 }
183 }
184 }
185 else
186 {
187 int ln = -1;
188 int mp;
189 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
190 switch (m_scrollpos)
191 {
192 case 1:
193 {
194 if (m_rotated)
195 {
196 if (_e->x() < m_bottommargin)
197 {
198 ln = height();
199 mp = _e->y();
200 }
201 }
202 else
203 {
204 if (_e->y() > height()-m_bottommargin)
205 {
206 ln = width();
207 mp = _e->x();
208 }
209 }
210 }
211 break;
212 case 2:
213 {
214 if (m_rotated)
215 {
216 if (_e->y() > height() - m_right_border)
217 {
218 ln = width();
219 mp = width()-_e->x();
220 }
221 }
222 else
223 {
224 if (_e->x() > width() - m_right_border)
225 {
226 ln = height();
227 mp = _e->y();
228 }
229 }
230 }
231 break;
232 case 3:
233 {
234 if (m_rotated)
235 {
236 if (_e->y() < m_left_border)
237 {
238 ln = width();
239 mp = width()-_e->x();
240 }
241 }
242 else
243 {
244 if (_e->x() < m_left_border)
245 {
246 ln = height();
247 mp = _e->y();
248 }
249 }
250 }
251 break;
252 case 0:
253 default:
254 ln = -1;
255 break;
256 }
257 if (ln >= 0)
258 {
259 int dp = (sectionsize*mp+ln/2)/ln + buffdoc.startSection();
260 int winsize = locnarray[numlines]-locnarray[0];
261 int slidersize = 10*(sectionsize+ln/2)/ln;
262 if (slidersize > winsize)
263 {
264 int mid = (locnarray[0] + locnarray[numlines])/2;
265 slidersize /= 2;
266 if (dp < mid-slidersize)
267 {
268 dopageup();
269 }
270 else if (dp > mid+slidersize)
271 {
272 dopagedn();
273 }
274 //if (mid-slidersize < dp && dp < mid+slidersize)
275 else
276 {
277 m_drageligible = true;
278 }
279 }
280 else
281 {
282 if (dp < locnarray[0])
283 {
284 dopageup();
285 }
286 else if (dp > locnarray[numlines])
287 {
288 dopagedn();
289 }
290 //if (locnarray[0] < dp && dp < locnarray[numlines])
291 else
292 {
293 m_drageligible = true;
294 }
295 }
296 qDebug("Drag eligible:%s", (m_drageligible) ? "true" : "false");
297 }
298 else
299 {
300 if (m_scrollpos == 1)
301 {
302 if (x < m_left_border)
303 {
304 lineUp();
305 }
306 if (y > ht - m_bottommargin)
307 {
308 lineDown();
309 }
310 }
311 else if (m_scrollpos != 0)
312 {
313 if (y < m_topmargin)
314 {
315 lineUp();
316 }
317 if (y > ht - m_bottommargin)
318 {
319 lineDown();
320 }
321 }
175 } 322 }
176 else
177 processmousepositionevent(_e);
178 } 323 }
179} 324}
180 325
@@ -295,7 +440,7 @@ void QTReader::goForward()
295 } 440 }
296} 441}
297 442
298linkType 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) 443linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t& start, size_t& offset, size_t& tgt, size_t& tgtoffset, size_t& pictgt, QImage*& img, size_t& tabtgt)
299{ 444{
300 int ht; 445 int ht;
301 if (m_scrolldy == m_topmargin) 446 if (m_scrolldy == m_topmargin)
@@ -340,7 +485,7 @@ linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t
340 for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--); 485 for (i = t->length(); i > 0 && t->width(availht, i, true, w, m_left_border, m_right_border) > x; i--);
341 offset = i; 486 offset = i;
342 } 487 }
343 return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img); 488 return textarray[lineno]->getLinkType(offset, tgt, tgtoffset, pictgt, img, tabtgt);
344} 489}
345 490
346void QTReader::suspend() 491void QTReader::suspend()
@@ -354,6 +499,38 @@ void QTReader::suspend()
354 */ 499 */
355} 500}
356 501
502void QTReader::setDoubleBuffer(bool _b)
503{
504 m_doubleBuffered = _b;
505 if (_b || m_rotated)
506 {
507 if (dbuff == NULL)
508 {
509 dbuff = new QPixmap();
510 dbp = new QPainter();
511 }
512 if (m_rotated)
513 {
514 dbuff->resize(height(), width());
515 }
516 else
517 {
518 dbuff->resize(width(), height());
519 }
520 m_outofdate = true;
521 }
522 else
523 {
524 if (dbuff != NULL)
525 {
526 delete dbuff;
527 delete dbp;
528 }
529 dbuff = NULL;
530 dbp = NULL;
531 }
532}
533
357void QTReader::setTwoTouch(bool _b) 534void QTReader::setTwoTouch(bool _b)
358{ 535{
359 setBackgroundColor( m_bg ); 536 setBackgroundColor( m_bg );
@@ -362,7 +539,6 @@ void QTReader::setTwoTouch(bool _b)
362 539
363void QTReader::setContinuous(bool _b) 540void QTReader::setContinuous(bool _b)
364{ 541{
365 buffdoc.unsuspend();
366 buffdoc.setContinuous(m_continuousDocument = _b); 542 buffdoc.setContinuous(m_continuousDocument = _b);
367} 543}
368 544
@@ -455,7 +631,7 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
455 } 631 }
456 if (!wrd.isEmpty()) 632 if (!wrd.isEmpty())
457 { 633 {
458 qDebug("Selecteed:%s", (const char*)wrd); 634 qDebug("Selected:%s", (const char*)wrd);
459 if (m_twotouch) 635 if (m_twotouch)
460 { 636 {
461 emit OnWordSelected(wrd, wrdstart, wrdend, wrd); 637 emit OnWordSelected(wrd, wrdstart, wrdend, wrd);
@@ -468,211 +644,347 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
468 } 644 }
469} 645}
470 646
471void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 647#ifdef USETIMER
648void QTReader::actionDrag()
472{ 649{
473 buffdoc.unsuspend(); 650 if (m_drageligible)
474 int x, y, ht, wh;
475 if (m_rotated)
476 { 651 {
477 x = _e->y(); 652 int fivepages = 5*((2*width()+m_textsize/2)/m_textsize)*((height()+m_textsize/2)/m_textsize);
478 y = width()-_e->x(); 653 if (m_dragtarget > fivepages && locnarray[numlines] < m_dragtarget - fivepages)
479 ht = width(); 654 {
480 wh = height(); 655 int tgt = m_dragtarget - fivepages/2;
656 //qDebug("Jumping to %u (%u)", tgt, fivepages);
657 if (tgt < buffdoc.startSection())
658 {
659 tgt = buffdoc.startSection();
660 }
661 locate(tgt);
662 drawFonts();
663 }
664 else if (locnarray[0] > m_dragtarget+fivepages)
665 {
666 int tgt = m_dragtarget + fivepages/2;
667 //qDebug("Jumping to %u (%u)", tgt, fivepages);
668 if (tgt > buffdoc.endSection())
669 {
670 dopageup();
671 }
672 else
673 {
674 locate(tgt);
675 drawFonts();
676 }
677 }
678 else if (locnarray[numlines] <= m_dragtarget)
679 {
680 dopagedn();
681 }
682 else if (locnarray[0] > m_dragtarget)
683 {
684 dopageup();
685 }
481 } 686 }
482 else 687 else
483 { 688 {
484 x = _e->x(); 689 m_dragtimer->stop();
485 y = _e->y();
486 ht = height();
487 wh = width();
488 } 690 }
489 if (_e->button() == LeftButton) 691}
692#endif
693
694void QTReader::mouseMoveEvent( QMouseEvent* _e )
695{
696 if (m_drageligible)
490 { 697 {
491 if (mouseUpOn) 698 int ht;
699 int mp;
700 int sectionsize = (buffdoc.endSection()-buffdoc.startSection());
701 //qDebug("Mouse moved to (%u, %u)", _e->x(), _e->y());
702 switch (m_scrollpos)
492 { 703 {
493 // qDebug("MouseRelease"); 704 case 1:
494 switch(m_scrollpos) 705 {
706 if (m_rotated)
707 {
708 ht = height();
709 mp = _e->y();
710 }
711 else
712 {
713 ht = width();
714 mp = _e->x();
715 }
716 }
717 break;
718 case 2:
719 case 3:
720 {
721 if (m_rotated)
722 {
723 ht = width();
724 mp = width()-_e->x();
725 }
726 else
727 {
728 ht = height();
729 mp = _e->y();
730 }
731 }
732 break;
733 case 0:
734 default:
735 ht = -1;
736 break;
737 }
738 if (ht >= 0)
739 {
740#ifdef USETIMER
741 m_dragtarget = (sectionsize*mp+ht/2)/ht + buffdoc.startSection();
742 if (!m_dragtimer->isActive())
495 { 743 {
496 case 1: // Bottom 744 m_dragtimer->start(0, false);
497 if (y > ht - 5)
498 {
499 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh);
500 return;
501 }
502 break;
503 case 2: // right
504 if (x > wh - m_right_border)
505 {
506 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
507 return;
508 }
509 break;
510 case 3: // left
511 if (x < m_left_border)
512 {
513 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
514 return;
515 }
516 break;
517 case 0:
518 default:
519 break;
520 } 745 }
521 if (textarray[0] != NULL) 746#else
747 int dp = (sectionsize*mp+ht/2)/ht + buffdoc.startSection();
748 locate(dp);
749#endif
750 }
751 }
752}
753
754void QTReader::mouseReleaseEvent( QMouseEvent* _e )
755{
756 qDebug("Mouse released at (%u, %u)", _e->x(), _e->y());
757 if (m_drageligible)
758 {
759 m_drageligible = false;
760 }
761 else
762 {
763 int x, y, ht, wh;
764 if (m_rotated)
765 {
766 x = _e->y();
767 y = width()-_e->x();
768 ht = width();
769 wh = height();
770 }
771 else
772 {
773 x = _e->x();
774 y = _e->y();
775 ht = height();
776 wh = width();
777 }
778 if (_e->button() == LeftButton)
779 {
780 if (mouseUpOn)
522 { 781 {
523 QString line; 782 // qDebug("MouseRelease");
524 // int lineno = _e->y()/m_linespacing; 783 /*
525 int lineno = 0; 784 switch(m_scrollpos)
526 /*
527 int ht = textarray[0]->lineSpacing();
528 while ((ht < y) && (lineno < numlines))
529 { 785 {
530 ht += textarray[++lineno]->lineSpacing(); 786 case 1: // Bottom
787 if (y > ht - 5)
788 {
789 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh);
790 return;
531 } 791 }
532 */ 792 break;
533 size_t startpos, startoffset, tgt, tgtoffset, pictgt; 793 case 2: // right
534 QImage* img; 794 if (x > wh - m_right_border)
535 if (m_currentlinkstyle != NULL) 795 {
536 { 796 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
537 textarray[m_currentlink]->invertLink(m_currentlinkoffset); 797 return;
538 m_currentlinkstyle = NULL; 798 }
539 m_currentlink = -1; 799 break;
540 m_currentlinkoffset = -1; 800 case 3: // left
541 } 801 if (x < m_left_border)
542 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img); 802 {
543 if ((glt & eLink) != 0) 803 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*y+ht/2)/ht);
544 { 804 return;
545 if ((glt & ePicture) != 0) 805 }
546 { 806 break;
547 qDebug("Big Picture:%x", pictgt); 807 case 0:
548 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) 808 default:
549 { 809 break;
550 QImage* pm = buffdoc.getPicture(pictgt); 810 }
551 if (pm != NULL) 811 */
552 { 812 if (textarray[0] != NULL)
553 emit OnShowPicture(*pm); 813 {
554 delete pm; 814 QString line;
555 return; 815 // int lineno = _e->y()/m_linespacing;
556 } 816 int lineno = 0;
557 } 817 /*
558 } 818 int ht = textarray[0]->lineSpacing();
559 else if (img != NULL) 819 while ((ht < y) && (lineno < numlines))
560 { 820 {
561 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) 821 ht += textarray[++lineno]->lineSpacing();
562 { 822 }
563 emit OnShowPicture(*img); 823 */
564 return; 824 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt;
565 } 825 QImage* img;
566 } 826 if (m_currentlinkstyle != NULL)
567 size_t saveposn = pagelocate(); 827 {
568 QString href, nm; 828 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
569 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm); 829 m_currentlinkstyle = NULL;
570 qDebug("URL(1):%s", (const char*)href); 830 m_currentlink = -1;
571 if ((lt & eFile) != 0) 831 m_currentlinkoffset = -1;
572 { 832 }
573 buffdoc.saveposn(m_lastfile, saveposn); 833 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img, tabtgt);
834 if (bNoInlineTables && ((glt & eTable) != 0))
835 {
836 size_t currentpos = locate();
837 QString tabtext = buffdoc.getTableAsHtml(tabtgt);
838 qDebug("TABLE:%u:%u:%s", currentpos, tabtgt, (const char*)tabtext);
839 QFont f(m_fontname, m_fontControl.currentsize());
574#ifdef USEQPE 840#ifdef USEQPE
841 CTableDialog td(f, tabtext, true, this);
842#else
843 CTableDialog td(f, tabtext, false, this);
844#endif
845 td.exec();
846 jumpto(currentpos);
847 }
848 if ((glt & eLink) != 0)
849 {
850 if ((glt & ePicture) != 0)
575 { 851 {
576 QCopEnvelope e("QPE/System", "busy()"); 852 qDebug("Big Picture:%x", pictgt);
853 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
854 {
855 QImage* pm = buffdoc.getPicture(pictgt);
856 if (pm != NULL)
857 {
858 emit OnShowPicture(*pm);
859 delete pm;
860 return;
861 }
862 }
577 } 863 }
578#endif 864 else if (img != NULL)
579 ResetScroll();
580 if (!href.isEmpty())
581 {
582 if (!buffdoc.getFile(href))
583 {
584 emit NewFileRequest(href);
585 }
586 else
587 {
588 ResetScroll();
589 fillbuffer();
590 update();
591 }
592 }
593 if (!nm.isEmpty())
594 {
595 qDebug("QTReader:Finding %s", (const char*)nm);
596 if (buffdoc.findanchor(nm))
597 {
598 fillbuffer();
599 update();
600 }
601 }
602 //fillbuffer();
603 //update();
604#ifdef USEQPE
605 { 865 {
606 QCopEnvelope e("QPE/System", "notBusy()"); 866 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
867 {
868 emit OnShowPicture(*img);
869 return;
870 }
607 } 871 }
608#endif 872 size_t saveposn = pagelocate();
609 } 873 QString href, nm;
610 else if ((lt & eLink) != 0) 874 linkType lt = buffdoc.hyperlink(tgt, tgtoffset, href, nm);
611 { 875 qDebug("URL(1):%s", (const char*)href);
612 buffdoc.saveposn(m_lastfile, saveposn); 876 if ((lt & eFile) != 0)
613 ResetScroll(); 877 {
614 fillbuffer(); 878 buffdoc.saveposn(m_lastfile, saveposn);
615 update(); 879#ifdef USEQPE
616 }
617 else
618 {
619 if ((lt & ePicture) != 0)
620 { 880 {
621 QImage* pm = buffdoc.getPicture(tgt); 881 QCopEnvelope e("QPE/System", "busy()");
622 if (pm != NULL)
623 {
624 emit OnShowPicture(*pm);
625 delete pm;
626 }
627 } 882 }
628 else 883#endif
884 ResetScroll();
885 if (!href.isEmpty())
886 {
887 if (!buffdoc.getFile(href, nm))
888 {
889 emit NewFileRequest(href);
890 }
891 else
892 {
893 qDebug("BEFORE:%u", pagelocate());
894 buffdoc.resetPos();
895 ResetScroll();
896 fillbuffer();
897 qDebug("AFTER:%u", pagelocate());
898 m_outofdate = true;
899 update();
900 }
901 }
902 if (!nm.isEmpty())
903 {
904 qDebug("QTReader:Finding %s", (const char*)nm);
905 if (buffdoc.findanchor(nm))
906 {
907 buffdoc.resetPos();
908 fillbuffer();
909 m_outofdate = true;
910 update();
911 }
912 }
913 //fillbuffer();
914 //update();
915#ifdef USEQPE
629 { 916 {
630 // QString anchortext = textarray[lineno]->getanchortext(startoffset); 917 QCopEnvelope e("QPE/System", "notBusy()");
631 if (!href.isEmpty())
632 {
633 emit OnURLSelected(href, tgt);
634 }
635 } 918 }
636 locate(pagelocate()); 919#endif
637 } 920 }
638 return; 921 else if ((lt & eLink) != 0)
639 } 922 {
640 else if ((glt & ePicture) != 0) 923 buffdoc.saveposn(m_lastfile, saveposn);
641 { 924 ResetScroll();
642 qDebug("Big Picture:%x", pictgt); 925 fillbuffer();
643 QImage* pm = buffdoc.getPicture(pictgt); 926 m_outofdate = true;
644 if (pm != NULL) 927 update();
645 { 928 }
646 emit OnShowPicture(*pm); 929 else
647 delete pm; 930 {
648 } 931 if ((lt & ePicture) != 0)
649 else 932 {
650 { 933 QImage* pm = buffdoc.getPicture(tgt);
651 locate(pagelocate()); 934 if (pm != NULL)
652 } 935 {
653 return; 936 emit OnShowPicture(*pm);
654 } 937 delete pm;
655 else if (img != NULL) 938 }
656 { 939 }
657 emit OnShowPicture(*img); 940 else
658 return; 941 {
659 } 942 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
660 if (m_swapmouse) 943 if (!href.isEmpty())
944 {
945 emit OnURLSelected(href, tgt);
946 }
947 }
948 }
949 return;
950 }
951 else if ((glt & ePicture) != 0)
952 {
953 qDebug("Big Picture:%x", pictgt);
954 QImage* pm = buffdoc.getPicture(pictgt);
955 if (pm != NULL)
956 {
957 emit OnShowPicture(*pm);
958 delete pm;
959 }
960 else
961 {
962 update();
963 }
964 return;
965 }
966 else if (img != NULL)
967 {
968 emit OnShowPicture(*img);
969 return;
970 }
971 if (m_swapmouse)
661 processmousepositionevent(_e); 972 processmousepositionevent(_e);
662 else 973 else
663 processmousewordevent(startpos, startoffset, _e, lineno); 974 processmousewordevent(startpos, startoffset, _e, lineno);
975 }
976 }
977 else
978 {
979 mouseUpOn = true;
664 } 980 }
665 }
666 else
667 {
668 mouseUpOn = true;
669 } 981 }
670 } 982 }
671} 983}
672 984
673void QTReader::focusInEvent(QFocusEvent* e) 985void QTReader::focusInEvent(QFocusEvent* e)
674{ 986{
675 if (m_autoScroll) timer->start(real_delay(), false); 987 if (m_autoScroll && (m_scrolltype != 4)) timer->start(real_delay(), false);
676 update(); 988 update();
677} 989}
678 990
@@ -680,7 +992,14 @@ void QTReader::focusOutEvent(QFocusEvent* e)
680{ 992{
681 if (m_autoScroll) 993 if (m_autoScroll)
682 { 994 {
683 timer->stop(); 995 if (m_scrolltype != 4)
996 {
997 timer->stop();
998 }
999 else
1000 {
1001 m_autoScroll = false;
1002 }
684 //m_scrolldy1 = m_scrolldy2 = 0; 1003 //m_scrolldy1 = m_scrolldy2 = 0;
685 } 1004 }
686} 1005}
@@ -717,7 +1036,6 @@ void QTReader::goUp()
717 1036
718void QTReader::NavUp() 1037void QTReader::NavUp()
719{ 1038{
720 buffdoc.unsuspend();
721 if (buffdoc.hasnavigation()) 1039 if (buffdoc.hasnavigation())
722 { 1040 {
723/* 1041/*
@@ -737,7 +1055,6 @@ void QTReader::NavUp()
737 1055
738void QTReader::NavDown() 1056void QTReader::NavDown()
739{ 1057{
740 buffdoc.unsuspend();
741 if (buffdoc.hasnavigation()) 1058 if (buffdoc.hasnavigation())
742 { 1059 {
743/* 1060/*
@@ -762,8 +1079,7 @@ void QTReader::zoomin()
762 bool sc = m_autoScroll; 1079 bool sc = m_autoScroll;
763 setautoscroll(false); 1080 setautoscroll(false);
764 setfont(); 1081 setfont();
765 locate(pagelocate()); 1082 refresh();
766 repaint();
767 setautoscroll(sc); 1083 setautoscroll(sc);
768 } 1084 }
769} 1085}
@@ -775,8 +1091,7 @@ void QTReader::zoomout()
775 bool sc = m_autoScroll; 1091 bool sc = m_autoScroll;
776 setautoscroll(false); 1092 setautoscroll(false);
777 setfont(); 1093 setfont();
778 locate(pagelocate()); 1094 refresh();
779 repaint();
780 setautoscroll(sc); 1095 setautoscroll(sc);
781 } 1096 }
782} 1097}
@@ -809,8 +1124,7 @@ void QTReader::increaseScroll()
809 1124
810void QTReader::keyPressEvent(QKeyEvent* e) 1125void QTReader::keyPressEvent(QKeyEvent* e)
811{ 1126{
812 buffdoc.unsuspend(); 1127
813
814 //((QTReaderApp*)parent()->parent())->handlekey(e); 1128 //((QTReaderApp*)parent()->parent())->handlekey(e);
815 emit HandleKeyRequest(e); 1129 emit HandleKeyRequest(e);
816// e->ignore(); 1130// e->ignore();
@@ -906,6 +1220,7 @@ void QTReader::CalculateScrollParameters()
906 1220
907void QTReader::setautoscroll(bool _sc) 1221void QTReader::setautoscroll(bool _sc)
908{ 1222{
1223 m_outofdate = true;
909 if (_sc == m_autoScroll) return; 1224 if (_sc == m_autoScroll) return;
910 if (m_autoScroll) 1225 if (m_autoScroll)
911 { 1226 {
@@ -927,6 +1242,9 @@ void QTReader::setautoscroll(bool _sc)
927 { 1242 {
928 CDrawBuffer* reusebuffer = textarray[numlines]; 1243 CDrawBuffer* reusebuffer = textarray[numlines];
929 if (reusebuffer == NULL || reusebuffer->eof()) return; 1244 if (reusebuffer == NULL || reusebuffer->eof()) return;
1245#ifndef __STATIC
1246 if ((m_scrolltype == 4) && !checkoutput()) return;
1247#endif
930 m_autoScroll = true; 1248 m_autoScroll = true;
931 CalculateScrollParameters(); 1249 CalculateScrollParameters();
932 1250
@@ -947,7 +1265,6 @@ void QTReader::setautoscroll(bool _sc)
947 1265
948bool QTReader::getline(CDrawBuffer *buff) 1266bool QTReader::getline(CDrawBuffer *buff)
949{ 1267{
950 buffdoc.unsuspend();
951 bool bRet; 1268 bool bRet;
952 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin; 1269 int availht = ((m_rotated) ? width() : height()) - m_topmargin - m_bottommargin;
953 if (m_bMonoSpaced) 1270 if (m_bMonoSpaced)
@@ -1065,24 +1382,6 @@ void QTReader::doinplacescroll()
1065 mylastpos = locate(); 1382 mylastpos = locate();
1066 if (!ch) 1383 if (!ch)
1067 { 1384 {
1068 /*
1069 if (m_rotated)
1070 {
1071 blitRot2(0,0,height(),width()-m_scrolldy,NULL);
1072 // blitRot2(0,0,0,height(),width()-m_scrolldy,NULL);
1073 }
1074 else
1075 {
1076 if (m_bgpm.isNull())
1077 {
1078 p.fillRect(0,m_scrolldy,width(),height()-m_scrolldy,m_bg);
1079 }
1080 else
1081 {
1082 bitBlt(this, 0, m_scrolldy, dbuff, 0, m_scrolldy, width(), height()-m_scrolldy);
1083 }
1084 }
1085 */
1086 m_scrolldy = m_topmargin; 1385 m_scrolldy = m_topmargin;
1087 m_autoScroll = false; 1386 m_autoScroll = false;
1088#ifdef _SCROLLPIPE 1387#ifdef _SCROLLPIPE
@@ -1099,7 +1398,6 @@ void QTReader::doinplacescroll()
1099 } 1398 }
1100 } 1399 }
1101#endif 1400#endif
1102 //((QTReaderApp*)parent()->parent())->setScrollState(m_autoScroll);
1103 emit SetScrollState(m_autoScroll); 1401 emit SetScrollState(m_autoScroll);
1104#ifdef USEQPE 1402#ifdef USEQPE
1105 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1403 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
@@ -1494,9 +1792,20 @@ void QTReader::redrawScroll(QPainter* p)
1494 1792
1495void QTReader::autoscroll() 1793void QTReader::autoscroll()
1496{ 1794{
1497 drawBackground(); 1795 if (m_scrolltype == 4)
1498 dbp->end(); 1796 {
1499 timer->start(real_delay(), false); 1797 readAloud();
1798 }
1799 else
1800 {
1801 if (dbuff != NULL)
1802 {
1803 dbp->begin(dbuff);
1804 drawBackground(dbp);
1805 dbp->end();
1806 }
1807 timer->start(real_delay(), false);
1808 }
1500} 1809}
1501 1810
1502void QTReader::setfont() 1811void QTReader::setfont()
@@ -1557,39 +1866,49 @@ void QTReader::redrawall()
1557{ 1866{
1558 if (m_rotated) 1867 if (m_rotated)
1559 { 1868 {
1560#ifdef DOUBLEBUFFER 1869 if (dbuff != NULL)
1561 drawBackground(); 1870 {
1562 DrawStraight(dbp, height(), width()); 1871 dbp->begin(dbuff);
1563 dbp->end(); 1872 drawBackground(dbp);
1564 1873 DrawStraight(dbp, height(), width());
1565 QWMatrix m; 1874 dbp->end();
1566 m.rotate(90); 1875
1567 QPixmap rp = dbuff->xForm(m); 1876 QWMatrix m;
1568 bitBlt(this, 0,0,&rp,0,0,-1,-1); 1877 m.rotate(90);
1569#else 1878 QPixmap rp = dbuff->xForm(m);
1570 QPixmap dbuff(height(), width()); 1879 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1571 QPainter dbp(&dbuff); 1880 }
1572 // dbp.setBackgroundMode(OpaqueMode); 1881 else
1573 dbp.fillRect(dbuff.rect(), m_bg); 1882 {
1574 1883 qDebug("This shouldn't happen but it doesn't matter if it does (rotated == double buffered)");
1575 DrawStraight(&dbp, height(), width()); 1884 QPixmap dbuff(height(), width());
1576 1885 QPainter dbp(&dbuff);
1577 QWMatrix m; 1886
1578 m.rotate(90); 1887 drawBackground(&dbp);
1579 QPixmap rp = dbuff.xForm(m); 1888 DrawStraight(&dbp, height(), width());
1580 bitBlt(this, 0,0,&rp,0,0,-1,-1); 1889
1581#endif 1890 QWMatrix m;
1891 m.rotate(90);
1892 QPixmap rp = dbuff.xForm(m);
1893 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1894 }
1582 } 1895 }
1583 else 1896 else
1584 { 1897 {
1585#ifdef DOUBLEBUFFER 1898 if (dbuff != NULL)
1586 drawBackground(); 1899 {
1587 DrawStraight(dbp, width(), height()); 1900 dbp->begin(dbuff);
1588 dbp->end(); 1901 drawBackground(dbp);
1589 bitBlt(this, 0,0,dbuff,0,0,-1,-1); 1902 DrawStraight(dbp, width(), height());
1590#else 1903 dbp->end();
1591 DrawStraight(p, width(), height()); 1904 bitBlt(this, 0,0,dbuff,0,0,-1,-1);
1592#endif 1905 }
1906 else
1907 {
1908 QPainter p(this);
1909 drawBackground(&p);
1910 DrawStraight(&p, width(), height());
1911 }
1593 } 1912 }
1594} 1913}
1595 1914
@@ -1600,10 +1919,36 @@ void QTReader::drawFonts()
1600 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 1919 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
1601 if (hmargin < m_bottommargin) hmargin = m_bottommargin; 1920 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
1602 //qDebug("How refreshing..."); 1921 //qDebug("How refreshing...");
1603 if (buffdoc.empty()) return; 1922 if (buffdoc.empty())
1923 {
1924 if (dbuff != NULL)
1925 {
1926 dbp->begin(dbuff);
1927 drawBackground(dbp);
1928 dbp->end();
1929 }
1930 else
1931 {
1932 QPainter p(this);
1933 drawBackground(&p);
1934 }
1935 return;
1936 }
1604 setfont(); 1937 setfont();
1605 //if (!m_autoScroll) m_scrolldy1 = 0; 1938 //if (!m_autoScroll) m_scrolldy1 = 0;
1606#ifdef ROTATION_ENABLED 1939 if (dbuff != NULL && (dbuff->width() != width() || dbuff->height() != height()))
1940 {
1941 qDebug("Oh no! A resize event was missed...");
1942 if (m_rotated)
1943 {
1944 dbuff->resize(height(), width());
1945 }
1946 else
1947 {
1948 dbuff->resize(width(), height());
1949 }
1950 m_lastwidth = 0;
1951 }
1607 if (m_lastwidth != ((m_rotated) ? height() : width())) 1952 if (m_lastwidth != ((m_rotated) ? height() : width()))
1608 { 1953 {
1609 m_scrolldy = m_topmargin; 1954 m_scrolldy = m_topmargin;
@@ -1611,7 +1956,9 @@ void QTReader::drawFonts()
1611 m_lastwidth = ((m_rotated) ? height() : width()); 1956 m_lastwidth = ((m_rotated) ? height() : width());
1612 m_lastheight = ((m_rotated) ? width() : height()); 1957 m_lastheight = ((m_rotated) ? width() : height());
1613 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); 1958 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1614 locate(pagelocate()); 1959 buffdoc.locate(pagelocate());
1960 fillbuffer();
1961 redrawall();
1615 // qDebug("Not Optimised %d", m_lastwidth); 1962 // qDebug("Not Optimised %d", m_lastwidth);
1616 } 1963 }
1617 else 1964 else
@@ -1651,63 +1998,6 @@ void QTReader::drawFonts()
1651 redrawall(); 1998 redrawall();
1652 } 1999 }
1653 } 2000 }
1654#else
1655 if (m_lastwidth != width())
1656 {
1657 // qDebug("Not Optimised %d", m_lastwidth);
1658 m_lastwidth = width();
1659 m_lastheight = height();
1660 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1661 locate(pagelocate());
1662 // qDebug("Not Optimised %d", m_lastwidth);
1663 }
1664 else
1665 {
1666 int newht = height();
1667 if (m_lastheight > newht)
1668 {
1669 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
1670 int ypos = m_topmargin;
1671 for (int i = 0; i < numlines; i++)
1672 {
1673 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
1674 {
1675 numlines = i;
1676 jumpto(mylastpos = locnarray[i+1]);
1677 break;
1678 }
1679 }
1680 // qDebug("Optimised < %d", numlines);
1681 m_lastheight = newht;
1682 }
1683 else if (m_lastheight < newht)
1684 {
1685 // qDebug("Optimised > %d", numlines);
1686 int ypos = m_topmargin;
1687 for (int i = 0; i <= numlines; i++)
1688 {
1689 ypos += textarray[i]->lineSpacing();
1690 }
1691 fillbuffer(numlines+1, ypos, newht);
1692 // qDebug("Optimised > %d", numlines);
1693 }
1694 if (numlines > 0)
1695 {
1696 int ypos = textarray[0]->ascent()+m_topmargin;
1697 textarray[0]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1698 // int last = (m_showlast) ? numlines : numlines-1;
1699 // for (int i = 1; i <= last; i++)
1700 for (int i = 1; i < numlines; i++)
1701 {
1702 // ypos += (textarray[i-1]->lineSpacing() + textarray[i]->lineSpacing())/2;
1703 ypos += (textarray[i-1]->descent() + textarray[i]->ascent())+
1704 (textarray[i-1]->lineExtraSpacing() + textarray[i]->lineExtraSpacing())/2;
1705 textarray[i]->render( p, ypos, m_bMonoSpaced, m_charWidth, width(), m_left_border, m_right_border, m_bg, height()-m_topmargin-m_bottommargin);
1706 }
1707// mylastpos = locate();
1708 }
1709 }
1710#endif
1711 emitRedraw(); 2001 emitRedraw();
1712 } 2002 }
1713/* 2003/*
@@ -1928,13 +2218,16 @@ bool QTReader::ChangeFont(int tgt)
1928 2218
1929void QTReader::init() 2219void QTReader::init()
1930{ 2220{
1931 buffdoc.unsuspend();
1932 setBackgroundColor( m_bg ); 2221 setBackgroundColor( m_bg );
1933 buffdoc.setfilter(getfilter()); 2222 buffdoc.setfilter(getfilter());
1934 ChangeFont(m_textsize); 2223 ChangeFont(m_textsize);
1935 setFocusPolicy(QWidget::StrongFocus); 2224 setFocusPolicy(QWidget::StrongFocus);
1936 timer = new QTimer(this); 2225 timer = new QTimer(this);
1937 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll())); 2226 connect(timer, SIGNAL(timeout()), this, SLOT(doscroll()));
2227#ifdef USETIMER
2228 m_dragtimer = new QTimer(this);
2229 connect(m_dragtimer, SIGNAL(timeout()), this, SLOT(actionDrag()));
2230#endif
1938 // QMessageBox::information(this, "init", m_lastfile, 1); 2231 // QMessageBox::information(this, "init", m_lastfile, 1);
1939 setfont(); 2232 setfont();
1940} 2233}
@@ -1944,10 +2237,15 @@ void QTReader::init()
1944// 2237//
1945QTReader::~QTReader() 2238QTReader::~QTReader()
1946{ 2239{
1947#ifdef DOUBLEBUFFER 2240 if (m_output != NULL)
1948 delete dbuff; 2241 {
1949 delete dbp; 2242 delete m_output;
1950#endif 2243 }
2244 if (dbuff != NULL)
2245 {
2246 delete dbuff;
2247 delete dbp;
2248 }
1951#ifdef USEQPE 2249#ifdef USEQPE
1952 if (m_autoScroll) 2250 if (m_autoScroll)
1953 { 2251 {
@@ -1982,9 +2280,47 @@ void QTReader::printIt()
1982// Called when the widget needs to be updated. 2280// Called when the widget needs to be updated.
1983// 2281//
1984 2282
1985void QTReader::paintEvent( QPaintEvent * ) 2283void QTReader::paintEvent( QPaintEvent * p )
1986{ 2284{
1987 drawFonts(); 2285 if ((dbuff != NULL) && !m_outofdate)
2286 {
2287 if (m_rotated)
2288 {
2289 if ((p->rect().width() != width()) || (p->rect().height() != height()))
2290 {
2291 qDebug("Partial paint");
2292 QRect r;
2293 r.setTop(width()-p->rect().right()-1);
2294 r.setLeft(p->rect().top());
2295 r.setHeight(p->rect().width());
2296 r.setWidth(p->rect().height());
2297 QPixmap p1(r.width(), r.height());
2298 bitBlt(&p1, QPoint(0, 0), dbuff, r);
2299 QWMatrix m;
2300 m.rotate(90);
2301 QPixmap p2 = p1.xForm(m);
2302 bitBlt(this, p->rect().left(), p->rect().top(), &p2, 0, 0, -1, -1);
2303 }
2304 else
2305 {
2306 qDebug("Full paint");
2307 QWMatrix m;
2308 m.rotate(90);
2309 QPixmap rp = dbuff->xForm(m);
2310 bitBlt(this, 0,0,&rp,0,0,-1,-1);
2311 }
2312 }
2313 else
2314 {
2315 //bitBlt(this, 0,0,dbuff,0,0,-1,-1);
2316 bitBlt(this,p->rect().topLeft(),dbuff,p->rect());
2317 }
2318 }
2319 else
2320 {
2321 drawFonts();
2322 }
2323 m_outofdate = false;
1988} 2324}
1989 2325
1990// 2326//
@@ -2016,20 +2352,30 @@ int main( int argc, tchar **argv )
2016*/ 2352*/
2017 2353
2018 2354
2355bool QTReader::locate(unsigned long n)
2356{
2357 m_outofdate = true;
2358 m_lastwidth = 0;
2359 locnarray[0] = n;
2360 ResetScroll();
2361 update();
2362 return true;
2363}
2364/*
2019bool QTReader::locate(unsigned long n) { 2365bool QTReader::locate(unsigned long n) {
2020 //printf("Locate\n"); 2366 //printf("Locate\n");
2021 buffdoc.unsuspend();
2022 buffdoc.locate(n); 2367 buffdoc.locate(n);
2023// // qDebug("&buffdoc.located"); 2368// // qDebug("&buffdoc.located");
2024 ResetScroll(); 2369 ResetScroll();
2025 fillbuffer(); 2370 fillbuffer();
2371 m_outofdate = true;
2026// // qDebug("&Buffer filled"); 2372// // qDebug("&Buffer filled");
2027 update(); 2373 update();
2028// // qDebug("&Located"); 2374// // qDebug("&Located");
2029 emitRedraw(); 2375 emitRedraw();
2030 return true; 2376 return true;
2031} 2377}
2032 2378*/
2033unsigned int QTReader::screenlines() 2379unsigned int QTReader::screenlines()
2034{ 2380{
2035 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent; 2381 // int linespacing = (tight) ? m_ascent : m_ascent+m_descent;
@@ -2039,7 +2385,6 @@ unsigned int QTReader::screenlines()
2039 2385
2040bool QTReader::fillbuffer(int reuse, int ht, int newht) 2386bool QTReader::fillbuffer(int reuse, int ht, int newht)
2041{ 2387{
2042 buffdoc.unsuspend();
2043 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0); 2388 int hmargin = ((m_scrollpos == 1) ? _SBARHEIGHT : 0);
2044 if (hmargin < m_bottommargin) hmargin = m_bottommargin; 2389 if (hmargin < m_bottommargin) hmargin = m_bottommargin;
2045 if (ht < 0) ht = m_topmargin; 2390 if (ht < 0) ht = m_topmargin;
@@ -2063,14 +2408,23 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
2063 locnarray[numlines] = locate(); 2408 locnarray[numlines] = locate();
2064 int ch = getline(textarray[numlines]); 2409 int ch = getline(textarray[numlines]);
2065 ypos += textarray[numlines]->lineSpacing(); 2410 ypos += textarray[numlines]->lineSpacing();
2411 /*
2412 QString tmp = toQString(textarray[numlines]->data());
2413 printf("[%u, %u, %u](%s):%s\n", lastypos, m_lastheight-hmargin, ypos,
2414 ((textarray[numlines]->showPartial()) ? "TRUE" : "FALSE"),
2415 (const char*)tmp);
2416 */
2066 numlines++; 2417 numlines++;
2067 if (!ch) 2418 if (!ch)
2068 { 2419 {
2069 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/) 2420 if (numlines - reuse == 1 /*&& locnarray[numlines] == buffdoc.locate()*/)
2070 { 2421 {
2071 qDebug("FALSE"); 2422 qDebug("FALSE");
2423 if (oldpagepos < buffdoc.endSection())
2072 locate(oldpagepos); 2424 locate(oldpagepos);
2073 return false; 2425 else
2426 dopageup(buffdoc.endSection());
2427 return false;
2074 } 2428 }
2075 else 2429 else
2076 { 2430 {
@@ -2101,7 +2455,6 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
2101void QTReader::dopagedn() 2455void QTReader::dopagedn()
2102{ 2456{
2103// qDebug("HEIGHT(2):%d", m_lastheight); 2457// qDebug("HEIGHT(2):%d", m_lastheight);
2104 buffdoc.unsuspend();
2105 ResetScroll(); 2458 ResetScroll();
2106 int skip = 0, ypos = m_topmargin; 2459 int skip = 0, ypos = m_topmargin;
2107 if (locate() != mylastpos) 2460 if (locate() != mylastpos)
@@ -2150,20 +2503,21 @@ bool QTReader::synch(size_t start, size_t end)
2150 { 2503 {
2151 tchar ch = getch(); 2504 tchar ch = getch();
2152 if (ch == 10) return true; 2505 if (ch == 10) return true;
2153 if (ch == UEOF) return false; 2506 if ((ch == UEOF) || (ch == 6))
2154 if (ch == 6) return false; 2507 {
2508 return false;
2509 }
2155 } 2510 }
2156 return false; 2511 return false;
2157} 2512}
2158 2513
2159void QTReader::dopageup(unsigned int target) 2514void QTReader::dopageup(unsigned int target)
2160{ 2515{
2161 buffdoc.unsuspend();
2162 ResetScroll(); 2516 ResetScroll();
2163 CBufferFace<CDrawBuffer*> buff; 2517 CBufferFace<CDrawBuffer*> buff;
2164 CBufferFace<size_t> loc; 2518 CBufferFace<size_t> loc;
2165
2166 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0; 2519 size_t delta, guess = 2*(locate()-pagelocate()), lastdelta = 0;
2520 qDebug("dopageup:: locate():%u pagelocate():%u guess:%u", locate(), pagelocate(), guess);
2167 bool ch = true; 2521 bool ch = true;
2168 int nbfl, ypos = m_topmargin; 2522 int nbfl, ypos = m_topmargin;
2169 if (guess < 128) guess = 128; 2523 if (guess < 128) guess = 128;
@@ -2180,6 +2534,7 @@ void QTReader::dopageup(unsigned int target)
2180 else if (!m_continuousDocument && (target - guess < buffdoc.startSection())) 2534 else if (!m_continuousDocument && (target - guess < buffdoc.startSection()))
2181 { 2535 {
2182 delta = 0; // 0 is a flag to say don't guess any more 2536 delta = 0; // 0 is a flag to say don't guess any more
2537 qDebug("Jumping to startsection:%d", buffdoc.startSection());
2183 jumpto(buffdoc.startSection()); 2538 jumpto(buffdoc.startSection());
2184 } 2539 }
2185 else 2540 else
@@ -2187,15 +2542,15 @@ void QTReader::dopageup(unsigned int target)
2187 delta = guess; 2542 delta = guess;
2188 if (!synch(target-delta, target-lastdelta)) 2543 if (!synch(target-delta, target-lastdelta))
2189 { 2544 {
2190 lastdelta = delta; 2545 lastdelta = delta;
2191 if (guess < 4000) 2546 if (guess < 4000)
2192 { 2547 {
2193 guess <<= 1; 2548 guess <<= 1;
2194 continue; 2549 continue;
2195 } 2550 }
2196 else 2551 else
2197 { 2552 {
2198 jumpto(target-delta); 2553 jumpto(target-delta);
2199 } 2554 }
2200 } 2555 }
2201 } 2556 }
@@ -2293,8 +2648,9 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
2293 int prog = 0; 2648 int prog = 0;
2294 bool bRC = false; 2649 bool bRC = false;
2295 unsigned int lcn = _lcn; 2650 unsigned int lcn = _lcn;
2651 bDoUpdates = false;
2296 ResetScroll(); 2652 ResetScroll();
2297 if (m_lastfile == newfile) 2653 if (m_lastfile == newfile && lcn == 0)
2298 { 2654 {
2299 lcn = m_lastposn; 2655 lcn = m_lastposn;
2300 } 2656 }
@@ -2316,11 +2672,11 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
2316 bRC = true; 2672 bRC = true;
2317 buffdoc.setContinuous(m_continuousDocument); 2673 buffdoc.setContinuous(m_continuousDocument);
2318 qDebug("buffdoc.openfile done"); 2674 qDebug("buffdoc.openfile done");
2319 locate(lcn);
2320 qDebug("buffdoc.locate done");
2321 } 2675 }
2322 setfilter(getfilter()); 2676 setfilter(getfilter());
2323 qDebug("Updated"); 2677 qDebug("Updated");
2678 bDoUpdates = true;
2679 locate(lcn);
2324 return bRC; 2680 return bRC;
2325} 2681}
2326 2682
@@ -2358,6 +2714,7 @@ void QTReader::lineDown()
2358 } 2714 }
2359 getline(textarray[numlines]); 2715 getline(textarray[numlines]);
2360 mylastpos = locate(); 2716 mylastpos = locate();
2717 m_outofdate = true;
2361 update(); 2718 update();
2362} 2719}
2363/* 2720/*
@@ -2572,16 +2929,21 @@ MarkupType QTReader::PreferredMarkup()
2572 } 2929 }
2573 return m; 2930 return m;
2574} 2931}
2575#ifdef DOUBLEBUFFER 2932
2576void QTReader::resizeEvent( QResizeEvent * p ) 2933void QTReader::resizeEvent( QResizeEvent * p )
2577{ 2934{
2578 if (m_rotated) 2935 qDebug("Resizing");
2579 { 2936 m_outofdate = true;
2580 dbuff->resize(p->size().height(),p->size().width()); 2937 if (dbuff != NULL)
2581 }
2582 else
2583 { 2938 {
2584 dbuff->resize(p->size()); 2939 if (m_rotated)
2940 {
2941 dbuff->resize(p->size().height(),p->size().width());
2942 }
2943 else
2944 {
2945 dbuff->resize(p->size());
2946 }
2585 } 2947 }
2586 m_bgIsScaled = false; 2948 m_bgIsScaled = false;
2587 if (m_bgtype == bgStretched) 2949 if (m_bgtype == bgStretched)
@@ -2605,29 +2967,23 @@ void QTReader::resizeEvent( QResizeEvent * p )
2605 m_bottommargin = (h*m_absbottommargin+500)/1000; 2967 m_bottommargin = (h*m_absbottommargin+500)/1000;
2606 m_left_border = (w*m_absleft_border+500)/1000; 2968 m_left_border = (w*m_absleft_border+500)/1000;
2607 m_right_border = (w*m_absright_border+500)/1000; 2969 m_right_border = (w*m_absright_border+500)/1000;
2608
2609 qDebug("Top margin:%u", m_topmargin );
2610 qDebug("Bottom margin:%u", m_bottommargin );
2611 qDebug("Left margin:%u", m_left_border );
2612 qDebug("Right margin:%u", m_right_border );
2613 } 2970 }
2971 if (dbuff != NULL && buffdoc.empty())
2972 {
2973 dbp->begin(dbuff);
2974 drawBackground(dbp);
2975 dbp->end();
2976 }
2614} 2977}
2615#endif
2616 2978
2617void QTReader::setrotated(bool sfs) 2979void QTReader::setrotated(bool sfs)
2618{ 2980{
2981 qDebug("Rotating");
2619 m_rotated = sfs; 2982 m_rotated = sfs;
2620#ifdef DOUBLEBUFFER 2983 setDoubleBuffer(m_doubleBuffered);
2621 if (m_rotated)
2622 {
2623 dbuff->resize(height(), width());
2624 }
2625 else
2626 {
2627 dbuff->resize(width(), height());
2628 }
2629 m_bgIsScaled = false; 2984 m_bgIsScaled = false;
2630#endif 2985 m_outofdate = true;
2986 /*
2631 int h, w; 2987 int h, w;
2632 if (m_rotated) 2988 if (m_rotated)
2633 { 2989 {
@@ -2648,38 +3004,57 @@ void QTReader::setrotated(bool sfs)
2648 qDebug("Bottom margin:%u", m_bottommargin ); 3004 qDebug("Bottom margin:%u", m_bottommargin );
2649 qDebug("Left margin:%u", m_left_border ); 3005 qDebug("Left margin:%u", m_left_border );
2650 qDebug("Right margin:%u", m_right_border ); 3006 qDebug("Right margin:%u", m_right_border );
3007 */
2651} 3008}
2652 3009
2653void QTReader::drawBackground() 3010void QTReader::drawBackground(QPainter *p)
2654{ 3011{
2655 dbp->begin(dbuff); 3012 // p->setBackgroundMode(OpaqueMode);
2656 // dbp->setBackgroundMode(OpaqueMode); 3013 p->setBackgroundColor(m_bg);
2657 dbp->setBackgroundColor(m_bg); 3014 if (dbuff != NULL)
2658 dbp->eraseRect(dbuff->rect()); 3015 {
3016 p->eraseRect(dbuff->rect());
3017 }
3018 else
3019 {
3020 if (m_rotated)
3021 {
3022 p->eraseRect(0,0,height(),width());
3023 }
3024 else
3025 {
3026 p->eraseRect(rect());
3027 }
3028 }
2659 if (!m_bgpm.isNull()) 3029 if (!m_bgpm.isNull())
2660 { 3030 {
2661 // dbp->setBackgroundMode(TransparentMode); 3031 // p->setBackgroundMode(TransparentMode);
2662 switch (m_bgtype) 3032 switch (m_bgtype)
2663 { 3033 {
2664 case bgCentred: 3034 case bgCentred:
2665 { 3035 {
2666 int w = (dbuff->rect().width()-m_bgpm.width())/2; 3036 if (dbuff == NULL)
2667 int h = (dbuff->rect().height()-m_bgpm.height())/2; 3037 {
2668 dbp->drawPixmap(w,h,m_bgpm); 3038 p->drawPixmap(width(),height(),m_bgpm);
3039 }
3040 else
3041 {
3042 int w = (dbuff->rect().width()-m_bgpm.width())/2;
3043 int h = (dbuff->rect().height()-m_bgpm.height())/2;
3044 p->drawPixmap(w,h,m_bgpm);
3045 }
2669 } 3046 }
2670 break; 3047 break;
2671 case bgTiled: 3048 case bgTiled:
2672 { 3049 {
2673 dbp->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm); 3050 if (dbuff == NULL)
2674 /*
2675 for (int h = 0; h < dbuff->rect().height(); h += m_bgpm.height())
2676 { 3051 {
2677 for (int w = 0; w < dbuff->rect().width(); w += m_bgpm.width()) 3052 p->drawTiledPixmap(0,0,width(),height(),m_bgpm);
2678 { 3053 }
2679 dbp->drawPixmap(w,h,m_bgpm); 3054 else
2680 } 3055 {
3056 p->drawTiledPixmap(0,0,dbuff->rect().width(),dbuff->rect().height(),m_bgpm);
2681 } 3057 }
2682 */
2683 } 3058 }
2684 break; 3059 break;
2685 case bgStretched: 3060 case bgStretched:
@@ -2688,15 +3063,22 @@ void QTReader::drawBackground()
2688 { 3063 {
2689 m_bgIsScaled = true; 3064 m_bgIsScaled = true;
2690 QImage im = m_bgpm.convertToImage(); 3065 QImage im = m_bgpm.convertToImage();
2691 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height())); 3066 if (dbuff == NULL)
3067 {
3068 m_bgpm.convertFromImage(im.smoothScale(width(),height()));
3069 }
3070 else
3071 {
3072 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height()));
3073 }
2692 } 3074 }
2693 dbp->drawPixmap(0,0,m_bgpm); 3075 p->drawPixmap(0,0,m_bgpm);
2694 } 3076 }
2695 break; 3077 break;
2696 default: 3078 default:
2697 qDebug("Unknown background type"); 3079 qDebug("Unknown background type");
2698 } 3080 }
2699 // dbp->setBackgroundMode(OpaqueMode); 3081 // p->setBackgroundMode(OpaqueMode);
2700 } 3082 }
2701} 3083}
2702 3084
@@ -2759,7 +3141,12 @@ void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
2759 3141
2760QString QTReader::about() 3142QString QTReader::about()
2761{ 3143{
2762 return QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka"; 3144 QString ab = QString("QTReader widget (c) Tim Wentford\n")+buffdoc.about() + "\nMini-scrollbar by Markus Gritsch\nNavigation History fixes by Frantisek Dufka";
3145 if (m_output != NULL)
3146 {
3147 ab += QString("\n") + m_output->about();
3148 }
3149 return ab;
2763} 3150}
2764 3151
2765void QTReader::getNextLink() 3152void QTReader::getNextLink()
@@ -2897,7 +3284,7 @@ void QTReader::gotoLink()
2897 ResetScroll(); 3284 ResetScroll();
2898 if (!href.isEmpty()) 3285 if (!href.isEmpty())
2899 { 3286 {
2900 if (!buffdoc.getFile(href)) 3287 if (!buffdoc.getFile(href, nm))
2901 { 3288 {
2902 emit NewFileRequest(href); 3289 emit NewFileRequest(href);
2903 } 3290 }
@@ -2905,6 +3292,7 @@ void QTReader::gotoLink()
2905 { 3292 {
2906 ResetScroll(); 3293 ResetScroll();
2907 fillbuffer(); 3294 fillbuffer();
3295 m_outofdate = true;
2908 update(); 3296 update();
2909 } 3297 }
2910 } 3298 }
@@ -2913,7 +3301,9 @@ void QTReader::gotoLink()
2913 qDebug("QTReader:Finding %s", (const char*)nm); 3301 qDebug("QTReader:Finding %s", (const char*)nm);
2914 if (buffdoc.findanchor(nm)) 3302 if (buffdoc.findanchor(nm))
2915 { 3303 {
3304 buffdoc.resetPos();
2916 fillbuffer(); 3305 fillbuffer();
3306 m_outofdate = true;
2917 update(); 3307 update();
2918 } 3308 }
2919 } 3309 }
@@ -2930,6 +3320,7 @@ void QTReader::gotoLink()
2930 buffdoc.saveposn(m_lastfile, saveposn); 3320 buffdoc.saveposn(m_lastfile, saveposn);
2931 ResetScroll(); 3321 ResetScroll();
2932 fillbuffer(); 3322 fillbuffer();
3323 m_outofdate = true;
2933 update(); 3324 update();
2934 } 3325 }
2935 else 3326 else
@@ -2949,9 +3340,9 @@ void QTReader::gotoLink()
2949 if (!href.isEmpty()) 3340 if (!href.isEmpty())
2950 { 3341 {
2951 emit OnURLSelected(href, tgt); 3342 emit OnURLSelected(href, tgt);
3343 refresh();
2952 } 3344 }
2953 } 3345 }
2954 locate(pagelocate());
2955 } 3346 }
2956 m_currentlinkstyle = NULL; 3347 m_currentlinkstyle = NULL;
2957 m_currentlink = -1; 3348 m_currentlink = -1;
@@ -2960,6 +3351,7 @@ void QTReader::gotoLink()
2960 3351
2961void QTReader::refresh(bool full) 3352void QTReader::refresh(bool full)
2962{ 3353{
3354 qDebug("Refreshing");
2963 int h, w; 3355 int h, w;
2964 if (m_rotated) 3356 if (m_rotated)
2965 { 3357 {
@@ -2981,5 +3373,120 @@ void QTReader::refresh(bool full)
2981 qDebug("Left margin:%u", m_left_border ); 3373 qDebug("Left margin:%u", m_left_border );
2982 qDebug("Right margin:%u", m_right_border ); 3374 qDebug("Right margin:%u", m_right_border );
2983 if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate()); 3375 if (full && m_highlightfilter) m_highlightfilter->refresh(pagelocate());
3376 m_outofdate = true;
2984 locate(pagelocate()); 3377 locate(pagelocate());
2985} 3378}
3379
3380#include "striphtml.h"
3381
3382CFilterChain* QTReader::getfilter()
3383{
3384 CFilterChain * filt = new CFilterChain(getencoding());
3385 if (bstripcr) filt->addfilter(new stripcr);
3386
3387 if (btextfmt || (bautofmt && (PreferredMarkup() == cTEXT))) filt->addfilter(new textfmt);
3388 if (bpeanut || (bautofmt && (PreferredMarkup() == cPML))) filt->addfilter(new PeanutFormatter);
3389 // if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile));
3390
3391#ifdef __STATIC
3392 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new striphtml(m_lastfile));
3393 if (bautofmt && (PreferredMarkup() == cCHM))
3394 {
3395 striphtml* f = new striphtml(m_lastfile);
3396 f->setchm(true);
3397 filt->addfilter(f);
3398 }
3399#else
3400 if (bstriphtml || (bautofmt && (PreferredMarkup() == cHTML))) filt->addfilter(new ExternFilter("HTMLfilter", m_lastfile));
3401 if (bautofmt && (PreferredMarkup() == cCHM))
3402 {
3403 ExternFilter* f = new ExternFilter("HTMLfilter",m_lastfile);
3404 ((striphtml*)f->filter())->setchm(true);
3405 filt->addfilter(f);
3406 }
3407#endif
3408 m_highlightfilter = new HighlightFilter(this);
3409 filt->addfilter(m_highlightfilter);
3410
3411 if (bdehyphen) filt->addfilter(new dehyphen);
3412 if (bunindent) filt->addfilter(new unindent);
3413 if (brepara) filt->addfilter(new repara(m_reparastring));
3414 if (bonespace) filt->addfilter(new OnePara);
3415 if (bindenter) filt->addfilter(new indenter(bindenter));
3416 if (bdblspce) filt->addfilter(new dblspce);
3417 if (bdepluck) filt->addfilter(new DePluck(pluckernextpart));
3418 if (bdejpluck) filt->addfilter(new DePluck(jplucknextpart));
3419 if (brepalm) filt->addfilter(new repalm);
3420 if (bunderlineLink) filt->addfilter(new underlineLink);
3421 if (bkern) filt->addfilter(new kern);
3422 if (bremap) filt->addfilter(new remap);
3423 if (bmakebold) filt->addfilter(new embolden);
3424 if (bfulljust) filt->addfilter(new FullJust);
3425 int r,g,b;
3426 m_default_bg.rgb(&r, &g, &b);
3427 if (r != 255 || g != 255 || b != 255)
3428 filt->addfilter(new setbg(r,g,b));
3429 m_default_fg.rgb(&r, &g, &b);
3430 if (r != 0 || g != 0 || b != 0)
3431 filt->addfilter(new setfg(r,g,b));
3432 // if (bNegative) filt->addfilter(new makeNegative);
3433 if (bInverse) filt->addfilter(new makeInverse);
3434 if (bNoInlineTables) filt->addfilter(new tableLink);
3435 return filt;
3436}
3437
3438void QTReader::readAloud()
3439{
3440#ifdef __STATIC
3441 return;
3442#else
3443 CBuffer para;
3444 jumpto(pagelocate());
3445 while (m_autoScroll && (buffdoc.getpara(para) != -1))
3446 {
3447 if (para.length() > 0)
3448 {
3449 unsigned long lastpos = buffdoc.explocate();
3450 while (lastpos > mylastpos)
3451 {
3452 dopagedn();
3453 qApp->processEvents();
3454 }
3455 jumpto(lastpos);
3456 QString txt = toQString(para.data());
3457
3458 doOutput(txt);
3459 }
3460 qApp->processEvents();
3461 }
3462#endif
3463}
3464
3465bool QTReader::doOutput(const QString& wrd)
3466{
3467 if (m_output != NULL)
3468 {
3469 m_output->output(wrd);
3470 return true;
3471 }
3472 else
3473 {
3474 return false;
3475 }
3476}
3477
3478bool QTReader::checkoutput()
3479{
3480 if (m_output == NULL)
3481 {
3482 m_output = new outputcodec(m_outputName);
3483 if (reinterpret_cast<outputcodec*>(m_output)->getStatus() != 0)
3484 {
3485 delete m_output;
3486 m_output = NULL;
3487 QMessageBox::warning(this, PROGNAME, QString("Couldn't find output codec\n")+m_outputName);
3488 return false;
3489 }
3490 }
3491 return true;
3492}