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.cpp855
1 files changed, 681 insertions, 174 deletions
diff --git a/noncore/apps/opie-reader/QTReader.cpp b/noncore/apps/opie-reader/QTReader.cpp
index 33884a0..0c56dd4 100644
--- a/noncore/apps/opie-reader/QTReader.cpp
+++ b/noncore/apps/opie-reader/QTReader.cpp
@@ -29,32 +29,36 @@ const int _SBARHEIGHT = 3;
29#include <qpe/applnk.h> 29#include <qpe/applnk.h>
30#include <qpe/global.h> 30#include <qpe/global.h>
31#include <qpe/qcopenvelope_qws.h> 31#include <qpe/qcopenvelope_qws.h>
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 };
44//const int QTReader::fontsizes[] = {10,16,17,22,0}; 48//const int QTReader::fontsizes[] = {10,16,17,22,0};
45//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 }; 49//const tchar *QTReader::fonts[] = { "verdana", "Courier", "Times", 0 };
46//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0}; 50//const int QTReader::fontsizes[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,0};
47 51
48tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 }; 52tchar QTReader::pluckernextpart[] = { 'C','l','i','c','k',' ','h','e','r','e',' ','f','o','r',' ','t','h','e',' ','n','e','x','t',' ','p','a','r','t',0 };
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),
58 m_delay(100), 62 m_delay(100),
59 m_scrolldy1(0), 63 m_scrolldy1(0),
60 m_scrolldy2(0), 64 m_scrolldy2(0),
@@ -86,22 +90,18 @@ QTReader::QTReader( QWidget *parent, const char *name, WFlags f) :
86 m_bottommargin(5), 90 m_bottommargin(5),
87 m_reparastring("{\\n[\\n ]}"), 91 m_reparastring("{\\n[\\n ]}"),
88 m_currentlinkstyle(NULL), 92 m_currentlinkstyle(NULL),
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/*
105QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) : 105QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *name=0, WFlags f = 0) :
106 QWidget(parent, name, f), 106 QWidget(parent, name, f),
107 m_textfont(0), 107 m_textfont(0),
@@ -114,13 +114,13 @@ QTReader::QTReader( const QString& filename, QWidget *parent=0, const tchar *nam
114 bdblspce(false), 114 bdblspce(false),
115 btight(false), 115 btight(false),
116 bindenter(0), 116 bindenter(0),
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*/
124 124
125/* 125/*
126void QTReader::mouseMoveEvent(QMouseEvent* _e) 126void QTReader::mouseMoveEvent(QMouseEvent* _e)
@@ -135,13 +135,14 @@ long QTReader::real_delay()
135{ 135{
136 return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing ); 136 return m_scrollstep*( 8976 + m_delay ) / ( m_linespacing * m_linespacing );
137} 137}
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 {
145 x = _e->y(); 146 x = _e->y();
146 y = width()-_e->x(); 147 y = width()-_e->x();
147 ht = width(); 148 ht = width();
@@ -151,12 +152,14 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
151 { 152 {
152 x = _e->x(); 153 x = _e->x();
153 y = _e->y(); 154 y = _e->y();
154 ht = height(); 155 ht = height();
155 wh = width(); 156 wh = width();
156 } 157 }
158 if (x >= m_left_border && x <= wh - m_right_border && y >= m_topmargin && y <= ht-m_bottommargin)
159 {
157 if (_e->button() == RightButton) 160 if (_e->button() == RightButton)
158 { 161 {
159 //qDebug("MousePress"); 162 //qDebug("MousePress");
160 mouseUpOn = false; 163 mouseUpOn = false;
161 if (m_swapmouse) 164 if (m_swapmouse)
162 { 165 {
@@ -165,21 +168,163 @@ void QTReader::mousePressEvent( QMouseEvent* _e )
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);
175 } 178 }
176 else 179 else
180 {
177 processmousepositionevent(_e); 181 processmousepositionevent(_e);
178 } 182 }
179} 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 }
322 }
323 }
324}
180 325
181void QTReader::processmousepositionevent( QMouseEvent* _e ) 326void QTReader::processmousepositionevent( QMouseEvent* _e )
182{ 327{
183 int x, y, ht, wh; 328 int x, y, ht, wh;
184 if (m_rotated) 329 if (m_rotated)
185 { 330 {
@@ -292,13 +437,13 @@ void QTReader::goForward()
292 { 437 {
293 locate(target); 438 locate(target);
294 } 439 }
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)
302 { 447 {
303 lineno = 0; 448 lineno = 0;
304 ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin; 449 ht = textarray[0]->lineSpacing()-m_scrolldy1 + m_topmargin;
@@ -337,13 +482,13 @@ linkType QTReader::getcurrentpos(int x, int y, int w, int h, int& lineno, size_t
337 int i; 482 int i;
338 CDrawBuffer* t = textarray[lineno]; 483 CDrawBuffer* t = textarray[lineno];
339 x = x - t->offset(width(), m_left_border, m_right_border, availht); 484 x = x - t->offset(width(), m_left_border, m_right_border, availht);
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()
347{ 492{
348 buffdoc.suspend(); 493 buffdoc.suspend();
349 /*#ifdef OPIE 494 /*#ifdef OPIE
@@ -351,21 +496,52 @@ void QTReader::suspend()
351#else 496#else
352 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend(); 497 if (memcmp("/usr/mnt.rom/", m_lastfile.latin1(), 13) == 0) buffdoc.suspend();
353#endif 498#endif
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 );
360 m_twotouch = m_touchone = _b; 537 m_twotouch = m_touchone = _b;
361} 538}
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
369void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno) 545void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouseEvent* _e, int lineno)
370{ 546{
371 unsigned long wrdstart, wrdend; 547 unsigned long wrdstart, wrdend;
@@ -452,28 +628,141 @@ void QTReader::processmousewordevent(size_t startpos, size_t startoffset, QMouse
452 if ((*t)[i] == 0) break; 628 if ((*t)[i] == 0) break;
453 first = i; 629 first = i;
454 } 630 }
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);
462 } 638 }
463 else 639 else
464 { 640 {
465 QString line = toQString(textarray[lineno]->data()); 641 QString line = toQString(textarray[lineno]->data());
466 emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line); 642 emit OnWordSelected(wrd, locnarray[lineno], locnarray[lineno]+line.length(), line);
467 } 643 }
468 } 644 }
469} 645}
470 646
647#ifdef USETIMER
648void QTReader::actionDrag()
649{
650 if (m_drageligible)
651 {
652 int fivepages = 5*((2*width()+m_textsize/2)/m_textsize)*((height()+m_textsize/2)/m_textsize);
653 if (m_dragtarget > fivepages && locnarray[numlines] < m_dragtarget - fivepages)
654 {
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 }
686 }
687 else
688 {
689 m_dragtimer->stop();
690 }
691}
692#endif
693
694void QTReader::mouseMoveEvent( QMouseEvent* _e )
695{
696 if (m_drageligible)
697 {
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)
703 {
704 case 1:
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())
743 {
744 m_dragtimer->start(0, false);
745 }
746#else
747 int dp = (sectionsize*mp+ht/2)/ht + buffdoc.startSection();
748 locate(dp);
749#endif
750 }
751 }
752}
753
471void QTReader::mouseReleaseEvent( QMouseEvent* _e ) 754void QTReader::mouseReleaseEvent( QMouseEvent* _e )
472{ 755{
473 buffdoc.unsuspend(); 756 qDebug("Mouse released at (%u, %u)", _e->x(), _e->y());
757 if (m_drageligible)
758 {
759 m_drageligible = false;
760 }
761 else
762 {
474 int x, y, ht, wh; 763 int x, y, ht, wh;
475 if (m_rotated) 764 if (m_rotated)
476 { 765 {
477 x = _e->y(); 766 x = _e->y();
478 y = width()-_e->x(); 767 y = width()-_e->x();
479 ht = width(); 768 ht = width();
@@ -488,12 +777,13 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
488 } 777 }
489 if (_e->button() == LeftButton) 778 if (_e->button() == LeftButton)
490 { 779 {
491 if (mouseUpOn) 780 if (mouseUpOn)
492 { 781 {
493 // qDebug("MouseRelease"); 782 // qDebug("MouseRelease");
783 /*
494 switch(m_scrollpos) 784 switch(m_scrollpos)
495 { 785 {
496 case 1: // Bottom 786 case 1: // Bottom
497 if (y > ht - 5) 787 if (y > ht - 5)
498 { 788 {
499 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh); 789 locate(buffdoc.startSection()+((buffdoc.endSection()-buffdoc.startSection())*x+wh/2)/wh);
@@ -515,34 +805,49 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
515 } 805 }
516 break; 806 break;
517 case 0: 807 case 0:
518 default: 808 default:
519 break; 809 break;
520 } 810 }
811 */
521 if (textarray[0] != NULL) 812 if (textarray[0] != NULL)
522 { 813 {
523 QString line; 814 QString line;
524 // int lineno = _e->y()/m_linespacing; 815 // int lineno = _e->y()/m_linespacing;
525 int lineno = 0; 816 int lineno = 0;
526 /* 817 /*
527 int ht = textarray[0]->lineSpacing(); 818 int ht = textarray[0]->lineSpacing();
528 while ((ht < y) && (lineno < numlines)) 819 while ((ht < y) && (lineno < numlines))
529 { 820 {
530 ht += textarray[++lineno]->lineSpacing(); 821 ht += textarray[++lineno]->lineSpacing();
531 } 822 }
532 */ 823 */
533 size_t startpos, startoffset, tgt, tgtoffset, pictgt; 824 size_t startpos, startoffset, tgt, tgtoffset, pictgt, tabtgt;
534 QImage* img; 825 QImage* img;
535 if (m_currentlinkstyle != NULL) 826 if (m_currentlinkstyle != NULL)
536 { 827 {
537 textarray[m_currentlink]->invertLink(m_currentlinkoffset); 828 textarray[m_currentlink]->invertLink(m_currentlinkoffset);
538 m_currentlinkstyle = NULL; 829 m_currentlinkstyle = NULL;
539 m_currentlink = -1; 830 m_currentlink = -1;
540 m_currentlinkoffset = -1; 831 m_currentlinkoffset = -1;
541 } 832 }
542 linkType glt = getcurrentpos(x, y, wh, ht, lineno, startpos, startoffset, tgt, tgtoffset, pictgt, img); 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());
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 }
543 if ((glt & eLink) != 0) 848 if ((glt & eLink) != 0)
544 { 849 {
545 if ((glt & ePicture) != 0) 850 if ((glt & ePicture) != 0)
546 { 851 {
547 qDebug("Big Picture:%x", pictgt); 852 qDebug("Big Picture:%x", pictgt);
548 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0) 853 if (QMessageBox::warning(this, PROGNAME, "Show picture or goto link?", "Show", "Goto Link") == 0)
@@ -576,29 +881,35 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
576 QCopEnvelope e("QPE/System", "busy()"); 881 QCopEnvelope e("QPE/System", "busy()");
577 } 882 }
578#endif 883#endif
579 ResetScroll(); 884 ResetScroll();
580 if (!href.isEmpty()) 885 if (!href.isEmpty())
581 { 886 {
582 if (!buffdoc.getFile(href)) 887 if (!buffdoc.getFile(href, nm))
583 { 888 {
584 emit NewFileRequest(href); 889 emit NewFileRequest(href);
585 } 890 }
586 else 891 else
587 { 892 {
893 qDebug("BEFORE:%u", pagelocate());
894 buffdoc.resetPos();
588 ResetScroll(); 895 ResetScroll();
589 fillbuffer(); 896 fillbuffer();
897 qDebug("AFTER:%u", pagelocate());
898 m_outofdate = true;
590 update(); 899 update();
591 } 900 }
592 } 901 }
593 if (!nm.isEmpty()) 902 if (!nm.isEmpty())
594 { 903 {
595 qDebug("QTReader:Finding %s", (const char*)nm); 904 qDebug("QTReader:Finding %s", (const char*)nm);
596 if (buffdoc.findanchor(nm)) 905 if (buffdoc.findanchor(nm))
597 { 906 {
907 buffdoc.resetPos();
598 fillbuffer(); 908 fillbuffer();
909 m_outofdate = true;
599 update(); 910 update();
600 } 911 }
601 } 912 }
602 //fillbuffer(); 913 //fillbuffer();
603 //update(); 914 //update();
604#ifdef USEQPE 915#ifdef USEQPE
@@ -609,12 +920,13 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
609 } 920 }
610 else if ((lt & eLink) != 0) 921 else if ((lt & eLink) != 0)
611 { 922 {
612 buffdoc.saveposn(m_lastfile, saveposn); 923 buffdoc.saveposn(m_lastfile, saveposn);
613 ResetScroll(); 924 ResetScroll();
614 fillbuffer(); 925 fillbuffer();
926 m_outofdate = true;
615 update(); 927 update();
616 } 928 }
617 else 929 else
618 { 930 {
619 if ((lt & ePicture) != 0) 931 if ((lt & ePicture) != 0)
620 { 932 {
@@ -630,13 +942,12 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
630 // QString anchortext = textarray[lineno]->getanchortext(startoffset); 942 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
631 if (!href.isEmpty()) 943 if (!href.isEmpty())
632 { 944 {
633 emit OnURLSelected(href, tgt); 945 emit OnURLSelected(href, tgt);
634 } 946 }
635 } 947 }
636 locate(pagelocate());
637 } 948 }
638 return; 949 return;
639 } 950 }
640 else if ((glt & ePicture) != 0) 951 else if ((glt & ePicture) != 0)
641 { 952 {
642 qDebug("Big Picture:%x", pictgt); 953 qDebug("Big Picture:%x", pictgt);
@@ -645,13 +956,13 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
645 { 956 {
646 emit OnShowPicture(*pm); 957 emit OnShowPicture(*pm);
647 delete pm; 958 delete pm;
648 } 959 }
649 else 960 else
650 { 961 {
651 locate(pagelocate()); 962 update();
652 } 963 }
653 return; 964 return;
654 } 965 }
655 else if (img != NULL) 966 else if (img != NULL)
656 { 967 {
657 emit OnShowPicture(*img); 968 emit OnShowPicture(*img);
@@ -666,24 +977,32 @@ void QTReader::mouseReleaseEvent( QMouseEvent* _e )
666 else 977 else
667 { 978 {
668 mouseUpOn = true; 979 mouseUpOn = true;
669 } 980 }
670 } 981 }
671} 982}
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
679void QTReader::focusOutEvent(QFocusEvent* e) 991void QTReader::focusOutEvent(QFocusEvent* e)
680{ 992{
681 if (m_autoScroll) 993 if (m_autoScroll)
682 { 994 {
995 if (m_scrolltype != 4)
996 {
683 timer->stop(); 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}
687 1006
688#include <qapplication.h> 1007#include <qapplication.h>
689#include <qdrawutil.h> 1008#include <qdrawutil.h>
@@ -714,13 +1033,12 @@ void QTReader::goUp()
714 lineUp(); 1033 lineUp();
715 } 1034 }
716} 1035}
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/*
724 size_t target = pagelocate(); 1042 size_t target = pagelocate();
725 if (buffdoc.back(target)) 1043 if (buffdoc.back(target))
726 { 1044 {
@@ -734,13 +1052,12 @@ void QTReader::NavUp()
734 goUp(); 1052 goUp();
735 } 1053 }
736} 1054}
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/*
744 size_t target = pagelocate(); 1061 size_t target = pagelocate();
745 if (buffdoc.forward(target)) 1062 if (buffdoc.forward(target))
746 { 1063 {
@@ -759,27 +1076,25 @@ void QTReader::zoomin()
759{ 1076{
760 if (m_fontControl.increasesize()) 1077 if (m_fontControl.increasesize())
761 { 1078 {
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}
770 1086
771void QTReader::zoomout() 1087void QTReader::zoomout()
772{ 1088{
773 if (m_fontControl.decreasesize()) 1089 if (m_fontControl.decreasesize())
774 { 1090 {
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}
783 1098
784void QTReader::reduceScroll() 1099void QTReader::reduceScroll()
785{ 1100{
@@ -806,13 +1121,12 @@ void QTReader::increaseScroll()
806 m_delay = 454; 1121 m_delay = 454;
807 } 1122 }
808} 1123}
809 1124
810void QTReader::keyPressEvent(QKeyEvent* e) 1125void QTReader::keyPressEvent(QKeyEvent* e)
811{ 1126{
812 buffdoc.unsuspend();
813 1127
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();
817 return; 1131 return;
818#ifdef _SCROLLPIPE 1132#ifdef _SCROLLPIPE
@@ -903,12 +1217,13 @@ void QTReader::CalculateScrollParameters()
903 break; 1217 break;
904 } 1218 }
905} 1219}
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 {
912 m_autoScroll = false; 1227 m_autoScroll = false;
913#ifdef USEQPE 1228#ifdef USEQPE
914 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 1229 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
@@ -924,12 +1239,15 @@ void QTReader::setautoscroll(bool _sc)
924 //refresh(); 1239 //refresh();
925 } 1240 }
926 else 1241 else
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
933#ifdef _SCROLLPIPE 1251#ifdef _SCROLLPIPE
934 if (!m_pipetarget.isEmpty()) 1252 if (!m_pipetarget.isEmpty())
935 { 1253 {
@@ -944,13 +1262,12 @@ void QTReader::setautoscroll(bool _sc)
944#endif 1262#endif
945 } 1263 }
946} 1264}
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)
954 { 1271 {
955 bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht); 1272 bRet = buffdoc.getline(buff ,(m_rotated) ? height() : width(), m_charWidth, m_left_border, m_right_border, availht);
956 } 1273 }
@@ -1062,30 +1379,12 @@ void QTReader::doinplacescroll()
1062 } 1379 }
1063 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); 1380 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);
1064 } 1381 }
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
1089 for (int i = 0; i < numlines; i++) 1388 for (int i = 0; i < numlines; i++)
1090 { 1389 {
1091 if (m_pipeout != NULL) 1390 if (m_pipeout != NULL)
@@ -1096,13 +1395,12 @@ void QTReader::doinplacescroll()
1096 fprintf(m_pipeout, "%s\n", (const char*)outstr); 1395 fprintf(m_pipeout, "%s\n", (const char*)outstr);
1097 fflush(m_pipeout); 1396 fflush(m_pipeout);
1098 } 1397 }
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;
1106#endif 1404#endif
1107 } 1405 }
1108 if (m_scrolldy > ht-textarray[numlines]->lineSpacing()) 1406 if (m_scrolldy > ht-textarray[numlines]->lineSpacing())
@@ -1491,16 +1789,27 @@ void QTReader::redrawScroll(QPainter* p)
1491 } 1789 }
1492 if (m_scrollpos != 0) DrawScroll(p, width(), height()); 1790 if (m_scrollpos != 0) DrawScroll(p, width(), height());
1493} 1791}
1494 1792
1495void QTReader::autoscroll() 1793void QTReader::autoscroll()
1496{ 1794{
1497 drawBackground(); 1795 if (m_scrolltype == 4)
1796 {
1797 readAloud();
1798 }
1799 else
1800 {
1801 if (dbuff != NULL)
1802 {
1803 dbp->begin(dbuff);
1804 drawBackground(dbp);
1498 dbp->end(); 1805 dbp->end();
1806 }
1499 timer->start(real_delay(), false); 1807 timer->start(real_delay(), false);
1500} 1808}
1809}
1501 1810
1502void QTReader::setfont() 1811void QTReader::setfont()
1503{ 1812{
1504// m_fontControl.Change 1813// m_fontControl.Change
1505 m_charWidth = (m_charpc*m_fontControl.currentsize())/100; 1814 m_charWidth = (m_charpc*m_fontControl.currentsize())/100;
1506 if (m_charWidth <= 0) m_charWidth = 1; 1815 if (m_charWidth <= 0) m_charWidth = 1;
@@ -1554,123 +1863,115 @@ void QTReader::DrawStraight(QPainter* p, int w, int h)
1554} 1863}
1555 1864
1556void QTReader::redrawall() 1865void QTReader::redrawall()
1557{ 1866{
1558 if (m_rotated) 1867 if (m_rotated)
1559 { 1868 {
1560#ifdef DOUBLEBUFFER 1869 if (dbuff != NULL)
1561 drawBackground(); 1870 {
1871 dbp->begin(dbuff);
1872 drawBackground(dbp);
1562 DrawStraight(dbp, height(), width()); 1873 DrawStraight(dbp, height(), width());
1563 dbp->end(); 1874 dbp->end();
1564 1875
1565 QWMatrix m; 1876 QWMatrix m;
1566 m.rotate(90); 1877 m.rotate(90);
1567 QPixmap rp = dbuff->xForm(m); 1878 QPixmap rp = dbuff->xForm(m);
1568 bitBlt(this, 0,0,&rp,0,0,-1,-1); 1879 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1569#else 1880 }
1881 else
1882 {
1883 qDebug("This shouldn't happen but it doesn't matter if it does (rotated == double buffered)");
1570 QPixmap dbuff(height(), width()); 1884 QPixmap dbuff(height(), width());
1571 QPainter dbp(&dbuff); 1885 QPainter dbp(&dbuff);
1572 // dbp.setBackgroundMode(OpaqueMode);
1573 dbp.fillRect(dbuff.rect(), m_bg);
1574 1886
1887 drawBackground(&dbp);
1575 DrawStraight(&dbp, height(), width()); 1888 DrawStraight(&dbp, height(), width());
1576 1889
1577 QWMatrix m; 1890 QWMatrix m;
1578 m.rotate(90); 1891 m.rotate(90);
1579 QPixmap rp = dbuff.xForm(m); 1892 QPixmap rp = dbuff.xForm(m);
1580 bitBlt(this, 0,0,&rp,0,0,-1,-1); 1893 bitBlt(this, 0,0,&rp,0,0,-1,-1);
1581#endif 1894 }
1582 } 1895 }
1583 else 1896 else
1584 { 1897 {
1585#ifdef DOUBLEBUFFER 1898 if (dbuff != NULL)
1586 drawBackground(); 1899 {
1900 dbp->begin(dbuff);
1901 drawBackground(dbp);
1587 DrawStraight(dbp, width(), height()); 1902 DrawStraight(dbp, width(), height());
1588 dbp->end(); 1903 dbp->end();
1589 bitBlt(this, 0,0,dbuff,0,0,-1,-1); 1904 bitBlt(this, 0,0,dbuff,0,0,-1,-1);
1590#else 1905 }
1591 DrawStraight(p, width(), height()); 1906 else
1592#endif 1907 {
1908 QPainter p(this);
1909 drawBackground(&p);
1910 DrawStraight(&p, width(), height());
1911 }
1593 } 1912 }
1594} 1913}
1595 1914
1596void QTReader::drawFonts() 1915void QTReader::drawFonts()
1597{ 1916{
1598 if (bDoUpdates) 1917 if (bDoUpdates)
1599 { 1918 {
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())
1604 setfont();
1605 //if (!m_autoScroll) m_scrolldy1 = 0;
1606#ifdef ROTATION_ENABLED
1607 if (m_lastwidth != ((m_rotated) ? height() : width()))
1608 { 1923 {
1609 m_scrolldy = m_topmargin; 1924 if (dbuff != NULL)
1610 // qDebug("Not Optimised %d", m_lastwidth); 1925 {
1611 m_lastwidth = ((m_rotated) ? height() : width()); 1926 dbp->begin(dbuff);
1612 m_lastheight = ((m_rotated) ? width() : height()); 1927 drawBackground(dbp);
1613 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); 1928 dbp->end();
1614 locate(pagelocate());
1615 // qDebug("Not Optimised %d", m_lastwidth);
1616 } 1929 }
1617 else 1930 else
1618 { 1931 {
1619 int newht = ((m_rotated) ? width() : height()); 1932 QPainter p(this);
1620 if (m_lastheight > newht) 1933 drawBackground(&p);
1621 {
1622 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
1623 m_scrolldy = m_topmargin;
1624 int ypos = m_scrolldy1+m_topmargin;
1625 for (int i = 0; i < numlines; i++)
1626 {
1627 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
1628 {
1629 numlines = i;
1630 jumpto(mylastpos = locnarray[i+1]);
1631 break;
1632 }
1633 } 1934 }
1634 // qDebug("Optimised < %d", numlines); 1935 return;
1635 m_lastheight = newht;
1636 } 1936 }
1637 else if (m_lastheight < newht) 1937 setfont();
1938 //if (!m_autoScroll) m_scrolldy1 = 0;
1939 if (dbuff != NULL && (dbuff->width() != width() || dbuff->height() != height()))
1638 { 1940 {
1639 m_scrolldy = m_topmargin; 1941 qDebug("Oh no! A resize event was missed...");
1640 // qDebug("Optimised > %d", numlines); 1942 if (m_rotated)
1641 int ypos = m_scrolldy1+m_topmargin;
1642 for (int i = 0; i <= numlines; i++)
1643 { 1943 {
1644 ypos += textarray[i]->lineSpacing(); 1944 dbuff->resize(height(), width());
1645 }
1646 fillbuffer(numlines+1, ypos, newht);
1647 // qDebug("Optimised > %d", numlines);
1648 } 1945 }
1649 if (numlines > 0) 1946 else
1650 { 1947 {
1651 redrawall(); 1948 dbuff->resize(width(), height());
1652 } 1949 }
1950 m_lastwidth = 0;
1653 } 1951 }
1654#else 1952 if (m_lastwidth != ((m_rotated) ? height() : width()))
1655 if (m_lastwidth != width())
1656 { 1953 {
1954 m_scrolldy = m_topmargin;
1657 // qDebug("Not Optimised %d", m_lastwidth); 1955 // qDebug("Not Optimised %d", m_lastwidth);
1658 m_lastwidth = width(); 1956 m_lastwidth = ((m_rotated) ? height() : width());
1659 m_lastheight = height(); 1957 m_lastheight = ((m_rotated) ? width() : height());
1660 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); 1958 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
1661 locate(pagelocate()); 1959 buffdoc.locate(pagelocate());
1960 fillbuffer();
1961 redrawall();
1662 // qDebug("Not Optimised %d", m_lastwidth); 1962 // qDebug("Not Optimised %d", m_lastwidth);
1663 } 1963 }
1664 else 1964 else
1665 { 1965 {
1666 int newht = height(); 1966 int newht = ((m_rotated) ? width() : height());
1667 if (m_lastheight > newht) 1967 if (m_lastheight > newht)
1668 { 1968 {
1669 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht); 1969 // qDebug("Optimised < %d %d %d", numlines, m_lastheight, newht);
1670 int ypos = m_topmargin; 1970 m_scrolldy = m_topmargin;
1971 int ypos = m_scrolldy1+m_topmargin;
1671 for (int i = 0; i < numlines; i++) 1972 for (int i = 0; i < numlines; i++)
1672 { 1973 {
1673 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin) 1974 if ((ypos += textarray[i]->lineSpacing()) > newht - hmargin)
1674 { 1975 {
1675 numlines = i; 1976 numlines = i;
1676 jumpto(mylastpos = locnarray[i+1]); 1977 jumpto(mylastpos = locnarray[i+1]);
@@ -1679,38 +1980,27 @@ void QTReader::drawFonts()
1679 } 1980 }
1680 // qDebug("Optimised < %d", numlines); 1981 // qDebug("Optimised < %d", numlines);
1681 m_lastheight = newht; 1982 m_lastheight = newht;
1682 } 1983 }
1683 else if (m_lastheight < newht) 1984 else if (m_lastheight < newht)
1684 { 1985 {
1986 m_scrolldy = m_topmargin;
1685 // qDebug("Optimised > %d", numlines); 1987 // qDebug("Optimised > %d", numlines);
1686 int ypos = m_topmargin; 1988 int ypos = m_scrolldy1+m_topmargin;
1687 for (int i = 0; i <= numlines; i++) 1989 for (int i = 0; i <= numlines; i++)
1688 { 1990 {
1689 ypos += textarray[i]->lineSpacing(); 1991 ypos += textarray[i]->lineSpacing();
1690 } 1992 }
1691 fillbuffer(numlines+1, ypos, newht); 1993 fillbuffer(numlines+1, ypos, newht);
1692 // qDebug("Optimised > %d", numlines); 1994 // qDebug("Optimised > %d", numlines);
1693 } 1995 }
1694 if (numlines > 0) 1996 if (numlines > 0)
1695 { 1997 {
1696 int ypos = textarray[0]->ascent()+m_topmargin; 1998 redrawall();
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 } 1999 }
1709 } 2000 }
1710#endif
1711 emitRedraw(); 2001 emitRedraw();
1712 } 2002 }
1713/* 2003/*
1714 else 2004 else
1715 { 2005 {
1716 qDebug("Not so refreshing..."); 2006 qDebug("Not so refreshing...");
@@ -1925,32 +2215,40 @@ bool QTReader::ChangeFont(int tgt)
1925{ 2215{
1926 return m_fontControl.ChangeFont(m_fontname, tgt); 2216 return m_fontControl.ChangeFont(m_fontname, tgt);
1927} 2217}
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}
1941 2234
1942// 2235//
1943// Clean up 2236// Clean up
1944// 2237//
1945QTReader::~QTReader() 2238QTReader::~QTReader()
1946{ 2239{
1947#ifdef DOUBLEBUFFER 2240 if (m_output != NULL)
2241 {
2242 delete m_output;
2243 }
2244 if (dbuff != NULL)
2245 {
1948 delete dbuff; 2246 delete dbuff;
1949 delete dbp; 2247 delete dbp;
1950#endif 2248 }
1951#ifdef USEQPE 2249#ifdef USEQPE
1952 if (m_autoScroll) 2250 if (m_autoScroll)
1953 { 2251 {
1954 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 2252 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
1955 } 2253 }
1956#endif 2254#endif
@@ -1979,16 +2277,54 @@ void QTReader::printIt()
1979} 2277}
1980*/ 2278*/
1981// 2279//
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 )
2284{
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
1986{ 2320{
1987 drawFonts(); 2321 drawFonts();
1988} 2322}
2323 m_outofdate = false;
2324}
1989 2325
1990// 2326//
1991// Called when the widget has been resized. 2327// Called when the widget has been resized.
1992// Moves the button group to the upper right corner 2328// Moves the button group to the upper right corner
1993// of the widget. 2329// of the widget.
1994 2330
@@ -2013,36 +2349,45 @@ int main( int argc, tchar **argv )
2013 draw.show(); 2349 draw.show();
2014 return app.exec(); 2350 return app.exec();
2015} 2351}
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;
2036 // return (height()-m_descent)/(m_linespacing); 2382 // return (height()-m_descent)/(m_linespacing);
2037 return (height()-2)/(m_linespacing); 2383 return (height()-2)/(m_linespacing);
2038}; 2384};
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;
2046 if (buffdoc.empty()) return false; 2391 if (buffdoc.empty()) return false;
2047 if (newht < 0) 2392 if (newht < 0)
2048 m_lastheight = (m_rotated) ? width() : height(); 2393 m_lastheight = (m_rotated) ? width() : height();
@@ -2060,19 +2405,28 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
2060 { 2405 {
2061 textarray[numlines] = new CDrawBuffer(&m_fontControl); 2406 textarray[numlines] = new CDrawBuffer(&m_fontControl);
2062 } 2407 }
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);
2425 else
2426 dopageup(buffdoc.endSection());
2073 return false; 2427 return false;
2074 } 2428 }
2075 else 2429 else
2076 { 2430 {
2077 qDebug("TRUE"); 2431 qDebug("TRUE");
2078 --numlines; 2432 --numlines;
@@ -2098,13 +2452,12 @@ bool QTReader::fillbuffer(int reuse, int ht, int newht)
2098 return true; 2452 return true;
2099} 2453}
2100 2454
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)
2108 { 2461 {
2109 jumpto(mylastpos); 2462 jumpto(mylastpos);
2110 } 2463 }
@@ -2147,26 +2500,27 @@ bool QTReader::synch(size_t start, size_t end)
2147{ 2500{
2148 jumpto(start); 2501 jumpto(start);
2149 while (start++ < end) 2502 while (start++ < 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;
2170 while (1) 2524 while (1)
2171 { 2525 {
2172 // qDebug("Guess:%u", guess); 2526 // qDebug("Guess:%u", guess);
@@ -2177,12 +2531,13 @@ void QTReader::dopageup(unsigned int target)
2177 delta = 0; // 0 is a flag to say don't guess any more 2531 delta = 0; // 0 is a flag to say don't guess any more
2178 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() ); 2532 jumpto( (m_continuousDocument) ? 0 : buffdoc.startSection() );
2179 } 2533 }
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
2186 { 2541 {
2187 delta = guess; 2542 delta = guess;
2188 if (!synch(target-delta, target-lastdelta)) 2543 if (!synch(target-delta, target-lastdelta))
@@ -2290,14 +2645,15 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
2290{ 2645{
2291// QMessageBox::information(this, "Name", name, 1); 2646// QMessageBox::information(this, "Name", name, 1);
2292// QMessageBox::information(this, "load_file", newfile, 1); 2647// QMessageBox::information(this, "load_file", newfile, 1);
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 }
2301 // QMessageBox::information(0, "Opening...", newfile); 2657 // QMessageBox::information(0, "Opening...", newfile);
2302 if (m_rotated) 2658 if (m_rotated)
2303 { 2659 {
@@ -2313,17 +2669,17 @@ bool QTReader::load_file(const char *newfile, unsigned int _lcn)
2313 { 2669 {
2314 m_lastfile = newfile; 2670 m_lastfile = newfile;
2315 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border)); 2671 buffdoc.setwidth(m_lastwidth-(m_left_border+m_right_border));
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
2327void QTReader::lineDown() 2683void QTReader::lineDown()
2328{ 2684{
2329 int ypos = m_topmargin; 2685 int ypos = m_topmargin;
@@ -2355,12 +2711,13 @@ void QTReader::lineDown()
2355 if (textarray[numlines] == NULL) 2711 if (textarray[numlines] == NULL)
2356 { 2712 {
2357 textarray[numlines] = new CDrawBuffer(&m_fontControl); 2713 textarray[numlines] = new CDrawBuffer(&m_fontControl);
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/*
2364void QTReader::lineUp() 2721void QTReader::lineUp()
2365{ 2722{
2366 CBuffer** buff = textarray; 2723 CBuffer** buff = textarray;
@@ -2569,23 +2926,28 @@ MarkupType QTReader::PreferredMarkup()
2569 m = cHTML; 2926 m = cHTML;
2570 } 2927 }
2571 } 2928 }
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{
2935 qDebug("Resizing");
2936 m_outofdate = true;
2937 if (dbuff != NULL)
2938 {
2578 if (m_rotated) 2939 if (m_rotated)
2579 { 2940 {
2580 dbuff->resize(p->size().height(),p->size().width()); 2941 dbuff->resize(p->size().height(),p->size().width());
2581 } 2942 }
2582 else 2943 else
2583 { 2944 {
2584 dbuff->resize(p->size()); 2945 dbuff->resize(p->size());
2585 } 2946 }
2947 }
2586 m_bgIsScaled = false; 2948 m_bgIsScaled = false;
2587 if (m_bgtype == bgStretched) 2949 if (m_bgtype == bgStretched)
2588 { 2950 {
2589 emit RefreshBitmap(); 2951 emit RefreshBitmap();
2590 } 2952 }
2591 2953
@@ -2602,35 +2964,29 @@ void QTReader::resizeEvent( QResizeEvent * p )
2602 h = p->size().height(); 2964 h = p->size().height();
2603 } 2965 }
2604 m_topmargin = (h*m_abstopmargin+500)/1000; 2966 m_topmargin = (h*m_abstopmargin+500)/1000;
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 2970 }
2609 qDebug("Top margin:%u", m_topmargin ); 2971 if (dbuff != NULL && buffdoc.empty())
2610 qDebug("Bottom margin:%u", m_bottommargin ); 2972 {
2611 qDebug("Left margin:%u", m_left_border ); 2973 dbp->begin(dbuff);
2612 qDebug("Right margin:%u", m_right_border ); 2974 drawBackground(dbp);
2975 dbp->end();
2613 } 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 {
2634 h = width(); 2990 h = width();
2635 w = height(); 2991 w = height();
2636 } 2992 }
@@ -2645,61 +3001,87 @@ void QTReader::setrotated(bool sfs)
2645 m_right_border = (w*m_absright_border+500)/1000; 3001 m_right_border = (w*m_absright_border+500)/1000;
2646 3002
2647 qDebug("Top margin:%u", m_topmargin ); 3003 qDebug("Top margin:%u", m_topmargin );
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 {
3036 if (dbuff == NULL)
3037 {
3038 p->drawPixmap(width(),height(),m_bgpm);
3039 }
3040 else
3041 {
2666 int w = (dbuff->rect().width()-m_bgpm.width())/2; 3042 int w = (dbuff->rect().width()-m_bgpm.width())/2;
2667 int h = (dbuff->rect().height()-m_bgpm.height())/2; 3043 int h = (dbuff->rect().height()-m_bgpm.height())/2;
2668 dbp->drawPixmap(w,h,m_bgpm); 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 {
2677 for (int w = 0; w < dbuff->rect().width(); w += m_bgpm.width())
2678 { 3051 {
2679 dbp->drawPixmap(w,h,m_bgpm); 3052 p->drawTiledPixmap(0,0,width(),height(),m_bgpm);
2680 } 3053 }
3054 else
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:
2686 { 3061 {
2687 if (!m_bgIsScaled) 3062 if (!m_bgIsScaled)
2688 { 3063 {
2689 m_bgIsScaled = true; 3064 m_bgIsScaled = true;
2690 QImage im = m_bgpm.convertToImage(); 3065 QImage im = m_bgpm.convertToImage();
3066 if (dbuff == NULL)
3067 {
3068 m_bgpm.convertFromImage(im.smoothScale(width(),height()));
3069 }
3070 else
3071 {
2691 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height())); 3072 m_bgpm.convertFromImage(im.smoothScale(dbuff->rect().width(), dbuff->rect().height()));
2692 } 3073 }
2693 dbp->drawPixmap(0,0,m_bgpm); 3074 }
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
2703void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt) 3085void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
2704{ 3086{
2705 if (txt != NULL) 3087 if (txt != NULL)
@@ -2756,13 +3138,18 @@ void QTReader::blitRot(int dx, int dy, int sw, int sh, CDrawBuffer* txt)
2756 */ 3138 */
2757 bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP); 3139 bitBlt(this, dx, dy, &rp, 0, 0, -1, -1, CopyROP);
2758} 3140}
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()
2766{ 3153{
2767 if (m_scrolldy != 0) 3154 if (m_scrolldy != 0)
2768 { 3155 {
@@ -2894,29 +3281,32 @@ void QTReader::gotoLink()
2894 QCopEnvelope e("QPE/System", "busy()"); 3281 QCopEnvelope e("QPE/System", "busy()");
2895 } 3282 }
2896#endif 3283#endif
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 }
2904 else 3291 else
2905 { 3292 {
2906 ResetScroll(); 3293 ResetScroll();
2907 fillbuffer(); 3294 fillbuffer();
3295 m_outofdate = true;
2908 update(); 3296 update();
2909 } 3297 }
2910 } 3298 }
2911 if (!nm.isEmpty()) 3299 if (!nm.isEmpty())
2912 { 3300 {
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 }
2920 //fillbuffer(); 3310 //fillbuffer();
2921 //update(); 3311 //update();
2922#ifdef USEQPE 3312#ifdef USEQPE
@@ -2927,12 +3317,13 @@ void QTReader::gotoLink()
2927 } 3317 }
2928 else if ((lt & eLink) != 0) 3318 else if ((lt & eLink) != 0)
2929 { 3319 {
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
2936 { 3327 {
2937 if ((lt & ePicture) != 0) 3328 if ((lt & ePicture) != 0)
2938 { 3329 {
@@ -2946,23 +3337,24 @@ void QTReader::gotoLink()
2946 else 3337 else
2947 { 3338 {
2948 // QString anchortext = textarray[lineno]->getanchortext(startoffset); 3339 // QString anchortext = textarray[lineno]->getanchortext(startoffset);
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;
2958 m_currentlinkoffset = -1; 3349 m_currentlinkoffset = -1;
2959} 3350}
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 {
2966 h = width(); 3358 h = width();
2967 w = height(); 3359 w = height();
2968 } 3360 }
@@ -2978,8 +3370,123 @@ void QTReader::refresh(bool full)
2978 3370
2979 qDebug("Top margin:%u", m_topmargin ); 3371 qDebug("Top margin:%u", m_topmargin );
2980 qDebug("Bottom margin:%u", m_bottommargin ); 3372 qDebug("Bottom margin:%u", m_bottommargin );
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}